idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
41,300
def set_menu ( self , menu ) : self . menu = menu self . in_queue . put ( MPImageMenu ( menu ) )
set a MPTopMenu on the frame
41,301
def set_popup_menu ( self , menu ) : self . popup_menu = menu self . in_queue . put ( MPImagePopupMenu ( menu ) )
set a popup menu on the frame
41,302
def image_coordinates ( self , point ) : ret = wx . Point ( int ( self . dragpos . x + point . x / self . zoom ) , int ( self . dragpos . y + point . y / self . zoom ) ) return ret
given a point in window coordinates calculate image coordinates
41,303
def redraw ( self ) : state = self . state if self . img is None : self . mainSizer . Fit ( self ) self . Refresh ( ) state . frame . Refresh ( ) self . SetFocus ( ) return size = self . frame . GetSize ( ) ( width , height ) = ( self . img . GetWidth ( ) , self . img . GetHeight ( ) ) rect = wx . Rect ( self . dragpos...
redraw the image with current settings
41,304
def limit_dragpos ( self ) : if self . dragpos . x < 0 : self . dragpos . x = 0 if self . dragpos . y < 0 : self . dragpos . y = 0 if self . img is None : return if self . dragpos . x >= self . img . GetWidth ( ) : self . dragpos . x = self . img . GetWidth ( ) - 1 if self . dragpos . y >= self . img . GetHeight ( ) : ...
limit dragpos to sane values
41,305
def on_drag_event ( self , event ) : state = self . state if not state . can_drag : return newpos = self . image_coordinates ( event . GetPosition ( ) ) dx = - ( newpos . x - self . mouse_down . x ) dy = - ( newpos . y - self . mouse_down . y ) self . dragpos = wx . Point ( self . dragpos . x + dx , self . dragpos . y ...
handle mouse drags
41,306
def show_popup_menu ( self , pos ) : self . popup_pos = self . image_coordinates ( pos ) self . frame . PopupMenu ( self . wx_popup_menu , pos )
show a popup menu
41,307
def on_key_event ( self , event ) : keycode = event . GetKeyCode ( ) if keycode == wx . WXK_HOME : self . zoom = 1.0 self . dragpos = wx . Point ( 0 , 0 ) self . need_redraw = True
handle key events
41,308
def on_event ( self , event ) : state = self . state if isinstance ( event , wx . MouseEvent ) : self . on_mouse_event ( event ) if isinstance ( event , wx . KeyEvent ) : self . on_key_event ( event ) if ( isinstance ( event , wx . MouseEvent ) and not event . ButtonIsDown ( wx . MOUSE_BTN_ANY ) and event . GetWheelRot...
pass events to the parent
41,309
def on_menu ( self , event ) : state = self . state if self . popup_menu is not None : ret = self . popup_menu . find_selected ( event ) if ret is not None : ret . popup_pos = self . popup_pos if ret . returnkey == 'fitWindow' : self . fit_to_window ( ) elif ret . returnkey == 'fullSize' : self . full_size ( ) else : s...
called on menu event
41,310
def set_menu ( self , menu ) : self . menu = menu wx_menu = menu . wx_menu ( ) self . frame . SetMenuBar ( wx_menu ) self . frame . Bind ( wx . EVT_MENU , self . on_menu )
add a menu from the parent
41,311
def set_popup_menu ( self , menu ) : self . popup_menu = menu if menu is None : self . wx_popup_menu = None else : self . wx_popup_menu = menu . wx_menu ( ) self . frame . Bind ( wx . EVT_MENU , self . on_menu )
add a popup menu from the parent
41,312
def fit_to_window ( self ) : state = self . state self . dragpos = wx . Point ( 0 , 0 ) client_area = state . frame . GetClientSize ( ) self . zoom = min ( float ( client_area . x ) / self . img . GetWidth ( ) , float ( client_area . y ) / self . img . GetHeight ( ) ) self . need_redraw = True
fit image to window
41,313
def full_size ( self ) : self . dragpos = wx . Point ( 0 , 0 ) self . zoom = 1.0 self . need_redraw = True
show image at full size
41,314
def mavmission ( logfile ) : mlog = mavutil . mavlink_connection ( filename ) wp = mavwp . MAVWPLoader ( ) while True : m = mlog . recv_match ( type = [ 'MISSION_ITEM' , 'CMD' , 'WAYPOINT' ] ) if m is None : break if m . get_type ( ) == 'CMD' : m = mavutil . mavlink . MAVLink_mission_item_message ( 0 , 0 , m . CNum , m...
extract mavlink mission
41,315
def message_checksum ( msg ) : from . mavcrc import x25crc crc = x25crc ( ) crc . accumulate_str ( msg . name + ' ' ) crc_end = msg . base_fields ( ) for i in range ( crc_end ) : f = msg . ordered_fields [ i ] crc . accumulate_str ( f . type + ' ' ) crc . accumulate_str ( f . name + ' ' ) if f . array_length : crc . ac...
calculate a 8 - bit checksum of the key fields of a message so we can detect incompatible XML changes
41,316
def merge_enums ( xml ) : emap = { } for x in xml : newenums = [ ] for enum in x . enum : if enum . name in emap : emapitem = emap [ enum . name ] if ( emapitem . start_value <= enum . highest_value and emapitem . highest_value >= enum . start_value ) : for entry in emapitem . entry : if entry . value <= enum . highest...
merge enums between XML files
41,317
def check_duplicates ( xml ) : merge_enums ( xml ) msgmap = { } enummap = { } for x in xml : for m in x . message : key = m . id if key in msgmap : print ( "ERROR: Duplicate message id %u for %s (%s:%u) also used by %s" % ( m . id , m . name , x . filename , m . linenumber , msgmap [ key ] ) ) return True fieldset = se...
check for duplicate message IDs
41,318
def total_msgs ( xml ) : count = 0 for x in xml : count += len ( x . message ) return count
count total number of msgs
41,319
def base_fields ( self ) : if self . extensions_start is None : return len ( self . fields ) return len ( self . fields [ : self . extensions_start ] )
return number of non - extended fields
41,320
def _dataflash_dir ( self , mpstate ) : if mpstate . settings . state_basedir is None : ret = 'dataflash' else : ret = os . path . join ( mpstate . settings . state_basedir , 'dataflash' ) try : os . makedirs ( ret ) except OSError as e : if e . errno != errno . EEXIST : print ( "DFLogger: OSError making (%s): %s" % ( ...
returns directory path to store DF logs in . May be relative
41,321
def new_log_filepath ( self ) : lastlog_filename = os . path . join ( self . dataflash_dir , 'LASTLOG.TXT' ) if os . path . exists ( lastlog_filename ) and os . stat ( lastlog_filename ) . st_size != 0 : fh = open ( lastlog_filename , 'rb' ) log_cnt = int ( fh . read ( ) ) + 1 fh . close ( ) else : log_cnt = 1 self . l...
returns a filepath to a log which does not currently exist and is suitable for DF logging
41,322
def start_new_log ( self ) : filename = self . new_log_filepath ( ) self . block_cnt = 0 self . logfile = open ( filename , 'w+b' ) print ( "DFLogger: logging started (%s)" % ( filename ) ) self . prev_cnt = 0 self . download = 0 self . prev_download = 0 self . last_idle_status_printed_time = time . time ( ) self . las...
open a new dataflash log reset state
41,323
def mavlink_packet ( self , m ) : now = time . time ( ) if m . get_type ( ) == 'REMOTE_LOG_DATA_BLOCK' : if self . stopped : if now - self . time_last_stop_packet_sent > 1 : if self . log_settings . verbose : print ( "DFLogger: Sending stop packet" ) self . master . mav . remote_log_block_status_send ( mavutil . mavlin...
handle REMOTE_LOG_DATA_BLOCK packets
41,324
def meminfo_send ( self , brkval , freemem , force_mavlink1 = False ) : return self . send ( self . meminfo_encode ( brkval , freemem ) , force_mavlink1 = force_mavlink1 )
state of APM memory
41,325
def older_message ( m , lastm ) : atts = { 'time_boot_ms' : 1.0e-3 , 'time_unix_usec' : 1.0e-6 , 'time_usec' : 1.0e-6 } for a in atts . keys ( ) : if hasattr ( m , a ) : mul = atts [ a ] t1 = m . getattr ( a ) * mul t2 = lastm . getattr ( a ) * mul if t2 >= t1 and t2 - t1 < 60 : return True return False
return true if m is older than lastm by timestamp
41,326
def process ( filename ) : print ( "Processing %s" % filename ) mlog = mavutil . mavlink_connection ( filename , notimestamps = args . notimestamps , robust_parsing = args . robust ) ext = os . path . splitext ( filename ) [ 1 ] isbin = ext in [ '.bin' , '.BIN' ] islog = ext in [ '.log' , '.LOG' ] output = None count =...
process one logfile
41,327
def handle_log_entry ( self , m ) : if m . time_utc == 0 : tstring = '' else : tstring = time . ctime ( m . time_utc ) self . entries [ m . id ] = m print ( "Log %u numLogs %u lastLog %u size %u %s" % ( m . id , m . num_logs , m . last_log_num , m . size , tstring ) )
handling incoming log entry
41,328
def handle_log_data_missing ( self ) : if len ( self . download_set ) == 0 : return highest = max ( self . download_set ) diff = set ( range ( highest ) ) . difference ( self . download_set ) if len ( diff ) == 0 : self . master . mav . log_request_data_send ( self . target_system , self . target_component , self . dow...
handling missing incoming log data
41,329
def log_status ( self ) : if self . download_filename is None : print ( "No download" ) return dt = time . time ( ) - self . download_start speed = os . path . getsize ( self . download_filename ) / ( 1000.0 * dt ) m = self . entries . get ( self . download_lognum , None ) if m is None : size = 0 else : size = m . size...
show download status
41,330
def log_download ( self , log_num , filename ) : print ( "Downloading log %u as %s" % ( log_num , filename ) ) self . download_lognum = log_num self . download_file = open ( filename , "wb" ) self . master . mav . log_request_data_send ( self . target_system , self . target_component , log_num , 0 , 0xFFFFFFFF ) self ....
download a log file
41,331
def idle_task ( self ) : if self . download_last_timestamp is not None and time . time ( ) - self . download_last_timestamp > 0.7 : self . download_last_timestamp = time . time ( ) self . handle_log_data_missing ( )
handle missing log data
41,332
def complete_modules ( text ) : import MAVProxy . modules , pkgutil modlist = [ x [ 1 ] for x in pkgutil . iter_modules ( MAVProxy . modules . __path__ ) ] ret = [ ] loaded = set ( complete_loadedmodules ( '' ) ) for m in modlist : if not m . startswith ( "mavproxy_" ) : continue name = m [ 9 : ] if not name in loaded ...
complete mavproxy module names
41,333
def complete_filename ( text ) : list = glob . glob ( text + '*' ) for idx , val in enumerate ( list ) : if os . path . isdir ( val ) : list [ idx ] = ( val + os . path . sep ) return list
complete a filename
41,334
def complete_variable ( text ) : if text . find ( '.' ) != - 1 : var = text . split ( '.' ) [ 0 ] if var in rline_mpstate . status . msgs : ret = [ ] for f in rline_mpstate . status . msgs [ var ] . get_fieldnames ( ) : ret . append ( var + '.' + f ) return ret return [ ] return rline_mpstate . status . msgs . keys ( )
complete a MAVLink variable
41,335
def rule_expand ( component , text ) : global rline_mpstate if component [ 0 ] == '<' and component [ - 1 ] == '>' : return component [ 1 : - 1 ] . split ( '|' ) if component in rline_mpstate . completion_functions : return rline_mpstate . completion_functions [ component ] ( text ) return [ component ]
expand one rule component
41,336
def rule_match ( component , cmd ) : if component == cmd : return True expanded = rule_expand ( component , cmd ) if cmd in expanded : return True return False
see if one rule component matches
41,337
def complete_rules ( rules , cmd ) : if not isinstance ( rules , list ) : rules = [ rules ] ret = [ ] for r in rules : ret += complete_rule ( r , cmd ) return ret
complete using a list of completion rules
41,338
def complete ( text , state ) : global last_clist global rline_mpstate if state != 0 and last_clist is not None : return last_clist [ state ] cmd = readline . get_line_buffer ( ) . split ( ) if len ( cmd ) == 1 : last_clist = complete_command ( text ) + complete_alias ( text ) elif cmd [ 0 ] in rline_mpstate . completi...
completion routine for when user presses tab
41,339
def laserScan2LaserData ( scan ) : laser = LaserData ( ) laser . values = scan . ranges laser . minAngle = scan . angle_min + PI / 2 laser . maxAngle = scan . angle_max + PI / 2 laser . maxRange = scan . range_max laser . minRange = scan . range_min laser . timeStamp = scan . header . stamp . secs + ( scan . header . s...
Translates from ROS LaserScan to JderobotTypes LaserData .
41,340
def __callback ( self , scan ) : laser = laserScan2LaserData ( scan ) self . lock . acquire ( ) self . data = laser self . lock . release ( )
Callback function to receive and save Laser Scans .
41,341
def add_to_linestring ( position_data , kml_linestring ) : global kml position_data [ 2 ] += float ( args . aoff ) kml_linestring . coords . addcoordinates ( [ position_data ] )
add a point to the kml file
41,342
def sniff_field_spelling ( mlog , source ) : position_field_type_default = position_field_types [ 0 ] msg = mlog . recv_match ( source ) mlog . _rewind ( ) position_field_selection = [ spelling for spelling in position_field_types if hasattr ( msg , spelling [ 0 ] ) ] return position_field_selection [ 0 ] if position_f...
attempt to detect whether APM or PX4 attributes names are in use
41,343
def cmd_link_ports ( self ) : ports = mavutil . auto_detect_serial ( preferred_list = [ '*FTDI*' , "*Arduino_Mega_2560*" , "*3D_Robotics*" , "*USB_to_UART*" , '*PX4*' , '*FMU*' ] ) for p in ports : print ( "%s : %s : %s" % ( p . device , p . description , p . hwid ) )
show available ports
41,344
def writeln ( self , text , fg = 'black' , bg = 'white' ) : if not isinstance ( text , str ) : text = str ( text ) self . write ( text + '\n' , fg = fg , bg = bg )
write to the console with linefeed
41,345
def match_extension ( f ) : ( root , ext ) = os . path . splitext ( f ) return ext . lower ( ) in extensions
see if the path matches a extension
41,346
def path ( self ) : ( x , y ) = self . tile return os . path . join ( '%u' % self . zoom , '%u' % y , '%u.img' % x )
return relative path of tile image
41,347
def url ( self , service ) : if service not in TILE_SERVICES : raise TileException ( 'unknown tile service %s' % service ) url = string . Template ( TILE_SERVICES [ service ] ) ( x , y ) = self . tile tile_info = TileServiceInfo ( x , y , self . zoom ) return url . substitute ( tile_info )
return URL for a tile
41,348
def tile_to_path ( self , tile ) : return os . path . join ( self . cache_path , self . service , tile . path ( ) )
return full path to a tile
41,349
def start_download_thread ( self ) : if self . _download_thread : return t = threading . Thread ( target = self . downloader ) t . daemon = True self . _download_thread = t t . start ( )
start the downloader
41,350
def qnh_estimate ( self ) : alt_gps = self . master . field ( 'GPS_RAW_INT' , 'alt' , 0 ) * 0.001 pressure2 = self . master . field ( 'SCALED_PRESSURE' , 'press_abs' , 0 ) ground_temp = self . get_mav_param ( 'GND_TEMP' , 21 ) temp = ground_temp + 273.15 pressure1 = pressure2 / math . exp ( math . log ( 1.0 - ( alt_gps...
estimate QNH pressure from GPS altitude and scaled pressure
41,351
def cmd_up ( self , args ) : if len ( args ) == 0 : adjust = 5.0 else : adjust = float ( args [ 0 ] ) old_trim = self . get_mav_param ( 'TRIM_PITCH_CD' , None ) if old_trim is None : print ( "Existing trim value unknown!" ) return new_trim = int ( old_trim + ( adjust * 100 ) ) if math . fabs ( new_trim - old_trim ) > 1...
adjust TRIM_PITCH_CD up by 5 degrees
41,352
def cmd_time ( self , args ) : tusec = self . master . field ( 'SYSTEM_TIME' , 'time_unix_usec' , 0 ) if tusec == 0 : print ( "No SYSTEM_TIME time available" ) return print ( "%s (%s)\n" % ( time . ctime ( tusec * 1.0e-6 ) , time . ctime ( ) ) )
show autopilot time
41,353
def cmd_changealt ( self , args ) : if len ( args ) < 1 : print ( "usage: changealt <relaltitude>" ) return relalt = float ( args [ 0 ] ) self . master . mav . mission_item_send ( self . settings . target_system , self . settings . target_component , 0 , 3 , mavutil . mavlink . MAV_CMD_NAV_WAYPOINT , 3 , 1 , 0 , 0 , 0 ...
change target altitude
41,354
def cmd_land ( self , args ) : if len ( args ) < 1 : self . master . mav . command_long_send ( self . settings . target_system , 0 , mavutil . mavlink . MAV_CMD_DO_LAND_START , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) elif args [ 0 ] == 'abort' : self . master . mav . command_long_send ( self . settings . target_system , 0 , ma...
auto land commands
41,355
def cmd_rcbind ( self , args ) : if len ( args ) < 1 : print ( "Usage: rcbind <dsmmode>" ) return self . master . mav . command_long_send ( self . settings . target_system , self . settings . target_component , mavutil . mavlink . MAV_CMD_START_RX_PAIR , 0 , float ( args [ 0 ] ) , 0 , 0 , 0 , 0 , 0 , 0 )
start RC bind
41,356
def cmd_repeat ( self , args ) : if len ( args ) == 0 : if len ( self . repeats ) == 0 : print ( "No repeats" ) return for i in range ( len ( self . repeats ) ) : print ( "%u: %s" % ( i , self . repeats [ i ] ) ) return if args [ 0 ] == 'add' : if len ( args ) < 3 : print ( "Usage: repeat add PERIOD CMD" ) return self ...
repeat a command at regular intervals
41,357
def show_position ( self ) : pos = self . click_position dms = ( mp_util . degrees_to_dms ( pos [ 0 ] ) , mp_util . degrees_to_dms ( pos [ 1 ] ) ) msg = "Coordinates in WGS84\n" msg += "Decimal: %.6f %.6f\n" % ( pos [ 0 ] , pos [ 1 ] ) msg += "DMS: %s %s\n" % ( dms [ 0 ] , dms [ 1 ] ) msg += "Grid: %s\n" % mp_ut...
show map position click information
41,358
def display_fence ( self ) : from MAVProxy . modules . mavproxy_map import mp_slipmap self . fence_change_time = self . module ( 'fence' ) . fenceloader . last_change points = self . module ( 'fence' ) . fenceloader . polygon ( ) self . mpstate . map . add_object ( mp_slipmap . SlipClearLayer ( 'Fence' ) ) if len ( poi...
display the fence
41,359
def closest_waypoint ( self , latlon ) : ( lat , lon ) = latlon best_distance = - 1 closest = - 1 for i in range ( self . module ( 'wp' ) . wploader . count ( ) ) : w = self . module ( 'wp' ) . wploader . wp ( i ) distance = mp_util . gps_distance ( lat , lon , w . x , w . y ) if best_distance == - 1 or distance < best...
find closest waypoint to a position
41,360
def selection_index_to_idx ( self , key , selection_index ) : a = key . split ( ' ' ) if a [ 0 ] != 'mission' or len ( a ) != 2 : print ( "Bad mission object %s" % key ) return None midx = int ( a [ 1 ] ) if midx < 0 or midx >= len ( self . mission_list ) : print ( "Bad mission index %s" % key ) return None mlist = sel...
return a mission idx from a selection_index
41,361
def move_mission ( self , key , selection_index ) : idx = self . selection_index_to_idx ( key , selection_index ) self . moving_wp = idx print ( "Moving wp %u" % idx )
move a mission point
41,362
def remove_mission ( self , key , selection_index ) : idx = self . selection_index_to_idx ( key , selection_index ) self . mpstate . functions . process_stdin ( 'wp remove %u' % idx )
remove a mission point
41,363
def create_vehicle_icon ( self , name , colour , follow = False , vehicle_type = None ) : from MAVProxy . modules . mavproxy_map import mp_slipmap if vehicle_type is None : vehicle_type = self . vehicle_type_name if name in self . have_vehicle and self . have_vehicle [ name ] == vehicle_type : return self . have_vehicl...
add a vehicle to the map
41,364
def drawing_update ( self ) : from MAVProxy . modules . mavproxy_map import mp_slipmap if self . draw_callback is None : return self . draw_line . append ( self . click_position ) if len ( self . draw_line ) > 1 : self . mpstate . map . add_object ( mp_slipmap . SlipPolygon ( 'drawing' , self . draw_line , layer = 'Dra...
update line drawing
41,365
def load ( filename ) : filepath = findConfigFile ( filename ) prop = None if ( filepath ) : print ( 'loading Config file %s' % ( filepath ) ) with open ( filepath , 'r' ) as stream : cfg = yaml . load ( stream ) prop = Properties ( cfg ) else : msg = "Ice.Config file '%s' could not being found" % ( filename ) raise Va...
Returns the configuration as dict
41,366
def fetch_check ( self , master ) : if self . param_period . trigger ( ) : if master is None : return if len ( self . mav_param_set ) == 0 : master . param_fetch_all ( ) elif self . mav_param_count != 0 and len ( self . mav_param_set ) != self . mav_param_count : if master . time_since ( 'PARAM_VALUE' ) >= 1 : diff = s...
check for missing parameters periodically
41,367
def watch_thread ( self ) : from mp_settings import MPSetting while True : setting = self . child_pipe . recv ( ) if not isinstance ( setting , MPSetting ) : break try : self . settings . set ( setting . name , setting . value ) except Exception : print ( "Unable to set %s to %s" % ( setting . name , setting . value ) ...
watch for settings changes from child
41,368
def report ( self , name , ok , msg = None , deltat = 20 ) : r = self . reports [ name ] if time . time ( ) < r . last_report + deltat : r . ok = ok return r . last_report = time . time ( ) if ok and not r . ok : self . say ( "%s OK" % name ) r . ok = ok if not r . ok : self . say ( msg )
report a sensor error
41,369
def report_change ( self , name , value , maxdiff = 1 , deltat = 10 ) : r = self . reports [ name ] if time . time ( ) < r . last_report + deltat : return r . last_report = time . time ( ) if math . fabs ( r . value - value ) < maxdiff : return r . value = value self . say ( "%s %u" % ( name , value ) )
report a sensor change
41,370
def close ( self ) : self . close_window . release ( ) count = 0 while self . child . is_alive ( ) and count < 30 : time . sleep ( 0.1 ) count += 1 if self . child . is_alive ( ) : self . child . terminate ( ) self . child . join ( )
close the window
41,371
def hide_object ( self , key , hide = True ) : self . object_queue . put ( SlipHideObject ( key , hide ) )
hide an object on the map by key
41,372
def set_position ( self , key , latlon , layer = None , rotation = 0 ) : self . object_queue . put ( SlipPosition ( key , latlon , layer , rotation ) )
move an object on the map
41,373
def check_events ( self ) : while self . event_count ( ) > 0 : event = self . get_event ( ) for callback in self . _callbacks : callback ( event )
check for events calling registered callbacks as needed
41,374
def radius_cmp ( a , b , offsets ) : diff = radius ( a , offsets ) - radius ( b , offsets ) if diff > 0 : return 1 if diff < 0 : return - 1 return 0
return + 1 or - 1 for for sorting
41,375
def plot_data ( orig_data , data ) : import numpy as np from mpl_toolkits . mplot3d import Axes3D import matplotlib . pyplot as plt for dd , c in [ ( orig_data , 'r' ) , ( data , 'b' ) ] : fig = plt . figure ( ) ax = fig . add_subplot ( 111 , projection = '3d' ) xs = [ d . x for d in dd ] ys = [ d . y for d in dd ] zs ...
plot data in 3D
41,376
def find_end ( self , text , start_token , end_token , ignore_end_token = None ) : if not text . startswith ( start_token ) : raise MAVParseError ( "invalid token start" ) offset = len ( start_token ) nesting = 1 while nesting > 0 : idx1 = text [ offset : ] . find ( start_token ) idx2 = text [ offset : ] . find ( end_t...
find the of a token . Returns the offset in the string immediately after the matching end_token
41,377
def find_var_end ( self , text ) : return self . find_end ( text , self . start_var_token , self . end_var_token )
find the of a variable
41,378
def find_rep_end ( self , text ) : return self . find_end ( text , self . start_rep_token , self . end_rep_token , ignore_end_token = self . end_var_token )
find the of a repitition
41,379
def write ( self , file , text , subvars = { } , trim_leading_lf = True ) : file . write ( self . substitute ( text , subvars = subvars , trim_leading_lf = trim_leading_lf ) )
write to a file with variable substitution
41,380
def flight_time ( logfile ) : print ( "Processing log %s" % filename ) mlog = mavutil . mavlink_connection ( filename ) in_air = False start_time = 0.0 total_time = 0.0 total_dist = 0.0 t = None last_msg = None last_time_usec = None while True : m = mlog . recv_match ( type = [ 'GPS' , 'GPS_RAW_INT' ] , condition = arg...
work out flight time for a log file
41,381
def match_type ( mtype , patterns ) : for p in patterns : if fnmatch . fnmatch ( mtype , p ) : return True return False
return True if mtype matches pattern
41,382
def apply ( self , img ) : yup , uup , vup = self . getUpLimit ( ) ydwn , udwn , vdwn = self . getDownLimit ( ) yuv = cv2 . cvtColor ( img , cv2 . COLOR_BGR2YUV ) minValues = np . array ( [ ydwn , udwn , vdwn ] , dtype = np . uint8 ) maxValues = np . array ( [ yup , uup , vup ] , dtype = np . uint8 ) mask = cv2 . inRan...
We convert RGB as BGR because OpenCV with RGB pass to YVU instead of YUV
41,383
def on_menu ( self , event ) : state = self . state ret = self . menu . find_selected ( event ) if ret is None : return ret . call_handler ( ) state . child_pipe_send . send ( ret )
handle menu selections
41,384
def aslctrl_data_encode ( self , timestamp , aslctrl_mode , h , hRef , hRef_t , PitchAngle , PitchAngleRef , q , qRef , uElev , uThrot , uThrot2 , nZ , AirspeedRef , SpoilersEngaged , YawAngle , YawAngleRef , RollAngle , RollAngleRef , p , pRef , r , rRef , uAil , uRud ) : return MAVLink_aslctrl_data_message ( timestam...
ASL - fixed - wing controller data
41,385
def average ( var , key , N ) : global average_data if not key in average_data : average_data [ key ] = [ var ] * N return var average_data [ key ] . pop ( 0 ) average_data [ key ] . append ( var ) return sum ( average_data [ key ] ) / N
average over N points
41,386
def second_derivative_5 ( var , key ) : global derivative_data import mavutil tnow = mavutil . mavfile_global . timestamp if not key in derivative_data : derivative_data [ key ] = ( tnow , [ var ] * 5 ) return 0 ( last_time , data ) = derivative_data [ key ] data . pop ( 0 ) data . append ( var ) derivative_data [ key ...
5 point 2nd derivative
41,387
def lowpass ( var , key , factor ) : global lowpass_data if not key in lowpass_data : lowpass_data [ key ] = var else : lowpass_data [ key ] = factor * lowpass_data [ key ] + ( 1.0 - factor ) * var return lowpass_data [ key ]
a simple lowpass filter
41,388
def diff ( var , key ) : global last_diff ret = 0 if not key in last_diff : last_diff [ key ] = var return 0 ret = var - last_diff [ key ] last_diff [ key ] = var return ret
calculate differences between values
41,389
def roll_estimate ( RAW_IMU , GPS_RAW_INT = None , ATTITUDE = None , SENSOR_OFFSETS = None , ofs = None , mul = None , smooth = 0.7 ) : rx = RAW_IMU . xacc * 9.81 / 1000.0 ry = RAW_IMU . yacc * 9.81 / 1000.0 rz = RAW_IMU . zacc * 9.81 / 1000.0 if ATTITUDE is not None and GPS_RAW_INT is not None : ry -= ATTITUDE . yawsp...
estimate roll from accelerometer
41,390
def mag_rotation ( RAW_IMU , inclination , declination ) : m_body = Vector3 ( RAW_IMU . xmag , RAW_IMU . ymag , RAW_IMU . zmag ) m_earth = Vector3 ( m_body . length ( ) , 0 , 0 ) r = Matrix3 ( ) r . from_euler ( 0 , - radians ( inclination ) , radians ( declination ) ) m_earth = r * m_earth r . from_two_vectors ( m_ear...
return an attitude rotation matrix that is consistent with the current mag vector
41,391
def mag_yaw ( RAW_IMU , inclination , declination ) : m = mag_rotation ( RAW_IMU , inclination , declination ) ( r , p , y ) = m . to_euler ( ) y = degrees ( y ) if y < 0 : y += 360 return y
estimate yaw from mag
41,392
def mag_roll ( RAW_IMU , inclination , declination ) : m = mag_rotation ( RAW_IMU , inclination , declination ) ( r , p , y ) = m . to_euler ( ) return degrees ( r )
estimate roll from mag
41,393
def expected_mag ( RAW_IMU , ATTITUDE , inclination , declination ) : m_body = Vector3 ( RAW_IMU . xmag , RAW_IMU . ymag , RAW_IMU . zmag ) field_strength = m_body . length ( ) m = rotation ( ATTITUDE ) r = Matrix3 ( ) r . from_euler ( 0 , - radians ( inclination ) , radians ( declination ) ) m_earth = r * Vector3 ( fi...
return expected mag vector
41,394
def gravity ( RAW_IMU , SENSOR_OFFSETS = None , ofs = None , mul = None , smooth = 0.7 ) : if hasattr ( RAW_IMU , 'xacc' ) : rx = RAW_IMU . xacc * 9.81 / 1000.0 ry = RAW_IMU . yacc * 9.81 / 1000.0 rz = RAW_IMU . zacc * 9.81 / 1000.0 else : rx = RAW_IMU . AccX ry = RAW_IMU . AccY rz = RAW_IMU . AccZ if SENSOR_OFFSETS is...
estimate pitch from accelerometer
41,395
def pitch_sim ( SIMSTATE , GPS_RAW ) : xacc = SIMSTATE . xacc - lowpass ( delta ( GPS_RAW . v , "v" ) * 6.6 , "v" , 0.9 ) zacc = SIMSTATE . zacc zacc += SIMSTATE . ygyro * GPS_RAW . v if xacc / zacc >= 1 : return 0 if xacc / zacc <= - 1 : return - 0 return degrees ( - asin ( xacc / zacc ) )
estimate pitch from SIMSTATE accels
41,396
def distance_home ( GPS_RAW ) : global first_fix if ( hasattr ( GPS_RAW , 'fix_type' ) and GPS_RAW . fix_type < 2 ) or ( hasattr ( GPS_RAW , 'Status' ) and GPS_RAW . Status < 2 ) : return 0 if first_fix == None : first_fix = GPS_RAW return 0 return distance_two ( GPS_RAW , first_fix )
distance from first fix point
41,397
def sawtooth ( ATTITUDE , amplitude = 2.0 , period = 5.0 ) : mins = ( ATTITUDE . usec * 1.0e-6 ) / 60 p = fmod ( mins , period * 2 ) if p < period : return amplitude * ( p / period ) return amplitude * ( period - ( p - period ) ) / period
sawtooth pattern based on uptime
41,398
def EAS2TAS ( ARSP , GPS , BARO , ground_temp = 25 ) : tempK = ground_temp + 273.15 - 0.0065 * GPS . Alt return sqrt ( 1.225 / ( BARO . Press / ( 287.26 * tempK ) ) )
EAS2TAS from ARSP . Temp
41,399
def airspeed_voltage ( VFR_HUD , ratio = None ) : import mavutil mav = mavutil . mavfile_global if ratio is None : ratio = 1.9936 if 'ARSPD_RATIO' in mav . params : used_ratio = mav . params [ 'ARSPD_RATIO' ] else : used_ratio = ratio if 'ARSPD_OFFSET' in mav . params : offset = mav . params [ 'ARSPD_OFFSET' ] else : r...
back - calculate the voltage the airspeed sensor must have seen