15#ifndef SEMANTIC_COMPONENTS__IMU_SENSOR_HPP_
16#define SEMANTIC_COMPONENTS__IMU_SENSOR_HPP_
23#include "semantic_components/semantic_component_interface.hpp"
24#include "sensor_msgs/msg/imu.hpp"
26namespace semantic_components
31 explicit IMUSensor(
const std::string & name)
33 name, {{name +
"/" +
"orientation.x"},
34 {name +
"/" +
"orientation.y"},
35 {name +
"/" +
"orientation.z"},
36 {name +
"/" +
"orientation.w"},
37 {name +
"/" +
"angular_velocity.x"},
38 {name +
"/" +
"angular_velocity.y"},
39 {name +
"/" +
"angular_velocity.z"},
40 {name +
"/" +
"linear_acceleration.x"},
41 {name +
"/" +
"linear_acceleration.y"},
42 {name +
"/" +
"linear_acceleration.z"}})
53 update_data_from_interfaces();
54 std::array<double, 4> orientation;
55 std::copy(data_.begin(), data_.begin() + 4, orientation.begin());
67 update_data_from_interfaces();
68 std::array<double, 3> angular_velocity;
69 std::copy(data_.begin() + 4, data_.begin() + 7, angular_velocity.begin());
70 return angular_velocity;
81 update_data_from_interfaces();
82 std::array<double, 3> linear_acceleration;
83 std::copy(data_.begin() + 7, data_.end(), linear_acceleration.begin());
84 return linear_acceleration;
94 update_data_from_interfaces();
95 message.orientation.x = data_[0];
96 message.orientation.y = data_[1];
97 message.orientation.z = data_[2];
98 message.orientation.w = data_[3];
100 message.angular_velocity.x = data_[4];
101 message.angular_velocity.y = data_[5];
102 message.angular_velocity.z = data_[6];
104 message.linear_acceleration.x = data_[7];
105 message.linear_acceleration.y = data_[8];
106 message.linear_acceleration.z = data_[9];
118 void update_data_from_interfaces()
const
120 for (
auto i = 0u; i < data_.size(); ++i)
122 const auto data = state_interfaces_[i].get().get_optional();
123 if (data.has_value())
125 data_[i] = data.value();
131 mutable std::array<double, 10> data_{{0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}};
Definition imu_sensor.hpp:29
std::array< double, 3 > get_linear_acceleration() const
Return linear acceleration.
Definition imu_sensor.hpp:79
bool get_values_as_message(sensor_msgs::msg::Imu &message) const
Return Imu message with orientation, angular velocity and linear acceleration.
Definition imu_sensor.hpp:92
std::array< double, 4 > get_orientation() const
Return orientation.
Definition imu_sensor.hpp:51
std::array< double, 3 > get_angular_velocity() const
Return angular velocity.
Definition imu_sensor.hpp:65
Definition semantic_component_interface.hpp:28