idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
41,500
def find_manifests ( self ) : manifest_dir = mp_util . dot_mavproxy ( ) ret = [ ] for file in os . listdir ( manifest_dir ) : try : file . index ( "manifest" ) ret . append ( os . path . join ( manifest_dir , file ) ) except ValueError : pass return ret
locate manifests and return filepaths thereof
41,501
def cmd_fw_manifest_purge ( self ) : for filepath in self . find_manifests ( ) : os . unlink ( filepath ) self . manifests_parse ( )
remove all downloaded manifests
41,502
def cmd_fw_manifest ( self , args ) : if len ( args ) == 0 : print ( self . fw_manifest_usage ( ) ) return rest = args [ 1 : ] if args [ 0 ] == "download" : return self . manifest_download ( ) if args [ 0 ] == "list" : return self . cmd_fw_manifest_list ( ) if args [ 0 ] == "load" : return self . cmd_fw_manifest_load (...
cmd handler for manipulating manifests
41,503
def manifest_parse ( self , path ) : print ( "fw: parsing manifests" ) content = open ( path ) . read ( ) return json . loads ( content )
parse manifest at path return JSON object
41,504
def manifest_path_is_old ( self , path ) : mtime = os . path . getmtime ( path ) return ( time . time ( ) - mtime ) > 24 * 60 * 60
return true if path is more than a day old
41,505
def manifests_parse ( self ) : self . manifests = [ ] for manifest_path in self . find_manifests ( ) : if self . manifest_path_is_old ( manifest_path ) : print ( "fw: Manifest (%s) is old; consider 'manifest download'" % ( manifest_path ) ) manifest = self . manifest_parse ( manifest_path ) if self . semver_major ( man...
parse manifests present on system
41,506
def make_safe_filename_from_url ( self , url ) : r = re . compile ( "([^a-zA-Z0-9_.-])" ) filename = r . sub ( lambda m : "%" + str ( hex ( ord ( str ( m . group ( 1 ) ) ) ) ) . upper ( ) , url ) return filename
return a version of url safe for use as a filename
41,507
def manifest_download ( self ) : if self . downloaders_lock . acquire ( False ) : if len ( self . downloaders ) : self . downloaders_lock . release ( ) return for url in [ 'http://firmware.ardupilot.org/manifest.json' ] : filename = self . make_safe_filename_from_url ( url ) path = mp_util . dot_mavproxy ( "manifest-%s...
download manifest files
41,508
def colour_for_point ( mlog , point , instance , options ) : global colour_expression_exceptions , colour_source_max , colour_source_min source = getattr ( options , "colour_source" , "flightmode" ) if source == "flightmode" : return colour_for_point_flightmode ( mlog , point , instance , options ) try : v = eval ( sou...
indicate a colour to be used to plot point
41,509
def mavlink_to_json ( msg ) : ret = '\"%s\": {' % msg . _type for fieldname in msg . _fieldnames : data = getattr ( msg , fieldname ) ret += '\"%s\" : \"%s\", ' % ( fieldname , data ) ret = ret [ 0 : - 2 ] + '}' return ret
Translate mavlink python messages in json string
41,510
def mpstatus_to_json ( status ) : msg_keys = list ( status . msgs . keys ( ) ) data = '{' for key in msg_keys [ : - 1 ] : data += mavlink_to_json ( status . msgs [ key ] ) + ',' data += mavlink_to_json ( status . msgs [ msg_keys [ - 1 ] ] ) data += '}' return data
Translate MPStatus in json string
41,511
def set_ip_port ( self , ip , port ) : self . address = ip self . port = port self . stop ( ) self . start ( )
set ip and port
41,512
def request ( self , arg = None ) : if not self . status : return '{"result": "No message"}' try : status_dict = json . loads ( mpstatus_to_json ( self . status ) ) except Exception as e : print ( e ) return if not arg : return json . dumps ( status_dict ) new_dict = status_dict args = arg . split ( '/' ) for key in ar...
Deal with requests
41,513
def power_status_update ( self , POWER_STATUS ) : now = time . time ( ) Vservo = POWER_STATUS . Vservo * 0.001 Vcc = POWER_STATUS . Vcc * 0.001 self . high_servo_voltage = max ( self . high_servo_voltage , Vservo ) if self . high_servo_voltage > 1 and Vservo < self . settings . servowarn : if now - self . last_servo_wa...
update POWER_STATUS warnings level
41,514
def valid_starter_settings ( self ) : if self . gasheli_settings . ignition_chan <= 0 or self . gasheli_settings . ignition_chan > 8 : print ( "Invalid ignition channel %d" % self . gasheli_settings . ignition_chan ) return False if self . gasheli_settings . starter_chan <= 0 or self . gasheli_settings . starter_chan >...
check starter settings
41,515
def cmd_gasheli ( self , args ) : usage = "Usage: gasheli <start|stop|set>" if len ( args ) < 1 : print ( usage ) return if args [ 0 ] == "start" : self . start_motor ( ) elif args [ 0 ] == "stop" : self . stop_motor ( ) elif args [ 0 ] == "set" : self . gasheli_settings . command ( args [ 1 : ] ) else : print ( usage ...
gas help commands
41,516
def wploader ( self ) : if self . target_system not in self . wploader_by_sysid : self . wploader_by_sysid [ self . target_system ] = mavwp . MAVWPLoader ( ) return self . wploader_by_sysid [ self . target_system ]
per - sysid wploader
41,517
def send_wp_requests ( self , wps = None ) : if wps is None : wps = self . missing_wps_to_request ( ) tnow = time . time ( ) for seq in wps : self . wp_requested [ seq ] = tnow self . master . waypoint_request_send ( seq )
send some more WP requests
41,518
def wp_status ( self ) : try : print ( "Have %u of %u waypoints" % ( self . wploader . count ( ) + len ( self . wp_received ) , self . wploader . expected_count ) ) except Exception : print ( "Have %u waypoints" % ( self . wploader . count ( ) + len ( self . wp_received ) ) )
show status of wp download
41,519
def wp_slope ( self ) : last_w = None for i in range ( 1 , self . wploader . count ( ) ) : w = self . wploader . wp ( i ) if w . command not in [ mavutil . mavlink . MAV_CMD_NAV_WAYPOINT , mavutil . mavlink . MAV_CMD_NAV_LAND ] : continue if last_w is not None : if last_w . frame != w . frame : print ( "WARNING: frame ...
show slope of waypoints
41,520
def save_waypoints_csv ( self , filename ) : try : self . wploader . savecsv ( filename . strip ( '"' ) ) except Exception as msg : print ( "Failed to save %s - %s" % ( filename , msg ) ) return print ( "Saved %u waypoints to CSV %s" % ( self . wploader . count ( ) , filename ) )
save waypoints to a file in a human readable CSV file
41,521
def get_home ( self ) : if 'HOME_POSITION' in self . master . messages : h = self . master . messages [ 'HOME_POSITION' ] return mavutil . mavlink . MAVLink_mission_item_message ( self . target_system , self . target_component , 0 , 0 , mavutil . mavlink . MAV_CMD_NAV_WAYPOINT , 0 , 0 , 0 , 0 , 0 , 0 , h . latitude * 1...
get home location
41,522
def nofly_add ( self ) : try : latlon = self . module ( 'map' ) . click_position except Exception : print ( "No position chosen" ) return loader = self . wploader ( center_lat , center_lon ) = latlon points = [ ] points . append ( mp_util . gps_offset ( center_lat , center_lon , - 25 , 25 ) ) points . append ( mp_util ...
add a square flight exclusion zone
41,523
def cmd_wp_changealt ( self , args ) : if len ( args ) < 2 : print ( "usage: wp changealt WPNUM NEWALT <NUMWP>" ) return idx = int ( args [ 0 ] ) if idx < 1 or idx > self . wploader . count ( ) : print ( "Invalid wp number %u" % idx ) return newalt = float ( args [ 1 ] ) if len ( args ) >= 3 : count = int ( args [ 2 ] ...
handle wp change target alt of multiple waypoints
41,524
def cmd_wp_remove ( self , args ) : if len ( args ) != 1 : print ( "usage: wp remove WPNUM" ) return idx = int ( args [ 0 ] ) if idx < 0 or idx >= self . wploader . count ( ) : print ( "Invalid wp number %u" % idx ) return wp = self . wploader . wp ( idx ) self . undo_wp = copy . copy ( wp ) self . undo_wp_idx = idx se...
handle wp remove
41,525
def cmd_wp_undo ( self ) : if self . undo_wp_idx == - 1 or self . undo_wp is None : print ( "No undo information" ) return wp = self . undo_wp if self . undo_type == 'move' : wp . target_system = self . target_system wp . target_component = self . target_component self . loading_waypoints = True self . loading_waypoint...
handle wp undo
41,526
def csv_line ( self , line ) : self . csv_sep = "," return self . csv_sep . join ( [ '"' + str ( x ) + '"' for x in line ] )
turn a list of values into a CSV line
41,527
def savecsv ( self , filename ) : f = open ( filename , mode = 'w' ) headers = [ "Seq" , "Frame" , "Cmd" , "P1" , "P2" , "P3" , "P4" , "X" , "Y" , "Z" ] print ( self . csv_line ( headers ) ) f . write ( self . csv_line ( headers ) + "\n" ) for w in self . wploader . wpoints : if getattr ( w , 'comment' , None ) : pass ...
save waypoints to a file in human - readable CSV file
41,528
def list_joysticks ( ) : print ( 'Available joysticks:' ) print ( ) for jid in range ( pygame . joystick . get_count ( ) ) : j = pygame . joystick . Joystick ( jid ) print ( '({}) {}' . format ( jid , j . get_name ( ) ) )
Print a list of available joysticks
41,529
def select_joystick ( ) : list_joysticks ( ) while True : print ( 'Select a joystick (L to list, Q to quit)' ) , choice = sys . stdin . readline ( ) . strip ( ) if choice . lower ( ) == 'l' : list_joysticks ( ) elif choice . lower ( ) == 'q' : return elif choice . isdigit ( ) : jid = int ( choice ) if jid not in range ...
Allow user to select a joystick from a menu
41,530
def select ( versions , optionsRequired = False ) : if type ( versions ) == str : versions = [ versions ] global _selected if _selected is not None : for ver in versions : if _selected . Score ( _wxPackageInfo ( ver ) , optionsRequired ) > 0 : return raise VersionError ( "A previously selected wx version does not match...
Search for a wxPython installation that matches version . If one is found then sys . path is modified so that version will be imported with a import wx otherwise a VersionError exception is raised . This function should only be called once at the beginning of the application before wxPython is imported .
41,531
def ensureMinimal ( minVersion , optionsRequired = False ) : assert type ( minVersion ) == str if sys . modules . has_key ( 'wx' ) or sys . modules . has_key ( 'wxPython' ) : raise AlreadyImportedError ( "wxversion.ensureMinimal() must be called before wxPython is imported" ) bestMatch = None minv = _wxPackageInfo ( mi...
Checks to see if the default version of wxPython is greater - than or equal to minVersion . If not then it will try to find an installed version that is > = minVersion . If none are available then a message is displayed that will inform the user and will offer to open their web browser to the wxPython downloads page an...
41,532
def checkInstalled ( versions , optionsRequired = False ) : if type ( versions ) == str : versions = [ versions ] installed = _find_installed ( ) bestMatch = _get_best_match ( installed , versions , optionsRequired ) return bestMatch is not None
Check if there is a version of wxPython installed that matches one of the versions given . Returns True if so False if not . This can be used to determine if calling select will succeed or not .
41,533
def getInstalled ( ) : installed = _find_installed ( ) return [ os . path . basename ( p . pathname ) [ 3 : ] for p in installed ]
Returns a list of strings representing the installed wxPython versions that are found on the system .
41,534
def flightmode_colours ( ) : from MAVProxy . modules . lib . grapher import flightmode_colours mapping = { } idx = 0 for ( mode , t0 , t1 ) in flightmodes : if not mode in mapping : mapping [ mode ] = flightmode_colours [ idx ] idx += 1 if idx >= len ( flightmode_colours ) : idx = 0 return mapping
return mapping of flight mode to colours
41,535
def cmd_fft ( args ) : from MAVProxy . modules . lib import mav_fft if len ( args ) > 0 : condition = args [ 0 ] else : condition = None child = multiproc . Process ( target = mav_fft . mavfft_display , args = [ mestate . filename , condition ] ) child . start ( )
display fft from log
41,536
def cmd_save ( args ) : child = multiproc . Process ( target = save_process , args = [ mestate . last_graph , mestate . child_pipe_send_console , mestate . child_pipe_send_graph , mestate . status . msgs ] ) child . start ( )
save a graph
41,537
def cmd_loadfile ( args ) : if len ( args ) != 1 : fileargs = " " . join ( args ) else : fileargs = args [ 0 ] if not os . path . exists ( fileargs ) : print ( "Error loading file " , fileargs ) return if os . name == 'nt' : fileargs = fileargs . replace ( "\\" , "/" ) loadfile ( fileargs . strip ( '"' ) )
callback from menu to load a log file
41,538
def cmd_port ( self , args ) : 'handle port selection' if len ( args ) != 1 : print ( "Usage: port <number>" ) return self . port . close ( ) self . portnum = int ( args [ 0 ] ) self . port = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) self . port . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADD...
handle port selection
41,539
def RunScript ( self , script ) : self . script = script self . script_command = 0 self . script_command_start_time = 0 self . script_command_state = 'ready' self . script_timer . Start ( 100 ) self . script_wait_time = 0
Actuate on the vehicle through a script . The script is a sequence of commands . Each command is a sequence with the first element as the command name and the remaining values as parameters .
41,540
def ppp_read ( self , ppp_fd ) : buf = os . read ( ppp_fd , 100 ) if len ( buf ) == 0 : self . stop_ppp_link ( ) return print ( "ppp packet len=%u" % len ( buf ) ) master = self . master master . mav . ppp_send ( len ( buf ) , buf )
called from main select loop in mavproxy when the pppd child sends us some data
41,541
def start_ppp_link ( self ) : cmd = [ 'pppd' ] cmd . extend ( self . command ) ( self . pid , self . ppp_fd ) = pty . fork ( ) if self . pid == 0 : os . execvp ( "pppd" , cmd ) raise RuntimeError ( "pppd exited" ) if self . ppp_fd == - 1 : print ( "Failed to create link fd" ) return fcntl . fcntl ( self . ppp_fd , fcnt...
startup the link
41,542
def stop_ppp_link ( self ) : if self . ppp_fd == - 1 : return try : self . mpself . select_extra . pop ( self . ppp_fd ) os . close ( self . ppp_fd ) os . waitpid ( self . pid , 0 ) except Exception : pass self . pid = - 1 self . ppp_fd = - 1 print ( "stopped ppp link" )
stop the link
41,543
def cmd_ppp ( self , args ) : usage = "ppp <command|start|stop>" if len ( args ) == 0 : print ( usage ) return if args [ 0 ] == "command" : if len ( args ) == 1 : print ( "ppp.command=%s" % " " . join ( self . command ) ) else : self . command = args [ 1 : ] elif args [ 0 ] == "start" : self . start_ppp_link ( ) elif a...
set ppp parameters and start link
41,544
def module_matching ( self , name ) : import fnmatch ret = [ ] for mname in self . mpstate . public_modules . keys ( ) : if fnmatch . fnmatch ( mname , name ) : ret . append ( self . mpstate . public_modules [ mname ] ) return ret
Find a list of modules matching a wildcard pattern
41,545
def get_time ( self ) : systime = time . time ( ) - self . mpstate . start_time_s if not self . mpstate . is_sitl : return systime try : speedup = int ( self . get_mav_param ( 'SIM_SPEEDUP' , 1 ) ) except Exception : return systime if speedup != 1 : return self . mpstate . attitude_time_s return systime
get time using ATTITUDE . time_boot_ms if in SITL with SIM_SPEEDUP ! = 1
41,546
def dist_string ( self , val_meters ) : if self . settings . dist_unit == 'nm' : return "%.1fnm" % ( val_meters * 0.000539957 ) if self . settings . dist_unit == 'miles' : return "%.1fmiles" % ( val_meters * 0.000621371 ) return "%um" % val_meters
return a distance as a string
41,547
def speed_convert_units ( self , val_ms ) : if self . settings . speed_unit == 'knots' : return val_ms * 1.94384 elif self . settings . speed_unit == 'mph' : return val_ms * 2.23694 return val_ms
return a speed in configured units
41,548
def set_prompt ( self , prompt ) : if prompt and self . settings . vehicle_name : prompt = self . settings . vehicle_name + ':' + prompt self . mpstate . rl . set_prompt ( prompt )
set prompt for command line
41,549
def link_label ( link ) : if hasattr ( link , 'label' ) : label = link . label else : label = str ( link . linknum + 1 ) return label
return a link label as a string
41,550
def is_primary_vehicle ( self , msg ) : sysid = msg . get_srcSystem ( ) if self . target_system == 0 or self . target_system == sysid : return True return False
see if a msg is from our primary vehicle
41,551
def next_flightmode_colour ( self ) : if self . flightmode_colour_index > len ( flightmode_colours ) : print ( "Out of colours; reusing" ) self . flightmode_colour_index = 0 ret = flightmode_colours [ self . flightmode_colour_index ] self . flightmode_colour_index += 1 return ret
allocate a colour to be used for a flight mode
41,552
def flightmode_colour ( self , flightmode ) : if flightmode not in self . flightmode_colourmap : self . flightmode_colourmap [ flightmode ] = self . next_flightmode_colour ( ) return self . flightmode_colourmap [ flightmode ]
return colour to be used for rendering a flight mode background
41,553
def setup_xrange ( self , xrange ) : if self . xaxis : return xrange *= 24 * 60 * 60 interval = 1 intervals = [ 1 , 2 , 5 , 10 , 15 , 30 , 60 , 120 , 240 , 300 , 600 , 900 , 1800 , 3600 , 7200 , 5 * 3600 , 10 * 3600 , 24 * 3600 ] for interval in intervals : if xrange / interval < 12 : break self . locator = matplotlib ...
setup plotting ticks on x axis
41,554
def xlim_changed ( self , axsubplot ) : xrange = axsubplot . get_xbound ( ) xlim = axsubplot . get_xlim ( ) self . setup_xrange ( xrange [ 1 ] - xrange [ 0 ] ) if self . draw_events == 0 : return if self . xlim_pipe is not None and axsubplot == self . ax1 and xlim != self . xlim : self . xlim = xlim self . xlim_pipe [ ...
called when x limits are changed
41,555
def timestamp_to_days ( self , timestamp ) : if self . tday_base is None : try : self . tday_base = matplotlib . dates . date2num ( datetime . datetime . fromtimestamp ( timestamp + self . timeshift ) ) self . tday_basetime = timestamp except ValueError : return 0 sec_to_days = 1.0 / ( 60 * 60 * 24 ) return self . tday...
convert log timestamp to days
41,556
def xlim_change_check ( self , idx ) : if not self . xlim_pipe [ 1 ] . poll ( ) : return xlim = self . xlim_pipe [ 1 ] . recv ( ) if xlim is None : return if self . ax1 is not None and xlim != self . xlim : self . xlim = xlim self . fig . canvas . toolbar . push_current ( ) self . ax1 . set_xlim ( xlim ) self . ani . e...
handle xlim change requests from queue
41,557
def cmd_lockup_autopilot ( self , args ) : if len ( args ) > 0 and args [ 0 ] == 'IREALLYMEANIT' : print ( "Sending lockup command" ) self . master . mav . command_long_send ( self . settings . target_system , self . settings . target_component , mavutil . mavlink . MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN , 0 , 42 , 24 , 71 ...
lockup autopilot for watchdog testing
41,558
def cmd_gethome ( self , args ) : self . master . mav . command_long_send ( self . settings . target_system , 0 , mavutil . mavlink . MAV_CMD_GET_HOME_POSITION , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 )
get home position
41,559
def cmd_led ( self , args ) : if len ( args ) < 3 : print ( "Usage: led RED GREEN BLUE <RATE>" ) return pattern = [ 0 ] * 24 pattern [ 0 ] = int ( args [ 0 ] ) pattern [ 1 ] = int ( args [ 1 ] ) pattern [ 2 ] = int ( args [ 2 ] ) if len ( args ) == 4 : plen = 4 pattern [ 3 ] = int ( args [ 3 ] ) else : plen = 3 self . ...
send LED pattern as override
41,560
def cmd_oreoled ( self , args ) : if len ( args ) < 4 : print ( "Usage: oreoled LEDNUM RED GREEN BLUE <RATE>" ) return lednum = int ( args [ 0 ] ) pattern = [ 0 ] * 24 pattern [ 0 ] = ord ( 'R' ) pattern [ 1 ] = ord ( 'G' ) pattern [ 2 ] = ord ( 'B' ) pattern [ 3 ] = ord ( '0' ) pattern [ 4 ] = 0 pattern [ 5 ] = int ( ...
send LED pattern as override using OreoLED conventions
41,561
def cmd_playtune ( self , args ) : if len ( args ) < 1 : print ( "Usage: playtune TUNE" ) return tune = args [ 0 ] str1 = tune [ 0 : 30 ] str2 = tune [ 30 : ] if sys . version_info . major >= 3 and not isinstance ( str1 , bytes ) : str1 = bytes ( str1 , "ascii" ) if sys . version_info . major >= 3 and not isinstance ( ...
send PLAY_TUNE message
41,562
def cmd_devid ( self , args ) : for p in self . mav_param . keys ( ) : if p . startswith ( 'COMPASS_DEV_ID' ) : mp_util . decode_devid ( self . mav_param [ p ] , p ) if p . startswith ( 'INS_' ) and p . endswith ( '_ID' ) : mp_util . decode_devid ( self . mav_param [ p ] , p )
decode device IDs from parameters
41,563
def add_menu ( self , menu ) : from MAVProxy . modules . mavproxy_map import mp_slipmap self . default_popup . add ( menu ) self . map . add_object ( mp_slipmap . SlipDefaultPopup ( self . default_popup , combine = True ) )
add to the default popup menu
41,564
def colour_for_wp ( self , wp_num ) : wp = self . module ( 'wp' ) . wploader . wp ( wp_num ) command = wp . command return self . _colour_for_wp_command . get ( command , ( 0 , 255 , 0 ) )
return a tuple describing the colour a waypoint should appear on the map
41,565
def label_for_waypoint ( self , wp_num ) : wp = self . module ( 'wp' ) . wploader . wp ( wp_num ) command = wp . command if command not in self . _label_suffix_for_wp_command : return str ( wp_num ) return str ( wp_num ) + "(" + self . _label_suffix_for_wp_command [ command ] + ")"
return the label the waypoint which should appear on the map
41,566
def remove_mission_nofly ( self , key , selection_index ) : if not self . validate_nofly ( ) : print ( "NoFly invalid" ) return print ( "NoFly valid" ) idx = self . selection_index_to_idx ( key , selection_index ) wploader = self . module ( 'wp' ) . wploader if idx < 0 or idx >= wploader . count ( ) : print ( "Invalid ...
remove a mission nofly polygon
41,567
def handle_menu_event ( self , obj ) : menuitem = obj . menuitem if menuitem . returnkey . startswith ( '# ' ) : cmd = menuitem . returnkey [ 2 : ] if menuitem . handler is not None : if menuitem . handler_result is None : return cmd += menuitem . handler_result self . mpstate . functions . process_stdin ( cmd ) elif m...
handle a popup menu event from the map
41,568
def map_callback ( self , obj ) : from MAVProxy . modules . mavproxy_map import mp_slipmap if isinstance ( obj , mp_slipmap . SlipMenuEvent ) : self . handle_menu_event ( obj ) return if not isinstance ( obj , mp_slipmap . SlipMouseEvent ) : return if obj . event . leftIsDown and self . moving_rally is not None : self ...
called when an event happens on the slipmap
41,569
def drawing_end ( self ) : from MAVProxy . modules . mavproxy_map import mp_slipmap if self . draw_callback is None : return self . draw_callback ( self . draw_line ) self . draw_callback = None self . map . add_object ( mp_slipmap . SlipDefaultPopup ( self . default_popup , combine = True ) ) self . map . add_object (...
end line drawing
41,570
def draw_lines ( self , callback ) : from MAVProxy . modules . mavproxy_map import mp_slipmap self . draw_callback = callback self . draw_line = [ ] self . map . add_object ( mp_slipmap . SlipDefaultPopup ( None ) )
draw a series of connected lines on the map calling callback when done
41,571
def cmd_set_originpos ( self , args ) : ( lat , lon ) = ( self . click_position [ 0 ] , self . click_position [ 1 ] ) print ( "Setting origin to: " , lat , lon ) self . master . mav . set_gps_global_origin_send ( self . settings . target_system , lat * 10000000 , lon * 10000000 , 0 * 1000 )
called when user selects Set Origin on map
41,572
def cmd_center ( self , args ) : if len ( args ) < 3 : print ( "map center LAT LON" ) return lat = float ( args [ 1 ] ) lon = float ( args [ 2 ] ) self . map . set_center ( lat , lon )
control center of view
41,573
def cmd_follow ( self , args ) : if len ( args ) < 2 : print ( "map follow 0|1" ) return follow = int ( args [ 1 ] ) self . map . set_follow ( follow )
control following of vehicle
41,574
def set_secondary_vehicle_position ( self , m ) : if m . get_type ( ) != 'GLOBAL_POSITION_INT' : return ( lat , lon , heading ) = ( m . lat * 1.0e-7 , m . lon * 1.0e-7 , m . hdg * 0.01 ) if abs ( lat ) < 1.0e-3 and abs ( lon ) > 1.0e-3 : return alt = self . ElevationMap . GetElevation ( lat , lon ) agl = m . alt * 0.00...
show 2nd vehicle on map
41,575
def cmd_param ( self , args ) : usage = "Usage: kml <clear | load (filename) | layers | toggle (layername) | fence (layername)>" if len ( args ) < 1 : print ( usage ) return elif args [ 0 ] == "clear" : self . clearkml ( ) elif args [ 0 ] == "snapwp" : self . cmd_snap_wp ( args [ 1 : ] ) elif args [ 0 ] == "snapfence" ...
control kml reading
41,576
def cmd_snap_wp ( self , args ) : threshold = 10.0 if len ( args ) > 0 : threshold = float ( args [ 0 ] ) wpmod = self . module ( 'wp' ) wploader = wpmod . wploader changed = False for i in range ( 1 , wploader . count ( ) ) : w = wploader . wp ( i ) if not wploader . is_location_command ( w . command ) : continue lat ...
snap waypoints to KML
41,577
def cmd_snap_fence ( self , args ) : threshold = 10.0 if len ( args ) > 0 : threshold = float ( args [ 0 ] ) fencemod = self . module ( 'fence' ) loader = fencemod . fenceloader changed = False for i in range ( 0 , loader . count ( ) ) : fp = loader . point ( i ) lat = fp . lat lon = fp . lng best = None best_dist = ( ...
snap fence to KML
41,578
def fencekml ( self , layername ) : if layername . startswith ( '"' ) and layername . endswith ( '"' ) : layername = layername [ 1 : - 1 ] for layer in self . allayers : if layer . key == layername : self . fenceloader . clear ( ) if len ( layer . points ) < 3 : return self . fenceloader . target_system = self . target...
set a layer as the geofence
41,579
def togglekml ( self , layername ) : if layername . startswith ( '"' ) and layername . endswith ( '"' ) : layername = layername [ 1 : - 1 ] if layername in self . curlayers : for layer in self . curlayers : if layer == layername : self . mpstate . map . remove_object ( layer ) self . curlayers . remove ( layername ) if...
toggle the display of a kml
41,580
def clearkml ( self ) : for layer in self . curlayers : self . mpstate . map . remove_object ( layer ) for layer in self . curtextlayers : self . mpstate . map . remove_object ( layer ) self . allayers = [ ] self . curlayers = [ ] self . alltextlayers = [ ] self . curtextlayers = [ ] self . menu_needs_refreshing = True
Clear the kmls from the map
41,581
def loadkml ( self , filename ) : nodes = self . readkmz ( filename ) self . snap_points = [ ] for n in nodes : point = self . readObject ( n ) if self . mpstate . map is not None and point [ 0 ] == 'Polygon' : self . snap_points . extend ( point [ 2 ] ) newcolour = ( random . randint ( 0 , 255 ) , 0 , random . randint...
Load a kml from file and put it on the map
41,582
def idle_task ( self ) : if not self . menu_needs_refreshing : return if self . module ( 'map' ) is not None and not self . menu_added_map : self . menu_added_map = True self . module ( 'map' ) . add_menu ( self . menu ) if mp_util . has_wxpython and self . menu_added_map : self . menu . items = [ MPMenuItem ( 'Clear' ...
handle GUI elements
41,583
def readkmz ( self , filename ) : filename . strip ( '"' ) if filename [ - 4 : ] == '.kml' : fo = open ( filename , "r" ) fstring = fo . read ( ) fo . close ( ) elif filename [ - 4 : ] == '.kmz' : zip = ZipFile ( filename ) for z in zip . filelist : if z . filename [ - 4 : ] == '.kml' : fstring = zip . read ( z ) break...
reads in a kmz file and returns xml nodes
41,584
def cmd_asterix ( self , args ) : usage = "usage: asterix <set|start|stop|restart|status>" if len ( args ) == 0 : print ( usage ) return if args [ 0 ] == "set" : self . asterix_settings . command ( args [ 1 : ] ) elif args [ 0 ] == "start" : self . start_listener ( ) elif args [ 0 ] == "stop" : self . stop_listener ( )...
asterix command parser
41,585
def start_listener ( self ) : if self . sock is not None : self . sock . close ( ) self . sock = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM , socket . IPPROTO_UDP ) self . sock . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , 1 ) self . sock . bind ( ( '' , self . asterix_settings . port ) ) s...
start listening for packets
41,586
def stop_listener ( self ) : if self . sock is not None : self . sock . close ( ) self . sock = None self . tracks = { }
stop listening for packets
41,587
def set_secondary_vehicle_position ( self , m ) : if m . get_type ( ) != 'GLOBAL_POSITION_INT' : return ( lat , lon , heading ) = ( m . lat * 1.0e-7 , m . lon * 1.0e-7 , m . hdg * 0.01 ) if abs ( lat ) < 1.0e-3 and abs ( lon ) < 1.0e-3 : return self . vehicle2_pos = VehiclePos ( m )
store second vehicle position for filtering purposes
41,588
def could_collide_hor ( self , vpos , adsb_pkt ) : margin = self . asterix_settings . filter_dist_xy timeout = self . asterix_settings . filter_time alat = adsb_pkt . lat * 1.0e-7 alon = adsb_pkt . lon * 1.0e-7 avel = adsb_pkt . hor_velocity * 0.01 vvel = sqrt ( vpos . vx ** 2 + vpos . vy ** 2 ) dist = mp_util . gps_di...
return true if vehicle could come within filter_dist_xy meters of adsb vehicle in timeout seconds
41,589
def could_collide_ver ( self , vpos , adsb_pkt ) : if adsb_pkt . emitter_type < 100 or adsb_pkt . emitter_type > 104 : return True margin = self . asterix_settings . filter_dist_z vtype = adsb_pkt . emitter_type - 100 valt = vpos . alt aalt1 = adsb_pkt . altitude * 0.001 if vtype == 2 : return True if vtype == 4 : retu...
return true if vehicle could come within filter_dist_z meters of adsb vehicle in timeout seconds
41,590
def mavlink_packet ( self , m ) : if m . get_type ( ) == 'GLOBAL_POSITION_INT' : if abs ( m . lat ) < 1000 and abs ( m . lon ) < 1000 : return self . vehicle_pos = VehiclePos ( m )
get time from mavlink ATTITUDE
41,591
def complete_serial_ports ( self , text ) : ports = mavutil . auto_detect_serial ( preferred_list = preferred_ports ) return [ p . device for p in ports ]
return list of serial ports
41,592
def complete_links ( self , text ) : try : ret = [ m . address for m in self . mpstate . mav_master ] for m in self . mpstate . mav_master : ret . append ( m . address ) if hasattr ( m , 'label' ) : ret . append ( m . label ) return ret except Exception as e : print ( "Caught exception: %s" % str ( e ) )
return list of links
41,593
def cmd_link_attributes ( self , args ) : link = args [ 0 ] attributes = args [ 1 ] print ( "Setting link %s attributes (%s)" % ( link , attributes ) ) self . link_attributes ( link , attributes )
change optional link attributes
41,594
def find_link ( self , device ) : for i in range ( len ( self . mpstate . mav_master ) ) : conn = self . mpstate . mav_master [ i ] if ( str ( i ) == device or conn . address == device or getattr ( conn , 'label' , None ) == device ) : return i return None
find a device based on number name or label
41,595
def cmd_link_remove ( self , args ) : device = args [ 0 ] if len ( self . mpstate . mav_master ) <= 1 : print ( "Not removing last link" ) return i = self . find_link ( device ) if i is None : return conn = self . mpstate . mav_master [ i ] print ( "Removing link %s" % conn . address ) try : try : mp_util . child_fd_li...
remove an link
41,596
def master_send_callback ( self , m , master ) : if self . status . watch is not None : for msg_type in self . status . watch : if fnmatch . fnmatch ( m . get_type ( ) . upper ( ) , msg_type . upper ( ) ) : self . mpstate . console . writeln ( '> ' + str ( m ) ) break mtype = m . get_type ( ) if mtype != 'BAD_DATA' and...
called on sending a message
41,597
def handle_msec_timestamp ( self , m , master ) : if m . get_type ( ) == 'GLOBAL_POSITION_INT' : return msec = m . time_boot_ms if msec + 30000 < master . highest_msec : self . say ( 'Time has wrapped' ) print ( 'Time has wrapped' , msec , master . highest_msec ) self . status . highest_msec = msec for mm in self . mps...
special handling for MAVLink packets with a time_boot_ms field
41,598
def report_altitude ( self , altitude ) : master = self . master if getattr ( self . console , 'ElevationMap' , None ) is not None and self . mpstate . settings . basealt != 0 : lat = master . field ( 'GLOBAL_POSITION_INT' , 'lat' , 0 ) * 1.0e-7 lon = master . field ( 'GLOBAL_POSITION_INT' , 'lon' , 0 ) * 1.0e-7 alt1 =...
possibly report a new altitude
41,599
def cmd_vehicle ( self , args ) : if len ( args ) < 1 : print ( "Usage: vehicle SYSID[:COMPID]" ) return a = args [ 0 ] . split ( ':' ) self . mpstate . settings . target_system = int ( a [ 0 ] ) if len ( a ) > 1 : self . mpstate . settings . target_component = int ( a [ 1 ] ) best_link = 0 best_timestamp = 0 for i in ...
handle vehicle commands