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

hokuyo subscriber callback delay??

asked 2019-04-23 08:01:31 -0500

Gspark gravatar image

updated 2019-04-23 09:15:19 -0500

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;
}
edit retag flag offensive close merge delete

Comments

2

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.

gvdhoorn gravatar image gvdhoorn  ( 2019-04-23 08:23:34 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-04-23 08:26:01 -0500

gvdhoorn gravatar image

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).

edit flag offensive delete link more

Comments

@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?

Gspark gravatar image Gspark  ( 2019-04-23 10:18:00 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-04-23 08:01:31 -0500

Seen: 236 times

Last updated: Apr 23 '19