# Ping360 sonar stops scanning

**URL:** <https://discuss.bluerobotics.com/t/ping360-sonar-stops-scanning/11091>\
**Category:** Ping Viewer\
**Tags:** ping\
**Created:** [November 26, 2021, 6:18pm UTC](https://discuss.bluerobotics.com/t/ping360-sonar-stops-scanning/11091 "2021-11-26T18:18:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wang](https://avatars.discourse-cdn.com/v4/letter/w/edb3f5/32.png) [@wang](https://discuss.bluerobotics.com/u/wang)\
**Post date:** [November 26, 2021, 6:18pm UTC](https://discuss.bluerobotics.com/t/ping360-sonar-stops-scanning/11091/1 "2021-11-26T18:18:28Z")

</div>

Hi,  
I have a problem when I ran the following code.

I tried to print the angle after p.transmitAngle(x);  
The code cannot print x continuously. It seems that the sonar stopped scanning. After a pause of a few second, it printed a serial of x again and then paused.

```python
from brping import Ping360

if __name__ == " __main__":
 
      import argparse

      parser = argparse.ArgumentParser(description="Ping python library example.")
      parser.add_argument('--device', action="store", required=False, type=str, help="Ping device port. E.g: /dev/ttyUSB0")
      parser.add_argument('--baudrate', action="store", type=int, default=115200, help="Ping device baudrate. E.g: 115200")
      parser.add_argument('--udp', action="store", required=False, type=str, help="Ping UDP server. E.g: 192.168.2.2:9092")
      args = parser.parse_args()
      def disk_exists(path):
          try:
                return stat.S_ISCHR(os.stat(path).st_mode)
          except:
               return False
      if args.device is None and args.udp is None:
           parser.print_help()
           exit(1)
      p = Ping360()
      if args.device is not None:
          p.connect_serial(args.device, args.baudrate)
      elif args.udp is not None:
          (host, port) = args.udp.split(':')
           p.connect_udp(host, int(port))
      print("Initialized: %s" % p.initialize())
     
      for x in range(400):
           device_data = p.transmitAngle(x)
           print(x)

```

This code worked before without any issues. Thanks.

---

<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:** [November 28, 2021, 11:41pm UTC](https://discuss.bluerobotics.com/t/ping360-sonar-stops-scanning/11091/2 "2021-11-28T23:41:49Z")

</div>

Hi @wang,

Beyond the missing imports/setup the code looks fine to me. Could you provide some more information about how you’re running this? I’m curious as to:

- which versions of Python and the `bluerobotics-ping` library are you using?
- whether you’re using serial or udp
  - if serial, which baudrate?

- your hardware setup (e.g. Ping360 connected directly to controlling computer/RPi, or Ping360 connected to Companion computer and controlled from topside computer)
  - if it’s going via Companion, which Companion version are you using?

- whether you experience the same pauses when using Ping Viewer

---

<div class="post-metadata">

**Author:** ![wang](https://avatars.discourse-cdn.com/v4/letter/w/edb3f5/32.png) [@wang](https://discuss.bluerobotics.com/u/wang)\
**Post date:** [November 29, 2021, 3:17pm UTC](https://discuss.bluerobotics.com/t/ping360-sonar-stops-scanning/11091/3 "2021-11-29T15:17:44Z")

</div>

Hi,

Thank you for your reply. The answers are below.

1. I use python 3.6.9 and bluerobotics-ping 0.1.0.
2. I use udp.
3. The sonar is connect to a BeagleBone Black through udp.
4. Before I connected the sonar to the BeagleBone black through usb, there was no problem. But this time I cannot use usb because of one underwater cable I use.

When I connect the ping360 to a laptop through udp, there was no problem.

There is one more problem: I cannot talk to the ping360 through pingviewer if I use an usb to ethernet adaptor, I need to connect the ping360 to the ethernet port in my laptop directly. This is a trouble as the laptops in my lap has no ethernet port.

Thanks.  
Wang

---

<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:** [November 30, 2021, 11:52am UTC](https://discuss.bluerobotics.com/t/ping360-sonar-stops-scanning/11091/4 "2021-11-30T11:52:59Z")

</div>

> [@wang](#):
>
> 1. I use python 3.6.9 and bluerobotics-ping 0.1.0.

Could you update your bluerobotics-ping to the latest (0.1.3)?

> [@wang](#):
>
> 1. I use udp.
> 2. The sonar is connect to a BeagleBone Black through udp.

How is that connected? Have you changed the Ping360 into the ethernet configuration, or are there other connections in between that you haven’t mentioned?

> [@wang](#):
>
> There is one more problem: I cannot talk to the ping360 through pingviewer if I use an usb to ethernet adaptor, I need to connect the ping360 to the ethernet port in my laptop directly.

Are you saying you’ve got the Ping360 in ethernet configuration, and it’s working when directly connected to your laptop but not when connected via an ethernet to USB converter? If so, that may be a network settings issue, or a faulty ethernet to USB converter.

---

<div class="post-metadata">

**Author:** ![wang](https://avatars.discourse-cdn.com/v4/letter/w/edb3f5/32.png) [@wang](https://discuss.bluerobotics.com/u/wang)\
**Post date:** [November 30, 2021, 7:57pm UTC](https://discuss.bluerobotics.com/t/ping360-sonar-stops-scanning/11091/5 "2021-11-30T19:57:04Z")

</div>

Hi,

1. I have updated to 0.1.3. There was no stopping for like 30 seconds when I ran my code for the first time. Then when I restarted the sonar, it stopped scanning frequently like before.

2. I have changed to ethernet configuration. The sonar is connected directly to the ethernet port of the BeagleBone.

3. There was no problem when connected to the laptop with Pingviewer, but had problem when used bluerobotics-ping with Beaglebone Black. I do not use converter.

4. Instead of using transmitAngle, I tried to use command control\_transducer()+wait\_message(). When I only used control\_transducer, there was no stop, but when I included wait\_message, it stopped. So what I can do now is to set the timeout parameter in wait\_message to be a small value instead of using the default value 4. But this means I may miss some data right? But I don’t want the sonar stop scanning.

5. In the function control\_transducer(self, mode, gain\_setting, angle, transmit\_duration, sample\_period, transmit\_frequency, number\_of\_samples, transmit, reserved), I cannot find the explanation of the last two parameters : transmit and reserved. Could you tell me what they mean?

Thank you so much.

Wang

---

<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:** [December 1, 2021, 11:31am UTC](https://discuss.bluerobotics.com/t/ping360-sonar-stops-scanning/11091/6 "2021-12-01T11:31:24Z")

</div>

> [@wang](#):
>
> 1. I have updated to 0.1.3. There was no stopping for like 30 seconds when I ran my code for the first time. Then when I restarted the sonar, it stopped scanning frequently like before.

We’ve just fixed a `ping-python` bug that was causing an issue somewhere else, but _may_ also be related to this. Please try updating to 0.1.4 in case that helps 🙂

> [@wang](#):
>
> 1. I have changed to ethernet configuration. The sonar is connected directly to the ethernet port of the BeagleBone.
> 2. There was no problem when connected to the laptop with Pingviewer, but had problem when used bluerobotics-ping with Beaglebone Black. I do not use converter.

Ok, good to know, thanks.

> [@wang](#):
>
> 1. Instead of using transmitAngle, I tried to use command control\_transducer()+wait\_message(). When I only used control\_transducer, there was no stop, but when I included wait\_message, it stopped. So what I can do now is to set the timeout parameter in wait\_message to be a small value instead of using the default value 4. But this means I may miss some data right? But I don’t want the sonar stop scanning.

The [Ping Protocol Ping360 `transducer` docs](https://docs.bluerobotics.com/ping-protocol/pingmessage-ping360/#2601-transducer) specify

> [@Ping Protocol - Ping360 Transducer](#):
>
> To allow for the worst case response time the command timeout should be set to 4000 msec.

which is why it’s set to 4 (seconds) in the code. It should be possible to dynamically set a lower value if you know you don’t need the full time (which I’m planning to do in a library update, but that may not occur until some time next year).

If you’re interested, the main steps I’m aware of that are likely factored into that “worst case” time are:

- up to 399 gradians of (clockwise) motor rotation while it gets to the hall effect sensor to calibrate the zero position, along with some time to detect/initialise (unsure how long this part takes)
- up to 200 gradians of rotation to get to the requested ping position (unsure how long this takes, but it could likely be timed quite easily - the time allocated could be reduced if you know where the requested position is relative to the current position)
- 1200ms for the transmitting + receiving of a 1200 sample ping with a 1000us sample period (could be reduced if you’re using fewer samples and/or a lower sample period)
- some time to send the response message (this may depend on communication mode + configuration (e.g. serial baudrate), as well as how many samples are included)

I’d note that if you’re having connection issues it’s likely best to fix those before focusing on minimising timeouts, but that said, having a failsafe that doesn’t wait around longer than absolutely necessary is still a good idea 🙂

> [@wang](#):
>
> 1. In the function control\_transducer(self, mode, gain\_setting, angle, transmit\_duration, sample\_period, transmit\_frequency, number\_of\_samples, transmit, reserved), I cannot find the explanation of the last two parameters : transmit and reserved. Could you tell me what they mean?

The protocol docs I linked to above are the best source of information for things like this. In this case `reserved` is a reserved parameter, so your best bet is following how it’s used elsewhere in the existing implementations (e.g. in the `transmitAngle` function it’s just set to 0).
