ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Don't see scan message on Rviz even though it's published [closed]

asked 2022-03-04 12:41:51 -0500

nigeno gravatar image

updated 2022-03-04 12:42:56 -0500

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.

Running

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
{
public:
    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());                            
    }

private:
    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;
        publisher_->publish(laser);

    }

    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>();
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by nigeno
close date 2022-03-25 15:35:50.689709

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-03-07 14:54:08 -0500

nigeno gravatar image

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

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-03-04 12:41:51 -0500

Seen: 276 times

Last updated: Mar 07 '22