ros2_control - humble
Loading...
Searching...
No Matches
pose_sensor.hpp
1// Copyright 2024 FZI Forschungszentrum Informatik
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#ifndef SEMANTIC_COMPONENTS__POSE_SENSOR_HPP_
15#define SEMANTIC_COMPONENTS__POSE_SENSOR_HPP_
16
17#include <array>
18#include <limits>
19#include <string>
20
21#include "geometry_msgs/msg/pose.hpp"
22#include "semantic_components/semantic_component_interface.hpp"
23
24namespace semantic_components
25{
26
27class PoseSensor : public SemanticComponentInterface<geometry_msgs::msg::Pose>
28{
29public:
31 explicit PoseSensor(const std::string & name) : SemanticComponentInterface{name, 7}
32 {
33 // Use standard interface names
34 interface_names_.emplace_back(name_ + '/' + "position.x");
35 interface_names_.emplace_back(name_ + '/' + "position.y");
36 interface_names_.emplace_back(name_ + '/' + "position.z");
37 interface_names_.emplace_back(name_ + '/' + "orientation.x");
38 interface_names_.emplace_back(name_ + '/' + "orientation.y");
39 interface_names_.emplace_back(name_ + '/' + "orientation.z");
40 interface_names_.emplace_back(name_ + '/' + "orientation.w");
41
42 // Set all sensor values to default value NaN
43 std::fill(position_.begin(), position_.end(), std::numeric_limits<double>::quiet_NaN());
44 std::fill(orientation_.begin(), orientation_.end(), std::numeric_limits<double>::quiet_NaN());
45 }
46
47 virtual ~PoseSensor() = default;
48
50
55 std::array<double, 3> get_position()
56 {
57 for (size_t i = 0; i < 3; ++i)
58 {
59 position_[i] = state_interfaces_[i].get().get_value();
60 }
61
62 return position_;
63 }
64
66
71 std::array<double, 4> get_orientation()
72 {
73 for (size_t i = 3; i < 7; ++i)
74 {
75 orientation_[i - 3] = state_interfaces_[i].get().get_value();
76 }
77
78 return orientation_;
79 }
80
82
85 bool get_values_as_message(geometry_msgs::msg::Pose & message)
86 {
87 // Update state from state interfaces
90
91 // Set message values from current state
92 message.position.x = position_[0];
93 message.position.y = position_[1];
94 message.position.z = position_[2];
95 message.orientation.x = orientation_[0];
96 message.orientation.y = orientation_[1];
97 message.orientation.z = orientation_[2];
98 message.orientation.w = orientation_[3];
99
100 return true;
101 }
102
103protected:
104 std::array<double, 3> position_;
105 std::array<double, 4> orientation_;
106};
107
108} // namespace semantic_components
109
110#endif // SEMANTIC_COMPONENTS__POSE_SENSOR_HPP_
Definition pose_sensor.hpp:28
bool get_values_as_message(geometry_msgs::msg::Pose &message)
Fill pose message with current values.
Definition pose_sensor.hpp:85
std::array< double, 4 > get_orientation()
Update and return orientation.
Definition pose_sensor.hpp:71
PoseSensor(const std::string &name)
Constructor for a standard pose sensor with interface names set based on sensor name.
Definition pose_sensor.hpp:31
std::array< double, 3 > get_position()
Update and return position.
Definition pose_sensor.hpp:55
Definition semantic_component_interface.hpp:28