Skip to content

Commit dc9022e

Browse files
committed
update message publisher with imu
1 parent d00f3e4 commit dc9022e

5 files changed

Lines changed: 26 additions & 15 deletions

File tree

vortex_utility_nodes/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ find_package(nav_msgs REQUIRED)
1010
find_package(vortex_msgs REQUIRED)
1111
find_package(vortex_utils REQUIRED)
1212
find_package(Eigen3 REQUIRED)
13+
find_package(sensor_msgs REQUIRED)
1314

1415
add_executable(message_publisher_node
1516
src/message_publisher.cpp
@@ -22,6 +23,8 @@ ament_target_dependencies(message_publisher_node PUBLIC
2223
Eigen3
2324
vortex_utils
2425
vortex_msgs
26+
sensor_msgs
27+
2528
)
2629

2730
install(TARGETS message_publisher_node
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/**:
22
ros__parameters:
3-
input_type: "reference_filter"
3+
input_type: "odometry"
44
output_namespace: ""
55
topics:
66
odometry: "/nautilus/odom"
77
waypoint: "/nautilus/waypoint"
88
reference_filter: "/nautilus/guidance/dp_quat"
99
pose_stamped: "/nautilus/pose_stamped"
1010
pose_with_covariance_stamped: "/nautilus/pose"
11-
output: "utils/message_publisher"
11+
imu: "mru/imu"
12+
output: "utils/message_publisher/odom_tf_rpy"

vortex_utility_nodes/launch/message_publisher.launch.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ def generate_launch_description():
1414
'message_publisher.yaml',
1515
)
1616

17-
input_type_arg = DeclareLaunchArgument(
18-
'input_type',
19-
default_value='odometry',
20-
description='Input message type: odometry, waypoint, reference_filter, '
21-
'pose_stamped, or pose_with_covariance_stamped',
22-
)
23-
2417
namespace_arg = DeclareLaunchArgument(
2518
'namespace',
2619
default_value='',
@@ -29,17 +22,13 @@ def generate_launch_description():
2922

3023
return LaunchDescription(
3124
[
32-
input_type_arg,
3325
namespace_arg,
3426
Node(
3527
package='vortex_utility_nodes',
3628
executable='message_publisher_node',
3729
name='message_publisher_node',
3830
namespace=LaunchConfiguration('namespace'),
39-
parameters=[
40-
config,
41-
{'input_type': LaunchConfiguration('input_type')},
42-
],
31+
parameters=[config],
4332
output='screen',
4433
),
4534
]

vortex_utility_nodes/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<depend>nav_msgs</depend>
1717
<depend>vortex_msgs</depend>
1818
<depend>vortex_utils</depend>
19+
<depend>sensor_msgs</depend>
1920

2021
<export>
2122
<build_type>ament_cmake</build_type>

vortex_utility_nodes/src/message_publisher.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <sensor_msgs/msg/imu.hpp>
12
#include <vortex/utils/math.hpp>
23
#include "geometry_msgs/msg/pose_stamped.hpp"
34
#include "geometry_msgs/msg/pose_with_covariance_stamped.hpp"
@@ -19,6 +20,7 @@ class MessagePublisherNode : public rclcpp::Node {
1920
this->declare_parameter<std::string>("topics.pose_stamped");
2021
this->declare_parameter<std::string>(
2122
"topics.pose_with_covariance_stamped");
23+
this->declare_parameter<std::string>("topics.imu");
2224
this->declare_parameter<std::string>("topics.output");
2325

2426
auto input_type = this->get_parameter("input_type").as_string();
@@ -86,6 +88,14 @@ class MessagePublisherNode : public rclcpp::Node {
8688
this->get_logger(),
8789
"Euler publisher [pose_with_covariance_stamped]: %s -> %s",
8890
topic.c_str(), output_topic.c_str());
91+
} else if (input_type == "imu") {
92+
auto topic = this->get_parameter("topics.imu").as_string();
93+
sub_ = this->create_subscription<sensor_msgs::msg::Imu>(
94+
topic, qos_profile,
95+
std::bind(&MessagePublisherNode::imu_callback, this,
96+
std::placeholders::_1));
97+
RCLCPP_INFO(this->get_logger(), "Euler publisher [imu]: %s -> %s",
98+
topic.c_str(), output_topic.c_str());
8999

90100
} else {
91101
RCLCPP_FATAL(
@@ -149,13 +159,20 @@ class MessagePublisherNode : public rclcpp::Node {
149159
publish_rpy(msg->header, euler);
150160
}
151161

162+
void imu_callback(const sensor_msgs::msg::Imu::SharedPtr msg) {
163+
const auto& q = msg->orientation;
164+
auto euler = convert_quat(q.w, q.x, q.y, q.z);
165+
publish_rpy(msg->header, euler);
166+
}
167+
152168
using SubVariant = std::variant<
153169
rclcpp::Subscription<nav_msgs::msg::Odometry>::SharedPtr,
154170
rclcpp::Subscription<vortex_msgs::msg::Waypoint>::SharedPtr,
155171
rclcpp::Subscription<vortex_msgs::msg::ReferenceFilterQuat>::SharedPtr,
156172
rclcpp::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr,
157173
rclcpp::Subscription<
158-
geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr>;
174+
geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr,
175+
rclcpp::Subscription<sensor_msgs::msg::Imu>::SharedPtr>;
159176

160177
SubVariant sub_;
161178
rclcpp::Publisher<vortex_msgs::msg::RPY>::SharedPtr rpy_pub_;

0 commit comments

Comments
 (0)