Can't get kobuki's laser scan at ROS basics in 5 days first assignment

Hi guys,

Any tips on getting the read from /kobuki/laser/scan topic on the first assignment of ROS basics in 5 days (follow the wall)?
My code is a simple copy-paste from here: How to read LaserScan data (ROS python) | The Construct
and it is just to be able to get the values as I didn’t succeed in my full code and decided to try to overcome that problem solely.
The topic is also listed when using rostopic list.
When I launch using roslaunch nothing happens and using echo doesn’t work either.

image

And the code:

#! /usr/bin/env python

import rospy

from sensor_msgs.msg import LaserScan

def callback(msg):

print(len(msg.ranges))

rospy.init_node(‘scan_values’)

sub = rospy.Subscriber(’/kobuki/laser/scan’, LaserScan, callback)

rospy.spin()

Can you guys please help me with that?

Thanks,

Hi, welcome to the community!

That is indeed strange that rostopic list shows the topic. Are you sure that the simulation is running? You can try to see if you catch more than one message by removing -n1 from the command.

You can also make sure that you haven’t paused the simulation by mistake by restarting the simulation with the reset button on the top right corner of the simulation window.

The simulation is running for sure, I enter the rosject, opens a shell and run it with: roslaunch realrobotlab main.launch
When the Gazebo window is ready with the simulation, I launch the code that is written above.
Trying rostopic echo /kobuki/laser/scan without -n1 also does not work.
I saw while googeling that there is also a topic that is called /scan and I can get the values from it.
I can also publish velocities and move the robot around the simulation. It’s just that kobuki/laser/scan that does not work…

I think I found something that might help, I noticed that when I try rostopic info /kobuki/laser/scan
I can see that my ‘topics_quiz_node’ is subscribed to it, but no node publishes it.
In a video I found online I noticed that the publishing node should be ‘gazebo’, and the gazebo node is up and running (I check that through rosnode list).

Any solution to that?

Only until now I realize that you are talking about the project. I apologize about this. Yes, you are correct, there is no /kobuki/laser/scan topic, the one you want is /scan. Almost no simulations will share the same topic names.

Gazebo is publishing a scan reading IF there is a lidar in the simulated robot, and it can be named anything. You have to be able to identify it and use it.

When using /scan, msg.ranges is a list of length 180 instead of 720.
Is there a way of knowing which index gives me the distance in front of the robot and to the right side of it?

Yes, you can put the robot right in front of the wall and see which are the smallest values