|
| 1 | +from brping import definitions |
| 2 | +from brping import Ping360 |
| 3 | +import time |
| 4 | +import argparse |
| 5 | + |
| 6 | +from builtins import input |
| 7 | + |
| 8 | +## Parse Command line options |
| 9 | +############################ |
| 10 | + |
| 11 | +parser = argparse.ArgumentParser(description="Ping360 auto scan example") |
| 12 | +parser.add_argument('--device', action="store", required=False, type=str, help="Ping device port. E.g: /dev/ttyUSB0") |
| 13 | +parser.add_argument('--baudrate', action="store", type=int, default=2000000, help="Ping device baudrate. E.g: 115200") |
| 14 | +parser.add_argument('--udp', action="store", required=False, type=str, help="Ping UDP server. E.g: 192.168.2.2:9090") |
| 15 | +args = parser.parse_args() |
| 16 | +if args.device is None and args.udp is None: |
| 17 | + parser.print_help() |
| 18 | + exit(1) |
| 19 | + |
| 20 | +# Make a new Ping360 |
| 21 | +myPing360 = Ping360() |
| 22 | +if args.device is not None: |
| 23 | + myPing360.connect_serial(args.device, args.baudrate) |
| 24 | +elif args.udp is not None: |
| 25 | + (host, port) = args.udp.split(':') |
| 26 | + myPing360.connect_udp(host, int(port)) |
| 27 | + |
| 28 | +if myPing360.initialize() is False: |
| 29 | + print("Failed to initialize Ping!") |
| 30 | + exit(1) |
| 31 | + |
| 32 | +print("------------------------------------") |
| 33 | +print("Ping360 auto scan..") |
| 34 | +print("Press CTRL+C to exit") |
| 35 | +print("------------------------------------") |
| 36 | + |
| 37 | +input("Press Enter to continue...") |
| 38 | + |
| 39 | +myPing360.control_auto_transmit( |
| 40 | + mode = 1, |
| 41 | + gain_setting = 0, |
| 42 | + transmit_duration = 80, |
| 43 | + sample_period = 80, |
| 44 | + transmit_frequency = 750, |
| 45 | + number_of_samples = 1024, |
| 46 | + start_angle = 0, |
| 47 | + stop_angle = 399, |
| 48 | + num_steps = 1, |
| 49 | + delay = 0 |
| 50 | +) |
| 51 | + |
| 52 | +# Print the scanning head angle |
| 53 | +for n in range(400): |
| 54 | + m = myPing360.wait_message([definitions.PING360_AUTO_DEVICE_DATA]) |
| 55 | + if m: |
| 56 | + print(m.angle) |
| 57 | + time.sleep(0.001) |
| 58 | + |
| 59 | +# if it is a serial device, reconnect to send a line break |
| 60 | +# and stop auto-transmitting |
| 61 | +if args.device is not None: |
| 62 | + myPing360.connect_serial(args.device, args.baudrate) |
| 63 | + |
| 64 | +# turn the motor off |
| 65 | +myPing360.control_motor_off() |
0 commit comments