0
$\begingroup$

Rosanswers logo

Hi! I am trying to subscribe to a laser scan of the hokuyo_node. (UTM-30LX)
I have checked that the rostopic(/scan) satisfied 40Hz.
$rostopic hz /scan

However, msg(/scan) callback is not satisfied 40Hz. (0.025sec)
Can I subscribe a rostopic(/scan) with 40Hz?

[ INFO] [1556028820.890011693]: 231]Laser 1.112000 0.117000 0.486000
[ INFO] [1556028820.890147465]: 232]Laser 1.113000 0.119000 0.485000
[ INFO] [1556028820.933906513]: 233]Laser 1.118000 0.120000 0.488000
[ INFO] [1556028820.934033465]: 234]Laser 1.114000 0.128000 0.486000
[ INFO] [1556028820.977954391]: 235]Laser 1.112000 0.109000 0.488000
[ INFO] [1556028820.978087813]: 236]Laser 1.112000 0.117000 0.493000
[ INFO] [1556028821.021961768]: 237]Laser 1.113000 0.110000 0.492000
[ INFO] [1556028821.027527888]: 238]Laser 1.116000 0.116000 0.487000
[ INFO] [1556028821.070109309]: 239]Laser 1.113000 0.128000 0.486000

I using a source code below.

#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>
void laserCallback(const sensor_msgs::LaserScan::ConstPtr & scan)
{
    ROS_INFO("%d]Laser %f %f %f", scan->header.seq, scan->ranges[0], scan->ranges[360], scan->ranges[719]);
}
int main(int argc, char **argv)
{
    ros::init(argc, argv, "laser_scan");
    ros::NodeHandle nh;

    ros::Subscriber scan_sub = nh.subscribe("/scan", 1000, laserCallback);
    ros::spin();
    return 0;
}

Originally posted by Gspark on ROS Answers with karma: 33 on 2019-04-23

Post score: 0


Original comments

Comment by gvdhoorn on 2019-04-23:
Please do not post screenshots of terminals, there is no need. It's all text, so copy-paste the console text into your question. Then use the Preformatted Text button (the one with 101010 on it) to properly format it.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I'm slightly confused by your statements, but if you mean that rostopic hz .. prints that the topic is publishing at 40 Hz but your callback doesn't appear to be receiving messages at 40 Hz, then you might want to look into setting the tcpNoDelay transport hint (docs).


Originally posted by gvdhoorn with karma: 86574 on 2019-04-23

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by Gspark on 2019-04-23:
@gvdhoorn Correct! I prints that the topic is publishing at 40 Hz but callback didn't appear to be receiving messages at 40 Hz. It was solved with your advice. thank you.

ros::Subscriber sub = nh.subscribe("/scan", 1000, laserCallback, ros::TransportHints().tcpNoDelay());

ps. How I select your comment for best answer?

$\endgroup$

Your Answer

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