Importing Sonar library instead of LaserScan

So, this question is a little primitive I guess but I don’t completely understand how does this work.

So for the code that I found, it is importing the LaserScan messages in the beginning of the code and not mentioning the messages ever again, so are these messages being used?
How can I replace this with sonar messages instead? I am not sure the name is clear with

I am not sure what’s the name for it?

One more thing, would that even work?

Can you offer more details?
‘for the code that I found’ Is this our code in our repositories ? If so link please.

Normally there is an include or two at the start of a file which by itself does nothing and is there so ‘real code’ can reference message types later.

Then in starting the node there will be a line to setup a ROS subscriber to a specific topic name and that line will specify the message type expected in that topic. That line will also specify a ‘callback’ routine. Later as the code runs whenever ROS sees a message on the topic it will do a callback to the callback you specified when registering the subscriber.

So you don’t see later in the code the message being directly handled, you go to that callback function that handles that message type on the topic being subscribed and there the user does what he wants with the contents with the message so his node can use that callback data.

Your next question about 'replace LaserScan messages with Sonar messages depends on what you want to do. The LaserScan message has an array of 360 ranges so lets say you only want to see straight ahead, 45deg to right, 45deg to left, full right and full left. If that is the case you can subscribe to the /sonars topic and pull off the 5 sonar ranges.

Examples of use of sonars topic to get ranges from sonars:
For C++ see our new sonar_detector node I did a couple weeks back.
For Python sonar subscriptions that is not in our default top level ‘demos’ repository yet.
you can go into your catkin_ws/src/demos folder and first use ‘git pull’ then use ‘git checkout SonarWanderer’ and see demos/sonar_wanderer node which I did a week or so ago.

If this did not help then I really don’t understand what you want to do or perhaps I don’t know just what code you found in some other example for some other ROS robot.

2 Likes

As of now the example to see how to read sonars, sonar_wanderer is now a demo in our master branch of our demos repository.

2 Likes

Please provide a link or instructions for locating the master branch of our demos repository.

The ubiquity robotics github repositories are all here: https://github.com/UbiquityRobotics

The demos repository is https://github.com/UbiquityRobotics/demos

1 Like