idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
230,200 | def rule_expand ( component , text ) : global rline_mpstate if component [ 0 ] == '<' and component [ - 1 ] == '>' : return component [ 1 : - 1 ] . split ( '|' ) if component in rline_mpstate . completion_functions : return rline_mpstate . completion_functions [ component ] ( text ) return [ component ] | expand one rule component |
230,201 | def rule_match ( component , cmd ) : if component == cmd : return True expanded = rule_expand ( component , cmd ) if cmd in expanded : return True return False | see if one rule component matches |
230,202 | def complete_rules ( rules , cmd ) : if not isinstance ( rules , list ) : rules = [ rules ] ret = [ ] for r in rules : ret += complete_rule ( r , cmd ) return ret | complete using a list of completion rules |
230,203 | def complete ( text , state ) : global last_clist global rline_mpstate if state != 0 and last_clist is not None : return last_clist [ state ] cmd = readline . get_line_buffer ( ) . split ( ) if len ( cmd ) == 1 : last_clist = complete_command ( text ) + complete_alias ( text ) elif cmd [ 0 ] in rline_mpstate . completi... | completion routine for when user presses tab |
230,204 | def laserScan2LaserData ( scan ) : laser = LaserData ( ) laser . values = scan . ranges laser . minAngle = scan . angle_min + PI / 2 laser . maxAngle = scan . angle_max + PI / 2 laser . maxRange = scan . range_max laser . minRange = scan . range_min laser . timeStamp = scan . header . stamp . secs + ( scan . header . s... | Translates from ROS LaserScan to JderobotTypes LaserData . |
230,205 | def __callback ( self , scan ) : laser = laserScan2LaserData ( scan ) self . lock . acquire ( ) self . data = laser self . lock . release ( ) | Callback function to receive and save Laser Scans . |
230,206 | def add_to_linestring ( position_data , kml_linestring ) : global kml position_data [ 2 ] += float ( args . aoff ) kml_linestring . coords . addcoordinates ( [ position_data ] ) | add a point to the kml file |
230,207 | def sniff_field_spelling ( mlog , source ) : position_field_type_default = position_field_types [ 0 ] msg = mlog . recv_match ( source ) mlog . _rewind ( ) position_field_selection = [ spelling for spelling in position_field_types if hasattr ( msg , spelling [ 0 ] ) ] return position_field_selection [ 0 ] if position_f... | attempt to detect whether APM or PX4 attributes names are in use |
230,208 | def cmd_link_ports ( self ) : ports = mavutil . auto_detect_serial ( preferred_list = [ '*FTDI*' , "*Arduino_Mega_2560*" , "*3D_Robotics*" , "*USB_to_UART*" , '*PX4*' , '*FMU*' ] ) for p in ports : print ( "%s : %s : %s" % ( p . device , p . description , p . hwid ) ) | show available ports |
230,209 | def writeln ( self , text , fg = 'black' , bg = 'white' ) : if not isinstance ( text , str ) : text = str ( text ) self . write ( text + '\n' , fg = fg , bg = bg ) | write to the console with linefeed |
230,210 | def match_extension ( f ) : ( root , ext ) = os . path . splitext ( f ) return ext . lower ( ) in extensions | see if the path matches a extension |
230,211 | def path ( self ) : ( x , y ) = self . tile return os . path . join ( '%u' % self . zoom , '%u' % y , '%u.img' % x ) | return relative path of tile image |
230,212 | def url ( self , service ) : if service not in TILE_SERVICES : raise TileException ( 'unknown tile service %s' % service ) url = string . Template ( TILE_SERVICES [ service ] ) ( x , y ) = self . tile tile_info = TileServiceInfo ( x , y , self . zoom ) return url . substitute ( tile_info ) | return URL for a tile |
230,213 | def tile_to_path ( self , tile ) : return os . path . join ( self . cache_path , self . service , tile . path ( ) ) | return full path to a tile |
230,214 | def start_download_thread ( self ) : if self . _download_thread : return t = threading . Thread ( target = self . downloader ) t . daemon = True self . _download_thread = t t . start ( ) | start the downloader |
230,215 | def qnh_estimate ( self ) : alt_gps = self . master . field ( 'GPS_RAW_INT' , 'alt' , 0 ) * 0.001 pressure2 = self . master . field ( 'SCALED_PRESSURE' , 'press_abs' , 0 ) ground_temp = self . get_mav_param ( 'GND_TEMP' , 21 ) temp = ground_temp + 273.15 pressure1 = pressure2 / math . exp ( math . log ( 1.0 - ( alt_gps... | estimate QNH pressure from GPS altitude and scaled pressure |
230,216 | def cmd_up ( self , args ) : if len ( args ) == 0 : adjust = 5.0 else : adjust = float ( args [ 0 ] ) old_trim = self . get_mav_param ( 'TRIM_PITCH_CD' , None ) if old_trim is None : print ( "Existing trim value unknown!" ) return new_trim = int ( old_trim + ( adjust * 100 ) ) if math . fabs ( new_trim - old_trim ) > 1... | adjust TRIM_PITCH_CD up by 5 degrees |
230,217 | def cmd_time ( self , args ) : tusec = self . master . field ( 'SYSTEM_TIME' , 'time_unix_usec' , 0 ) if tusec == 0 : print ( "No SYSTEM_TIME time available" ) return print ( "%s (%s)\n" % ( time . ctime ( tusec * 1.0e-6 ) , time . ctime ( ) ) ) | show autopilot time |
230,218 | def cmd_changealt ( self , args ) : if len ( args ) < 1 : print ( "usage: changealt <relaltitude>" ) return relalt = float ( args [ 0 ] ) self . master . mav . mission_item_send ( self . settings . target_system , self . settings . target_component , 0 , 3 , mavutil . mavlink . MAV_CMD_NAV_WAYPOINT , 3 , 1 , 0 , 0 , 0 ... | change target altitude |
230,219 | def cmd_land ( self , args ) : if len ( args ) < 1 : self . master . mav . command_long_send ( self . settings . target_system , 0 , mavutil . mavlink . MAV_CMD_DO_LAND_START , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) elif args [ 0 ] == 'abort' : self . master . mav . command_long_send ( self . settings . target_system , 0 , ma... | auto land commands |
230,220 | def cmd_rcbind ( self , args ) : if len ( args ) < 1 : print ( "Usage: rcbind <dsmmode>" ) return self . master . mav . command_long_send ( self . settings . target_system , self . settings . target_component , mavutil . mavlink . MAV_CMD_START_RX_PAIR , 0 , float ( args [ 0 ] ) , 0 , 0 , 0 , 0 , 0 , 0 ) | start RC bind |
230,221 | def cmd_repeat ( self , args ) : if len ( args ) == 0 : if len ( self . repeats ) == 0 : print ( "No repeats" ) return for i in range ( len ( self . repeats ) ) : print ( "%u: %s" % ( i , self . repeats [ i ] ) ) return if args [ 0 ] == 'add' : if len ( args ) < 3 : print ( "Usage: repeat add PERIOD CMD" ) return self ... | repeat a command at regular intervals |
230,222 | def show_position ( self ) : pos = self . click_position dms = ( mp_util . degrees_to_dms ( pos [ 0 ] ) , mp_util . degrees_to_dms ( pos [ 1 ] ) ) msg = "Coordinates in WGS84\n" msg += "Decimal: %.6f %.6f\n" % ( pos [ 0 ] , pos [ 1 ] ) msg += "DMS: %s %s\n" % ( dms [ 0 ] , dms [ 1 ] ) msg += "Grid: %s\n" % mp_ut... | show map position click information |
230,223 | def display_fence ( self ) : from MAVProxy . modules . mavproxy_map import mp_slipmap self . fence_change_time = self . module ( 'fence' ) . fenceloader . last_change points = self . module ( 'fence' ) . fenceloader . polygon ( ) self . mpstate . map . add_object ( mp_slipmap . SlipClearLayer ( 'Fence' ) ) if len ( poi... | display the fence |
230,224 | def closest_waypoint ( self , latlon ) : ( lat , lon ) = latlon best_distance = - 1 closest = - 1 for i in range ( self . module ( 'wp' ) . wploader . count ( ) ) : w = self . module ( 'wp' ) . wploader . wp ( i ) distance = mp_util . gps_distance ( lat , lon , w . x , w . y ) if best_distance == - 1 or distance < best... | find closest waypoint to a position |
230,225 | def selection_index_to_idx ( self , key , selection_index ) : a = key . split ( ' ' ) if a [ 0 ] != 'mission' or len ( a ) != 2 : print ( "Bad mission object %s" % key ) return None midx = int ( a [ 1 ] ) if midx < 0 or midx >= len ( self . mission_list ) : print ( "Bad mission index %s" % key ) return None mlist = sel... | return a mission idx from a selection_index |
230,226 | def move_mission ( self , key , selection_index ) : idx = self . selection_index_to_idx ( key , selection_index ) self . moving_wp = idx print ( "Moving wp %u" % idx ) | move a mission point |
230,227 | def remove_mission ( self , key , selection_index ) : idx = self . selection_index_to_idx ( key , selection_index ) self . mpstate . functions . process_stdin ( 'wp remove %u' % idx ) | remove a mission point |
230,228 | def create_vehicle_icon ( self , name , colour , follow = False , vehicle_type = None ) : from MAVProxy . modules . mavproxy_map import mp_slipmap if vehicle_type is None : vehicle_type = self . vehicle_type_name if name in self . have_vehicle and self . have_vehicle [ name ] == vehicle_type : return self . have_vehicl... | add a vehicle to the map |
230,229 | def drawing_update ( self ) : from MAVProxy . modules . mavproxy_map import mp_slipmap if self . draw_callback is None : return self . draw_line . append ( self . click_position ) if len ( self . draw_line ) > 1 : self . mpstate . map . add_object ( mp_slipmap . SlipPolygon ( 'drawing' , self . draw_line , layer = 'Dra... | update line drawing |
230,230 | def load ( filename ) : filepath = findConfigFile ( filename ) prop = None if ( filepath ) : print ( 'loading Config file %s' % ( filepath ) ) with open ( filepath , 'r' ) as stream : cfg = yaml . load ( stream ) prop = Properties ( cfg ) else : msg = "Ice.Config file '%s' could not being found" % ( filename ) raise Va... | Returns the configuration as dict |
230,231 | def fetch_check ( self , master ) : if self . param_period . trigger ( ) : if master is None : return if len ( self . mav_param_set ) == 0 : master . param_fetch_all ( ) elif self . mav_param_count != 0 and len ( self . mav_param_set ) != self . mav_param_count : if master . time_since ( 'PARAM_VALUE' ) >= 1 : diff = s... | check for missing parameters periodically |
230,232 | def watch_thread ( self ) : from mp_settings import MPSetting while True : setting = self . child_pipe . recv ( ) if not isinstance ( setting , MPSetting ) : break try : self . settings . set ( setting . name , setting . value ) except Exception : print ( "Unable to set %s to %s" % ( setting . name , setting . value ) ... | watch for settings changes from child |
230,233 | def report ( self , name , ok , msg = None , deltat = 20 ) : r = self . reports [ name ] if time . time ( ) < r . last_report + deltat : r . ok = ok return r . last_report = time . time ( ) if ok and not r . ok : self . say ( "%s OK" % name ) r . ok = ok if not r . ok : self . say ( msg ) | report a sensor error |
230,234 | def report_change ( self , name , value , maxdiff = 1 , deltat = 10 ) : r = self . reports [ name ] if time . time ( ) < r . last_report + deltat : return r . last_report = time . time ( ) if math . fabs ( r . value - value ) < maxdiff : return r . value = value self . say ( "%s %u" % ( name , value ) ) | report a sensor change |
230,235 | def close ( self ) : self . close_window . release ( ) count = 0 while self . child . is_alive ( ) and count < 30 : time . sleep ( 0.1 ) count += 1 if self . child . is_alive ( ) : self . child . terminate ( ) self . child . join ( ) | close the window |
230,236 | def hide_object ( self , key , hide = True ) : self . object_queue . put ( SlipHideObject ( key , hide ) ) | hide an object on the map by key |
230,237 | def set_position ( self , key , latlon , layer = None , rotation = 0 ) : self . object_queue . put ( SlipPosition ( key , latlon , layer , rotation ) ) | move an object on the map |
230,238 | def check_events ( self ) : while self . event_count ( ) > 0 : event = self . get_event ( ) for callback in self . _callbacks : callback ( event ) | check for events calling registered callbacks as needed |
230,239 | def radius_cmp ( a , b , offsets ) : diff = radius ( a , offsets ) - radius ( b , offsets ) if diff > 0 : return 1 if diff < 0 : return - 1 return 0 | return + 1 or - 1 for for sorting |
230,240 | def plot_data ( orig_data , data ) : import numpy as np from mpl_toolkits . mplot3d import Axes3D import matplotlib . pyplot as plt for dd , c in [ ( orig_data , 'r' ) , ( data , 'b' ) ] : fig = plt . figure ( ) ax = fig . add_subplot ( 111 , projection = '3d' ) xs = [ d . x for d in dd ] ys = [ d . y for d in dd ] zs ... | plot data in 3D |
230,241 | def find_end ( self , text , start_token , end_token , ignore_end_token = None ) : if not text . startswith ( start_token ) : raise MAVParseError ( "invalid token start" ) offset = len ( start_token ) nesting = 1 while nesting > 0 : idx1 = text [ offset : ] . find ( start_token ) idx2 = text [ offset : ] . find ( end_t... | find the of a token . Returns the offset in the string immediately after the matching end_token |
230,242 | def find_var_end ( self , text ) : return self . find_end ( text , self . start_var_token , self . end_var_token ) | find the of a variable |
230,243 | def find_rep_end ( self , text ) : return self . find_end ( text , self . start_rep_token , self . end_rep_token , ignore_end_token = self . end_var_token ) | find the of a repitition |
230,244 | def write ( self , file , text , subvars = { } , trim_leading_lf = True ) : file . write ( self . substitute ( text , subvars = subvars , trim_leading_lf = trim_leading_lf ) ) | write to a file with variable substitution |
230,245 | def flight_time ( logfile ) : print ( "Processing log %s" % filename ) mlog = mavutil . mavlink_connection ( filename ) in_air = False start_time = 0.0 total_time = 0.0 total_dist = 0.0 t = None last_msg = None last_time_usec = None while True : m = mlog . recv_match ( type = [ 'GPS' , 'GPS_RAW_INT' ] , condition = arg... | work out flight time for a log file |
230,246 | def match_type ( mtype , patterns ) : for p in patterns : if fnmatch . fnmatch ( mtype , p ) : return True return False | return True if mtype matches pattern |
230,247 | def apply ( self , img ) : yup , uup , vup = self . getUpLimit ( ) ydwn , udwn , vdwn = self . getDownLimit ( ) yuv = cv2 . cvtColor ( img , cv2 . COLOR_BGR2YUV ) minValues = np . array ( [ ydwn , udwn , vdwn ] , dtype = np . uint8 ) maxValues = np . array ( [ yup , uup , vup ] , dtype = np . uint8 ) mask = cv2 . inRan... | We convert RGB as BGR because OpenCV with RGB pass to YVU instead of YUV |
230,248 | def on_menu ( self , event ) : state = self . state ret = self . menu . find_selected ( event ) if ret is None : return ret . call_handler ( ) state . child_pipe_send . send ( ret ) | handle menu selections |
230,249 | def aslctrl_data_encode ( self , timestamp , aslctrl_mode , h , hRef , hRef_t , PitchAngle , PitchAngleRef , q , qRef , uElev , uThrot , uThrot2 , nZ , AirspeedRef , SpoilersEngaged , YawAngle , YawAngleRef , RollAngle , RollAngleRef , p , pRef , r , rRef , uAil , uRud ) : return MAVLink_aslctrl_data_message ( timestam... | ASL - fixed - wing controller data |
230,250 | def average ( var , key , N ) : global average_data if not key in average_data : average_data [ key ] = [ var ] * N return var average_data [ key ] . pop ( 0 ) average_data [ key ] . append ( var ) return sum ( average_data [ key ] ) / N | average over N points |
230,251 | def second_derivative_5 ( var , key ) : global derivative_data import mavutil tnow = mavutil . mavfile_global . timestamp if not key in derivative_data : derivative_data [ key ] = ( tnow , [ var ] * 5 ) return 0 ( last_time , data ) = derivative_data [ key ] data . pop ( 0 ) data . append ( var ) derivative_data [ key ... | 5 point 2nd derivative |
230,252 | def lowpass ( var , key , factor ) : global lowpass_data if not key in lowpass_data : lowpass_data [ key ] = var else : lowpass_data [ key ] = factor * lowpass_data [ key ] + ( 1.0 - factor ) * var return lowpass_data [ key ] | a simple lowpass filter |
230,253 | def diff ( var , key ) : global last_diff ret = 0 if not key in last_diff : last_diff [ key ] = var return 0 ret = var - last_diff [ key ] last_diff [ key ] = var return ret | calculate differences between values |
230,254 | def roll_estimate ( RAW_IMU , GPS_RAW_INT = None , ATTITUDE = None , SENSOR_OFFSETS = None , ofs = None , mul = None , smooth = 0.7 ) : rx = RAW_IMU . xacc * 9.81 / 1000.0 ry = RAW_IMU . yacc * 9.81 / 1000.0 rz = RAW_IMU . zacc * 9.81 / 1000.0 if ATTITUDE is not None and GPS_RAW_INT is not None : ry -= ATTITUDE . yawsp... | estimate roll from accelerometer |
230,255 | def mag_rotation ( RAW_IMU , inclination , declination ) : m_body = Vector3 ( RAW_IMU . xmag , RAW_IMU . ymag , RAW_IMU . zmag ) m_earth = Vector3 ( m_body . length ( ) , 0 , 0 ) r = Matrix3 ( ) r . from_euler ( 0 , - radians ( inclination ) , radians ( declination ) ) m_earth = r * m_earth r . from_two_vectors ( m_ear... | return an attitude rotation matrix that is consistent with the current mag vector |
230,256 | def mag_yaw ( RAW_IMU , inclination , declination ) : m = mag_rotation ( RAW_IMU , inclination , declination ) ( r , p , y ) = m . to_euler ( ) y = degrees ( y ) if y < 0 : y += 360 return y | estimate yaw from mag |
230,257 | def mag_roll ( RAW_IMU , inclination , declination ) : m = mag_rotation ( RAW_IMU , inclination , declination ) ( r , p , y ) = m . to_euler ( ) return degrees ( r ) | estimate roll from mag |
230,258 | def expected_mag ( RAW_IMU , ATTITUDE , inclination , declination ) : m_body = Vector3 ( RAW_IMU . xmag , RAW_IMU . ymag , RAW_IMU . zmag ) field_strength = m_body . length ( ) m = rotation ( ATTITUDE ) r = Matrix3 ( ) r . from_euler ( 0 , - radians ( inclination ) , radians ( declination ) ) m_earth = r * Vector3 ( fi... | return expected mag vector |
230,259 | def gravity ( RAW_IMU , SENSOR_OFFSETS = None , ofs = None , mul = None , smooth = 0.7 ) : if hasattr ( RAW_IMU , 'xacc' ) : rx = RAW_IMU . xacc * 9.81 / 1000.0 ry = RAW_IMU . yacc * 9.81 / 1000.0 rz = RAW_IMU . zacc * 9.81 / 1000.0 else : rx = RAW_IMU . AccX ry = RAW_IMU . AccY rz = RAW_IMU . AccZ if SENSOR_OFFSETS is... | estimate pitch from accelerometer |
230,260 | def pitch_sim ( SIMSTATE , GPS_RAW ) : xacc = SIMSTATE . xacc - lowpass ( delta ( GPS_RAW . v , "v" ) * 6.6 , "v" , 0.9 ) zacc = SIMSTATE . zacc zacc += SIMSTATE . ygyro * GPS_RAW . v if xacc / zacc >= 1 : return 0 if xacc / zacc <= - 1 : return - 0 return degrees ( - asin ( xacc / zacc ) ) | estimate pitch from SIMSTATE accels |
230,261 | def distance_home ( GPS_RAW ) : global first_fix if ( hasattr ( GPS_RAW , 'fix_type' ) and GPS_RAW . fix_type < 2 ) or ( hasattr ( GPS_RAW , 'Status' ) and GPS_RAW . Status < 2 ) : return 0 if first_fix == None : first_fix = GPS_RAW return 0 return distance_two ( GPS_RAW , first_fix ) | distance from first fix point |
230,262 | def sawtooth ( ATTITUDE , amplitude = 2.0 , period = 5.0 ) : mins = ( ATTITUDE . usec * 1.0e-6 ) / 60 p = fmod ( mins , period * 2 ) if p < period : return amplitude * ( p / period ) return amplitude * ( period - ( p - period ) ) / period | sawtooth pattern based on uptime |
230,263 | def EAS2TAS ( ARSP , GPS , BARO , ground_temp = 25 ) : tempK = ground_temp + 273.15 - 0.0065 * GPS . Alt return sqrt ( 1.225 / ( BARO . Press / ( 287.26 * tempK ) ) ) | EAS2TAS from ARSP . Temp |
230,264 | def airspeed_voltage ( VFR_HUD , ratio = None ) : import mavutil mav = mavutil . mavfile_global if ratio is None : ratio = 1.9936 if 'ARSPD_RATIO' in mav . params : used_ratio = mav . params [ 'ARSPD_RATIO' ] else : used_ratio = ratio if 'ARSPD_OFFSET' in mav . params : offset = mav . params [ 'ARSPD_OFFSET' ] else : r... | back - calculate the voltage the airspeed sensor must have seen |
230,265 | def earth_rates ( ATTITUDE ) : from math import sin , cos , tan , fabs p = ATTITUDE . rollspeed q = ATTITUDE . pitchspeed r = ATTITUDE . yawspeed phi = ATTITUDE . roll theta = ATTITUDE . pitch psi = ATTITUDE . yaw phiDot = p + tan ( theta ) * ( q * sin ( phi ) + r * cos ( phi ) ) thetaDot = q * cos ( phi ) - r * sin ( ... | return angular velocities in earth frame |
230,266 | def gps_velocity_body ( GPS_RAW_INT , ATTITUDE ) : r = rotation ( ATTITUDE ) return r . transposed ( ) * Vector3 ( GPS_RAW_INT . vel * 0.01 * cos ( radians ( GPS_RAW_INT . cog * 0.01 ) ) , GPS_RAW_INT . vel * 0.01 * sin ( radians ( GPS_RAW_INT . cog * 0.01 ) ) , - tan ( ATTITUDE . pitch ) * GPS_RAW_INT . vel * 0.01 ) | return GPS velocity vector in body frame |
230,267 | def earth_accel ( RAW_IMU , ATTITUDE ) : r = rotation ( ATTITUDE ) accel = Vector3 ( RAW_IMU . xacc , RAW_IMU . yacc , RAW_IMU . zacc ) * 9.81 * 0.001 return r * accel | return earth frame acceleration vector |
230,268 | def earth_gyro ( RAW_IMU , ATTITUDE ) : r = rotation ( ATTITUDE ) accel = Vector3 ( degrees ( RAW_IMU . xgyro ) , degrees ( RAW_IMU . ygyro ) , degrees ( RAW_IMU . zgyro ) ) * 0.001 return r * accel | return earth frame gyro vector |
230,269 | def airspeed_energy_error ( NAV_CONTROLLER_OUTPUT , VFR_HUD ) : aspeed_cm = VFR_HUD . airspeed * 100 target_airspeed = NAV_CONTROLLER_OUTPUT . aspd_error + aspeed_cm airspeed_energy_error = ( ( target_airspeed * target_airspeed ) - ( aspeed_cm * aspeed_cm ) ) * 0.00005 return airspeed_energy_error | return airspeed energy error matching APM internals This is positive when we are going too slow |
230,270 | def energy_error ( NAV_CONTROLLER_OUTPUT , VFR_HUD ) : aspeed_energy_error = airspeed_energy_error ( NAV_CONTROLLER_OUTPUT , VFR_HUD ) alt_error = NAV_CONTROLLER_OUTPUT . alt_error * 100 energy_error = aspeed_energy_error + alt_error * 0.098 return energy_error | return energy error matching APM internals This is positive when we are too low or going too slow |
230,271 | def mixer ( servo1 , servo2 , mixtype = 1 , gain = 0.5 ) : s1 = servo1 - 1500 s2 = servo2 - 1500 v1 = ( s1 - s2 ) * gain v2 = ( s1 + s2 ) * gain if mixtype == 2 : v2 = - v2 elif mixtype == 3 : v1 = - v1 elif mixtype == 4 : v1 = - v1 v2 = - v2 if v1 > 600 : v1 = 600 elif v1 < - 600 : v1 = - 600 if v2 > 600 : v2 = 600 el... | mix two servos |
230,272 | def DCM_update ( IMU , ATT , MAG , GPS ) : global dcm_state if dcm_state is None : dcm_state = DCM_State ( ATT . Roll , ATT . Pitch , ATT . Yaw ) mag = Vector3 ( MAG . MagX , MAG . MagY , MAG . MagZ ) gyro = Vector3 ( IMU . GyrX , IMU . GyrY , IMU . GyrZ ) accel = Vector3 ( IMU . AccX , IMU . AccY , IMU . AccZ ) accel2... | implement full DCM system |
230,273 | def PX4_update ( IMU , ATT ) : global px4_state if px4_state is None : px4_state = PX4_State ( degrees ( ATT . Roll ) , degrees ( ATT . Pitch ) , degrees ( ATT . Yaw ) , IMU . _timestamp ) gyro = Vector3 ( IMU . GyroX , IMU . GyroY , IMU . GyroZ ) accel = Vector3 ( IMU . AccX , IMU . AccY , IMU . AccZ ) px4_state . upd... | implement full DCM using PX4 native SD log data |
230,274 | def armed ( HEARTBEAT ) : from . import mavutil if HEARTBEAT . type == mavutil . mavlink . MAV_TYPE_GCS : self = mavutil . mavfile_global if self . motors_armed ( ) : return 1 return 0 if HEARTBEAT . base_mode & mavutil . mavlink . MAV_MODE_FLAG_SAFETY_ARMED : return 1 return 0 | return 1 if armed 0 if not |
230,275 | def earth_accel2 ( RAW_IMU , ATTITUDE ) : r = rotation2 ( ATTITUDE ) accel = Vector3 ( RAW_IMU . xacc , RAW_IMU . yacc , RAW_IMU . zacc ) * 9.81 * 0.001 return r * accel | return earth frame acceleration vector from AHRS2 |
230,276 | def ekf1_pos ( EKF1 ) : global ekf_home from . import mavutil self = mavutil . mavfile_global if ekf_home is None : if not 'GPS' in self . messages or self . messages [ 'GPS' ] . Status != 3 : return None ekf_home = self . messages [ 'GPS' ] ( ekf_home . Lat , ekf_home . Lng ) = gps_offset ( ekf_home . Lat , ekf_home .... | calculate EKF position when EKF disabled |
230,277 | def cmd_condition_yaw ( self , args ) : if ( len ( args ) != 3 ) : print ( "Usage: yaw ANGLE ANGULAR_SPEED MODE:[0 absolute / 1 relative]" ) return if ( len ( args ) == 3 ) : angle = float ( args [ 0 ] ) angular_speed = float ( args [ 1 ] ) angle_mode = float ( args [ 2 ] ) print ( "ANGLE %s" % ( str ( angle ) ) ) self... | yaw angle angular_speed angle_mode |
230,278 | def cmd_velocity ( self , args ) : if ( len ( args ) != 3 ) : print ( "Usage: velocity x y z (m/s)" ) return if ( len ( args ) == 3 ) : x_mps = float ( args [ 0 ] ) y_mps = float ( args [ 1 ] ) z_mps = float ( args [ 2 ] ) self . master . mav . set_position_target_local_ned_send ( 0 , 0 , 0 , mavutil . mavlink . MAV_FR... | velocity x - ms y - ms z - ms |
230,279 | def cmd_position ( self , args ) : if ( len ( args ) != 3 ) : print ( "Usage: position x y z (meters)" ) return if ( len ( args ) == 3 ) : x_m = float ( args [ 0 ] ) y_m = float ( args [ 1 ] ) z_m = float ( args [ 2 ] ) print ( "x:%f, y:%f, z:%f" % ( x_m , y_m , z_m ) ) self . master . mav . set_position_target_local_n... | position x - m y - m z - m |
230,280 | def cmd_attitude ( self , args ) : if len ( args ) != 5 : print ( "Usage: attitude q0 q1 q2 q3 thrust (0~1)" ) return if len ( args ) == 5 : q0 = float ( args [ 0 ] ) q1 = float ( args [ 1 ] ) q2 = float ( args [ 2 ] ) q3 = float ( args [ 3 ] ) thrust = float ( args [ 4 ] ) att_target = [ q0 , q1 , q2 , q3 ] print ( "q... | attitude q0 q1 q2 q3 thrust |
230,281 | def cmd_posvel ( self , args ) : ignoremask = 511 latlon = None try : latlon = self . module ( 'map' ) . click_position except Exception : pass if latlon is None : print ( "set latlon to zeros" ) latlon = [ 0 , 0 ] else : ignoremask = ignoremask & 504 print ( "found latlon" , ignoremask ) vN = 0 vE = 0 vD = 0 if ( len ... | posvel mapclick vN vE vD |
230,282 | def on_paint ( self , event ) : dc = wx . AutoBufferedPaintDC ( self ) dc . DrawBitmap ( self . _bmp , 0 , 0 ) | repaint the image |
230,283 | def mavgen_python_dialect ( dialect , wire_protocol ) : dialects = os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , '..' , 'dialects' ) mdef = os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , '..' , '..' , 'message_definitions' ) if wire_protocol == mavparse .... | generate the python code on the fly for a MAVLink dialect |
230,284 | def process_tlog ( filename ) : print ( "Processing %s" % filename ) mlog = mavutil . mavlink_connection ( filename , dialect = args . dialect , zero_time_base = True ) msg_types = { } msg_lists = { } types = args . types if types is not None : types = types . split ( ',' ) ( head , tail ) = os . path . split ( filenam... | convert a tlog to a . m file |
230,285 | def radius ( d , offsets , motor_ofs ) : ( mag , motor ) = d return ( mag + offsets + motor * motor_ofs ) . length ( ) | return radius give data point and offsets |
230,286 | def camel_case_from_underscores ( string ) : components = string . split ( '_' ) string = '' for component in components : string += component [ 0 ] . upper ( ) + component [ 1 : ] return string | generate a CamelCase string from an underscore_string . |
230,287 | def generate ( basename , xml_list ) : generate_shared ( basename , xml_list ) for xml in xml_list : generate_message_definitions ( basename , xml ) | generate complete MAVLink Objective - C implemenation |
230,288 | def add_values ( self , values ) : if self . child . is_alive ( ) : self . parent_pipe . send ( values ) | add some data to the graph |
230,289 | def close ( self ) : self . close_graph . set ( ) if self . is_alive ( ) : self . child . join ( 2 ) | close the graph |
230,290 | def get_enum_raw_type ( enum , msgs ) : for msg in msgs : for field in msg . fields : if field . enum == enum . name : return swift_types [ field . type ] [ 0 ] return "Int" | Search appropirate raw type for enums in messages fields |
230,291 | def append_static_code ( filename , outf ) : basepath = os . path . dirname ( os . path . realpath ( __file__ ) ) filepath = os . path . join ( basepath , 'swift/%s' % filename ) print ( "Appending content of %s" % filename ) with open ( filepath ) as inf : for line in inf : outf . write ( line ) | Open and copy static code from specified file |
230,292 | def camel_case_from_underscores ( string ) : components = string . split ( '_' ) string = '' for component in components : if component in abbreviations : string += component else : string += component [ 0 ] . upper ( ) + component [ 1 : ] . lower ( ) return string | Generate a CamelCase string from an underscore_string |
230,293 | def generate_enums_info ( enums , msgs ) : for enum in enums : enum . swift_name = camel_case_from_underscores ( enum . name ) enum . raw_value_type = get_enum_raw_type ( enum , msgs ) enum . formatted_description = "" if enum . description : enum . description = " " . join ( enum . description . split ( ) ) enum . for... | Add camel case swift names for enums an entries descriptions and sort enums alphabetically |
230,294 | def generate_messages_info ( msgs ) : for msg in msgs : msg . swift_name = camel_case_from_underscores ( msg . name ) msg . formatted_description = "" if msg . description : msg . description = " " . join ( msg . description . split ( ) ) msg . formatted_description = "\n/**\n %s\n*/\n" % " " . join ( msg . descript... | Add proper formated variable names initializers and type names to use in templates |
230,295 | def generate ( basename , xml_list ) : if os . path . isdir ( basename ) : filename = os . path . join ( basename , 'MAVLink.swift' ) else : filename = basename msgs = [ ] enums = [ ] filelist = [ ] for xml in xml_list : msgs . extend ( xml . message ) enums . extend ( xml . enum ) filelist . append ( os . path . basen... | Generate complete MAVLink Swift implemenation |
230,296 | def wp_is_loiter ( self , i ) : loiter_cmds = [ 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_LOITER_TO_ALT ] if ( self . wpoints [ i ] . command in loiter_cmds ) : return True return False | return true if waypoint is a loiter waypoint |
230,297 | def add ( self , w , comment = '' ) : w = copy . copy ( w ) if comment : w . comment = comment w . seq = self . count ( ) self . wpoints . append ( w ) self . last_change = time . time ( ) | add a waypoint |
230,298 | def insert ( self , idx , w , comment = '' ) : if idx >= self . count ( ) : self . add ( w , comment ) return if idx < 0 : return w = copy . copy ( w ) if comment : w . comment = comment w . seq = idx self . wpoints . insert ( idx , w ) self . last_change = time . time ( ) self . reindex ( ) | insert a waypoint |
230,299 | def set ( self , w , idx ) : w . seq = idx if w . seq == self . count ( ) : return self . add ( w ) if self . count ( ) <= idx : raise MAVWPError ( 'adding waypoint at idx=%u past end of list (count=%u)' % ( idx , self . count ( ) ) ) self . wpoints [ idx ] = w self . last_change = time . time ( ) | set a waypoint |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.