# Importing Sonar library instead of LaserScan

**URL:** <https://forum.ubiquityrobotics.com/t/importing-sonar-library-instead-of-laserscan/803>\
**Category:** Uncategorized\
**Created:** [April 19, 2021, 8:52pm UTC](https://forum.ubiquityrobotics.com/t/importing-sonar-library-instead-of-laserscan/803 "2021-04-19T20:52:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![IngeniousDoc](https://forum.ubiquityrobotics.com/letter_avatar_proxy/v4/letter/i/94ad74/32.png) [@IngeniousDoc](https://forum.ubiquityrobotics.com/u/IngeniousDoc)\
**Post date:** [April 19, 2021, 8:52pm UTC](https://forum.ubiquityrobotics.com/t/importing-sonar-library-instead-of-laserscan/803/1 "2021-04-19T20:52:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mjstn2011](https://forum.ubiquityrobotics.com/user_avatar/forum.ubiquityrobotics.com/mjstn2011/32/30_2.png) [@mjstn2011](https://forum.ubiquityrobotics.com/u/mjstn2011)\
**Post date:** [April 20, 2021, 1:12am UTC](https://forum.ubiquityrobotics.com/t/importing-sonar-library-instead-of-laserscan/803/2 "2021-04-20T01:12:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mjstn2011](https://forum.ubiquityrobotics.com/user_avatar/forum.ubiquityrobotics.com/mjstn2011/32/30_2.png) [@mjstn2011](https://forum.ubiquityrobotics.com/u/mjstn2011)\
**Post date:** [April 20, 2021, 9:00pm UTC](https://forum.ubiquityrobotics.com/t/importing-sonar-library-instead-of-laserscan/803/3 "2021-04-20T21:00:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![EdSeymore](https://forum.ubiquityrobotics.com/letter_avatar_proxy/v4/letter/e/ecb155/32.png) [@EdSeymore](https://forum.ubiquityrobotics.com/u/EdSeymore)\
**Post date:** [April 27, 2021, 3:48pm UTC](https://forum.ubiquityrobotics.com/t/importing-sonar-library-instead-of-laserscan/803/4 "2021-04-27T15:48:38Z")

</div>

> [@mjstn2011](#):
>
> master branch of our demos repository.

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

---

<div class="post-metadata">

**Author:** ![mjstn2011](https://forum.ubiquityrobotics.com/user_avatar/forum.ubiquityrobotics.com/mjstn2011/32/30_2.png) [@mjstn2011](https://forum.ubiquityrobotics.com/u/mjstn2011)\
**Post date:** [April 28, 2021, 6:30am UTC](https://forum.ubiquityrobotics.com/t/importing-sonar-library-instead-of-laserscan/803/5 "2021-04-28T06:30:15Z")

</div>

The ubiquity robotics github repositories are all here: [https://github.com/UbiquityRobotics](https://github.com/UbiquityRobotics)

The demos repository is [https://github.com/UbiquityRobotics/demos](https://github.com/UbiquityRobotics/demos)
