1818parser = argparse .ArgumentParser (description = "Ping python library example." )
1919parser .add_argument ('--device' , action = "store" , required = False , type = str , help = "Ping device port. E.g: /dev/ttyUSB0" )
2020parser .add_argument ('--baudrate' , action = "store" , type = int , default = 115200 , help = "Ping device baudrate. E.g: 115200" )
21- parser .add_argument ('--udp' , action = "store" , required = False , type = str , help = "Ping UDP server. E.g: 192.168.2.2:9090" )
21+ parser .add_argument ('--udp' , action = "store" , required = False , type = str , help = "Surveyor IP:Port. E.g: 192.168.2.86:62312" )
22+ parser .add_argument ('--tcp' , action = "store" , required = False , type = str , help = "Surveyor IP:Port. E.g: 192.168.2.86:62312" )
2223args = parser .parse_args ()
23- if args .device is None and args .udp is None :
24+ if args .device is None and args .udp is None and args . tcp is None :
2425 parser .print_help ()
2526 exit (1 )
2627
2728# Signal handler to stop pinging on the Surveyor240
2829def signal_handler (sig , frame ):
2930 print ("Stopping pinging on Surveyor240..." )
30- mySurveyor240 .control_set_ping_parameters (
31- start_mm = 5 ,
32- end_mm = 0 ,
33- sos_mps = 1500 ,
34- gain_index = - 1 ,
35- msec_per_ping = 100 ,
36- deprecated = 0 ,
37- diagnostic_injected_signal = 0 ,
38- ping_enable = False ,
39- enable_channel_data = False ,
40- reserved_for_raw_data = False ,
41- enable_yz_point_data = True ,
42- enable_atof_data = True ,
43- target_ping_hz = 240000 ,
44- n_range_steps = 400 ,
45- reserved = 0 ,
46- pulse_len_steps = 1.5
47- )
31+ mySurveyor240 .control_set_ping_parameters (ping_enable = False )
4832 # Close socket if open
4933 if mySurveyor240 .iodev :
5034 try :
@@ -63,6 +47,9 @@ def signal_handler(sig, frame):
6347elif args .udp is not None :
6448 (host , port ) = args .udp .split (':' )
6549 mySurveyor240 .connect_udp (host , int (port ))
50+ elif args .tcp is not None :
51+ (host , port ) = args .tcp .split (':' )
52+ mySurveyor240 .connect_tcp (host , int (port ))
6653
6754if mySurveyor240 .initialize () is False :
6855 print ("Failed to initialize Surveyor240!" )
@@ -79,24 +66,12 @@ def signal_handler(sig, frame):
7966input ("Press Enter to continue..." )
8067
8168mySurveyor240 .control_set_ping_parameters (
82- start_mm = 0 ,
83- end_mm = 0 ,
84- sos_mps = 1500 ,
85- gain_index = - 1 ,
86- msec_per_ping = 100 ,
87- deprecated = 0 ,
88- diagnostic_injected_signal = 0 ,
8969 ping_enable = True ,
90- enable_channel_data = False ,
91- reserved_for_raw_data = False ,
9270 enable_yz_point_data = True ,
9371 enable_atof_data = True ,
94- target_ping_hz = 240000 ,
95- n_range_steps = 400 ,
96- reserved = 0 ,
97- pulse_len_steps = 1.5
9872)
9973
74+ print ("\n ---------Attitude Report---------" )
10075while True :
10176 data = mySurveyor240 .wait_message ([definitions .SURVEYOR240_ATTITUDE_REPORT ])
10277 if data :
@@ -109,21 +84,25 @@ def signal_handler(sig, frame):
10984 print ("Failed to get attitude report" )
11085 time .sleep (0.1 )
11186
87+ print ("\n ---------ATOF Point Data---------" )
11288while True :
11389 data = mySurveyor240 .wait_message ([definitions .SURVEYOR240_ATOF_POINT_DATA ])
11490 if data :
11591 # Use create_atof_list to get formatted atof_t[num_points] list
11692 atof_data = Surveyor240 .create_atof_list (data )
117- for i in range (len (atof_data )):
118- distance = 0.5 * data .sos_mps * atof_data [i ].tof
119- y = distance * math .sin (atof_data [i ].angle )
120- z = - distance * math .cos (atof_data [i ].angle )
121- print (f"{ i } .\t Distance: { distance :.3f} meters\t Y: { y :.3f} \t Z: { z :.3f} \t { atof_data [i ]} " )
122- break
123-
93+ if len (atof_data ) == 0 :
94+ continue
95+ else :
96+ for i in range (len (atof_data )):
97+ distance = 0.5 * data .sos_mps * atof_data [i ].tof
98+ y = distance * math .sin (atof_data [i ].angle )
99+ z = - distance * math .cos (atof_data [i ].angle )
100+ print (f"{ i } .\t Distance: { distance :.3f} meters\t Y: { y :.3f} \t Z: { z :.3f} \t { atof_data [i ]} " )
101+ break
124102 else :
125- print ("Failed to get attitude report " )
103+ print ("Failed to get atof point data " )
126104
105+ print ("\n ---------YZ Point Data---------" )
127106while True :
128107 data = mySurveyor240 .wait_message ([definitions .SURVEYOR240_YZ_POINT_DATA ])
129108 if data :
@@ -134,24 +113,12 @@ def signal_handler(sig, frame):
134113 print (f"{ i // 2 } \t { yz_data [i ]:.2f} \t { yz_data [i + 1 ]:.2f} " )
135114 break
136115 else :
137- print ("Failed to get attitude report " )
116+ print ("Failed to get yz point data " )
138117
139118# Stop pinging from Surveyor
140- mySurveyor240 .control_set_ping_parameters (
141- start_mm = 5 ,
142- end_mm = 0 ,
143- sos_mps = 1500 ,
144- gain_index = - 1 ,
145- msec_per_ping = 100 ,
146- deprecated = 0 ,
147- diagnostic_injected_signal = 0 ,
148- ping_enable = False ,
149- enable_channel_data = False ,
150- reserved_for_raw_data = False ,
151- enable_yz_point_data = True ,
152- enable_atof_data = True ,
153- target_ping_hz = 240000 ,
154- n_range_steps = 400 ,
155- reserved = 0 ,
156- pulse_len_steps = 1.5
157- )
119+ mySurveyor240 .control_set_ping_parameters (ping_enable = False )
120+ if mySurveyor240 .iodev :
121+ try :
122+ mySurveyor240 .iodev .close ()
123+ except Exception as e :
124+ print (f"Failed to close socket: { e } " )
0 commit comments