idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
41,100 | def battery_update ( self , SYS_STATUS ) : self . battery_level = SYS_STATUS . battery_remaining self . voltage_level = SYS_STATUS . voltage_battery self . current_battery = SYS_STATUS . current_battery if self . settings . numcells != 0 : self . per_cell = ( self . voltage_level * 0.001 ) / self . settings . numcells | update battery level |
41,101 | def cmd_accelcal ( self , args ) : mav = self . master mav . mav . command_long_send ( mav . target_system , mav . target_component , mavutil . mavlink . MAV_CMD_PREFLIGHT_CALIBRATION , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 ) self . accelcal_count = 0 self . accelcal_wait_enter = False | do a full 3D accel calibration |
41,102 | def cmd_gyrocal ( self , args ) : mav = self . master mav . mav . command_long_send ( mav . target_system , mav . target_component , mavutil . mavlink . MAV_CMD_PREFLIGHT_CALIBRATION , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 ) | do a full gyro calibration |
41,103 | def cmd_magcal ( self , args ) : if len ( args ) < 1 : print ( "Usage: magcal <start|accept|cancel>" ) return if args [ 0 ] == 'start' : self . master . mav . command_long_send ( self . settings . target_system , 0 , mavutil . mavlink . MAV_CMD_DO_START_MAG_CAL , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 ) elif args [ 0 ] == 'accept' : self . master . mav . command_long_send ( self . settings . target_system , 0 , mavutil . mavlink . MAV_CMD_DO_ACCEPT_MAG_CAL , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 ) elif args [ 0 ] == 'cancel' : self . master . mav . command_long_send ( self . settings . target_system , 0 , mavutil . mavlink . MAV_CMD_DO_CANCEL_MAG_CAL , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 ) | control magnetometer calibration |
41,104 | def set_fence_enabled ( self , do_enable ) : self . master . mav . command_long_send ( self . target_system , self . target_component , mavutil . mavlink . MAV_CMD_DO_FENCE_ENABLE , 0 , do_enable , 0 , 0 , 0 , 0 , 0 , 0 ) | Enable or disable fence |
41,105 | def cmd_fence_move ( self , args ) : if len ( args ) < 1 : print ( "Usage: fence move FENCEPOINTNUM" ) return if not self . have_list : print ( "Please list fence points first" ) return idx = int ( args [ 0 ] ) if idx <= 0 or idx > self . fenceloader . count ( ) : print ( "Invalid fence point number %u" % idx ) return try : latlon = self . module ( 'map' ) . click_position except Exception : print ( "No map available" ) return if latlon is None : print ( "No map click position available" ) return self . fenceloader . move ( idx , latlon [ 0 ] , latlon [ 1 ] ) if self . send_fence ( ) : print ( "Moved fence point %u" % idx ) | handle fencepoint move |
41,106 | def cmd_fence_remove ( self , args ) : if len ( args ) < 1 : print ( "Usage: fence remove FENCEPOINTNUM" ) return if not self . have_list : print ( "Please list fence points first" ) return idx = int ( args [ 0 ] ) if idx <= 0 or idx > self . fenceloader . count ( ) : print ( "Invalid fence point number %u" % idx ) return self . fenceloader . remove ( idx ) if self . send_fence ( ) : print ( "Removed fence point %u" % idx ) else : print ( "Failed to remove fence point %u" % idx ) | handle fencepoint remove |
41,107 | def send_fence ( self ) : self . fenceloader . target_system = self . target_system self . fenceloader . target_component = self . target_component self . fenceloader . reindex ( ) action = self . get_mav_param ( 'FENCE_ACTION' , mavutil . mavlink . FENCE_ACTION_NONE ) self . param_set ( 'FENCE_ACTION' , mavutil . mavlink . FENCE_ACTION_NONE , 3 ) self . param_set ( 'FENCE_TOTAL' , self . fenceloader . count ( ) , 3 ) for i in range ( self . fenceloader . count ( ) ) : p = self . fenceloader . point ( i ) self . master . mav . send ( p ) p2 = self . fetch_fence_point ( i ) if p2 is None : self . param_set ( 'FENCE_ACTION' , action , 3 ) return False if ( p . idx != p2 . idx or abs ( p . lat - p2 . lat ) >= 0.00003 or abs ( p . lng - p2 . lng ) >= 0.00003 ) : print ( "Failed to send fence point %u" % i ) self . param_set ( 'FENCE_ACTION' , action , 3 ) return False self . param_set ( 'FENCE_ACTION' , action , 3 ) return True | send fence points from fenceloader |
41,108 | def fetch_fence_point ( self , i ) : self . master . mav . fence_fetch_point_send ( self . target_system , self . target_component , i ) tstart = time . time ( ) p = None while time . time ( ) - tstart < 3 : p = self . master . recv_match ( type = 'FENCE_POINT' , blocking = False ) if p is not None : break time . sleep ( 0.1 ) continue if p is None : self . console . error ( "Failed to fetch point %u" % i ) return None return p | fetch one fence point |
41,109 | def fence_draw_callback ( self , points ) : self . fenceloader . clear ( ) if len ( points ) < 3 : return self . fenceloader . target_system = self . target_system self . fenceloader . target_component = self . target_component bounds = mp_util . polygon_bounds ( points ) ( lat , lon , width , height ) = bounds center = ( lat + width / 2 , lon + height / 2 ) self . fenceloader . add_latlon ( center [ 0 ] , center [ 1 ] ) for p in points : self . fenceloader . add_latlon ( p [ 0 ] , p [ 1 ] ) self . fenceloader . add_latlon ( points [ 0 ] [ 0 ] , points [ 0 ] [ 1 ] ) self . send_fence ( ) self . have_list = True | callback from drawing a fence |
41,110 | def add_menu ( self , menu ) : self . menu . add ( menu ) self . mpstate . console . set_menu ( self . menu , self . menu_callback ) | add a new menu |
41,111 | def estimated_time_remaining ( self , lat , lon , wpnum , speed ) : idx = wpnum if wpnum >= self . module ( 'wp' ) . wploader . count ( ) : return 0 distance = 0 done = set ( ) while idx < self . module ( 'wp' ) . wploader . count ( ) : if idx in done : break done . add ( idx ) w = self . module ( 'wp' ) . wploader . wp ( idx ) if w . command == mavutil . mavlink . MAV_CMD_DO_JUMP : idx = int ( w . param1 ) continue idx += 1 if ( w . x != 0 or w . y != 0 ) and w . command in [ mavutil . mavlink . MAV_CMD_NAV_WAYPOINT , mavutil . mavlink . MAV_CMD_NAV_LOITER_UNLIM , mavutil . mavlink . MAV_CMD_NAV_LOITER_TURNS , mavutil . mavlink . MAV_CMD_NAV_LOITER_TIME , mavutil . mavlink . MAV_CMD_NAV_LAND , mavutil . mavlink . MAV_CMD_NAV_TAKEOFF ] : distance += mp_util . gps_distance ( lat , lon , w . x , w . y ) lat = w . x lon = w . y if w . command == mavutil . mavlink . MAV_CMD_NAV_LAND : break return distance / speed | estimate time remaining in mission in seconds |
41,112 | def angle ( self , v ) : return acos ( ( self * v ) / ( self . length ( ) * v . length ( ) ) ) | return the angle between this vector and another vector |
41,113 | def from_euler ( self , roll , pitch , yaw ) : cp = cos ( pitch ) sp = sin ( pitch ) sr = sin ( roll ) cr = cos ( roll ) sy = sin ( yaw ) cy = cos ( yaw ) self . a . x = cp * cy self . a . y = ( sr * sp * cy ) - ( cr * sy ) self . a . z = ( cr * sp * cy ) + ( sr * sy ) self . b . x = cp * sy self . b . y = ( sr * sp * sy ) + ( cr * cy ) self . b . z = ( cr * sp * sy ) - ( sr * cy ) self . c . x = - sp self . c . y = sr * cp self . c . z = cr * cp | fill the matrix from Euler angles in radians |
41,114 | def from_euler312 ( self , roll , pitch , yaw ) : c3 = cos ( pitch ) s3 = sin ( pitch ) s2 = sin ( roll ) c2 = cos ( roll ) s1 = sin ( yaw ) c1 = cos ( yaw ) self . a . x = c1 * c3 - s1 * s2 * s3 self . b . y = c1 * c2 self . c . z = c3 * c2 self . a . y = - c2 * s1 self . a . z = s3 * c1 + c3 * s2 * s1 self . b . x = c3 * s1 + s3 * s2 * c1 self . b . z = s1 * s3 - s2 * c1 * c3 self . c . x = - s3 * c2 self . c . y = s2 | fill the matrix from Euler angles in radians in 312 convention |
41,115 | def rotate ( self , g ) : temp_matrix = Matrix3 ( ) a = self . a b = self . b c = self . c temp_matrix . a . x = a . y * g . z - a . z * g . y temp_matrix . a . y = a . z * g . x - a . x * g . z temp_matrix . a . z = a . x * g . y - a . y * g . x temp_matrix . b . x = b . y * g . z - b . z * g . y temp_matrix . b . y = b . z * g . x - b . x * g . z temp_matrix . b . z = b . x * g . y - b . y * g . x temp_matrix . c . x = c . y * g . z - c . z * g . y temp_matrix . c . y = c . z * g . x - c . x * g . z temp_matrix . c . z = c . x * g . y - c . y * g . x self . a += temp_matrix . a self . b += temp_matrix . b self . c += temp_matrix . c | rotate the matrix by a given amount on 3 axes |
41,116 | def normalize ( self ) : error = self . a * self . b t0 = self . a - ( self . b * ( 0.5 * error ) ) t1 = self . b - ( self . a * ( 0.5 * error ) ) t2 = t0 % t1 self . a = t0 * ( 1.0 / t0 . length ( ) ) self . b = t1 * ( 1.0 / t1 . length ( ) ) self . c = t2 * ( 1.0 / t2 . length ( ) ) | re - normalise a rotation matrix |
41,117 | def trace ( self ) : return self . a . x + self . b . y + self . c . z | the trace of the matrix |
41,118 | def from_axis_angle ( self , axis , angle ) : ux = axis . x uy = axis . y uz = axis . z ct = cos ( angle ) st = sin ( angle ) self . a . x = ct + ( 1 - ct ) * ux ** 2 self . a . y = ux * uy * ( 1 - ct ) - uz * st self . a . z = ux * uz * ( 1 - ct ) + uy * st self . b . x = uy * ux * ( 1 - ct ) + uz * st self . b . y = ct + ( 1 - ct ) * uy ** 2 self . b . z = uy * uz * ( 1 - ct ) - ux * st self . c . x = uz * ux * ( 1 - ct ) - uy * st self . c . y = uz * uy * ( 1 - ct ) + ux * st self . c . z = ct + ( 1 - ct ) * uz ** 2 | create a rotation matrix from axis and angle |
41,119 | def from_two_vectors ( self , vec1 , vec2 ) : angle = vec1 . angle ( vec2 ) cross = vec1 % vec2 if cross . length ( ) == 0 : return self . from_euler ( 0 , 0 , angle ) cross . normalize ( ) return self . from_axis_angle ( cross , angle ) | get a rotation matrix from two vectors . This returns a rotation matrix which when applied to vec1 will produce a vector pointing in the same direction as vec2 |
41,120 | def plane_intersection ( self , plane , forward_only = False ) : l_dot_n = self . vector * plane . normal if l_dot_n == 0.0 : return None d = ( ( plane . point - self . point ) * plane . normal ) / l_dot_n if forward_only and d < 0 : return None return ( self . vector * d ) + self . point | return point where line intersects with a plane |
41,121 | def getRgbd ( self ) : img = Rgb ( ) if self . hasproxy ( ) : self . lock . acquire ( ) img = self . image self . lock . release ( ) return img | Returns last Rgbd . |
41,122 | def add_mavlink_packet ( self , msg ) : mtype = msg . get_type ( ) if mtype not in self . msg_types : return for i in range ( len ( self . fields ) ) : if mtype not in self . field_types [ i ] : continue f = self . fields [ i ] self . values [ i ] = mavutil . evaluate_expression ( f , self . state . master . messages ) if self . livegraph is not None : self . livegraph . add_values ( self . values ) | add data to the graph |
41,123 | def generate ( basename , xml ) : if basename . endswith ( '.js' ) : filename = basename else : filename = basename + '.js' 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 : if xml [ 0 ] . little_endian : m . fmtstr = '<' else : m . fmtstr = '>' for f in m . ordered_fields : m . fmtstr += mavfmt ( f ) m . order_map = [ 0 ] * len ( m . fieldnames ) for i in range ( 0 , len ( m . fieldnames ) ) : m . order_map [ i ] = m . ordered_fieldnames . index ( m . fieldnames [ i ] ) print ( "Generating %s" % filename ) outf = open ( filename , "w" ) generate_preamble ( outf , msgs , filelist , xml [ 0 ] ) generate_enums ( outf , enums ) generate_message_ids ( outf , msgs ) generate_classes ( outf , msgs ) generate_mavlink_class ( outf , msgs , xml [ 0 ] ) generate_footer ( outf ) outf . close ( ) print ( "Generated %s OK" % filename ) | generate complete javascript implementation |
41,124 | def flight_modes ( logfile ) : print ( "Processing log %s" % filename ) mlog = mavutil . mavlink_connection ( filename ) mode = "" previous_mode = "" mode_start_timestamp = - 1 time_in_mode = { } previous_percent = - 1 seconds_per_percent = - 1 filesize = os . path . getsize ( filename ) while True : m = mlog . recv_match ( type = [ 'SYS_STATUS' , 'HEARTBEAT' , 'MODE' ] , condition = 'MAV.flightmode!="%s"' % mlog . flightmode ) if m is None : break print ( '%s MAV.flightmode=%-12s (MAV.timestamp=%u %u%%)' % ( time . asctime ( time . localtime ( m . _timestamp ) ) , mlog . flightmode , m . _timestamp , mlog . percent ) ) mode = mlog . flightmode if ( mode not in time_in_mode ) : time_in_mode [ mode ] = 0 if ( mode_start_timestamp == - 1 ) : mode_start_timestamp = m . _timestamp elif ( previous_mode != "" and previous_mode != mode ) : time_in_mode [ previous_mode ] = time_in_mode [ previous_mode ] + ( m . _timestamp - mode_start_timestamp ) if ( seconds_per_percent == - 1 and previous_percent != - 1 and previous_percent != mlog . percent ) : seconds_per_percent = ( m . _timestamp - mode_start_timestamp ) / ( mlog . percent - previous_percent ) mode_start_timestamp = m . _timestamp previous_mode = mode previous_percent = mlog . percent print ( ) print ( "Time per mode:" ) if ( seconds_per_percent != - 1 ) : seconds_remaining = ( 100.0 - previous_percent ) * seconds_per_percent time_in_mode [ previous_mode ] = time_in_mode [ previous_mode ] + seconds_remaining total_flight_time = 0 for key , value in time_in_mode . iteritems ( ) : total_flight_time = total_flight_time + value for key , value in time_in_mode . iteritems ( ) : print ( '%-12s %s %.2f%%' % ( key , str ( datetime . timedelta ( seconds = int ( value ) ) ) , ( value / total_flight_time ) * 100.0 ) ) else : print ( previous_mode , " 100% of flight time" ) | show flight modes for a log file |
41,125 | def have_graph ( name ) : for g in mestate . graphs : if g . name == name : return True return False | return true if we have a graph of the given name |
41,126 | def expression_ok ( expression ) : expression_ok = True fields = expression . split ( ) for f in fields : try : if f . endswith ( ':2' ) : f = f [ : - 2 ] if mavutil . evaluate_expression ( f , mestate . status . msgs ) is None : expression_ok = False except Exception : expression_ok = False break return expression_ok | return True if an expression is OK with current messages |
41,127 | def load_graph_xml ( xml , filename , load_all = False ) : ret = [ ] try : root = objectify . fromstring ( xml ) except Exception : return [ ] if root . tag != 'graphs' : return [ ] if not hasattr ( root , 'graph' ) : return [ ] for g in root . graph : name = g . attrib [ 'name' ] expressions = [ e . text for e in g . expression ] if load_all : ret . append ( GraphDefinition ( name , e , g . description . text , expressions , filename ) ) continue if have_graph ( name ) : continue for e in expressions : if expression_ok ( e ) : ret . append ( GraphDefinition ( name , e , g . description . text , expressions , filename ) ) break return ret | load a graph from one xml string |
41,128 | def cmd_condition ( args ) : if len ( args ) == 0 : print ( "condition is: %s" % mestate . settings . condition ) return mestate . settings . condition = ' ' . join ( args ) if len ( mestate . settings . condition ) == 0 or mestate . settings . condition == 'clear' : mestate . settings . condition = None | control MAVExporer conditions |
41,129 | def ualberta_sys_status_send ( self , mode , nav_mode , pilot , force_mavlink1 = False ) : return self . send ( self . ualberta_sys_status_encode ( mode , nav_mode , pilot ) , force_mavlink1 = force_mavlink1 ) | System status specific to ualberta uav |
41,130 | def button_change_send ( self , time_boot_ms , last_change_ms , state , force_mavlink1 = False ) : return self . send ( self . button_change_encode ( time_boot_ms , last_change_ms , state ) , force_mavlink1 = force_mavlink1 ) | Report button state change |
41,131 | def convert_from_latlon_to_utm ( points = None , latitudes = None , longitudes = None , false_easting = None , false_northing = None ) : old_geo = Geo_reference ( ) utm_points = [ ] if points == None : assert len ( latitudes ) == len ( longitudes ) points = map ( None , latitudes , longitudes ) for point in points : zone , easting , northing = redfearn ( float ( point [ 0 ] ) , float ( point [ 1 ] ) , false_easting = false_easting , false_northing = false_northing ) new_geo = Geo_reference ( zone ) old_geo . reconcile_zones ( new_geo ) utm_points . append ( [ easting , northing ] ) return utm_points , old_geo . get_zone ( ) | Convert latitude and longitude data to UTM as a list of coordinates . |
41,132 | def dcm ( self ) : if self . _dcm is None : if self . _q is not None : self . _dcm = self . _q_to_dcm ( self . q ) elif self . _euler is not None : self . _dcm = self . _euler_to_dcm ( self . _euler ) return self . _dcm | Get the DCM |
41,133 | def lock_time ( logfile ) : print ( "Processing log %s" % filename ) mlog = mavutil . mavlink_connection ( filename ) locked = False start_time = 0.0 total_time = 0.0 t = None m = mlog . recv_match ( type = [ 'GPS_RAW_INT' , 'GPS_RAW' ] , condition = args . condition ) if m is None : return 0 unlock_time = time . mktime ( time . localtime ( m . _timestamp ) ) while True : m = mlog . recv_match ( type = [ 'GPS_RAW_INT' , 'GPS_RAW' ] , condition = args . condition ) if m is None : if locked : total_time += time . mktime ( t ) - start_time if total_time > 0 : print ( "Lock time : %u:%02u" % ( int ( total_time ) / 60 , int ( total_time ) % 60 ) ) return total_time t = time . localtime ( m . _timestamp ) if m . fix_type >= 2 and not locked : print ( "Locked at %s after %u seconds" % ( time . asctime ( t ) , time . mktime ( t ) - unlock_time ) ) locked = True start_time = time . mktime ( t ) elif m . fix_type == 1 and locked : print ( "Lost GPS lock at %s" % time . asctime ( t ) ) locked = False total_time += time . mktime ( t ) - start_time unlock_time = time . mktime ( t ) elif m . fix_type == 0 and locked : print ( "Lost protocol lock at %s" % time . asctime ( t ) ) locked = False total_time += time . mktime ( t ) - start_time unlock_time = time . mktime ( t ) return total_time | work out gps lock times for a log file |
41,134 | def on_menu ( self , event ) : state = self . state if state . popup_object is not None : obj = state . popup_object ret = obj . popup_menu . find_selected ( event ) if ret is not None : ret . call_handler ( ) state . event_queue . put ( SlipMenuEvent ( state . popup_latlon , event , [ SlipObjectSelection ( obj . key , 0 , obj . layer , obj . selection_info ( ) ) ] , ret ) ) state . popup_object = None state . popup_latlon = None if state . default_popup is not None : ret = state . default_popup . popup . find_selected ( event ) if ret is not None : ret . call_handler ( ) state . event_queue . put ( SlipMenuEvent ( state . popup_latlon , event , [ ] , ret ) ) ret = self . menu . find_selected ( event ) if ret is None : return ret . call_handler ( ) if ret . returnkey == 'toggleGrid' : state . grid = ret . IsChecked ( ) elif ret . returnkey == 'toggleFollow' : state . follow = ret . IsChecked ( ) elif ret . returnkey == 'toggleDownload' : state . download = ret . IsChecked ( ) elif ret . returnkey == 'setService' : state . mt . set_service ( ret . get_choice ( ) ) elif ret . returnkey == 'gotoPosition' : state . panel . enter_position ( ) elif ret . returnkey == 'increaseBrightness' : state . brightness *= 1.25 elif ret . returnkey == 'decreaseBrightness' : state . brightness /= 1.25 state . need_redraw = True | handle menu selection |
41,135 | def follow ( self , object ) : state = self . state ( px , py ) = state . panel . pixmapper ( object . latlon ) ratio = 0.25 if ( px > ratio * state . width and px < ( 1.0 - ratio ) * state . width and py > ratio * state . height and py < ( 1.0 - ratio ) * state . height ) : return if not state . follow : return ( lat , lon ) = object . latlon state . panel . re_center ( state . width / 2 , state . height / 2 , lat , lon ) | follow an object on the map |
41,136 | def add_object ( self , obj ) : state = self . state if not obj . layer in state . layers : state . layers [ obj . layer ] = { } state . layers [ obj . layer ] [ obj . key ] = obj state . need_redraw = True | add an object to a later |
41,137 | def remove_object ( self , key ) : state = self . state for layer in state . layers : state . layers [ layer ] . pop ( key , None ) state . need_redraw = True | remove an object by key from all layers |
41,138 | def current_view ( self ) : state = self . state return ( state . lat , state . lon , state . width , state . height , state . ground_width , state . mt . tiles_pending ( ) ) | return a tuple representing the current view |
41,139 | def coordinates ( self , x , y ) : state = self . state return state . mt . coord_from_area ( x , y , state . lat , state . lon , state . width , state . ground_width ) | return coordinates of a pixel in the map |
41,140 | def re_center ( self , x , y , lat , lon ) : state = self . state if lat is None or lon is None : return ( lat2 , lon2 ) = self . coordinates ( x , y ) distance = mp_util . gps_distance ( lat2 , lon2 , lat , lon ) bearing = mp_util . gps_bearing ( lat2 , lon2 , lat , lon ) ( state . lat , state . lon ) = mp_util . gps_newpos ( state . lat , state . lon , bearing , distance ) | re - center view for pixel x y |
41,141 | def change_zoom ( self , zoom ) : state = self . state if self . mouse_pos : ( x , y ) = ( self . mouse_pos . x , self . mouse_pos . y ) else : ( x , y ) = ( state . width / 2 , state . height / 2 ) ( lat , lon ) = self . coordinates ( x , y ) state . ground_width *= zoom state . ground_width = max ( state . ground_width , 20 ) state . ground_width = min ( state . ground_width , 20000000 ) self . re_center ( x , y , lat , lon ) | zoom in or out by zoom factor keeping centered |
41,142 | def enter_position ( self ) : state = self . state dlg = wx . TextEntryDialog ( self , 'Enter new position' , 'Position' ) dlg . SetValue ( "%f %f" % ( state . lat , state . lon ) ) if dlg . ShowModal ( ) == wx . ID_OK : latlon = dlg . GetValue ( ) . split ( ) dlg . Destroy ( ) state . lat = float ( latlon [ 0 ] ) state . lon = float ( latlon [ 1 ] ) self . re_center ( state . width / 2 , state . height / 2 , state . lat , state . lon ) self . redraw_map ( ) | enter new position |
41,143 | def update_position ( self ) : state = self . state pos = self . mouse_pos newtext = '' alt = 0 if pos is not None : ( lat , lon ) = self . coordinates ( pos . x , pos . y ) newtext += 'Cursor: %f %f (%s)' % ( lat , lon , mp_util . latlon_to_grid ( ( lat , lon ) ) ) if state . elevation : alt = self . ElevationMap . GetElevation ( lat , lon ) if alt is not None : newtext += ' %.1fm' % alt state . mt . set_download ( state . download ) pending = 0 if state . download : pending = state . mt . tiles_pending ( ) if pending : newtext += ' Map Downloading %u ' % pending if alt == - 1 : newtext += ' SRTM Downloading ' newtext += '\n' if self . click_pos is not None : newtext += 'Click: %f %f (%s %s) (%s)' % ( self . click_pos [ 0 ] , self . click_pos [ 1 ] , mp_util . degrees_to_dms ( self . click_pos [ 0 ] ) , mp_util . degrees_to_dms ( self . click_pos [ 1 ] ) , mp_util . latlon_to_grid ( self . click_pos ) ) if self . last_click_pos is not None : distance = mp_util . gps_distance ( self . last_click_pos [ 0 ] , self . last_click_pos [ 1 ] , self . click_pos [ 0 ] , self . click_pos [ 1 ] ) bearing = mp_util . gps_bearing ( self . last_click_pos [ 0 ] , self . last_click_pos [ 1 ] , self . click_pos [ 0 ] , self . click_pos [ 1 ] ) newtext += ' Distance: %.1fm Bearing %.1f' % ( distance , bearing ) if newtext != state . oldtext : self . position . Clear ( ) self . position . WriteText ( newtext ) state . oldtext = newtext | update position text |
41,144 | def selected_objects ( self , pos ) : state = self . state selected = [ ] ( px , py ) = pos for layer in state . layers : for key in state . layers [ layer ] : obj = state . layers [ layer ] [ key ] distance = obj . clicked ( px , py ) if distance is not None : selected . append ( SlipObjectSelection ( key , distance , layer , extra_info = obj . selection_info ( ) ) ) selected . sort ( key = lambda c : c . distance ) return selected | return a list of matching objects for a position |
41,145 | def show_default_popup ( self , pos ) : state = self . state if state . default_popup . popup is not None : wx_menu = state . default_popup . popup . wx_menu ( ) state . frame . PopupMenu ( wx_menu , pos ) | show default popup menu |
41,146 | def clear_thumbnails ( self ) : state = self . state for l in state . layers : keys = state . layers [ l ] . keys ( ) [ : ] for key in keys : if ( isinstance ( state . layers [ l ] [ key ] , SlipThumbnail ) and not isinstance ( state . layers [ l ] [ key ] , SlipIcon ) ) : state . layers [ l ] . pop ( key ) | clear all thumbnails from the map |
41,147 | def on_key_down ( self , event ) : state = self . state if self . mouse_pos : latlon = self . coordinates ( self . mouse_pos . x , self . mouse_pos . y ) selected = self . selected_objects ( self . mouse_pos ) state . event_queue . put ( SlipKeyEvent ( latlon , event , selected ) ) c = event . GetUniChar ( ) if c == ord ( '+' ) or ( c == ord ( '=' ) and event . ShiftDown ( ) ) : self . change_zoom ( 1.0 / 1.2 ) event . Skip ( ) elif c == ord ( '-' ) : self . change_zoom ( 1.2 ) event . Skip ( ) elif c == ord ( 'G' ) : self . enter_position ( ) event . Skip ( ) elif c == ord ( 'C' ) : self . clear_thumbnails ( ) event . Skip ( ) | handle keyboard input |
41,148 | def evaluate_expression ( expression , vars ) : try : v = eval ( expression , globals ( ) , vars ) except NameError : return None except ZeroDivisionError : return None return v | evaluation an expression |
41,149 | def compile_all ( ) : print ( "Compiling for PyQt4: style.qrc -> pyqt_style_rc.py" ) os . system ( "pyrcc4 -py3 style.qrc -o pyqt_style_rc.py" ) print ( "Compiling for PyQt5: style.qrc -> pyqt5_style_rc.py" ) os . system ( "pyrcc5 style.qrc -o pyqt5_style_rc.py" ) print ( "Compiling for PySide: style.qrc -> pyside_style_rc.py" ) os . system ( "pyside-rcc -py3 style.qrc -o pyside_style_rc.py" ) | Compile style . qrc using rcc pyside - rcc and pyrcc4 |
41,150 | def null_term ( str ) : idx = str . find ( "\0" ) if idx != - 1 : str = str [ : idx ] return str | null terminate a string |
41,151 | def DFReader_is_text_log ( filename ) : f = open ( filename ) ret = ( f . read ( 8000 ) . find ( 'FMT, ' ) != - 1 ) f . close ( ) return ret | return True if a file appears to be a valid text log |
41,152 | def get_msgbuf ( self ) : values = [ ] for i in range ( len ( self . fmt . columns ) ) : if i >= len ( self . fmt . msg_mults ) : continue mul = self . fmt . msg_mults [ i ] name = self . fmt . columns [ i ] if name == 'Mode' and 'ModeNum' in self . fmt . columns : name = 'ModeNum' v = self . __getattr__ ( name ) if mul is not None : v /= mul values . append ( v ) return struct . pack ( "BBB" , 0xA3 , 0x95 , self . fmt . type ) + struct . pack ( self . fmt . msg_struct , * values ) | create a binary message buffer for a message |
41,153 | def find_time_base ( self , gps , first_us_stamp ) : t = self . _gpsTimeToTime ( gps . GWk , gps . GMS ) self . set_timebase ( t - gps . TimeUS * 0.000001 ) self . timestamp = self . timebase + first_us_stamp * 0.000001 | work out time basis for the log - even newer style |
41,154 | def find_time_base ( self , gps , first_ms_stamp ) : t = self . _gpsTimeToTime ( gps . Week , gps . TimeMS ) self . set_timebase ( t - gps . T * 0.001 ) self . timestamp = self . timebase + first_ms_stamp * 0.001 | work out time basis for the log - new style |
41,155 | def find_time_base ( self , gps ) : t = gps . GPSTime * 1.0e-6 self . timebase = t - self . px4_timebase | work out time basis for the log - PX4 native |
41,156 | def gps_message_arrived ( self , m ) : gps_week = getattr ( m , 'Week' , None ) gps_timems = getattr ( m , 'TimeMS' , None ) if gps_week is None : gps_week = getattr ( m , 'GWk' , None ) gps_timems = getattr ( m , 'GMS' , None ) if gps_week is None : if getattr ( m , 'GPSTime' , None ) is not None : return t = self . _gpsTimeToTime ( gps_week , gps_timems ) deltat = t - self . timebase if deltat <= 0 : return for type in self . counts_since_gps : rate = self . counts_since_gps [ type ] / deltat if rate > self . msg_rate . get ( type , 0 ) : self . msg_rate [ type ] = rate self . msg_rate [ 'IMU' ] = 50.0 self . timebase = t self . counts_since_gps = { } | adjust time base from GPS message |
41,157 | def _rewind ( self ) : self . messages = { 'MAV' : self } self . flightmode = "UNKNOWN" self . percent = 0 if self . clock : self . clock . rewind_event ( ) | reset state on rewind |
41,158 | def init_clock ( self ) : self . _rewind ( ) gps_clock = DFReaderClock_gps_interpolated ( ) self . clock = gps_clock px4_msg_time = None px4_msg_gps = None gps_interp_msg_gps1 = None gps_interp_msg_gps2 = None first_us_stamp = None first_ms_stamp = None have_good_clock = False while True : m = self . recv_msg ( ) if m is None : break type = m . get_type ( ) if first_us_stamp is None : first_us_stamp = getattr ( m , "TimeUS" , None ) if first_ms_stamp is None and ( type != 'GPS' and type != 'GPS2' ) : first_ms_stamp = getattr ( m , "TimeMS" , None ) if type == 'GPS' or type == 'GPS2' : if getattr ( m , "TimeUS" , 0 ) != 0 and getattr ( m , "GWk" , 0 ) != 0 : self . init_clock_usec ( ) if not self . _zero_time_base : self . clock . find_time_base ( m , first_us_stamp ) have_good_clock = True break if getattr ( m , "T" , 0 ) != 0 and getattr ( m , "Week" , 0 ) != 0 : if first_ms_stamp is None : first_ms_stamp = m . T self . init_clock_msec ( ) if not self . _zero_time_base : self . clock . find_time_base ( m , first_ms_stamp ) have_good_clock = True break if getattr ( m , "GPSTime" , 0 ) != 0 : px4_msg_gps = m if getattr ( m , "Week" , 0 ) != 0 : if gps_interp_msg_gps1 is not None and ( gps_interp_msg_gps1 . TimeMS != m . TimeMS or gps_interp_msg_gps1 . Week != m . Week ) : self . init_clock_gps_interpolated ( gps_clock ) have_good_clock = True break gps_interp_msg_gps1 = m elif type == 'TIME' : if getattr ( m , "StartTime" , None ) != None : px4_msg_time = m if px4_msg_time is not None and px4_msg_gps is not None : self . init_clock_px4 ( px4_msg_time , px4_msg_gps ) have_good_clock = True break if not have_good_clock : if first_us_stamp is not None : self . init_clock_usec ( ) elif first_ms_stamp is not None : self . init_clock_msec ( ) self . _rewind ( ) return | work out time basis for the log |
41,159 | def _set_time ( self , m ) : m . _timestamp = self . timestamp if len ( m . _fieldnames ) > 0 and self . clock is not None : self . clock . set_message_timestamp ( m ) | set time for a message |
41,160 | def _add_msg ( self , m ) : type = m . get_type ( ) self . messages [ type ] = m if self . clock : self . clock . message_arrived ( m ) if type == 'MSG' : if m . Message . find ( "Rover" ) != - 1 : self . mav_type = mavutil . mavlink . MAV_TYPE_GROUND_ROVER elif m . Message . find ( "Plane" ) != - 1 : self . mav_type = mavutil . mavlink . MAV_TYPE_FIXED_WING elif m . Message . find ( "Copter" ) != - 1 : self . mav_type = mavutil . mavlink . MAV_TYPE_QUADROTOR elif m . Message . startswith ( "Antenna" ) : self . mav_type = mavutil . mavlink . MAV_TYPE_ANTENNA_TRACKER if type == 'MODE' : if isinstance ( m . Mode , str ) : self . flightmode = m . Mode . upper ( ) elif 'ModeNum' in m . _fieldnames : mapping = mavutil . mode_mapping_bynumber ( self . mav_type ) if mapping is not None and m . ModeNum in mapping : self . flightmode = mapping [ m . ModeNum ] else : self . flightmode = mavutil . mode_string_acm ( m . Mode ) if type == 'STAT' and 'MainState' in m . _fieldnames : self . flightmode = mavutil . mode_string_px4 ( m . MainState ) if type == 'PARM' and getattr ( m , 'Name' , None ) is not None : self . params [ m . Name ] = m . Value self . _set_time ( m ) | add a new message |
41,161 | def recv_match ( self , condition = None , type = None , blocking = False ) : if type is not None and not isinstance ( type , list ) : type = [ type ] while True : m = self . recv_msg ( ) if m is None : return None if type is not None and not m . get_type ( ) in type : continue if not mavutil . evaluate_condition ( condition , self . messages ) : continue return m | recv the next message that matches the given condition type can be a string or a list of strings |
41,162 | def param ( self , name , default = None ) : if not name in self . params : return default return self . params [ name ] | convenient function for returning an arbitrary MAVLink parameter with a default |
41,163 | def cpu_load_send ( self , sensLoad , ctrlLoad , batVolt , force_mavlink1 = False ) : return self . send ( self . cpu_load_encode ( sensLoad , ctrlLoad , batVolt ) , force_mavlink1 = force_mavlink1 ) | Sensor and DSC control loads . |
41,164 | def ctrl_srfc_pt_send ( self , target , bitfieldPt , force_mavlink1 = False ) : return self . send ( self . ctrl_srfc_pt_encode ( target , bitfieldPt ) , force_mavlink1 = force_mavlink1 ) | This message sets the control surfaces for selective passthrough mode . |
41,165 | def slugs_mobile_location_send ( self , target , latitude , longitude , force_mavlink1 = False ) : return self . send ( self . slugs_mobile_location_encode ( target , latitude , longitude ) , force_mavlink1 = force_mavlink1 ) | Transmits the last known position of the mobile GS to the UAV . Very relevant when Track Mobile is enabled |
41,166 | def slugs_configuration_camera_send ( self , target , idOrder , order , force_mavlink1 = False ) : return self . send ( self . slugs_configuration_camera_encode ( target , idOrder , order ) , force_mavlink1 = force_mavlink1 ) | Control for camara . |
41,167 | def volt_sensor_send ( self , r2Type , voltage , reading2 , force_mavlink1 = False ) : return self . send ( self . volt_sensor_encode ( r2Type , voltage , reading2 ) , force_mavlink1 = force_mavlink1 ) | Transmits the readings from the voltage and current sensors |
41,168 | def ptz_status_send ( self , zoom , pan , tilt , force_mavlink1 = False ) : return self . send ( self . ptz_status_encode ( zoom , pan , tilt ) , force_mavlink1 = force_mavlink1 ) | Transmits the actual Pan Tilt and Zoom values of the camera unit |
41,169 | def script_request_send ( self , target_system , target_component , seq , force_mavlink1 = False ) : return self . send ( self . script_request_encode ( target_system , target_component , seq ) , force_mavlink1 = force_mavlink1 ) | Request script item with the sequence number seq . The response of the system to this message should be a SCRIPT_ITEM message . |
41,170 | def script_count_send ( self , target_system , target_component , count , force_mavlink1 = False ) : return self . send ( self . script_count_encode ( target_system , target_component , count ) , force_mavlink1 = force_mavlink1 ) | This message is emitted as response to SCRIPT_REQUEST_LIST by the MAV to get the number of mission scripts . |
41,171 | def script_current_send ( self , seq , force_mavlink1 = False ) : return self . send ( self . script_current_encode ( seq ) , force_mavlink1 = force_mavlink1 ) | This message informs about the currently active SCRIPT . |
41,172 | def generate ( basename , xml_list ) : for idx in range ( len ( xml_list ) ) : xml = xml_list [ idx ] xml . xml_idx = idx generate_one ( basename , xml ) copy_fixed_headers ( basename , xml_list [ 0 ] ) | generate complete MAVLink C implemenation |
41,173 | def update ( self ) : pos = Pose3d ( ) if self . hasproxy ( ) : pose = self . proxy . getPose3DData ( ) pos . yaw = self . quat2Yaw ( pose . q0 , pose . q1 , pose . q2 , pose . q3 ) pos . pitch = self . quat2Pitch ( pose . q0 , pose . q1 , pose . q2 , pose . q3 ) pos . roll = self . quat2Roll ( pose . q0 , pose . q1 , pose . q2 , pose . q3 ) pos . x = pose . x pos . y = pose . y pos . z = pose . z pos . h = pose . h pos . q = [ pose . q0 , pose . q1 , pose . q2 , pose . q3 ] self . lock . acquire ( ) self . pose = pos self . lock . release ( ) | Updates Pose3d . |
41,174 | def getPose3d ( self ) : self . lock . acquire ( ) pose = self . pose self . lock . release ( ) return pose | Returns last Pose3d . |
41,175 | def quat2Roll ( self , qw , qx , qy , qz ) : rotateXa0 = 2.0 * ( qy * qz + qw * qx ) rotateXa1 = qw * qw - qx * qx - qy * qy + qz * qz rotateX = 0.0 if ( rotateXa0 != 0.0 and rotateXa1 != 0.0 ) : rotateX = atan2 ( rotateXa0 , rotateXa1 ) return rotateX | Translates from Quaternion to Roll . |
41,176 | def kill_speech_dispatcher ( self ) : if not 'HOME' in os . environ : return pidpath = os . path . join ( os . environ [ 'HOME' ] , '.speech-dispatcher' , 'pid' , 'speech-dispatcher.pid' ) if os . path . exists ( pidpath ) : try : import signal pid = int ( open ( pidpath ) . read ( ) ) if pid > 1 and os . kill ( pid , 0 ) is None : print ( "Killing speech dispatcher pid %u" % pid ) os . kill ( pid , signal . SIGINT ) time . sleep ( 1 ) except Exception as e : pass | kill speech dispatcher processs |
41,177 | def loadFileList ( self ) : try : data = open ( self . filelist_file , 'rb' ) except IOError : if self . offline == 0 : self . createFileList ( ) return try : self . filelist = pickle . load ( data ) data . close ( ) if len ( self . filelist ) < self . min_filelist_len : self . filelist = { } if self . offline == 0 : self . createFileList ( ) except : if self . offline == 0 : self . createFileList ( ) | Load a previously created file list or create a new one if none is available . |
41,178 | def _avg ( value1 , value2 , weight ) : if value1 is None : return value2 if value2 is None : return value1 return value2 * weight + value1 * ( 1 - weight ) | Returns the weighted average of two values and handles the case where one value is None . If both values are None None is returned . |
41,179 | def calcOffset ( self , x , y ) : return x + self . size * ( self . size - y - 1 ) | Calculate offset into data array . Only uses to test correctness of the formula . |
41,180 | def getPixelValue ( self , x , y ) : assert x < self . size , "x: %d<%d" % ( x , self . size ) assert y < self . size , "y: %d<%d" % ( y , self . size ) offset = x + self . size * ( self . size - y - 1 ) value = self . data [ offset ] if value == - 32768 : return - 1 return value | Get the value of a pixel from the data handling voids in the SRTM data . |
41,181 | def getAltitudeFromLatLon ( self , lat , lon ) : lat -= self . lat lon -= self . lon if lat < 0.0 or lat >= 1.0 or lon < 0.0 or lon >= 1.0 : raise WrongTileError ( self . lat , self . lon , self . lat + lat , self . lon + lon ) x = lon * ( self . size - 1 ) y = lat * ( self . size - 1 ) x_int = int ( x ) x_frac = x - int ( x ) y_int = int ( y ) y_frac = y - int ( y ) value00 = self . getPixelValue ( x_int , y_int ) value10 = self . getPixelValue ( x_int + 1 , y_int ) value01 = self . getPixelValue ( x_int , y_int + 1 ) value11 = self . getPixelValue ( x_int + 1 , y_int + 1 ) value1 = self . _avg ( value00 , value10 , x_frac ) value2 = self . _avg ( value01 , value11 , x_frac ) value = self . _avg ( value1 , value2 , y_frac ) return value | Get the altitude of a lat lon pair using the four neighbouring pixels for interpolation . |
41,182 | def rewind ( self ) : self . _index = 0 self . percent = 0 self . messages = { } self . _flightmode_index = 0 self . _timestamp = None self . flightmode = None self . params = { } | rewind to start |
41,183 | def mavset ( self , mav , name , value , retries = 3 ) : got_ack = False while retries > 0 and not got_ack : retries -= 1 mav . param_set_send ( name . upper ( ) , float ( value ) ) tstart = time . time ( ) while time . time ( ) - tstart < 1 : ack = mav . recv_match ( type = 'PARAM_VALUE' , blocking = False ) if ack == None : time . sleep ( 0.1 ) continue if str ( name ) . upper ( ) == str ( ack . param_id ) . upper ( ) : got_ack = True self . __setitem__ ( name , float ( value ) ) break if not got_ack : print ( "timeout setting %s to %f" % ( name , float ( value ) ) ) return False return True | set a parameter on a mavlink connection |
41,184 | def save ( self , filename , wildcard = '*' , verbose = False ) : f = open ( filename , mode = 'w' ) k = list ( self . keys ( ) ) k . sort ( ) count = 0 for p in k : if p and fnmatch . fnmatch ( str ( p ) . upper ( ) , wildcard . upper ( ) ) : f . write ( "%-16.16s %f\n" % ( p , self . __getitem__ ( p ) ) ) count += 1 f . close ( ) if verbose : print ( "Saved %u parameters to %s" % ( count , filename ) ) | save parameters to a file |
41,185 | def load ( self , filename , wildcard = '*' , mav = None , check = True ) : try : f = open ( filename , mode = 'r' ) except : print ( "Failed to open file '%s'" % filename ) return False count = 0 changed = 0 for line in f : line = line . strip ( ) if not line or line [ 0 ] == "#" : continue line = line . replace ( ',' , ' ' ) a = line . split ( ) if len ( a ) != 2 : print ( "Invalid line: %s" % line ) continue if a [ 0 ] in self . exclude_load : continue if not fnmatch . fnmatch ( a [ 0 ] . upper ( ) , wildcard . upper ( ) ) : continue if mav is not None : if check : if a [ 0 ] not in self . keys ( ) : print ( "Unknown parameter %s" % a [ 0 ] ) continue old_value = self . __getitem__ ( a [ 0 ] ) if math . fabs ( old_value - float ( a [ 1 ] ) ) <= self . mindelta : count += 1 continue if self . mavset ( mav , a [ 0 ] , a [ 1 ] ) : print ( "changed %s from %f to %f" % ( a [ 0 ] , old_value , float ( a [ 1 ] ) ) ) else : print ( "set %s to %f" % ( a [ 0 ] , float ( a [ 1 ] ) ) ) self . mavset ( mav , a [ 0 ] , a [ 1 ] ) changed += 1 else : self . __setitem__ ( a [ 0 ] , float ( a [ 1 ] ) ) count += 1 f . close ( ) if mav is not None : print ( "Loaded %u parameters from %s (changed %u)" % ( count , filename , changed ) ) else : print ( "Loaded %u parameters from %s" % ( count , filename ) ) return True | load parameters from a file |
41,186 | def diff ( self , filename , wildcard = '*' ) : other = MAVParmDict ( ) if not other . load ( filename ) : return keys = sorted ( list ( set ( self . keys ( ) ) . union ( set ( other . keys ( ) ) ) ) ) for k in keys : if not fnmatch . fnmatch ( str ( k ) . upper ( ) , wildcard . upper ( ) ) : continue if not k in other : print ( "%-16.16s %12.4f" % ( k , self [ k ] ) ) elif not k in self : print ( "%-16.16s %12.4f" % ( k , other [ k ] ) ) elif abs ( self [ k ] - other [ k ] ) > self . mindelta : print ( "%-16.16s %12.4f %12.4f" % ( k , other [ k ] , self [ k ] ) ) | show differences with another parameter file |
41,187 | def generate ( basename , xml_list ) : for xml in xml_list : generate_one ( basename , xml ) generate_enums ( basename , xml ) generate_MAVLinkMessage ( basename , xml_list ) copy_fixed_headers ( basename , xml_list [ 0 ] ) | generate complete MAVLink Java implemenation |
41,188 | def aq_telemetry_f_encode ( self , Index , value1 , value2 , value3 , value4 , value5 , value6 , value7 , value8 , value9 , value10 , value11 , value12 , value13 , value14 , value15 , value16 , value17 , value18 , value19 , value20 ) : return MAVLink_aq_telemetry_f_message ( Index , value1 , value2 , value3 , value4 , value5 , value6 , value7 , value8 , value9 , value10 , value11 , value12 , value13 , value14 , value15 , value16 , value17 , value18 , value19 , value20 ) | Sends up to 20 raw float values . |
41,189 | def close ( self ) : self . close_event . set ( ) if self . is_alive ( ) : self . child . join ( 2 ) | close the console |
41,190 | def cmd_rally_add ( self , args ) : if len ( args ) < 1 : alt = self . settings . rallyalt else : alt = float ( args [ 0 ] ) if len ( args ) < 2 : break_alt = self . settings . rally_breakalt else : break_alt = float ( args [ 1 ] ) if len ( args ) < 3 : flag = self . settings . rally_flags else : flag = int ( args [ 2 ] ) if ( flag != 0 ) : flag = 2 if not self . have_list : print ( "Please list rally points first" ) return if ( self . rallyloader . rally_count ( ) > 4 ) : print ( "Only 5 rally points possible per flight plan." ) return try : latlon = self . module ( 'map' ) . click_position except Exception : print ( "No map available" ) return if latlon is None : print ( "No map click position available" ) return land_hdg = 0.0 self . rallyloader . create_and_append_rally_point ( latlon [ 0 ] * 1e7 , latlon [ 1 ] * 1e7 , alt , break_alt , land_hdg , flag ) self . send_rally_points ( ) print ( "Added Rally point at %s %f %f, autoland: %s" % ( str ( latlon ) , alt , break_alt , bool ( flag & 2 ) ) ) | handle rally add |
41,191 | def cmd_rally_alt ( self , args ) : if ( len ( args ) < 2 ) : print ( "Usage: rally alt RALLYNUM newAlt <newBreakAlt>" ) return if not self . have_list : print ( "Please list rally points first" ) return idx = int ( args [ 0 ] ) if idx <= 0 or idx > self . rallyloader . rally_count ( ) : print ( "Invalid rally point number %u" % idx ) return new_alt = int ( args [ 1 ] ) new_break_alt = None if ( len ( args ) > 2 ) : new_break_alt = int ( args [ 2 ] ) self . rallyloader . set_alt ( idx , new_alt , new_break_alt ) self . send_rally_point ( idx - 1 ) self . fetch_rally_point ( idx - 1 ) self . rallyloader . reindex ( ) | handle rally alt change |
41,192 | def cmd_rally_move ( self , args ) : if len ( args ) < 1 : print ( "Usage: rally move RALLYNUM" ) return if not self . have_list : print ( "Please list rally points first" ) return idx = int ( args [ 0 ] ) if idx <= 0 or idx > self . rallyloader . rally_count ( ) : print ( "Invalid rally point number %u" % idx ) return rpoint = self . rallyloader . rally_point ( idx - 1 ) try : latlon = self . module ( 'map' ) . click_position except Exception : print ( "No map available" ) return if latlon is None : print ( "No map click position available" ) return oldpos = ( rpoint . lat * 1e-7 , rpoint . lng * 1e-7 ) self . rallyloader . move ( idx , latlon [ 0 ] , latlon [ 1 ] ) self . send_rally_point ( idx - 1 ) p = self . fetch_rally_point ( idx - 1 ) if p . lat != int ( latlon [ 0 ] * 1e7 ) or p . lng != int ( latlon [ 1 ] * 1e7 ) : print ( "Rally move failed" ) return self . rallyloader . reindex ( ) print ( "Moved rally point from %s to %s at %fm" % ( str ( oldpos ) , str ( latlon ) , rpoint . alt ) ) | handle rally move |
41,193 | def cmd_rally ( self , args ) : if len ( args ) < 1 : self . print_usage ( ) return elif args [ 0 ] == "add" : self . cmd_rally_add ( args [ 1 : ] ) elif args [ 0 ] == "move" : self . cmd_rally_move ( args [ 1 : ] ) elif args [ 0 ] == "clear" : self . rallyloader . clear ( ) self . mav_param . mavset ( self . master , 'RALLY_TOTAL' , 0 , 3 ) elif args [ 0 ] == "remove" : if not self . have_list : print ( "Please list rally points first" ) return if ( len ( args ) < 2 ) : print ( "Usage: rally remove RALLYNUM" ) return self . rallyloader . remove ( int ( args [ 1 ] ) ) self . send_rally_points ( ) elif args [ 0 ] == "list" : self . list_rally_points ( ) self . have_list = True elif args [ 0 ] == "load" : if ( len ( args ) < 2 ) : print ( "Usage: rally load filename" ) return try : self . rallyloader . load ( args [ 1 ] ) except Exception as msg : print ( "Unable to load %s - %s" % ( args [ 1 ] , msg ) ) return self . send_rally_points ( ) self . have_list = True print ( "Loaded %u rally points from %s" % ( self . rallyloader . rally_count ( ) , args [ 1 ] ) ) elif args [ 0 ] == "save" : if ( len ( args ) < 2 ) : print ( "Usage: rally save filename" ) return self . rallyloader . save ( args [ 1 ] ) print ( "Saved rally file %s" % args [ 1 ] ) elif args [ 0 ] == "alt" : self . cmd_rally_alt ( args [ 1 : ] ) elif args [ 0 ] == "land" : if ( len ( args ) >= 2 and args [ 1 ] == "abort" ) : self . abort_ack_received = False self . abort_first_send_time = 0 self . abort_alt = self . settings . rally_breakalt if ( len ( args ) >= 3 ) : self . abort_alt = int ( args [ 2 ] ) else : self . master . mav . command_long_send ( self . settings . target_system , self . settings . target_component , mavutil . mavlink . MAV_CMD_DO_RALLY_LAND , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) else : self . print_usage ( ) | rally point commands |
41,194 | def mavlink_packet ( self , m ) : type = m . get_type ( ) if type in [ 'COMMAND_ACK' ] : if m . command == mavutil . mavlink . MAV_CMD_DO_GO_AROUND : if ( m . result == 0 and self . abort_ack_received == False ) : self . say ( "Landing Abort Command Successfully Sent." ) self . abort_ack_received = True elif ( m . result != 0 and self . abort_ack_received == False ) : self . say ( "Landing Abort Command Unsuccessful." ) elif m . command == mavutil . mavlink . MAV_CMD_DO_RALLY_LAND : if ( m . result == 0 ) : self . say ( "Landing." ) | handle incoming mavlink packet |
41,195 | def send_rally_point ( self , i ) : p = self . rallyloader . rally_point ( i ) p . target_system = self . target_system p . target_component = self . target_component self . master . mav . send ( p ) | send rally points from fenceloader |
41,196 | def send_rally_points ( self ) : self . mav_param . mavset ( self . master , 'RALLY_TOTAL' , self . rallyloader . rally_count ( ) , 3 ) for i in range ( self . rallyloader . rally_count ( ) ) : self . send_rally_point ( i ) | send rally points from rallyloader |
41,197 | def getBumper ( self ) : if self . hasproxy ( ) : self . lock . acquire ( ) bumper = self . bumper self . lock . release ( ) return bumper return None | Returns last Bumper . |
41,198 | def imageMsg2Image ( img , bridge ) : image = Image ( ) image . width = img . width image . height = img . height image . format = "RGB8" image . timeStamp = img . header . stamp . secs + ( img . header . stamp . nsecs * 1e-9 ) cv_image = 0 if ( img . encoding == "32FC1" ) : gray_img_buff = bridge . imgmsg_to_cv2 ( img , "32FC1" ) cv_image = depthToRGB8 ( gray_img_buff ) else : cv_image = bridge . imgmsg_to_cv2 ( img , "rgb8" ) image . data = cv_image return image | Translates from ROS Image to JderobotTypes Image . |
41,199 | def Images2Rgbd ( rgb , d ) : data = Rgbd ( ) data . color = imageMsg2Image ( rgb ) data . depth = imageMsg2Image ( d ) data . timeStamp = rgb . header . stamp . secs + ( rgb . header . stamp . nsecs * 1e-9 ) return data | Translates from ROS Images to JderobotTypes Rgbd . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.