idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
230,400
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
230,401
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
230,402
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
230,403
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
230,404
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 .
230,405
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
230,406
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
230,407
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
230,408
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
230,409
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
230,410
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
230,411
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
230,412
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
230,413
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
230,414
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
230,415
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
230,416
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
230,417
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
230,418
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
230,419
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
230,420
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
230,421
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
230,422
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
230,423
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
230,424
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
230,425
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
230,426
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
230,427
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
230,428
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
230,429
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
230,430
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
230,431
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
230,432
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
230,433
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
230,434
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
230,435
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
230,436
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
230,437
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
230,438
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
230,439
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
230,440
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
230,441
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
230,442
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
230,443
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
230,444
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
230,445
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
230,446
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
230,447
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
230,448
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
230,449
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
230,450
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
230,451
def stop_listener ( self ) : if self . sock is not None : self . sock . close ( ) self . sock = None self . tracks = { }
stop listening for packets
230,452
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
230,453
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
230,454
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
230,455
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
230,456
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
230,457
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
230,458
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
230,459
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
230,460
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
230,461
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
230,462
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
230,463
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
230,464
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
230,465
def devop_read ( self , args , bustype ) : if len ( args ) < 5 : print ( "Usage: devop read <spi|i2c> name bus address regstart count" ) return name = args [ 0 ] bus = int ( args [ 1 ] , base = 0 ) address = int ( args [ 2 ] , base = 0 ) reg = int ( args [ 3 ] , base = 0 ) count = int ( args [ 4 ] , base = 0 ) self . m...
read from device
230,466
def devop_write ( self , args , bustype ) : usage = "Usage: devop write <spi|i2c> name bus address regstart count <bytes>" if len ( args ) < 5 : print ( usage ) return name = args [ 0 ] bus = int ( args [ 1 ] , base = 0 ) address = int ( args [ 2 ] , base = 0 ) reg = int ( args [ 3 ] , base = 0 ) count = int ( args [ 4...
write to a device
230,467
def get_absolute ( self , points ) : is_list = isinstance ( points , list ) points = ensure_numeric ( points , num . float ) if len ( points . shape ) == 1 : msg = 'Single point must have two elements' if not len ( points ) == 2 : raise ValueError ( msg ) msg = 'Input must be an N x 2 array or list of (x,y) values. ' m...
Given a set of points geo referenced to this instance return the points as absolute values .
230,468
def cmd_cameraview ( self , args ) : state = self if args and args [ 0 ] == 'set' : if len ( args ) < 3 : state . view_settings . show_all ( ) else : state . view_settings . set ( args [ 1 ] , args [ 2 ] ) state . update_col ( ) else : print ( 'usage: cameraview set' )
camera view commands
230,469
def scale_rc ( self , servo , min , max , param ) : min_pwm = self . get_mav_param ( '%s_MIN' % param , 0 ) max_pwm = self . get_mav_param ( '%s_MAX' % param , 0 ) if min_pwm == 0 or max_pwm == 0 : return 0 if max_pwm == min_pwm : p = 0.0 else : p = ( servo - min_pwm ) / float ( max_pwm - min_pwm ) v = min + p * ( max ...
scale a PWM value
230,470
def raise_msg_to_str ( msg ) : if not is_string_like ( msg ) : msg = '\n' . join ( map ( str , msg ) ) return msg
msg is a return arg from a raise . Join with new lines
230,471
def _create_wx_app ( ) : wxapp = wx . GetApp ( ) if wxapp is None : wxapp = wx . App ( False ) wxapp . SetExitOnFrameDelete ( True ) _create_wx_app . theWxApp = wxapp
Creates a wx . App instance if it has not been created sofar .
230,472
def draw_if_interactive ( ) : DEBUG_MSG ( "draw_if_interactive()" , 1 , None ) if matplotlib . is_interactive ( ) : figManager = Gcf . get_active ( ) if figManager is not None : figManager . canvas . draw_idle ( )
This should be overriden in a windowing environment if drawing should be done in interactive python mode
230,473
def new_gc ( self ) : DEBUG_MSG ( 'new_gc()' , 2 , self ) self . gc = GraphicsContextWx ( self . bitmap , self ) self . gc . select ( ) self . gc . unselect ( ) return self . gc
Return an instance of a GraphicsContextWx and sets the current gc copy
230,474
def get_wx_font ( self , s , prop ) : DEBUG_MSG ( "get_wx_font()" , 1 , self ) key = hash ( prop ) fontprop = prop fontname = fontprop . get_name ( ) font = self . fontd . get ( key ) if font is not None : return font wxFontname = self . fontnames . get ( fontname , wx . ROMAN ) wxFacename = '' size = self . points_to_...
Return a wx font . Cache instances in a font dictionary for efficiency
230,475
def select ( self ) : if sys . platform == 'win32' : self . dc . SelectObject ( self . bitmap ) self . IsSelected = True
Select the current bitmap into this wxDC instance
230,476
def unselect ( self ) : if sys . platform == 'win32' : self . dc . SelectObject ( wx . NullBitmap ) self . IsSelected = False
Select a Null bitmasp into this wxDC instance
230,477
def set_linewidth ( self , w ) : DEBUG_MSG ( "set_linewidth()" , 1 , self ) self . select ( ) if w > 0 and w < 1 : w = 1 GraphicsContextBase . set_linewidth ( self , w ) lw = int ( self . renderer . points_to_pixels ( self . _linewidth ) ) if lw == 0 : lw = 1 self . _pen . SetWidth ( lw ) self . gfx_ctx . SetPen ( self...
Set the line width .
230,478
def set_linestyle ( self , ls ) : DEBUG_MSG ( "set_linestyle()" , 1 , self ) self . select ( ) GraphicsContextBase . set_linestyle ( self , ls ) try : self . _style = GraphicsContextWx . _dashd_wx [ ls ] except KeyError : self . _style = wx . LONG_DASH if wx . Platform == '__WXMSW__' : self . set_linewidth ( 1 ) self ....
Set the line style to be one of
230,479
def get_wxcolour ( self , color ) : DEBUG_MSG ( "get_wx_color()" , 1 , self ) if len ( color ) == 3 : r , g , b = color r *= 255 g *= 255 b *= 255 return wx . Colour ( red = int ( r ) , green = int ( g ) , blue = int ( b ) ) else : r , g , b , a = color r *= 255 g *= 255 b *= 255 a *= 255 return wx . Colour ( red = int...
return a wx . Colour from RGB format
230,480
def Copy_to_Clipboard ( self , event = None ) : "copy bitmap of canvas to system clipboard" bmp_obj = wx . BitmapDataObject ( ) bmp_obj . SetBitmap ( self . bitmap ) if not wx . TheClipboard . IsOpened ( ) : open_success = wx . TheClipboard . Open ( ) if open_success : wx . TheClipboard . SetData ( bmp_obj ) wx . TheCl...
copy bitmap of canvas to system clipboard
230,481
def draw_idle ( self ) : DEBUG_MSG ( "draw_idle()" , 1 , self ) self . _isDrawn = False if hasattr ( self , '_idletimer' ) : self . _idletimer . Restart ( IDLE_DELAY ) else : self . _idletimer = wx . FutureCall ( IDLE_DELAY , self . _onDrawIdle )
Delay rendering until the GUI is idle .
230,482
def draw ( self , drawDC = None ) : DEBUG_MSG ( "draw()" , 1 , self ) self . renderer = RendererWx ( self . bitmap , self . figure . dpi ) self . figure . draw ( self . renderer ) self . _isDrawn = True self . gui_repaint ( drawDC = drawDC )
Render the figure using RendererWx instance renderer or using a previously defined renderer if none is specified .
230,483
def start_event_loop ( self , timeout = 0 ) : if hasattr ( self , '_event_loop' ) : raise RuntimeError ( "Event loop already running" ) id = wx . NewId ( ) timer = wx . Timer ( self , id = id ) if timeout > 0 : timer . Start ( timeout * 1000 , oneShot = True ) bind ( self , wx . EVT_TIMER , self . stop_event_loop , id ...
Start an event loop . This is used to start a blocking event loop so that interactive functions such as ginput and waitforbuttonpress can wait for events . This should not be confused with the main GUI event loop which is always running and has nothing to do with this .
230,484
def stop_event_loop ( self , event = None ) : if hasattr ( self , '_event_loop' ) : if self . _event_loop . IsRunning ( ) : self . _event_loop . Exit ( ) del self . _event_loop
Stop an event loop . This is used to stop a blocking event loop so that interactive functions such as ginput and waitforbuttonpress can wait for events .
230,485
def _get_imagesave_wildcards ( self ) : 'return the wildcard string for the filesave dialog' default_filetype = self . get_default_filetype ( ) filetypes = self . get_supported_filetypes_grouped ( ) sorted_filetypes = filetypes . items ( ) sorted_filetypes . sort ( ) wildcards = [ ] extensions = [ ] filter_index = 0 fo...
return the wildcard string for the filesave dialog
230,486
def gui_repaint ( self , drawDC = None ) : DEBUG_MSG ( "gui_repaint()" , 1 , self ) if self . IsShownOnScreen ( ) : if drawDC is None : drawDC = wx . ClientDC ( self ) drawDC . DrawBitmap ( self . bitmap , 0 , 0 ) else : pass
Performs update of the displayed image on the GUI canvas using the supplied device context . If drawDC is None a ClientDC will be used to redraw the image .
230,487
def _onPaint ( self , evt ) : DEBUG_MSG ( "_onPaint()" , 1 , self ) drawDC = wx . PaintDC ( self ) if not self . _isDrawn : self . draw ( drawDC = drawDC ) else : self . gui_repaint ( drawDC = drawDC ) evt . Skip ( )
Called when wxPaintEvt is generated
230,488
def _onSize ( self , evt ) : DEBUG_MSG ( "_onSize()" , 2 , self ) self . _width , self . _height = self . GetClientSize ( ) self . bitmap = wx . EmptyBitmap ( self . _width , self . _height ) self . _isDrawn = False if self . _width <= 1 or self . _height <= 1 : return dpival = self . figure . dpi winch = self . _width...
Called when wxEventSize is generated .
230,489
def _onIdle ( self , evt ) : 'a GUI idle event' evt . Skip ( ) FigureCanvasBase . idle_event ( self , guiEvent = evt )
a GUI idle event
230,490
def _onKeyDown ( self , evt ) : key = self . _get_key ( evt ) evt . Skip ( ) FigureCanvasBase . key_press_event ( self , key , guiEvent = evt )
Capture key press .
230,491
def _onKeyUp ( self , evt ) : key = self . _get_key ( evt ) evt . Skip ( ) FigureCanvasBase . key_release_event ( self , key , guiEvent = evt )
Release key .
230,492
def _onLeftButtonUp ( self , evt ) : x = evt . GetX ( ) y = self . figure . bbox . height - evt . GetY ( ) evt . Skip ( ) if self . HasCapture ( ) : self . ReleaseMouse ( ) FigureCanvasBase . button_release_event ( self , x , y , 1 , guiEvent = evt )
End measuring on an axis .
230,493
def _onMouseWheel ( self , evt ) : x = evt . GetX ( ) y = self . figure . bbox . height - evt . GetY ( ) delta = evt . GetWheelDelta ( ) rotation = evt . GetWheelRotation ( ) rate = evt . GetLinesPerAction ( ) step = rate * float ( rotation ) / delta evt . Skip ( ) if wx . Platform == '__WXMAC__' : if not hasattr ( sel...
Translate mouse wheel events into matplotlib events
230,494
def _onLeave ( self , evt ) : evt . Skip ( ) FigureCanvasBase . leave_notify_event ( self , guiEvent = evt )
Mouse has left the window .
230,495
def resize ( self , width , height ) : 'Set the canvas size in pixels' self . canvas . SetInitialSize ( wx . Size ( width , height ) ) self . window . GetSizer ( ) . Fit ( self . window )
Set the canvas size in pixels
230,496
def _onMenuButton ( self , evt ) : x , y = self . GetPositionTuple ( ) w , h = self . GetSizeTuple ( ) self . PopupMenuXY ( self . _menu , x , y + h - 4 ) evt . Skip ( )
Handle menu button pressed .
230,497
def _handleSelectAllAxes ( self , evt ) : if len ( self . _axisId ) == 0 : return for i in range ( len ( self . _axisId ) ) : self . _menu . Check ( self . _axisId [ i ] , True ) self . _toolbar . set_active ( self . getActiveAxes ( ) ) evt . Skip ( )
Called when the select all axes menu item is selected .
230,498
def _handleInvertAxesSelected ( self , evt ) : if len ( self . _axisId ) == 0 : return for i in range ( len ( self . _axisId ) ) : if self . _menu . IsChecked ( self . _axisId [ i ] ) : self . _menu . Check ( self . _axisId [ i ] , False ) else : self . _menu . Check ( self . _axisId [ i ] , True ) self . _toolbar . se...
Called when the invert all menu item is selected
230,499
def _onMenuItemSelected ( self , evt ) : current = self . _menu . IsChecked ( evt . GetId ( ) ) if current : new = False else : new = True self . _menu . Check ( evt . GetId ( ) , new ) self . _toolbar . set_active ( self . getActiveAxes ( ) ) evt . Skip ( )
Called whenever one of the specific axis menu items is selected