Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

populate imu covariances when converting #375

Merged
merged 8 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions ros_gz_bridge/src/convert/sensor_msgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,16 @@ convert_ros_to_gz(
convert_ros_to_gz(ros_msg.orientation, (*gz_msg.mutable_orientation()));
convert_ros_to_gz(ros_msg.angular_velocity, (*gz_msg.mutable_angular_velocity()));
convert_ros_to_gz(ros_msg.linear_acceleration, (*gz_msg.mutable_linear_acceleration()));

for (const auto & elem : ros_msg.linear_acceleration_covariance){
gz_msg.mutable_linear_acceleration_covariance()->add_data(elem);
}
for (const auto & elem : ros_msg.orientation_covariance){
gz_msg.mutable_orientation_covariance()->add_data(elem);
}
for (const auto & elem : ros_msg.angular_velocity_covariance){
gz_msg.mutable_angular_velocity_covariance()->add_data(elem);
}
}

template<>
Expand All @@ -288,6 +298,30 @@ convert_gz_to_ros(
convert_gz_to_ros(gz_msg.linear_acceleration(), ros_msg.linear_acceleration);

// Covariances not supported in gz::msgs::IMU
int data_size = gz_msg.linear_acceleration_covariance().data_size();
if (data_size == 9)
mjcarroll marked this conversation as resolved.
Show resolved Hide resolved
{
for (int i = 0; i < data_size; ++i) {
auto data = gz_msg.linear_acceleration_covariance().data()[i];
ros_msg.linear_acceleration_covariance[i] = data;
}
}
data_size = gz_msg.angular_velocity_covariance().data_size();
if (data_size == 9)
{
for (int i = 0; i < data_size; ++i) {
auto data = gz_msg.angular_velocity_covariance().data()[i];
ros_msg.angular_velocity_covariance[i] = data;
}
}
data_size = gz_msg.orientation_covariance().data_size();
if (data_size == 9)
{
for (int i = 0; i < data_size; ++i) {
auto data = gz_msg.orientation_covariance().data()[i];
ros_msg.orientation_covariance[i] = data;
}
}
}

template<>
Expand Down
10 changes: 10 additions & 0 deletions ros_gz_bridge/test/utils/gz_test_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,11 @@ void createTestMsg(gz::msgs::IMU & _msg)
_msg.mutable_orientation()->CopyFrom(quaternion_msg);
_msg.mutable_angular_velocity()->CopyFrom(vector3_msg);
_msg.mutable_linear_acceleration()->CopyFrom(vector3_msg);
for (int i = 0; i < 9; i++) {
_msg.mutable_orientation_covariance()->add_data(i);
_msg.mutable_angular_velocity_covariance()->add_data(i);
_msg.mutable_linear_acceleration_covariance()->add_data(i);
}
}

void compareTestMsg(const std::shared_ptr<gz::msgs::IMU> & _msg)
Expand All @@ -765,6 +770,11 @@ void compareTestMsg(const std::shared_ptr<gz::msgs::IMU> & _msg)
compareTestMsg(std::make_shared<gz::msgs::Quaternion>(_msg->orientation()));
compareTestMsg(std::make_shared<gz::msgs::Vector3d>(_msg->angular_velocity()));
compareTestMsg(std::make_shared<gz::msgs::Vector3d>(_msg->linear_acceleration()));
for (int i = 0; i < 9; i++) {
EXPECT_EQ(_msg->orientation_covariance().data(i), i);
EXPECT_EQ(_msg->angular_velocity_covariance().data(i), i);
EXPECT_EQ(_msg->linear_acceleration_covariance().data(i), i);
}
}

void createTestMsg(gz::msgs::Axis & _msg)
Expand Down
9 changes: 9 additions & 0 deletions ros_gz_bridge/test/utils/ros_test_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,9 @@ void createTestMsg(sensor_msgs::msg::Imu & _msg)
_msg.orientation = quaternion_msg;
_msg.angular_velocity = vector3_msg;
_msg.linear_acceleration = vector3_msg;
_msg.orientation_covariance = {1, 2, 3, 4, 5, 6, 7, 8, 9};
_msg.angular_velocity_covariance = {1, 2, 3, 4, 5, 6, 7, 8, 9};
_msg.linear_acceleration_covariance = {1, 2, 3, 4, 5, 6, 7, 8, 9};
}

void compareTestMsg(const std::shared_ptr<sensor_msgs::msg::Imu> & _msg)
Expand All @@ -956,6 +959,12 @@ void compareTestMsg(const std::shared_ptr<sensor_msgs::msg::Imu> & _msg)
compareTestMsg(_msg->orientation);
compareTestMsg(std::make_shared<geometry_msgs::msg::Vector3>(_msg->angular_velocity));
compareTestMsg(std::make_shared<geometry_msgs::msg::Vector3>(_msg->linear_acceleration));

for (int i = 1; i < 10; ++i){
mjcarroll marked this conversation as resolved.
Show resolved Hide resolved
EXPECT_EQ(_msg->orientation_covariance[i], i);
EXPECT_EQ(_msg->angular_velocity_covariance[i], i);
EXPECT_EQ(_msg->linear_acceleration_covariance[i], i);
}
}

void createTestMsg(sensor_msgs::msg::JointState & _msg)
Expand Down