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

add XBow AHRS ROS2 plugin #41

Merged
merged 7 commits into from
May 14, 2022
Merged

Conversation

andermi
Copy link
Collaborator

@andermi andermi commented May 12, 2022

addresses part of #30

  • @andermi Add XBRecord data to ECM from plugin or use sensor
  • @andermi Publish XBRecord data from ECM in CrossbowController ROS2 System Plugin

passes colcon test

@andermi andermi changed the base branch from main to andermi/spring_controller May 12, 2022 19:22
@andermi andermi linked an issue May 12, 2022 that may be closed by this pull request
Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏽

xb_record_.imu.angular_velocity.z = _imu.angular_velocity().z();
xb_record_.imu.linear_acceleration.x = _imu.linear_acceleration().x();
xb_record_.imu.linear_acceleration.y = _imu.linear_acceleration().y();
xb_record_.imu.linear_acceleration.z = _imu.linear_acceleration().z();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some helper functions to do these conversions in ros_ign_bridge. I was curious to see whether it would be usable here and it worked like this:

diff

diff --git a/buoy_gazebo/CMakeLists.txt b/buoy_gazebo/CMakeLists.txt
index 3af2b97..052cebc 100644
--- a/buoy_gazebo/CMakeLists.txt
+++ b/buoy_gazebo/CMakeLists.txt
@@ -3,6 +3,7 @@ project(buoy_gazebo)
 
 find_package(ament_cmake REQUIRED)
 find_package(rclcpp REQUIRED)
+find_package(ros_ign_bridge REQUIRED)
 find_package(buoy_msgs REQUIRED)
 
 find_package(ignition-cmake2 REQUIRED)
@@ -57,7 +58,7 @@ function(gz_add_plugin plugin_name)
       ${gz_add_plugin_PRIVATE_LINK_LIBS}
   )
   if(gz_add_plugin_ROS)
-    ament_target_dependencies(${plugin_name} PUBLIC rclcpp buoy_msgs)
+    ament_target_dependencies(${plugin_name} PUBLIC rclcpp ros_ign_bridge buoy_msgs)
   endif()
   target_include_directories(${plugin_name}
       PUBLIC ${gz_add_plugin_INCLUDE_DIRS})
diff --git a/buoy_gazebo/package.xml b/buoy_gazebo/package.xml
index 05fe4dd..be544da 100644
--- a/buoy_gazebo/package.xml
+++ b/buoy_gazebo/package.xml
@@ -14,6 +14,7 @@
   <depend>buoy_examples</depend>
   <depend>buoy_msgs</depend>
   <depend>ignition-gazebo6</depend>
+  <depend>ros_ign_bridge</depend>
   <depend>ros_ign_gazebo</depend>
 
   <test_depend>ament_lint_auto</test_depend>
diff --git a/buoy_gazebo/src/controllers/XBowAHRS/XBowAHRS.cpp b/buoy_gazebo/src/controllers/XBowAHRS/XBowAHRS.cpp
index 9f8172e..8b03206 100644
--- a/buoy_gazebo/src/controllers/XBowAHRS/XBowAHRS.cpp
+++ b/buoy_gazebo/src/controllers/XBowAHRS/XBowAHRS.cpp
@@ -23,6 +23,7 @@
 #include <ignition/transport/Node.hh>
 
 #include <rclcpp/rclcpp.hpp>
+#include <ros_ign_bridge/convert/sensor_msgs.hpp>
 
 #include <buoy_msgs/msg/xb_record.hpp>
 #include <sensor_msgs/msg/imu.hpp>
@@ -57,16 +58,7 @@ struct buoy_gazebo::XBowAHRSPrivate
     xb_record_.header.stamp.nanosec = _imu.header().stamp().nsec();
     xb_record_.header.frame_id = "Buoy";
     xb_record_.imu.header = xb_record_.header;
-    xb_record_.imu.orientation.x = _imu.orientation().x();
-    xb_record_.imu.orientation.y = _imu.orientation().y();
-    xb_record_.imu.orientation.z = _imu.orientation().z();
-    xb_record_.imu.orientation.w = _imu.orientation().w();
-    xb_record_.imu.angular_velocity.x = _imu.angular_velocity().x();
-    xb_record_.imu.angular_velocity.y = _imu.angular_velocity().y();
-    xb_record_.imu.angular_velocity.z = _imu.angular_velocity().z();
-    xb_record_.imu.linear_acceleration.x = _imu.linear_acceleration().x();
-    xb_record_.imu.linear_acceleration.y = _imu.linear_acceleration().y();
-    xb_record_.imu.linear_acceleration.z = _imu.linear_acceleration().z();
+    ros_ign_bridge::convert_ign_to_ros(_imu, xb_record_.imu);
   }
 
   bool data_valid() const

I don't think it's necessarily worth the added dependency, but it's something to keep in mind for future messages.

@andermi andermi merged commit 8533c87 into andermi/spring_controller May 14, 2022
@andermi andermi deleted the andermi/ahrs_ros2 branch May 14, 2022 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Aggregate data in ECM and use system to publish to ROS 2
2 participants