ros2_control - jazzy
Loading...
Searching...
No Matches
range_sensor.hpp
1// Copyright 2023 flochre
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef SEMANTIC_COMPONENTS__RANGE_SENSOR_HPP_
16#define SEMANTIC_COMPONENTS__RANGE_SENSOR_HPP_
17
18#include <limits>
19#include <string>
20#include <vector>
21
22#include "semantic_components/semantic_component_interface.hpp"
23#include "sensor_msgs/msg/range.hpp"
24
25namespace semantic_components
26{
27class RangeSensor : public SemanticComponentInterface<sensor_msgs::msg::Range>
28{
29public:
30 explicit RangeSensor(const std::string & name)
31 : SemanticComponentInterface(name, {name + "/" + "range"})
32 {
33 }
39 float get_range() const
40 {
41 const auto data = state_interfaces_[0].get().get_optional();
42 if (data.has_value())
43 {
44 return data.value();
45 }
46 return std::numeric_limits<float>::quiet_NaN();
47 }
48
50
54 bool get_values_as_message(sensor_msgs::msg::Range & message) const
55 {
56 message.range = get_range();
57 return true;
58 }
59};
60
61} // namespace semantic_components
62
63#endif // SEMANTIC_COMPONENTS__RANGE_SENSOR_HPP_
Definition range_sensor.hpp:28
bool get_values_as_message(sensor_msgs::msg::Range &message) const
Return Range message with range in meters.
Definition range_sensor.hpp:54
float get_range() const
Definition range_sensor.hpp:39
Definition semantic_component_interface.hpp:28