Skip to content

Commit ca0232d

Browse files
committed
fix(demos/ota): subscribe only TwistStamped on /cmd_vel
broken_lidar's reactive-fault path was subscribing to both Twist and TwistStamped on /cmd_vel "to be safe". At runtime that worked, but Foxglove inspects every subscriber when listing topic schemas and emitted: "Multiple channels advertise the same topic /cmd_vel but the schema, schema name or encodings do not match". The mixed-types entry also confused ros2 topic info, which then reported the topic with two type strings. Nav2 Jazzy publishes TwistStamped (docking_server / collision_monitor / velocity_smoother all use the stamped variant). The demo doesn't ship any teleop or legacy publisher; there's no Twist source on this stack. Drop the Twist subscription, keep TwistStamped.
1 parent 6b9e084 commit ca0232d

1 file changed

Lines changed: 13 additions & 19 deletions

File tree

demos/ota_nav2_sensor_fix/ros2_packages/broken_lidar/src/broken_lidar_node.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#include <rclcpp/rclcpp.hpp>
2727
#include <sensor_msgs/msg/laser_scan.hpp>
28-
#include <geometry_msgs/msg/twist.hpp>
2928
#include <geometry_msgs/msg/twist_stamped.hpp>
3029
#include <ros2_medkit_msgs/srv/report_fault.hpp>
3130

@@ -38,24 +37,20 @@ class BrokenLidarNode : public rclcpp::Node {
3837
pub_ = create_publisher<sensor_msgs::msg::LaserScan>("scan", 10);
3938
timer_ = create_wall_timer(100ms, [this]() { publish_scan(); });
4039

41-
// Nav2 Jazzy publishes /cmd_vel as TwistStamped; older stacks (and
42-
// teleop) still use plain Twist. Subscribe to both so the reactive
43-
// fault works regardless of which side is driving.
40+
// Nav2 Jazzy publishes /cmd_vel as TwistStamped. Subscribing to
41+
// both Twist and TwistStamped works at runtime, but Foxglove
42+
// (which inspects subscribers when listing schemas) complains:
43+
// "Multiple channels advertise the same topic /cmd_vel but the
44+
// schema, schema name or encodings do not match". Stick to the
45+
// Nav2 Jazzy default - TwistStamped only.
4446
constexpr double kThresh = 0.01;
45-
auto handle_motion = [this](double linear_x, double angular_z) {
46-
if (std::fabs(linear_x) > kThresh || std::fabs(angular_z) > kThresh) {
47-
last_motion_command_ = now();
48-
}
49-
};
50-
cmd_vel_sub_ = create_subscription<geometry_msgs::msg::Twist>(
47+
cmd_vel_sub_ = create_subscription<geometry_msgs::msg::TwistStamped>(
5148
"cmd_vel", 10,
52-
[handle_motion](const geometry_msgs::msg::Twist::SharedPtr msg) {
53-
handle_motion(msg->linear.x, msg->angular.z);
54-
});
55-
cmd_vel_stamped_sub_ = create_subscription<geometry_msgs::msg::TwistStamped>(
56-
"cmd_vel", 10,
57-
[handle_motion](const geometry_msgs::msg::TwistStamped::SharedPtr msg) {
58-
handle_motion(msg->twist.linear.x, msg->twist.angular.z);
49+
[this](const geometry_msgs::msg::TwistStamped::SharedPtr msg) {
50+
if (std::fabs(msg->twist.linear.x) > kThresh ||
51+
std::fabs(msg->twist.angular.z) > kThresh) {
52+
last_motion_command_ = now();
53+
}
5954
});
6055

6156
fault_client_ = create_client<ros2_medkit_msgs::srv::ReportFault>(
@@ -142,8 +137,7 @@ class BrokenLidarNode : public rclcpp::Node {
142137

143138
rclcpp::Publisher<sensor_msgs::msg::LaserScan>::SharedPtr pub_;
144139
rclcpp::TimerBase::SharedPtr timer_;
145-
rclcpp::Subscription<geometry_msgs::msg::Twist>::SharedPtr cmd_vel_sub_;
146-
rclcpp::Subscription<geometry_msgs::msg::TwistStamped>::SharedPtr cmd_vel_stamped_sub_;
140+
rclcpp::Subscription<geometry_msgs::msg::TwistStamped>::SharedPtr cmd_vel_sub_;
147141
rclcpp::Client<ros2_medkit_msgs::srv::ReportFault>::SharedPtr fault_client_;
148142
rclcpp::TimerBase::SharedPtr fault_timer_;
149143
rclcpp::Time last_motion_command_{0, 0, RCL_ROS_TIME};

0 commit comments

Comments
 (0)