# Changing the Ping360 scan distance

**URL:** <https://discuss.bluerobotics.com/t/changing-the-ping360-scan-distance/11762>\
**Category:** Ping Sonar Devices\
**Tags:** ping, sonar\
**Created:** [March 17, 2022, 2:18pm UTC](https://discuss.bluerobotics.com/t/changing-the-ping360-scan-distance/11762 "2022-03-17T14:18:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tonyp](https://avatars.discourse-cdn.com/v4/letter/t/c89c15/32.png) [@tonyp](https://discuss.bluerobotics.com/u/tonyp)\
**Post date:** [March 17, 2022, 2:18pm UTC](https://discuss.bluerobotics.com/t/changing-the-ping360-scan-distance/11762/1 "2022-03-17T14:18:31Z")

</div>

Hello, I am currently working on software using data from the scanning imaging sonar (Ping360).  
Part of the software is creating a collision avoidance system, and in that regard I need to change the scan length. I am using the python libraries.

From the data sheet it is given that the ranged is from 0.75m til 50m.

I am using an example program from Github, but I am not sure how to actually find what range I am scanning. Which class methods should I use to set a new scan range? I am guessing it have to do something with the transmit\_duration, but osme help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [March 17, 2022, 9:38pm UTC](https://discuss.bluerobotics.com/t/changing-the-ping360-scan-distance/11762/2 "2022-03-17T21:38:07Z")

</div>

Hi @tonyp, welcome to the forum! 🙂

I’d suggest you have a read of [this thread](https://discuss.bluerobotics.com/t/ping-sonar-range-setting-and-the-angle-definition/11686), then ask any follow-ups you’ve got beyond that 🙂

> [@tonyp](#):
>
> I am guessing it have to do something with the transmit\_duration, but osme help would be greatly appreciated.

`transmit_duration` partly determines the effective resolution, and to some extent the return strength, but doesn’t have a direct impact on the actual scan range.

---

<div class="post-metadata">

**Author:** ![tonyp](https://avatars.discourse-cdn.com/v4/letter/t/c89c15/32.png) [@tonyp](https://discuss.bluerobotics.com/u/tonyp)\
**Post date:** [March 18, 2022, 12:00am UTC](https://discuss.bluerobotics.com/t/changing-the-ping360-scan-distance/11762/3 "2022-03-18T00:00:53Z")

</div>

It makes it a bit clearer, however as I am implementing my logic in Python, some of the c++ code example is a bit confusing to me. For example what is a good substitution for the qFuzzyCompare functions.

Are there any other examples of setting range implemented in Python?  
Or could I get some additional help in setting up the functions, and some help with which parameters I should set?

I see that there is implemented setting range functions in Ping1D, is there any particular reason that it is not in Ping360?

Thanks for the help so far!

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [March 18, 2022, 4:18am UTC](https://discuss.bluerobotics.com/t/changing-the-ping360-scan-distance/11762/4 "2022-03-18T04:18:42Z")

</div>

> [@tonyp](#):
>
> what is a good substitution for the qFuzzyCompare functions.

`qFuzzyCompare` is a Qt function that checks if two numbers are equivalent (same as the `==` operator in Python). In the `set_range` function, it’s being used to check if the new commanded range is the same as the existing stored range, and if so returning early (there’s not much value in commanding a settings change without actually changing any settings).

> [@tonyp](#):
>
> Are there any other examples of setting range implemented in Python?

I’ve raised [an issue](https://github.com/bluerobotics/ping-python/issues/122) for us to add an implementation of it in the library (because I think it would be a useful addition), but I don’t know what kind of timeline that will have. I’m not aware of any existing Python implementations.

> [@tonyp](#):
>
> Or could I get some additional help in setting up the functions, and some help with which parameters I should set?

What help are you after, specifically? The thread I linked you to covers the parameters that determine the range (`sample_period` and `number_of_sampes`), as well as the equation that relates them. The Ping Viewer implementation that’s linked to covers the actual [`set_range`](https://github.com/bluerobotics/ping-viewer/blob/master/src/sensor/ping360.h#L176-L203) functionality, which calculates the sample period ([`calculateSamplePeriod`](https://github.com/bluerobotics/ping-viewer/blob/master/src/sensor/ping360.cpp#L613-L629)) from the currently specified sound speed and number of samples, and updates the transmit duration ([`adjustTransmitDuration`](https://github.com/bluerobotics/ping-viewer/blob/master/src/sensor/ping360.h#L438-L465)) to stay within reasonable limits for the sensor.

> [@tonyp](#):
>
> I see that there is implemented setting range functions in Ping1D, is there any particular reason that it is not in Ping360?

The Ping1D firmware stores a [speed of sound](https://docs.bluerobotics.com/ping-protocol/pingmessage-ping1d/#1203-speed_of_sound) internally, and supports directly [setting the range](https://docs.bluerobotics.com/ping-protocol/pingmessage-ping1d/#1001-set_range) with a message.

As in the thread I linked you to:

> [@Sound speed python ping360 sonar](https://discuss.bluerobotics.com/t/sound-speed-python-ping360-sonar/8412/2):
>
> With Ping360 you have access to the direct parameters to configure the sensor without any abstraction, making the sensor more powerful and as result a bit more complex to configure.

Basically, the Ping360 firmware provides more direct access to the device itself, and additional abstraction needs to be implemented by the code that’s communicating with it. Our libraries currently only implement the [ping-protocol](https://docs.bluerobotics.com/ping-protocol/) and what’s required to make a connection (e.g. serial / udp connection functions), which provides access to everything the devices themselves can do.

Additional abstract functionality could definitely be useful, but interface and accessibility improvements are frequently prioritised below fixing or implementing critical functionality elsewhere. Our software team is small, and time is unfortunately a limited resource.

---

<div class="post-metadata">

**Author:** ![tonyp](https://avatars.discourse-cdn.com/v4/letter/t/c89c15/32.png) [@tonyp](https://discuss.bluerobotics.com/u/tonyp)\
**Post date:** [March 18, 2022, 5:41pm UTC](https://discuss.bluerobotics.com/t/changing-the-ping360-scan-distance/11762/5 "2022-03-18T17:41:43Z")

</div>

Hello. I have tried to implement the range functionality as described in the ping-viewer c++ program that is mentioned previously. However I am a bit stuck as it is difficult to test my functions properly, as I can only operate the sonar above water for the time being. Below is a sample of my script, all functions are implemented within the ping360 Class. When I set the “\_sample\_period” to 80, and the “\_number\_of\_samples” to 800. And finally call the “range” function, it outputs only 1.2 meters.

My problem is that I don’t know if this is a correct output, as I have no reference.

- Does this value under the given parameters make sense?

Additionally, I would appreciate if I could get some direction as to where to find which values would give what range readings.

- Could I get some example parameters, and the resulting range value?

That would help me with testing the software.

Finally, in the Ping360 class there is some explanation about parameters, as for example “sample\_period” and “transmit\_frequency”.

- But is there some place where I could find more precise information about the parameters, as for minimum and maximum values for good sonar readings?

```auto

def samplePeriod(self):
        # Multiply with samplePeriodTickDuration which is 25 nanoseconds
        return self._sample_period * 25E-9

# Returns the set scanning range currently set
def range(self):
        # 1500 is the speed of sound and is constant
        print("samplePeriod=", self.samplePeriod())
        print("Number of samples", self._number_of_samples)
        return self.samplePeriod() * self._number_of_samples * 1500 / 2

# Sets new sonar scan range
def set_range(self, newRange):
        # Checks if new argument is different from set range
        if (newRange == range()):
            return

```

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [March 18, 2022, 10:10pm UTC](https://discuss.bluerobotics.com/t/changing-the-ping360-scan-distance/11762/6 "2022-03-18T22:10:50Z")

</div>

> [@tonyp](#):
>
> When I set the “\_sample\_period” to 80, and the “\_number\_of\_samples” to 800. And finally call the “range” function, it outputs only 1.2 meters.
> 
> My problem is that I don’t know if this is a correct output, as I have no reference.
> 
> - Does this value under the given parameters make sense?

Yes, that’s correct. 800 2 microsecond samples with a sound speed of 1500m/s gives a total distance travelled of 2.4m, and since the sonar measures reflections then the range is half of that, which is 1.2m 🙂

> [@tonyp](#):
>
> I would appreciate if I could get some direction as to where to find which values would give what range readings.
> 
> - Could I get some example parameters, and the resulting range value?

Your calculations are already correct, but if you want to double check you can turn on [debug mode](http://docs.bluerobotics.com/ping-viewer/display-settings/) in Ping Viewer, and see what the parameters are for a given range.

![Ping Viewer Debug Mode](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/c/cf58fe4265cd42bc3d5ce9976fc7df89590b9170.png)

> [@tonyp](#):
>
> is there some place where I could find more precise information about the parameters, as for minimum and maximum values for good sonar readings?

“Good” depends on the operating conditions, but the parameters are described in the [ping protocol docs](https://docs.bluerobotics.com/ping-protocol/pingmessage-ping360/#2300-device_data). The [parameter descriptions](http://docs.bluerobotics.com/ping-viewer/device-settings-ping360/) in the Ping Viewer docs may also be useful, together with the Ping Viewer implementation for setting default values.

---

<div class="post-metadata">

**Author:** ![tonyp](https://avatars.discourse-cdn.com/v4/letter/t/c89c15/32.png) [@tonyp](https://discuss.bluerobotics.com/u/tonyp)\
**Post date:** [March 18, 2022, 10:35pm UTC](https://discuss.bluerobotics.com/t/changing-the-ping360-scan-distance/11762/7 "2022-03-18T22:35:47Z")

</div>

Thank you for the help, the ping viewer troubleshooter interface is a good tool.

So to reiterate, the adjusting of range functionality, will in practice be determined by to parameters. Which is “number\_of\_samples” and “sample\_period”.  
Follow up question: when adjusting from my 1.2 meter scan settings as described above, which parameters should be changed for best quality output signal? Should I only change one of the parameters, or should I scale up both with a certain relationship?  
For example if I want to change the scan range to 50 meters? Does this depend on operating conditions, or are there some general rule of thumb to follow?

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [March 18, 2022, 11:47pm UTC](https://discuss.bluerobotics.com/t/changing-the-ping360-scan-distance/11762/8 "2022-03-18T23:47:48Z")

</div>

> [@tonyp](#):
>
> So to reiterate, the adjusting of range functionality, will in practice be determined by to parameters. Which is “number\_of\_samples” and “sample\_period”.

Yes, `sample_period` and `number_of_samples` are the Ping360 parameters that define the range, although the speed of sound is also part of the calculation.

> [@tonyp](#):
>
> when adjusting from my 1.2 meter scan settings as described above, which parameters should be changed for best quality output signal? Should I only change one of the parameters, or should I scale up both with a certain relationship?

More samples means more data you need to process, which may or may not be a problem. Shorter sample period means higher range resolution, so you can detect finer details. Ping Viewer just uses as many samples as possible for the range (which is basically always 1200), but you may want/need to use fewer samples per ping if your processing isn’t fast enough for the rotation/scanning rate you want.

Note that the transmit duration and gain are relevant to signal quality, and should both in general go up with the range.
