idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
230,300 | def remove ( self , w ) : self . wpoints . remove ( w ) self . last_change = time . time ( ) self . reindex ( ) | remove a waypoint |
230,301 | def _read_waypoints_v100 ( self , file ) : cmdmap = { 2 : mavutil . mavlink . MAV_CMD_NAV_TAKEOFF , 3 : mavutil . mavlink . MAV_CMD_NAV_RETURN_TO_LAUNCH , 4 : mavutil . mavlink . MAV_CMD_NAV_LAND , 24 : mavutil . mavlink . MAV_CMD_NAV_TAKEOFF , 26 : mavutil . mavlink . MAV_CMD_NAV_LAND , 25 : mavutil . mavlink . MAV_CM... | read a version 100 waypoint |
230,302 | def _read_waypoints_v110 ( self , file ) : comment = '' for line in file : if line . startswith ( '#' ) : comment = line [ 1 : ] . lstrip ( ) continue line = line . strip ( ) if not line : continue a = line . split ( ) if len ( a ) != 12 : raise MAVWPError ( "invalid waypoint line with %u values" % len ( a ) ) if mavut... | read a version 110 waypoint |
230,303 | def load ( self , filename ) : f = open ( filename , mode = 'r' ) version_line = f . readline ( ) . strip ( ) if version_line == "QGC WPL 100" : readfn = self . _read_waypoints_v100 elif version_line == "QGC WPL 110" : readfn = self . _read_waypoints_v110 elif version_line == "QGC WPL PB 110" : readfn = self . _read_wa... | load waypoints from a file . returns number of waypoints loaded |
230,304 | def view_indexes ( self , done = None ) : ret = [ ] if done is None : done = set ( ) idx = 0 while idx < self . count ( ) : if not idx in done : break idx += 1 while idx < self . count ( ) : w = self . wp ( idx ) if idx in done : if w . x != 0 or w . y != 0 : ret . append ( idx ) break done . add ( idx ) if w . command... | return a list waypoint indexes in view order |
230,305 | def polygon ( self , done = None ) : indexes = self . view_indexes ( done ) points = [ ] for idx in indexes : w = self . wp ( idx ) points . append ( ( w . x , w . y ) ) return points | return a polygon for the waypoints |
230,306 | def polygon_list ( self ) : done = set ( ) ret = [ ] while len ( done ) != self . count ( ) : p = self . polygon ( done ) if len ( p ) > 0 : ret . append ( p ) return ret | return a list of polygons for the waypoints |
230,307 | def view_list ( self ) : done = set ( ) ret = [ ] while len ( done ) != self . count ( ) : p = self . view_indexes ( done ) if len ( p ) > 0 : ret . append ( p ) return ret | return a list of polygon indexes lists for the waypoints |
230,308 | def reindex ( self ) : for i in range ( self . rally_count ( ) ) : self . rally_points [ i ] . count = self . rally_count ( ) self . rally_points [ i ] . idx = i self . last_change = time . time ( ) | reset counters and indexes |
230,309 | def append_rally_point ( self , p ) : if ( self . rally_count ( ) > 9 ) : print ( "Can't have more than 10 rally points, not adding." ) return self . rally_points . append ( p ) self . reindex ( ) | add rallypoint to end of list |
230,310 | def load ( self , filename ) : f = open ( filename , mode = 'r' ) self . clear ( ) for line in f : if line . startswith ( '#' ) : continue line = line . strip ( ) if not line : continue a = line . split ( ) if len ( a ) != 7 : raise MAVRallyError ( "invalid rally file line: %s" % line ) if ( a [ 0 ] . lower ( ) == "ral... | load rally and rally_land points from a file . returns number of points loaded |
230,311 | def load ( self , filename ) : f = open ( filename , mode = 'r' ) self . clear ( ) for line in f : if line . startswith ( '#' ) : continue line = line . strip ( ) if not line : continue a = line . split ( ) if len ( a ) != 2 : raise MAVFenceError ( "invalid fence point line: %s" % line ) self . add_latlon ( float ( a [... | load points from a file . returns number of points loaded |
230,312 | def move ( self , i , lat , lng , change_time = True ) : if i < 0 or i >= self . count ( ) : print ( "Invalid fence point number %u" % i ) self . points [ i ] . lat = lat self . points [ i ] . lng = lng if i == 1 : self . points [ self . count ( ) - 1 ] . lat = lat self . points [ self . count ( ) - 1 ] . lng = lng if ... | move a fence point |
230,313 | def remove ( self , i , change_time = True ) : if i < 0 or i >= self . count ( ) : print ( "Invalid fence point number %u" % i ) self . points . pop ( i ) if i == 1 : self . points [ self . count ( ) - 1 ] . lat = self . points [ 1 ] . lat self . points [ self . count ( ) - 1 ] . lng = self . points [ 1 ] . lng if i ==... | remove a fence point |
230,314 | def polygon ( self ) : points = [ ] for fp in self . points [ 1 : ] : points . append ( ( fp . lat , fp . lng ) ) return points | return a polygon for the fence |
230,315 | def add_input ( cmd , immediate = False ) : if immediate : process_stdin ( cmd ) else : mpstate . input_queue . put ( cmd ) | add some command input to be processed |
230,316 | def param_set ( name , value , retries = 3 ) : name = name . upper ( ) return mpstate . mav_param . mavset ( mpstate . master ( ) , name , value , retries = retries ) | set a parameter |
230,317 | def unload_module ( modname ) : for ( m , pm ) in mpstate . modules : if m . name == modname : if hasattr ( m , 'unload' ) : m . unload ( ) mpstate . modules . remove ( ( m , pm ) ) print ( "Unloaded module %s" % modname ) return True print ( "Unable to find module %s" % modname ) return False | unload a module |
230,318 | def import_package ( name ) : import zipimport try : mod = __import__ ( name ) except ImportError : clear_zipimport_cache ( ) mod = __import__ ( name ) components = name . split ( '.' ) for comp in components [ 1 : ] : mod = getattr ( mod , comp ) return mod | Given a package name like foo . bar . quux imports the package and returns the desired module . |
230,319 | def process_master ( m ) : try : s = m . recv ( 16 * 1024 ) except Exception : time . sleep ( 0.1 ) return if len ( s ) == 0 : time . sleep ( 0.1 ) return if ( mpstate . settings . compdebug & 1 ) != 0 : return if mpstate . logqueue_raw : mpstate . logqueue_raw . put ( str ( s ) ) if mpstate . status . setup_mode : if ... | process packets from the MAVLink master |
230,320 | def set_stream_rates ( ) : if ( not msg_period . trigger ( ) and mpstate . status . last_streamrate1 == mpstate . settings . streamrate and mpstate . status . last_streamrate2 == mpstate . settings . streamrate2 ) : return mpstate . status . last_streamrate1 = mpstate . settings . streamrate mpstate . status . last_str... | set mavlink stream rates |
230,321 | def periodic_tasks ( ) : if mpstate . status . setup_mode : return if ( mpstate . settings . compdebug & 2 ) != 0 : return if mpstate . settings . heartbeat != 0 : heartbeat_period . frequency = mpstate . settings . heartbeat if heartbeat_period . trigger ( ) and mpstate . settings . heartbeat != 0 : mpstate . status .... | run periodic checks |
230,322 | def master ( self ) : if len ( self . mav_master ) == 0 : return None if self . settings . link > len ( self . mav_master ) : self . settings . link = 1 if not self . mav_master [ self . settings . link - 1 ] . linkerror : return self . mav_master [ self . settings . link - 1 ] for m in self . mav_master : if not m . l... | return the currently chosen mavlink master object |
230,323 | def generate ( basename , xml ) : structsfilename = basename + '.generated.cs' msgs = [ ] enums = [ ] filelist = [ ] for x in xml : msgs . extend ( x . message ) enums . extend ( x . enum ) filelist . append ( os . path . basename ( x . filename ) ) for m in msgs : m . order_map = [ 0 ] * len ( m . fieldnames ) for i i... | generate complete MAVLink CSharp implemenation |
230,324 | def load_stylesheet ( pyside = True ) : if pyside : import qdarkstyle . pyside_style_rc else : import qdarkstyle . pyqt_style_rc if not pyside : from PyQt4 . QtCore import QFile , QTextStream else : from PySide . QtCore import QFile , QTextStream f = QFile ( ":qdarkstyle/style.qss" ) if not f . exists ( ) : _logger ( )... | Loads the stylesheet . Takes care of importing the rc module . |
230,325 | def load_stylesheet_pyqt5 ( ) : import qdarkstyle . pyqt5_style_rc from PyQt5 . QtCore import QFile , QTextStream f = QFile ( ":qdarkstyle/style.qss" ) if not f . exists ( ) : _logger ( ) . error ( "Unable to load stylesheet, file not found in " "resources" ) return "" else : f . open ( QFile . ReadOnly | QFile . Text ... | Loads the stylesheet for use in a pyqt5 application . |
230,326 | def call_handler ( self ) : if self . handler is None : return call = getattr ( self . handler , 'call' , None ) if call is not None : self . handler_result = call ( ) | optionally call a handler function |
230,327 | def add ( self , items ) : if not isinstance ( items , list ) : items = [ items ] for m in items : updated = False for i in range ( len ( self . items ) ) : if self . items [ i ] . name == m . name : self . items [ i ] = m updated = True if not updated : self . items . append ( m ) | add a submenu |
230,328 | def call ( self ) : mp_util . child_close_fds ( ) import wx_processguard from wx_loader import wx from wx . lib . agw . genericmessagedialog import GenericMessageDialog app = wx . App ( False ) font = wx . Font ( self . font_size , wx . MODERN , wx . NORMAL , wx . NORMAL ) dlg = GenericMessageDialog ( None , self . mes... | show the dialog as a child process |
230,329 | def read_ermapper ( self , ifile ) : ers_index = ifile . find ( '.ers' ) if ers_index > 0 : data_file = ifile [ 0 : ers_index ] header_file = ifile else : data_file = ifile header_file = ifile + '.ers' self . header = self . read_ermapper_header ( header_file ) nroflines = int ( self . header [ 'nroflines' ] ) nrofcell... | Read in a DEM file and associated . ers file |
230,330 | def printBoundingBox ( self ) : print ( "Bounding Latitude: " ) print ( self . startlatitude ) print ( self . endlatitude ) print ( "Bounding Longitude: " ) print ( self . startlongitude ) print ( self . endlongitude ) | Print the bounding box that this DEM covers |
230,331 | def getPercentBlank ( self ) : blank = 0 nonblank = 0 for x in self . data . flat : if x == - 99999.0 : blank = blank + 1 else : nonblank = nonblank + 1 print ( "Blank tiles = " , blank , "out of " , ( nonblank + blank ) ) | Print how many null cells are in the DEM - Quality measure |
230,332 | def send_rc_override ( self ) : if self . sitl_output : buf = struct . pack ( '<HHHHHHHH' , * self . override ) self . sitl_output . write ( buf ) else : self . master . mav . rc_channels_override_send ( self . target_system , self . target_component , * self . override ) | send RC override packet |
230,333 | def cmd_switch ( self , args ) : mapping = [ 0 , 1165 , 1295 , 1425 , 1555 , 1685 , 1815 ] if len ( args ) != 1 : print ( "Usage: switch <pwmvalue>" ) return value = int ( args [ 0 ] ) if value < 0 or value > 6 : print ( "Invalid switch value. Use 1-6 for flight modes, '0' to disable" ) return if self . vehicle_type ==... | handle RC switch changes |
230,334 | def write_NetCDF_georeference ( origin , outfile ) : geo_ref = ensure_geo_reference ( origin ) geo_ref . write_NetCDF ( outfile ) return geo_ref | Write georeference info to a netcdf file usually sww . |
230,335 | def is_absolute ( self ) : if not hasattr ( self , 'absolute' ) : self . absolute = num . allclose ( [ self . xllcorner , self . yllcorner ] , 0 ) return self . absolute | Return True if xllcorner == yllcorner == 0 indicating that points in question are absolute . |
230,336 | def mkdir_p ( dir ) : if not dir : return if dir . endswith ( "/" ) or dir . endswith ( "\\" ) : mkdir_p ( dir [ : - 1 ] ) return if os . path . isdir ( dir ) : return mkdir_p ( os . path . dirname ( dir ) ) try : os . mkdir ( dir ) except Exception : pass | like mkdir - p |
230,337 | def polygon_load ( filename ) : ret = [ ] f = open ( filename ) for line in f : if line . startswith ( '#' ) : continue line = line . strip ( ) if not line : continue a = line . split ( ) if len ( a ) != 2 : raise RuntimeError ( "invalid polygon line: %s" % line ) ret . append ( ( float ( a [ 0 ] ) , float ( a [ 1 ] ) ... | load a polygon from a file |
230,338 | def bounds_overlap ( bound1 , bound2 ) : ( x1 , y1 , w1 , h1 ) = bound1 ( x2 , y2 , w2 , h2 ) = bound2 if x1 + w1 < x2 : return False if x2 + w2 < x1 : return False if y1 + h1 < y2 : return False if y2 + h2 < y1 : return False return True | return true if two bounding boxes overlap |
230,339 | def latlon_to_grid ( latlon ) : from MAVProxy . modules . lib . ANUGA import redfearn ( zone , easting , northing ) = redfearn . redfearn ( latlon [ 0 ] , latlon [ 1 ] ) if latlon [ 0 ] < 0 : hemisphere = 'S' else : hemisphere = 'N' return UTMGrid ( zone , easting , northing , hemisphere = hemisphere ) | convert to grid reference |
230,340 | def latlon_round ( latlon , spacing = 1000 ) : g = latlon_to_grid ( latlon ) g . easting = ( g . easting // spacing ) * spacing g . northing = ( g . northing // spacing ) * spacing return g . latlon ( ) | round to nearest grid corner |
230,341 | def wxToPIL ( wimg ) : from PIL import Image ( w , h ) = wimg . GetSize ( ) d = wimg . GetData ( ) pimg = Image . new ( "RGB" , ( w , h ) , color = 1 ) pimg . fromstring ( d ) return pimg | convert a wxImage to a PIL Image |
230,342 | def child_close_fds ( ) : global child_fd_list import os while len ( child_fd_list ) > 0 : fd = child_fd_list . pop ( 0 ) try : os . close ( fd ) except Exception as msg : pass | close file descriptors that a child process should not inherit . Should be called from child processes . |
230,343 | def snapshot_folder ( ) : logger . info ( "Snapshot folder" ) try : stdout = subprocess . check_output ( [ "git" , "show" , "-s" , "--format=%cI" , "HEAD" ] ) except subprocess . CalledProcessError as e : logger . error ( "Error: {}" . format ( e . output . decode ( 'ascii' , 'ignore' ) . strip ( ) ) ) sys . exit ( 2 )... | Use the commit date in UTC as folder name |
230,344 | def opengraph_get ( html , prop ) : match = re . search ( '<meta [^>]*property="og:' + prop + '" content="([^"]*)"' , html ) if match is None : match = re . search ( '<meta [^>]*content="([^"]*)" property="og:' + prop + '"' , html ) if match is None : return None return match . group ( 1 ) | Extract specified OpenGraph property from html . |
230,345 | def decode_html_entities ( s ) : parser = HTMLParser . HTMLParser ( ) def unesc ( m ) : return parser . unescape ( m . group ( ) ) return re . sub ( r'(&[^;]+;)' , unesc , ensure_unicode ( s ) ) | Replaces html entities with the character they represent . |
230,346 | def filenamify ( title ) : title = ensure_unicode ( title ) title = unicodedata . normalize ( 'NFD' , title ) title = re . sub ( r'[^a-z0-9 .-]' , '' , title . lower ( ) . strip ( ) ) title = re . sub ( r'\s+' , '.' , title ) title = re . sub ( r'\.-\.' , '-' , title ) return title | Convert a string to something suitable as a file name . E . g . |
230,347 | def download ( self ) : _ , ext = os . path . splitext ( self . url ) if ext == ".mp3" : self . output_extention = "mp3" else : self . output_extention = "mp4" data = self . http . request ( "get" , self . url , stream = True ) try : total_size = data . headers [ 'content-length' ] except KeyError : total_size = 0 tota... | Get the stream from HTTP |
230,348 | def progress ( byte , total , extra = "" ) : if total == 0 : progresstr = "Downloaded %dkB bytes" % ( byte >> 10 ) progress_stream . write ( progresstr + '\r' ) return progressbar ( total , byte , extra ) | Print some info about how much we have downloaded |
230,349 | def update ( self , pos ) : self . pos = pos self . now = time . time ( ) | Set new absolute progress position . |
230,350 | def check_xlim_change ( self ) : if self . xlim_pipe is None : return None xlim = None while self . xlim_pipe [ 0 ] . poll ( ) : try : xlim = self . xlim_pipe [ 0 ] . recv ( ) except EOFError : return None if xlim != self . xlim : return xlim return None | check for new X bounds |
230,351 | def set_xlim ( self , xlim ) : if self . xlim_pipe is not None and self . xlim != xlim : try : self . xlim_pipe [ 0 ] . send ( xlim ) except IOError : return False self . xlim = xlim return True | set new X bounds |
230,352 | def serial_lock ( self , lock ) : mav = self . master . mav if lock : flags = mavutil . mavlink . SERIAL_CONTROL_FLAG_EXCLUSIVE self . locked = True else : flags = 0 self . locked = False mav . serial_control_send ( self . serial_settings . port , flags , 0 , 0 , 0 , [ 0 ] * 70 ) | lock or unlock the port |
230,353 | def cmd_serial ( self , args ) : usage = "Usage: serial <lock|unlock|set|send>" if len ( args ) < 1 : print ( usage ) return if args [ 0 ] == "lock" : self . serial_lock ( True ) elif args [ 0 ] == "unlock" : self . serial_lock ( False ) elif args [ 0 ] == "set" : self . serial_settings . command ( args [ 1 : ] ) elif ... | serial control commands |
230,354 | def downloader ( self ) : while self . tiles_pending ( ) > 0 : time . sleep ( self . tile_delay ) keys = sorted ( self . _download_pending . keys ( ) ) tile_info = self . _download_pending [ keys [ 0 ] ] for key in keys : if self . _download_pending [ key ] . request_time > tile_info . request_time : tile_info = self .... | the download thread |
230,355 | def cmd_fw ( self , args ) : if len ( args ) == 0 : print ( self . usage ( ) ) return rest = args [ 1 : ] if args [ 0 ] == "manifest" : self . cmd_fw_manifest ( rest ) elif args [ 0 ] == "list" : self . cmd_fw_list ( rest ) elif args [ 0 ] == "download" : self . cmd_fw_download ( rest ) elif args [ 0 ] in [ "help" , "u... | execute command defined in args |
230,356 | def frame_from_firmware ( self , firmware ) : frame_to_mavlink_dict = { "quad" : "QUADROTOR" , "hexa" : "HEXAROTOR" , "y6" : "ARDUPILOT_Y6" , "tri" : "TRICOPTER" , "octa" : "OCTOROTOR" , "octa-quad" : "ARDUPILOT_OCTAQUAD" , "heli" : "HELICOPTER" , "Plane" : "FIXED_WING" , "Tracker" : "ANTENNA_TRACKER" , "Rover" : "GROU... | extract information from firmware return pretty string to user |
230,357 | def row_is_filtered ( self , row_subs , filters ) : for filtername in filters : filtervalue = filters [ filtername ] if filtername in row_subs : row_subs_value = row_subs [ filtername ] if str ( row_subs_value ) != str ( filtervalue ) : return True else : print ( "fw: Unknown filter keyword (%s)" % ( filtername , ) ) r... | returns True if row should NOT be included according to filters |
230,358 | def filters_from_args ( self , args ) : filters = dict ( ) remainder = [ ] for arg in args : try : equals = arg . index ( '=' ) filters [ arg [ 0 : equals ] ] = arg [ equals + 1 : ] except ValueError : remainder . append ( arg ) return ( filters , remainder ) | take any argument of the form name = value anmd put it into a dict ; return that and the remaining arguments |
230,359 | def all_firmwares ( self ) : all = [ ] for manifest in self . manifests : for firmware in manifest [ "firmware" ] : all . append ( firmware ) return all | return firmware entries from all manifests |
230,360 | def rows_for_firmwares ( self , firmwares ) : rows = [ ] i = 0 for firmware in firmwares : frame = self . frame_from_firmware ( firmware ) row = { "seq" : i , "platform" : firmware [ "platform" ] , "frame" : frame , "releasetype" : firmware [ "mav-firmware-version-type" ] , "latest" : firmware [ "latest" ] , "git-sha" ... | provide user - readable text for a firmware entry |
230,361 | def filter_rows ( self , filters , rows ) : ret = [ ] for row in rows : if not self . row_is_filtered ( row , filters ) : ret . append ( row ) return ret | returns rows as filtered by filters |
230,362 | def filtered_rows_from_args ( self , args ) : if len ( self . manifests ) == 0 : print ( "fw: No manifests downloaded. Try 'manifest download'" ) return None ( filters , remainder ) = self . filters_from_args ( args ) all = self . all_firmwares ( ) rows = self . rows_for_firmwares ( all ) filtered = self . filter_rows... | extracts filters from args rows from manifests returns filtered rows |
230,363 | def cmd_fw_list ( self , args ) : stuff = self . filtered_rows_from_args ( args ) if stuff is None : return ( filtered , remainder ) = stuff print ( "" ) print ( " seq platform frame major.minor.patch releasetype latest git-sha format" ) for row in filtered : print ( "{seq:>5} {platform:<13} {frame:<10} {version:<10... | cmd handler for list |
230,364 | def cmd_fw_download ( self , args ) : stuff = self . filtered_rows_from_args ( args ) if stuff is None : return ( filtered , remainder ) = stuff if len ( filtered ) == 0 : print ( "fw: No firmware specified" ) return if len ( filtered ) > 1 : print ( "fw: No single firmware specified" ) return firmware = filtered [ 0 ]... | cmd handler for downloading firmware |
230,365 | 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 |
230,366 | def cmd_fw_manifest_purge ( self ) : for filepath in self . find_manifests ( ) : os . unlink ( filepath ) self . manifests_parse ( ) | remove all downloaded manifests |
230,367 | 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 |
230,368 | def manifest_parse ( self , path ) : print ( "fw: parsing manifests" ) content = open ( path ) . read ( ) return json . loads ( content ) | parse manifest at path return JSON object |
230,369 | 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 |
230,370 | 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 |
230,371 | 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 |
230,372 | 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 |
230,373 | 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 |
230,374 | 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 |
230,375 | 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 |
230,376 | def set_ip_port ( self , ip , port ) : self . address = ip self . port = port self . stop ( ) self . start ( ) | set ip and port |
230,377 | 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 |
230,378 | 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 |
230,379 | 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 |
230,380 | 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 |
230,381 | 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 |
230,382 | 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 |
230,383 | 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 |
230,384 | 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 |
230,385 | 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 |
230,386 | 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 |
230,387 | 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 |
230,388 | 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 |
230,389 | 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 |
230,390 | 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 |
230,391 | 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 |
230,392 | 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 |
230,393 | 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 |
230,394 | 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 |
230,395 | 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 . |
230,396 | 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... |
230,397 | 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 . |
230,398 | 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 . |
230,399 | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.