idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
41,200 | def __callback ( self , rgb , d ) : data = Images2Rgbd ( rgb , d ) self . lock . acquire ( ) self . data = data self . lock . release ( ) | Callback function to receive and save Rgbd Scans . |
41,201 | def getRgbdData ( self ) : self . lock . acquire ( ) data = self . data self . lock . release ( ) return data | Returns last RgbdData . |
41,202 | def fence_fetch_point_send ( self , target_system , target_component , idx , force_mavlink1 = False ) : return self . send ( self . fence_fetch_point_encode ( target_system , target_component , idx ) , force_mavlink1 = force_mavlink1 ) | Request a current fence point from MAV |
41,203 | def hwstatus_send ( self , Vcc , I2Cerr , force_mavlink1 = False ) : return self . send ( self . hwstatus_encode ( Vcc , I2Cerr ) , force_mavlink1 = force_mavlink1 ) | Status of key hardware |
41,204 | def data16_send ( self , type , len , data , force_mavlink1 = False ) : return self . send ( self . data16_encode ( type , len , data ) , force_mavlink1 = force_mavlink1 ) | Data packet size 16 |
41,205 | def data32_send ( self , type , len , data , force_mavlink1 = False ) : return self . send ( self . data32_encode ( type , len , data ) , force_mavlink1 = force_mavlink1 ) | Data packet size 32 |
41,206 | def data64_send ( self , type , len , data , force_mavlink1 = False ) : return self . send ( self . data64_encode ( type , len , data ) , force_mavlink1 = force_mavlink1 ) | Data packet size 64 |
41,207 | def data96_send ( self , type , len , data , force_mavlink1 = False ) : return self . send ( self . data96_encode ( type , len , data ) , force_mavlink1 = force_mavlink1 ) | Data packet size 96 |
41,208 | def rally_fetch_point_send ( self , target_system , target_component , idx , force_mavlink1 = False ) : return self . send ( self . rally_fetch_point_encode ( target_system , target_component , idx ) , force_mavlink1 = force_mavlink1 ) | Request a current rally point from MAV . MAV should respond with a RALLY_POINT message . MAV should not respond if the request is invalid . |
41,209 | def battery2_send ( self , voltage , current_battery , force_mavlink1 = False ) : return self . send ( self . battery2_encode ( voltage , current_battery ) , force_mavlink1 = force_mavlink1 ) | 2nd Battery status |
41,210 | def gopro_heartbeat_send ( self , status , capture_mode , flags , force_mavlink1 = False ) : return self . send ( self . gopro_heartbeat_encode ( status , capture_mode , flags ) , force_mavlink1 = force_mavlink1 ) | Heartbeat from a HeroBus attached GoPro |
41,211 | def gopro_get_request_send ( self , target_system , target_component , cmd_id , force_mavlink1 = False ) : return self . send ( self . gopro_get_request_encode ( target_system , target_component , cmd_id ) , force_mavlink1 = force_mavlink1 ) | Request a GOPRO_COMMAND response from the GoPro |
41,212 | def gopro_get_response_send ( self , cmd_id , status , value , force_mavlink1 = False ) : return self . send ( self . gopro_get_response_encode ( cmd_id , status , value ) , force_mavlink1 = force_mavlink1 ) | Response from a GOPRO_COMMAND get request |
41,213 | def gopro_set_response_send ( self , cmd_id , status , force_mavlink1 = False ) : return self . send ( self . gopro_set_response_encode ( cmd_id , status ) , force_mavlink1 = force_mavlink1 ) | Response from a GOPRO_COMMAND set request |
41,214 | def rpm_send ( self , rpm1 , rpm2 , force_mavlink1 = False ) : return self . send ( self . rpm_encode ( rpm1 , rpm2 ) , force_mavlink1 = force_mavlink1 ) | RPM sensor output |
41,215 | def convert ( self , value , fromunits , tounits ) : if fromunits == tounits : return value if ( fromunits , tounits ) in self . unitmap : return value * self . unitmap [ ( fromunits , tounits ) ] if ( tounits , fromunits ) in self . unitmap : return value / self . unitmap [ ( tounits , fromunits ) ] raise fgFDMError ( "unknown unit mapping (%s,%s)" % ( fromunits , tounits ) ) | convert a value from one set of units to another |
41,216 | def units ( self , varname ) : if not varname in self . mapping . vars : raise fgFDMError ( 'Unknown variable %s' % varname ) return self . mapping . vars [ varname ] . units | return the default units of a variable |
41,217 | def variables ( self ) : return sorted ( list ( self . mapping . vars . keys ( ) ) , key = lambda v : self . mapping . vars [ v ] . index ) | return a list of available variables |
41,218 | def get ( self , varname , idx = 0 , units = None ) : if not varname in self . mapping . vars : raise fgFDMError ( 'Unknown variable %s' % varname ) if idx >= self . mapping . vars [ varname ] . arraylength : raise fgFDMError ( 'index of %s beyond end of array idx=%u arraylength=%u' % ( varname , idx , self . mapping . vars [ varname ] . arraylength ) ) value = self . values [ self . mapping . vars [ varname ] . index + idx ] if units : value = self . convert ( value , self . mapping . vars [ varname ] . units , units ) return value | get a variable value |
41,219 | def set ( self , varname , value , idx = 0 , units = None ) : if not varname in self . mapping . vars : raise fgFDMError ( 'Unknown variable %s' % varname ) if idx >= self . mapping . vars [ varname ] . arraylength : raise fgFDMError ( 'index of %s beyond end of array idx=%u arraylength=%u' % ( varname , idx , self . mapping . vars [ varname ] . arraylength ) ) if units : value = self . convert ( value , units , self . mapping . vars [ varname ] . units ) if math . isinf ( value ) or math . isnan ( value ) or math . fabs ( value ) > 3.4e38 : value = 0 self . values [ self . mapping . vars [ varname ] . index + idx ] = value | set a variable value |
41,220 | def parse ( self , buf ) : try : t = struct . unpack ( self . pack_string , buf ) except struct . error as msg : raise fgFDMError ( 'unable to parse - %s' % msg ) self . values = list ( t ) | parse a FD FDM buffer |
41,221 | def pack ( self ) : for i in range ( len ( self . values ) ) : if math . isnan ( self . values [ i ] ) : self . values [ i ] = 0 return struct . pack ( self . pack_string , * self . values ) | pack a FD FDM buffer from current values |
41,222 | def quat2Yaw ( qw , qx , qy , qz ) : rotateZa0 = 2.0 * ( qx * qy + qw * qz ) rotateZa1 = qw * qw + qx * qx - qy * qy - qz * qz rotateZ = 0.0 if ( rotateZa0 != 0.0 and rotateZa1 != 0.0 ) : rotateZ = atan2 ( rotateZa0 , rotateZa1 ) return rotateZ | Translates from Quaternion to Yaw . |
41,223 | def quat2Pitch ( qw , qx , qy , qz ) : rotateYa0 = - 2.0 * ( qx * qz - qw * qy ) rotateY = 0.0 if ( rotateYa0 >= 1.0 ) : rotateY = pi / 2.0 elif ( rotateYa0 <= - 1.0 ) : rotateY = - pi / 2.0 else : rotateY = asin ( rotateYa0 ) return rotateY | Translates from Quaternion to Pitch . |
41,224 | def odometry2Pose3D ( odom ) : pose = Pose3d ( ) ori = odom . pose . pose . orientation pose . x = odom . pose . pose . position . x pose . y = odom . pose . pose . position . y pose . z = odom . pose . pose . position . z pose . yaw = quat2Yaw ( ori . w , ori . x , ori . y , ori . z ) pose . pitch = quat2Pitch ( ori . w , ori . x , ori . y , ori . z ) pose . roll = quat2Roll ( ori . w , ori . x , ori . y , ori . z ) pose . q = [ ori . w , ori . x , ori . y , ori . z ] pose . timeStamp = odom . header . stamp . secs + ( odom . header . stamp . nsecs * 1e-9 ) return pose | Translates from ROS Odometry to JderobotTypes Pose3d . |
41,225 | def __callback ( self , odom ) : pose = odometry2Pose3D ( odom ) self . lock . acquire ( ) self . data = pose self . lock . release ( ) | Callback function to receive and save Pose3d . |
41,226 | def clip ( self , px , py , w , h , img ) : sx = 0 sy = 0 if px < 0 : sx = - px w += px px = 0 if py < 0 : sy = - py h += py py = 0 if px + w > img . width : w = img . width - px if py + h > img . height : h = img . height - py return ( px , py , sx , sy , w , h ) | clip an area for display on the map |
41,227 | def update_position ( self , newpos ) : if getattr ( self , 'trail' , None ) is not None : self . trail . update_position ( newpos ) self . latlon = newpos . latlon if hasattr ( self , 'rotation' ) : self . rotation = newpos . rotation | update object position |
41,228 | def clicked ( self , px , py ) : if self . hidden : return None for i in range ( len ( self . _pix_points ) ) : if self . _pix_points [ i ] is None : continue ( pixx , pixy ) = self . _pix_points [ i ] if abs ( px - pixx ) < 6 and abs ( py - pixy ) < 6 : self . _selected_vertex = i return math . sqrt ( ( px - pixx ) ** 2 + ( py - pixy ) ** 2 ) return None | see if the polygon has been clicked on . Consider it clicked if the pixel is within 6 of the point |
41,229 | def clicked ( self , px , py ) : if self . hidden : return None if ( abs ( px - self . posx ) > self . width / 2 or abs ( py - self . posy ) > self . height / 2 ) : return None return math . sqrt ( ( px - self . posx ) ** 2 + ( py - self . posy ) ** 2 ) | see if the image has been clicked on |
41,230 | def draw ( self , parent , box ) : import wx from MAVProxy . modules . lib import mp_widgets if self . imgpanel is None : self . imgpanel = mp_widgets . ImagePanel ( parent , self . img ( ) ) box . Add ( self . imgpanel , flag = wx . LEFT , border = 0 ) box . Layout ( ) | redraw the image |
41,231 | def _resize ( self ) : lines = self . text . split ( '\n' ) xsize , ysize = 0 , 0 for line in lines : size = self . textctrl . GetTextExtent ( line ) xsize = max ( xsize , size [ 0 ] ) ysize = ysize + size [ 1 ] xsize = int ( xsize * 1.2 ) self . textctrl . SetSize ( ( xsize , ysize ) ) self . textctrl . SetMinSize ( ( xsize , ysize ) ) | calculate and set text size handling multi - line |
41,232 | def draw ( self , parent , box ) : import wx if self . textctrl is None : self . textctrl = wx . TextCtrl ( parent , style = wx . TE_MULTILINE | wx . TE_READONLY ) self . textctrl . WriteText ( self . text ) self . _resize ( ) box . Add ( self . textctrl , flag = wx . LEFT , border = 0 ) box . Layout ( ) | redraw the text |
41,233 | def button ( self , name , filename , command ) : try : img = LoadImage ( filename ) b = Tkinter . Button ( self . frame , image = img , command = command ) b . image = img except Exception : b = Tkinter . Button ( self . frame , text = filename , command = command ) b . pack ( side = Tkinter . LEFT ) self . buttons [ name ] = b | add a button |
41,234 | def find_message ( self ) : while True : self . msg = self . mlog . recv_match ( condition = args . condition ) if self . msg is not None and self . msg . get_type ( ) != 'BAD_DATA' : break if self . mlog . f . tell ( ) > self . filesize - 10 : self . paused = True break self . last_timestamp = getattr ( self . msg , '_timestamp' ) | find the next valid message |
41,235 | def slew ( self , value ) : if float ( value ) != self . filepos : pos = float ( value ) * self . filesize self . mlog . f . seek ( int ( pos ) ) self . find_message ( ) | move to a given position in the file |
41,236 | def draw_plot ( self ) : import numpy , pylab state = self . state if len ( self . data [ 0 ] ) == 0 : print ( "no data to plot" ) return vhigh = max ( self . data [ 0 ] ) vlow = min ( self . data [ 0 ] ) for i in range ( 1 , len ( self . plot_data ) ) : vhigh = max ( vhigh , max ( self . data [ i ] ) ) vlow = min ( vlow , min ( self . data [ i ] ) ) ymin = vlow - 0.05 * ( vhigh - vlow ) ymax = vhigh + 0.05 * ( vhigh - vlow ) if ymin == ymax : ymax = ymin + 0.1 ymin = ymin - 0.1 self . axes . set_ybound ( lower = ymin , upper = ymax ) self . axes . grid ( True , color = 'gray' ) pylab . setp ( self . axes . get_xticklabels ( ) , visible = True ) pylab . setp ( self . axes . get_legend ( ) . get_texts ( ) , fontsize = 'small' ) for i in range ( len ( self . plot_data ) ) : ydata = numpy . array ( self . data [ i ] ) xdata = self . xdata if len ( ydata ) < len ( self . xdata ) : xdata = xdata [ - len ( ydata ) : ] self . plot_data [ i ] . set_xdata ( xdata ) self . plot_data [ i ] . set_ydata ( ydata ) self . canvas . draw ( ) | Redraws the plot |
41,237 | def set_close_on_exec ( fd ) : try : import fcntl flags = fcntl . fcntl ( fd , fcntl . F_GETFD ) flags |= fcntl . FD_CLOEXEC fcntl . fcntl ( fd , fcntl . F_SETFD , flags ) except Exception : pass | set the clone on exec flag on a file descriptor . Ignore exceptions |
41,238 | def mavlink_connection ( device , baud = 115200 , source_system = 255 , planner_format = None , write = False , append = False , robust_parsing = True , notimestamps = False , input = True , dialect = None , autoreconnect = False , zero_time_base = False , retries = 3 , use_native = default_native ) : global mavfile_global if dialect is not None : set_dialect ( dialect ) if device . startswith ( 'tcp:' ) : return mavtcp ( device [ 4 : ] , source_system = source_system , retries = retries , use_native = use_native ) if device . startswith ( 'tcpin:' ) : return mavtcpin ( device [ 6 : ] , source_system = source_system , retries = retries , use_native = use_native ) if device . startswith ( 'udpin:' ) : return mavudp ( device [ 6 : ] , input = True , source_system = source_system , use_native = use_native ) if device . startswith ( 'udpout:' ) : return mavudp ( device [ 7 : ] , input = False , source_system = source_system , use_native = use_native ) if device . startswith ( 'udpbcast:' ) : return mavudp ( device [ 9 : ] , input = False , source_system = source_system , use_native = use_native , broadcast = True ) if device . startswith ( 'udp:' ) : return mavudp ( device [ 4 : ] , input = input , source_system = source_system , use_native = use_native ) if device . lower ( ) . endswith ( '.bin' ) or device . lower ( ) . endswith ( '.px4log' ) : from pymavlink import DFReader m = DFReader . DFReader_binary ( device , zero_time_base = zero_time_base ) mavfile_global = m return m if device . endswith ( '.log' ) : from pymavlink import DFReader if DFReader . DFReader_is_text_log ( device ) : m = DFReader . DFReader_text ( device , zero_time_base = zero_time_base ) mavfile_global = m return m logsuffixes = [ 'mavlink' , 'log' , 'raw' , 'tlog' ] suffix = device . split ( '.' ) [ - 1 ] . lower ( ) if device . find ( ':' ) != - 1 and not suffix in logsuffixes : return mavudp ( device , source_system = source_system , input = input , use_native = use_native ) if os . path . isfile ( device ) : if device . endswith ( ".elf" ) or device . find ( "/bin/" ) != - 1 : print ( "executing '%s'" % device ) return mavchildexec ( device , source_system = source_system , use_native = use_native ) else : return mavlogfile ( device , planner_format = planner_format , write = write , append = append , robust_parsing = robust_parsing , notimestamps = notimestamps , source_system = source_system , use_native = use_native ) return mavserial ( device , baud = baud , source_system = source_system , autoreconnect = autoreconnect , use_native = use_native ) | open a serial UDP TCP or file mavlink connection |
41,239 | def is_printable ( c ) : global have_ascii if have_ascii : return ascii . isprint ( c ) if isinstance ( c , int ) : ic = c else : ic = ord ( c ) return ic >= 32 and ic <= 126 | see if a character is printable |
41,240 | def auto_detect_serial_win32 ( preferred_list = [ '*' ] ) : try : from serial . tools . list_ports_windows import comports list = sorted ( comports ( ) ) except : return [ ] ret = [ ] others = [ ] for port , description , hwid in list : matches = False p = SerialPort ( port , description = description , hwid = hwid ) for preferred in preferred_list : if fnmatch . fnmatch ( description , preferred ) or fnmatch . fnmatch ( hwid , preferred ) : matches = True if matches : ret . append ( p ) else : others . append ( p ) if len ( ret ) > 0 : return ret ret . extend ( others ) return ret | try to auto - detect serial ports on win32 |
41,241 | def auto_detect_serial_unix ( preferred_list = [ '*' ] ) : import glob glist = glob . glob ( '/dev/ttyS*' ) + glob . glob ( '/dev/ttyUSB*' ) + glob . glob ( '/dev/ttyACM*' ) + glob . glob ( '/dev/serial/by-id/*' ) ret = [ ] others = [ ] for d in glist : matches = False for preferred in preferred_list : if fnmatch . fnmatch ( d , preferred ) : matches = True if matches : ret . append ( SerialPort ( d ) ) else : others . append ( SerialPort ( d ) ) if len ( ret ) > 0 : return ret ret . extend ( others ) return ret | try to auto - detect serial ports on unix |
41,242 | def auto_detect_serial ( preferred_list = [ '*' ] ) : if os . name == 'nt' : return auto_detect_serial_win32 ( preferred_list = preferred_list ) return auto_detect_serial_unix ( preferred_list = preferred_list ) | try to auto - detect serial port |
41,243 | def mode_string_v09 ( msg ) : mode = msg . mode nav_mode = msg . nav_mode MAV_MODE_UNINIT = 0 MAV_MODE_MANUAL = 2 MAV_MODE_GUIDED = 3 MAV_MODE_AUTO = 4 MAV_MODE_TEST1 = 5 MAV_MODE_TEST2 = 6 MAV_MODE_TEST3 = 7 MAV_NAV_GROUNDED = 0 MAV_NAV_LIFTOFF = 1 MAV_NAV_HOLD = 2 MAV_NAV_WAYPOINT = 3 MAV_NAV_VECTOR = 4 MAV_NAV_RETURNING = 5 MAV_NAV_LANDING = 6 MAV_NAV_LOST = 7 MAV_NAV_LOITER = 8 cmode = ( mode , nav_mode ) mapping = { ( MAV_MODE_UNINIT , MAV_NAV_GROUNDED ) : "INITIALISING" , ( MAV_MODE_MANUAL , MAV_NAV_VECTOR ) : "MANUAL" , ( MAV_MODE_TEST3 , MAV_NAV_VECTOR ) : "CIRCLE" , ( MAV_MODE_GUIDED , MAV_NAV_VECTOR ) : "GUIDED" , ( MAV_MODE_TEST1 , MAV_NAV_VECTOR ) : "STABILIZE" , ( MAV_MODE_TEST2 , MAV_NAV_LIFTOFF ) : "FBWA" , ( MAV_MODE_AUTO , MAV_NAV_WAYPOINT ) : "AUTO" , ( MAV_MODE_AUTO , MAV_NAV_RETURNING ) : "RTL" , ( MAV_MODE_AUTO , MAV_NAV_LOITER ) : "LOITER" , ( MAV_MODE_AUTO , MAV_NAV_LIFTOFF ) : "TAKEOFF" , ( MAV_MODE_AUTO , MAV_NAV_LANDING ) : "LANDING" , ( MAV_MODE_AUTO , MAV_NAV_HOLD ) : "LOITER" , ( MAV_MODE_GUIDED , MAV_NAV_VECTOR ) : "GUIDED" , ( MAV_MODE_GUIDED , MAV_NAV_WAYPOINT ) : "GUIDED" , ( 100 , MAV_NAV_VECTOR ) : "STABILIZE" , ( 101 , MAV_NAV_VECTOR ) : "ACRO" , ( 102 , MAV_NAV_VECTOR ) : "ALT_HOLD" , ( 107 , MAV_NAV_VECTOR ) : "CIRCLE" , ( 109 , MAV_NAV_VECTOR ) : "LAND" , } if cmode in mapping : return mapping [ cmode ] return "Mode(%s,%s)" % cmode | mode string for 0 . 9 protocol |
41,244 | def mode_mapping_bynumber ( mav_type ) : map = None if mav_type in [ mavlink . MAV_TYPE_QUADROTOR , mavlink . MAV_TYPE_HELICOPTER , mavlink . MAV_TYPE_HEXAROTOR , mavlink . MAV_TYPE_OCTOROTOR , mavlink . MAV_TYPE_COAXIAL , mavlink . MAV_TYPE_TRICOPTER ] : map = mode_mapping_acm if mav_type == mavlink . MAV_TYPE_FIXED_WING : map = mode_mapping_apm if mav_type == mavlink . MAV_TYPE_GROUND_ROVER : map = mode_mapping_rover if mav_type == mavlink . MAV_TYPE_ANTENNA_TRACKER : map = mode_mapping_tracker if map is None : return None return map | return dictionary mapping mode numbers to name or None if unknown |
41,245 | def mode_string_v10 ( msg ) : if msg . autopilot == mavlink . MAV_AUTOPILOT_PX4 : return interpret_px4_mode ( msg . base_mode , msg . custom_mode ) if not msg . base_mode & mavlink . MAV_MODE_FLAG_CUSTOM_MODE_ENABLED : return "Mode(0x%08x)" % msg . base_mode if msg . type in [ mavlink . MAV_TYPE_QUADROTOR , mavlink . MAV_TYPE_HEXAROTOR , mavlink . MAV_TYPE_OCTOROTOR , mavlink . MAV_TYPE_TRICOPTER , mavlink . MAV_TYPE_COAXIAL , mavlink . MAV_TYPE_HELICOPTER ] : if msg . custom_mode in mode_mapping_acm : return mode_mapping_acm [ msg . custom_mode ] if msg . type == mavlink . MAV_TYPE_FIXED_WING : if msg . custom_mode in mode_mapping_apm : return mode_mapping_apm [ msg . custom_mode ] if msg . type == mavlink . MAV_TYPE_GROUND_ROVER : if msg . custom_mode in mode_mapping_rover : return mode_mapping_rover [ msg . custom_mode ] if msg . type == mavlink . MAV_TYPE_ANTENNA_TRACKER : if msg . custom_mode in mode_mapping_tracker : return mode_mapping_tracker [ msg . custom_mode ] return "Mode(%u)" % msg . custom_mode | mode string for 1 . 0 protocol from heartbeat |
41,246 | def auto_mavlink_version ( self , buf ) : global mavlink if len ( buf ) == 0 : return try : magic = ord ( buf [ 0 ] ) except : magic = buf [ 0 ] if not magic in [ 85 , 254 , 253 ] : return self . first_byte = False if self . WIRE_PROTOCOL_VERSION == "0.9" and magic == 254 : self . WIRE_PROTOCOL_VERSION = "1.0" set_dialect ( current_dialect ) elif self . WIRE_PROTOCOL_VERSION == "1.0" and magic == 85 : self . WIRE_PROTOCOL_VERSION = "0.9" os . environ [ 'MAVLINK09' ] = '1' set_dialect ( current_dialect ) elif self . WIRE_PROTOCOL_VERSION != "2.0" and magic == 253 : self . WIRE_PROTOCOL_VERSION = "2.0" os . environ [ 'MAVLINK20' ] = '1' set_dialect ( current_dialect ) else : return ( callback , callback_args , callback_kwargs ) = ( self . mav . callback , self . mav . callback_args , self . mav . callback_kwargs ) self . mav = mavlink . MAVLink ( self , srcSystem = self . source_system ) self . mav . robust_parsing = self . robust_parsing self . WIRE_PROTOCOL_VERSION = mavlink . WIRE_PROTOCOL_VERSION ( self . mav . callback , self . mav . callback_args , self . mav . callback_kwargs ) = ( callback , callback_args , callback_kwargs ) | auto - switch mavlink protocol version |
41,247 | def select ( self , timeout ) : if self . fd is None : time . sleep ( min ( timeout , 0.5 ) ) return True try : ( rin , win , xin ) = select . select ( [ self . fd ] , [ ] , [ ] , timeout ) except select . error : return False return len ( rin ) == 1 | wait for up to timeout seconds for more data |
41,248 | def packet_loss ( self ) : if self . mav_count == 0 : return 0 return ( 100.0 * self . mav_loss ) / ( self . mav_count + self . mav_loss ) | packet loss as a percentage |
41,249 | def recv_match ( self , condition = None , type = None , blocking = False , timeout = None ) : if type is not None and not isinstance ( type , list ) : type = [ type ] start_time = time . time ( ) while True : if timeout is not None : now = time . time ( ) if now < start_time : start_time = now if start_time + timeout < time . time ( ) : return None m = self . recv_msg ( ) if m is None : if blocking : for hook in self . idle_hooks : hook ( self ) if timeout is None : self . select ( 0.05 ) else : self . select ( timeout / 2 ) continue return None if type is not None and not m . get_type ( ) in type : continue if not evaluate_condition ( condition , self . messages ) : continue return m | recv the next MAVLink message that matches the given condition type can be a string or a list of strings |
41,250 | def setup_logfile ( self , logfile , mode = 'w' ) : self . logfile = open ( logfile , mode = mode ) | start logging to the given logfile with timestamps |
41,251 | def setup_logfile_raw ( self , logfile , mode = 'w' ) : self . logfile_raw = open ( logfile , mode = mode ) | start logging raw bytes to the given logfile without timestamps |
41,252 | def param_fetch_all ( self ) : if time . time ( ) - getattr ( self , 'param_fetch_start' , 0 ) < 2.0 : return self . param_fetch_start = time . time ( ) self . param_fetch_in_progress = True self . mav . param_request_list_send ( self . target_system , self . target_component ) | initiate fetch of all parameters |
41,253 | def param_fetch_one ( self , name ) : try : idx = int ( name ) self . mav . param_request_read_send ( self . target_system , self . target_component , "" , idx ) except Exception : self . mav . param_request_read_send ( self . target_system , self . target_component , name , - 1 ) | initiate fetch of one parameter |
41,254 | def time_since ( self , mtype ) : if not mtype in self . messages : return time . time ( ) - self . start_time return time . time ( ) - self . messages [ mtype ] . _timestamp | return the time since the last message of type mtype was received |
41,255 | def param_set_send ( self , parm_name , parm_value , parm_type = None ) : if self . mavlink10 ( ) : if parm_type == None : parm_type = mavlink . MAVLINK_TYPE_FLOAT self . mav . param_set_send ( self . target_system , self . target_component , parm_name , parm_value , parm_type ) else : self . mav . param_set_send ( self . target_system , self . target_component , parm_name , parm_value ) | wrapper for parameter set |
41,256 | def waypoint_request_list_send ( self ) : if self . mavlink10 ( ) : self . mav . mission_request_list_send ( self . target_system , self . target_component ) else : self . mav . waypoint_request_list_send ( self . target_system , self . target_component ) | wrapper for waypoint_request_list_send |
41,257 | def waypoint_clear_all_send ( self ) : if self . mavlink10 ( ) : self . mav . mission_clear_all_send ( self . target_system , self . target_component ) else : self . mav . waypoint_clear_all_send ( self . target_system , self . target_component ) | wrapper for waypoint_clear_all_send |
41,258 | def waypoint_request_send ( self , seq ) : if self . mavlink10 ( ) : self . mav . mission_request_send ( self . target_system , self . target_component , seq ) else : self . mav . waypoint_request_send ( self . target_system , self . target_component , seq ) | wrapper for waypoint_request_send |
41,259 | def waypoint_set_current_send ( self , seq ) : if self . mavlink10 ( ) : self . mav . mission_set_current_send ( self . target_system , self . target_component , seq ) else : self . mav . waypoint_set_current_send ( self . target_system , self . target_component , seq ) | wrapper for waypoint_set_current_send |
41,260 | def waypoint_current ( self ) : if self . mavlink10 ( ) : m = self . recv_match ( type = 'MISSION_CURRENT' , blocking = True ) else : m = self . recv_match ( type = 'WAYPOINT_CURRENT' , blocking = True ) return m . seq | return current waypoint |
41,261 | def waypoint_count_send ( self , seq ) : if self . mavlink10 ( ) : self . mav . mission_count_send ( self . target_system , self . target_component , seq ) else : self . mav . waypoint_count_send ( self . target_system , self . target_component , seq ) | wrapper for waypoint_count_send |
41,262 | def set_mode_auto ( self ) : if self . mavlink10 ( ) : self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_MISSION_START , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) else : MAV_ACTION_SET_AUTO = 13 self . mav . action_send ( self . target_system , self . target_component , MAV_ACTION_SET_AUTO ) | enter auto mode |
41,263 | def set_mode ( self , mode , custom_mode = 0 , custom_sub_mode = 0 ) : mav_autopilot = self . field ( 'HEARTBEAT' , 'autopilot' , None ) if mav_autopilot == mavlink . MAV_AUTOPILOT_PX4 : self . set_mode_px4 ( mode , custom_mode , custom_sub_mode ) else : self . set_mode_apm ( mode ) | set arbitrary flight mode |
41,264 | def set_mode_rtl ( self ) : if self . mavlink10 ( ) : self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_NAV_RETURN_TO_LAUNCH , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) else : MAV_ACTION_RETURN = 3 self . mav . action_send ( self . target_system , self . target_component , MAV_ACTION_RETURN ) | enter RTL mode |
41,265 | def set_mode_manual ( self ) : if self . mavlink10 ( ) : self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_DO_SET_MODE , 0 , mavlink . MAV_MODE_MANUAL_ARMED , 0 , 0 , 0 , 0 , 0 , 0 ) else : MAV_ACTION_SET_MANUAL = 12 self . mav . action_send ( self . target_system , self . target_component , MAV_ACTION_SET_MANUAL ) | enter MANUAL mode |
41,266 | def set_mode_fbwa ( self ) : if self . mavlink10 ( ) : self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_DO_SET_MODE , 0 , mavlink . MAV_MODE_STABILIZE_ARMED , 0 , 0 , 0 , 0 , 0 , 0 ) else : print ( "Forcing FBWA not supported" ) | enter FBWA mode |
41,267 | def set_mode_loiter ( self ) : if self . mavlink10 ( ) : self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_NAV_LOITER_UNLIM , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) else : MAV_ACTION_LOITER = 27 self . mav . action_send ( self . target_system , self . target_component , MAV_ACTION_LOITER ) | enter LOITER mode |
41,268 | def set_servo ( self , channel , pwm ) : self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_DO_SET_SERVO , 0 , channel , pwm , 0 , 0 , 0 , 0 , 0 ) | set a servo value |
41,269 | def set_relay ( self , relay_pin = 0 , state = True ) : if self . mavlink10 ( ) : self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_DO_SET_RELAY , 0 , relay_pin , int ( state ) , 0 , 0 , 0 , 0 , 0 ) else : print ( "Setting relays not supported." ) | Set relay_pin to value of state |
41,270 | def reboot_autopilot ( self , hold_in_bootloader = False ) : if self . mavlink10 ( ) : if hold_in_bootloader : param1 = 3 else : param1 = 1 self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN , 0 , param1 , 0 , 0 , 0 , 0 , 0 , 0 ) self . mav . command_long_send ( self . target_system , self . target_component , mavlink . MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 ) | reboot the autopilot |
41,271 | def location ( self , relative_alt = False ) : self . wait_gps_fix ( ) self . recv_match ( type = 'VFR_HUD' , blocking = True ) self . recv_match ( type = 'GLOBAL_POSITION_INT' , blocking = True ) if relative_alt : alt = self . messages [ 'GLOBAL_POSITION_INT' ] . relative_alt * 0.001 else : alt = self . messages [ 'VFR_HUD' ] . alt return location ( self . messages [ 'GPS_RAW_INT' ] . lat * 1.0e-7 , self . messages [ 'GPS_RAW_INT' ] . lon * 1.0e-7 , alt , self . messages [ 'VFR_HUD' ] . heading ) | return current location |
41,272 | def motors_armed ( self ) : if not 'HEARTBEAT' in self . messages : return False m = self . messages [ 'HEARTBEAT' ] return ( m . base_mode & mavlink . MAV_MODE_FLAG_SAFETY_ARMED ) != 0 | return true if motors armed |
41,273 | def field ( self , type , field , default = None ) : if not type in self . messages : return default return getattr ( self . messages [ type ] , field , default ) | convenient function for returning an arbitrary MAVLink field with a default |
41,274 | def setup_signing ( self , secret_key , sign_outgoing = True , allow_unsigned_callback = None , initial_timestamp = None , link_id = None ) : self . mav . signing . secret_key = secret_key self . mav . signing . sign_outgoing = sign_outgoing self . mav . signing . allow_unsigned_callback = allow_unsigned_callback if link_id is None : global global_link_id link_id = global_link_id global_link_id = min ( global_link_id + 1 , 255 ) self . mav . signing . link_id = link_id if initial_timestamp is None : epoch_offset = 1420070400 now = max ( time . time ( ) , epoch_offset ) initial_timestamp = now - epoch_offset initial_timestamp = int ( initial_timestamp * 100 * 1000 ) self . mav . signing . timestamp = initial_timestamp | setup for MAVLink2 signing |
41,275 | def disable_signing ( self ) : self . mav . signing . secret_key = None self . mav . signing . sign_outgoing = False self . mav . signing . allow_unsigned_callback = None self . mav . signing . link_id = 0 self . mav . signing . timestamp = 0 | disable MAVLink2 signing |
41,276 | def scan_timestamp ( self , tbuf ) : while True : ( tusec , ) = struct . unpack ( '>Q' , tbuf ) t = tusec * 1.0e-6 if abs ( t - self . _last_timestamp ) <= 3 * 24 * 60 * 60 : break c = self . f . read ( 1 ) if len ( c ) != 1 : break tbuf = tbuf [ 1 : ] + c return t | scan forward looking in a tlog for a timestamp in a reasonable range |
41,277 | def pre_message ( self ) : if self . filesize != 0 : self . percent = ( 100.0 * self . f . tell ( ) ) / self . filesize if self . notimestamps : return if self . planner_format : tbuf = self . f . read ( 21 ) if len ( tbuf ) != 21 or tbuf [ 0 ] != '-' or tbuf [ 20 ] != ':' : raise RuntimeError ( 'bad planner timestamp %s' % tbuf ) hnsec = self . _two64 + float ( tbuf [ 0 : 20 ] ) t = hnsec * 1.0e-7 t -= 719163 * 24 * 60 * 60 self . _link = 0 else : tbuf = self . f . read ( 8 ) if len ( tbuf ) != 8 : return ( tusec , ) = struct . unpack ( '>Q' , tbuf ) t = tusec * 1.0e-6 if ( self . _last_timestamp is not None and self . _last_message . get_type ( ) == "BAD_DATA" and abs ( t - self . _last_timestamp ) > 3 * 24 * 60 * 60 ) : t = self . scan_timestamp ( tbuf ) self . _link = tusec & 0x3 self . _timestamp = t | read timestamp if needed |
41,278 | def post_message ( self , msg ) : super ( mavlogfile , self ) . post_message ( msg ) if self . planner_format : self . f . read ( 1 ) self . timestamp = msg . _timestamp self . _last_message = msg if msg . get_type ( ) != "BAD_DATA" : self . _last_timestamp = msg . _timestamp msg . _link = self . _link | add timestamp to message |
41,279 | def trigger ( self ) : tnow = time . time ( ) if tnow < self . last_time : print ( "Warning, time moved backwards. Restarting timer." ) self . last_time = tnow if self . last_time + ( 1.0 / self . frequency ) <= tnow : self . last_time = tnow return True return False | return True if we should trigger now |
41,280 | def write ( self , b ) : from . import mavutil self . debug ( "sending '%s' (0x%02x) of len %u\n" % ( b , ord ( b [ 0 ] ) , len ( b ) ) , 2 ) while len ( b ) > 0 : n = len ( b ) if n > 70 : n = 70 buf = [ ord ( x ) for x in b [ : n ] ] buf . extend ( [ 0 ] * ( 70 - len ( buf ) ) ) self . mav . mav . serial_control_send ( self . port , mavutil . mavlink . SERIAL_CONTROL_FLAG_EXCLUSIVE | mavutil . mavlink . SERIAL_CONTROL_FLAG_RESPOND , 0 , 0 , n , buf ) b = b [ n : ] | write some bytes |
41,281 | def _recv ( self ) : from . import mavutil start_time = time . time ( ) while time . time ( ) < start_time + self . timeout : m = self . mav . recv_match ( condition = 'SERIAL_CONTROL.count!=0' , type = 'SERIAL_CONTROL' , blocking = False , timeout = 0 ) if m is not None and m . count != 0 : break self . mav . mav . serial_control_send ( self . port , mavutil . mavlink . SERIAL_CONTROL_FLAG_EXCLUSIVE | mavutil . mavlink . SERIAL_CONTROL_FLAG_RESPOND , 0 , 0 , 0 , [ 0 ] * 70 ) m = self . mav . recv_match ( condition = 'SERIAL_CONTROL.count!=0' , type = 'SERIAL_CONTROL' , blocking = True , timeout = 0.01 ) if m is not None and m . count != 0 : break if m is not None : if self . _debug > 2 : print ( m ) data = m . data [ : m . count ] self . buf += '' . join ( str ( chr ( x ) ) for x in data ) | read some bytes into self . buf |
41,282 | def read ( self , n ) : if len ( self . buf ) == 0 : self . _recv ( ) if len ( self . buf ) > 0 : if n > len ( self . buf ) : n = len ( self . buf ) ret = self . buf [ : n ] self . buf = self . buf [ n : ] if self . _debug >= 2 : for b in ret : self . debug ( "read 0x%x" % ord ( b ) , 2 ) return ret return '' | read some bytes |
41,283 | def flushInput ( self ) : self . buf = '' saved_timeout = self . timeout self . timeout = 0.5 self . _recv ( ) self . timeout = saved_timeout self . buf = '' self . debug ( "flushInput" ) | flush any pending input |
41,284 | def stop ( self ) : self . mpstate . rl . set_prompt ( self . status . flightmode + "> " ) self . mpstate . functions . input_handler = None self . started = False mav = self . master . mav mav . serial_control_send ( self . serial_settings . port , 0 , 0 , self . serial_settings . baudrate , 0 , [ 0 ] * 70 ) | stop nsh input |
41,285 | def cmd_nsh ( self , args ) : usage = "Usage: nsh <start|stop|set>" if len ( args ) < 1 : print ( usage ) return if args [ 0 ] == "start" : self . mpstate . functions . input_handler = self . send self . started = True self . mpstate . rl . set_prompt ( "" ) elif args [ 0 ] == "stop" : self . stop ( ) elif args [ 0 ] == "set" : self . serial_settings . command ( args [ 1 : ] ) else : print ( usage ) | nsh shell commands |
41,286 | def process_waypoint_request ( self , m , master ) : if ( not self . loading_waypoints or time . time ( ) > self . loading_waypoint_lasttime + 10.0 ) : self . loading_waypoints = False self . console . error ( "not loading waypoints" ) return if m . seq >= self . wploader . count ( ) : self . console . error ( "Request for bad waypoint %u (max %u)" % ( m . seq , self . wploader . count ( ) ) ) return wp = self . wploader . wp ( m . seq ) wp . target_system = self . target_system wp . target_component = self . target_component self . master . mav . send ( self . wploader . wp ( m . seq ) ) self . loading_waypoint_lasttime = time . time ( ) self . console . writeln ( "Sent waypoint %u : %s" % ( m . seq , self . wploader . wp ( m . seq ) ) ) if m . seq == self . wploader . count ( ) - 1 : self . loading_waypoints = False self . console . writeln ( "Sent all %u waypoints" % self . wploader . count ( ) ) | process a waypoint request from the master |
41,287 | def send_all_waypoints ( self ) : self . master . waypoint_clear_all_send ( ) if self . wploader . count ( ) == 0 : return self . loading_waypoints = True self . loading_waypoint_lasttime = time . time ( ) self . master . waypoint_count_send ( self . wploader . count ( ) ) | send all waypoints to vehicle |
41,288 | def load_waypoints ( self , filename ) : self . wploader . target_system = self . target_system self . wploader . target_component = self . target_component try : self . wploader . load ( filename ) except Exception as msg : print ( "Unable to load %s - %s" % ( filename , msg ) ) return print ( "Loaded %u waypoints from %s" % ( self . wploader . count ( ) , filename ) ) self . send_all_waypoints ( ) | load waypoints from a file |
41,289 | def update_waypoints ( self , filename , wpnum ) : self . wploader . target_system = self . target_system self . wploader . target_component = self . target_component try : self . wploader . load ( filename ) except Exception as msg : print ( "Unable to load %s - %s" % ( filename , msg ) ) return if self . wploader . count ( ) == 0 : print ( "No waypoints found in %s" % filename ) return if wpnum == - 1 : print ( "Loaded %u updated waypoints from %s" % ( self . wploader . count ( ) , filename ) ) elif wpnum >= self . wploader . count ( ) : print ( "Invalid waypoint number %u" % wpnum ) return else : print ( "Loaded updated waypoint %u from %s" % ( wpnum , filename ) ) self . loading_waypoints = True self . loading_waypoint_lasttime = time . time ( ) if wpnum == - 1 : start = 0 end = self . wploader . count ( ) - 1 else : start = wpnum end = wpnum self . master . mav . mission_write_partial_list_send ( self . target_system , self . target_component , start , end ) | update waypoints from a file |
41,290 | def get_default_frame ( self ) : if self . settings . terrainalt == 'Auto' : if self . get_mav_param ( 'TERRAIN_FOLLOW' , 0 ) == 1 : return mavutil . mavlink . MAV_FRAME_GLOBAL_TERRAIN_ALT return mavutil . mavlink . MAV_FRAME_GLOBAL_RELATIVE_ALT if self . settings . terrainalt == 'True' : return mavutil . mavlink . MAV_FRAME_GLOBAL_TERRAIN_ALT return mavutil . mavlink . MAV_FRAME_GLOBAL_RELATIVE_ALT | default frame for waypoints |
41,291 | def wp_draw_callback ( self , points ) : if len ( points ) < 3 : return from MAVProxy . modules . lib import mp_util home = self . wploader . wp ( 0 ) self . wploader . clear ( ) self . wploader . target_system = self . target_system self . wploader . target_component = self . target_component self . wploader . add ( home ) if self . get_default_frame ( ) == mavutil . mavlink . MAV_FRAME_GLOBAL_TERRAIN_ALT : use_terrain = True else : use_terrain = False for p in points : self . wploader . add_latlonalt ( p [ 0 ] , p [ 1 ] , self . settings . wpalt , terrain_alt = use_terrain ) self . send_all_waypoints ( ) | callback from drawing waypoints |
41,292 | def wp_loop ( self ) : loader = self . wploader if loader . count ( ) < 2 : print ( "Not enough waypoints (%u)" % loader . count ( ) ) return wp = loader . wp ( loader . count ( ) - 2 ) if wp . command == mavutil . mavlink . MAV_CMD_DO_JUMP : print ( "Mission is already looped" ) return wp = mavutil . mavlink . MAVLink_mission_item_message ( 0 , 0 , 0 , 0 , mavutil . mavlink . MAV_CMD_DO_JUMP , 0 , 1 , 1 , - 1 , 0 , 0 , 0 , 0 , 0 ) loader . add ( wp ) self . loading_waypoints = True self . loading_waypoint_lasttime = time . time ( ) self . master . waypoint_count_send ( self . wploader . count ( ) ) print ( "Closed loop on mission" ) | close the loop on a mission |
41,293 | def set_home_location ( self ) : try : latlon = self . module ( 'map' ) . click_position except Exception : print ( "No map available" ) return lat = float ( latlon [ 0 ] ) lon = float ( latlon [ 1 ] ) if self . wploader . count ( ) == 0 : self . wploader . add_latlonalt ( lat , lon , 0 ) w = self . wploader . wp ( 0 ) w . x = lat w . y = lon self . wploader . set ( w , 0 ) self . loading_waypoints = True self . loading_waypoint_lasttime = time . time ( ) self . master . mav . mission_write_partial_list_send ( self . target_system , self . target_component , 0 , 0 ) | set home location from last map click |
41,294 | def cmd_wp_move ( self , args ) : if len ( args ) != 1 : print ( "usage: wp move WPNUM" ) return idx = int ( args [ 0 ] ) if idx < 1 or idx > self . wploader . count ( ) : print ( "Invalid wp 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 wp = self . wploader . wp ( idx ) self . undo_wp = copy . copy ( wp ) self . undo_wp_idx = idx self . undo_type = "move" ( lat , lon ) = latlon if getattr ( self . console , 'ElevationMap' , None ) is not None and wp . frame != mavutil . mavlink . MAV_FRAME_GLOBAL_TERRAIN_ALT : alt1 = self . console . ElevationMap . GetElevation ( lat , lon ) alt2 = self . console . ElevationMap . GetElevation ( wp . x , wp . y ) if alt1 is not None and alt2 is not None : wp . z += alt1 - alt2 wp . x = lat wp . y = lon wp . target_system = self . target_system wp . target_component = self . target_component self . loading_waypoints = True self . loading_waypoint_lasttime = time . time ( ) self . master . mav . mission_write_partial_list_send ( self . target_system , self . target_component , idx , idx ) self . wploader . set ( wp , idx ) print ( "Moved WP %u to %f, %f at %.1fm" % ( idx , lat , lon , wp . z ) ) | handle wp move |
41,295 | def cmd_wp_param ( self , args ) : if len ( args ) < 2 : print ( "usage: wp param WPNUM PNUM <VALUE>" ) return idx = int ( args [ 0 ] ) if idx < 1 or idx > self . wploader . count ( ) : print ( "Invalid wp number %u" % idx ) return wp = self . wploader . wp ( idx ) param = [ wp . param1 , wp . param2 , wp . param3 , wp . param4 ] pnum = int ( args [ 1 ] ) if pnum < 1 or pnum > 4 : print ( "Invalid param number %u" % pnum ) return if len ( args ) == 2 : print ( "Param %u: %f" % ( pnum , param [ pnum - 1 ] ) ) return param [ pnum - 1 ] = float ( args [ 2 ] ) wp . param1 = param [ 0 ] wp . param2 = param [ 1 ] wp . param3 = param [ 2 ] wp . param4 = param [ 3 ] wp . target_system = self . target_system wp . target_component = self . target_component self . loading_waypoints = True self . loading_waypoint_lasttime = time . time ( ) self . master . mav . mission_write_partial_list_send ( self . target_system , self . target_component , idx , idx ) self . wploader . set ( wp , idx ) print ( "Set param %u for %u to %f" % ( pnum , idx , param [ pnum - 1 ] ) ) | handle wp parameter change |
41,296 | def depthToRGB8 ( float_img_buff , encoding ) : gray_image = None if ( encoding [ - 3 : - 2 ] == "U" ) : gray_image = float_img_buff else : float_img = np . zeros ( ( float_img_buff . shape [ 0 ] , float_img_buff . shape [ 1 ] , 1 ) , dtype = "float32" ) float_img . data = float_img_buff . data gray_image = cv2 . convertScaleAbs ( float_img , alpha = 255 / MAXRANGE ) cv_image = cv2 . cvtColor ( gray_image , cv2 . COLOR_GRAY2RGB ) return cv_image | Translates from Distance Image format to RGB . Inf values are represented by NaN when converting to RGB NaN passed to 0 |
41,297 | def __callback ( self , img ) : image = imageMsg2Image ( img , self . bridge ) self . lock . acquire ( ) self . data = image self . lock . release ( ) | Callback function to receive and save Images . |
41,298 | def noise ( ) : from random import gauss v = Vector3 ( gauss ( 0 , 1 ) , gauss ( 0 , 1 ) , gauss ( 0 , 1 ) ) v . normalize ( ) return v * args . noise | a noise vector |
41,299 | def find_offsets ( data , ofs ) : max_change = args . max_change gain = args . gain data2 = [ ] for d in data : d = d . copy ( ) + noise ( ) d . x = float ( int ( d . x + 0.5 ) ) d . y = float ( int ( d . y + 0.5 ) ) d . z = float ( int ( d . z + 0.5 ) ) data2 . append ( d ) data = data2 history_idx = 0 mag_history = data [ 0 : args . history ] for i in range ( args . history , len ( data ) ) : B1 = mag_history [ history_idx ] + ofs B2 = data [ i ] + ofs diff = B2 - B1 diff_length = diff . length ( ) if diff_length <= args . min_diff : history_idx = ( history_idx + 1 ) % args . history continue mag_history [ history_idx ] = data [ i ] history_idx = ( history_idx + 1 ) % args . history delta = diff * ( gain * ( B2 . length ( ) - B1 . length ( ) ) / diff_length ) delta_length = delta . length ( ) if max_change != 0 and delta_length > max_change : delta *= max_change / delta_length ofs = ofs - delta if args . verbose : print ( ofs ) return ofs | find mag offsets by applying Bills offsets revisited algorithm on the data |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.