88
99from MAVProxy .modules .lib import mp_module
1010from MAVProxy .modules .lib import mp_settings
11+ from MAVProxy .modules .lib import mp_util
1112from pymavlink import mavutil
1213from PIL import ImageColor
1314
2728 104 : 200
2829}
2930
30- def get_threat_radius (emitter_type ):
31+ def get_threat_radius (emitter_type , squawk ):
3132
3233 if emitter_type == 255 :
3334 ''' objectAvoidance Database item, squawk contains radius in cm'''
34- return m . squawk * 0.01
35+ return squawk * 0.01
3536 '''get threat radius for an OBC item'''
3637 return obc_radius .get (emitter_type ,0 )
3738
@@ -83,15 +84,18 @@ def __init__(self, mpstate):
8384 ("threat_radius_clear_multiplier" , int , 2 ),
8485 ("show_threat_radius_clear" , bool , False ),
8586 ("show_callsign" , bool , True ),
87+ ("traffic_warning" , bool , False ),
8688 ("alt_color1" , str , "blue" ),
8789 ("alt_color2" , str , "red" ),
88- ("alt_color_thresh" , int , 300 )])
90+ ("alt_color_alt_thresh" , int , 300 ),
91+ ("alt_color_dist_thresh" , int , 3000 )])
8992 self .add_completion_function ('(ADSBSETTING)' ,
9093 self .ADSB_settings .completion )
9194
9295 self .threat_detection_timer = mavutil .periodic_event (2 )
9396 self .threat_timeout_timer = mavutil .periodic_event (2 )
9497 self .tnow = self .get_time ()
98+ self .last_traffic = self .tnow
9599
96100 def cmd_ADSB (self , args ):
97101 '''adsb command parser'''
@@ -201,19 +205,23 @@ def add_vehicle(self, state):
201205 callsign = state ['callsign' ]
202206 heading = state ['heading' ]
203207 emitter_type = state ['emitter_type' ]
208+ squawk = state ['squawk' ]
204209
205210 if id not in self .threat_vehicles .keys (): # check to see if the vehicle is in the dict
211+ #print("NEW: ", state)
206212 # if not then add it
207213 self .threat_vehicles [id ] = ADSBVehicle (id = id , state = state )
214+ #print("NEW: ", state)
208215 for mp in self .module_matching ('map*' ):
209216 from MAVProxy .modules .lib import mp_menu
210217 from MAVProxy .modules .mavproxy_map import mp_slipmap
211218 self .threat_vehicles [id ].menu_item = mp_menu .MPMenuItem (name = id , returnkey = None )
212219
213- threat_radius = get_threat_radius (emitter_type )
220+ threat_radius = get_threat_radius (emitter_type , squawk )
214221 selected_icon = get_threat_icon (emitter_type , self .threat_vehicles [id ].icon )
215222
216223 if selected_icon is not None :
224+ #print("map add ", state)
217225 # draw the vehicle on the map
218226 popup = mp_menu .MPMenuSubMenu ('ADSB' , items = [self .threat_vehicles [id ].menu_item ])
219227 icon = mp .map .icon (selected_icon )
@@ -231,20 +239,33 @@ def add_vehicle(self, state):
231239
232240 for mp in self .module_matching ('map*' ):
233241 # update the map, labelling alt above/below our alt
234- ground_alt = self .module ('terrain' ).ElevationModel .GetElevation (lat * 1e-7 , lon * 1e-7 )
242+ GPI = self .master .messages .get ("GLOBAL_POSITION_INT" , None )
243+ if GPI is None :
244+ return
245+ ref_alt = GPI .alt * 0.001
246+ lat_deg = lat * 1.0e-7
247+ lon_deg = lon * 1.0e-7
248+ our_lat_deg = GPI .lat * 1.0e-7
249+ our_lon_deg = GPI .lon * 1.0e-7
250+
251+ dist = mp_util .gps_distance (our_lat_deg , our_lon_deg , lat_deg , lon_deg )
235252 alt_amsl = altitude_km * 0.001
236253 color = ImageColor .getrgb (self .ADSB_settings .alt_color1 )
237254 label = ""
238255 if self .ADSB_settings .show_callsign :
239- label = "[%s] " % callsign
256+ label = "[%s] " % callsign . rstrip ()
240257 if alt_amsl > 0 :
241- alt = int (alt_amsl - ground_alt )
258+ alt = int (alt_amsl - ref_alt )
242259 label += self .height_string (alt )
243- if abs (alt ) < self .ADSB_settings .alt_color_thresh :
260+ if abs (alt ) < self .ADSB_settings .alt_color_alt_thresh and dist < self .ADSB_settings .alt_color_dist_thresh :
261+ tnow = self .get_time ()
262+ if self .ADSB_settings .traffic_warning and tnow - self .last_traffic > 5 :
263+ self .last_traffic = tnow
264+ self .say ("traffic" )
244265 color = ImageColor .getrgb (self .ADSB_settings .alt_color2 )
245266
246- mp .map .set_position (id , (lat * 1e-7 , lon * 1e-7 ), rotation = heading * 0.01 , label = label , colour = color )
247- mp .map .set_position (id + ":circle" , (lat * 1e-7 , lon * 1e-7 ))
267+ mp .map .set_position (id , (lat_deg , lon_deg ), rotation = heading * 0.01 , label = label , colour = color )
268+ mp .map .set_position (id + ":circle" , (lat_deg , lon_deg ))
248269
249270 def mavlink_packet (self , m ):
250271 '''handle an incoming mavlink packet'''
0 commit comments