Rosanswers logo

I'm trying to solve this puzzle. It seems to be simple but it doesn't work.

So, the OdomNode is subscribed to the original LaserScan message on /sick_lrs_36x1/scan topic. It receives the message and call LaserScan publisher to publish the message on /scan topic. A customized message is published with a new frame_id and with now timestamp.

The original scan message is getting played using the bag tool.


ros2 topic echo /sick_lrs_36x1/scan

seems to give exact message as

ros2 topic echo /scan message

Interestingly, I can observe the /sick_lrs_36x1/scan in rviz, but cannot see the customized message.

Below is my code:

class OdomNode : public rclcpp::Node
    OdomNode() : Node("odom")
        scan_ = this->create_subscription<sensor_msgs::msg::LaserScan>("/sick_lrs_36x1/scan", rclcpp::SensorDataQoS(),
                                    std::bind(&OdomNode::callbackPose, this, std::placeholders::_1));
        publisher_ = this->create_publisher<sensor_msgs::msg::LaserScan>("scan", rclcpp::SensorDataQoS());                            

    void callbackPose(const sensor_msgs::msg::LaserScan::SharedPtr msg)

        now = this->get_clock()->now();

        sensor_msgs::msg::LaserScan laser;
        laser.header.frame_id = "cloud";
        laser.header.stamp = now;
        laser.angle_min = msg->angle_min;
        laser.angle_max = msg->angle_max;
        laser.angle_increment = msg->angle_increment;
        laser.scan_time = msg->scan_time;
        laser.time_increment = msg->time_increment;
        laser.range_min = msg->range_min;
        laser.range_max = msg->range_max;
        laser.ranges = msg->ranges;


    rclcpp::Time now;
    rclcpp::Subscription<sensor_msgs::msg::LaserScan>::SharedPtr scan_;
    rclcpp::Publisher<sensor_msgs::msg::LaserScan>::SharedPtr publisher_;
    rclcpp::TimerBase::SharedPtr transform_timer_;

int main(int argc, char **argv)
    rclcpp::init(argc, argv);
    auto node = std::make_shared<OdomNode>();
    return 0;

Originally posted by nigeno on ROS Answers with karma: 76 on 2022-03-04

Post score: 0


1 Answer 1


Rosanswers logo

I figured. You need to set the Reliability Policy of the LaserScan topic in Rviz to Best Effort or System Default

Originally posted by nigeno with karma: 76 on 2022-03-07

This answer was ACCEPTED on the original site

Post score: 0


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.