INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
check for events, calling registered callbacks as needed
def check_events(self): '''check for events, calling registered callbacks as needed''' while self.event_count() > 0: event = self.get_event() for callback in self._callbacks: callback(event)
Updates LaserData.
def update(self): ''' Updates LaserData. ''' if self.hasproxy(): laserD = LaserData() values = [] data = self.proxy.getLaserData() #laserD.values = laser.distanceData for i in range (data.numLaser): values.appen...
return +1 or -1 for for sorting
def radius_cmp(a, b, offsets): '''return +1 or -1 for for sorting''' diff = radius(a, offsets) - radius(b, offsets) if diff > 0: return 1 if diff < 0: return -1 return 0
find best magnetometer offset fit to a log file
def magfit(logfile): '''find best magnetometer offset fit to a log file''' print("Processing log %s" % filename) mlog = mavutil.mavlink_connection(filename, notimestamps=args.notimestamps) data = [] last_t = 0 offsets = Vector3(0,0,0) # now gather all the data while True: m =...
plot data in 3D
def plot_data(orig_data, data): '''plot data in 3D''' 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 d...
find the of a token. Returns the offset in the string immediately after the matching end_token
def find_end(self, text, start_token, end_token, ignore_end_token=None): '''find the of a token. Returns the offset in the string immediately after the matching end_token''' if not text.startswith(start_token): raise MAVParseError("invalid token start") offset = len(start_tok...
find the of a variable
def find_var_end(self, text): '''find the of a variable''' return self.find_end(text, self.start_var_token, self.end_var_token)
find the of a repitition
def find_rep_end(self, text): '''find the of a repitition''' return self.find_end(text, self.start_rep_token, self.end_rep_token, ignore_end_token=self.end_var_token)
substitute variables in a string
def substitute(self, text, subvars={}, trim_leading_lf=None, checkmissing=None): '''substitute variables in a string''' if trim_leading_lf is None: trim_leading_lf = self.trim_leading_lf if checkmissing is None: checkmissing = self.checkmissing ...
write to a file with variable substitution
def write(self, file, text, subvars={}, trim_leading_lf=True): '''write to a file with variable substitution''' file.write(self.substitute(text, subvars=subvars, trim_leading_lf=trim_leading_lf))
work out flight time for a log file
def flight_time(logfile): '''work out flight time for a log file''' 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:...
called in idle time
def idle_task(self): '''called in idle time''' if self.js is None: return for e in pygame.event.get(): # iterate over event stack #the following is somewhat custom for the specific joystick model: override = self.module('rc').override[:] for i in r...
return True if mtype matches pattern
def match_type(mtype, patterns): '''return True if mtype matches pattern''' for p in patterns: if fnmatch.fnmatch(mtype, p): return True return False
We convert RGB as BGR because OpenCV with RGB pass to YVU instead of YUV
def apply (self, img): yup,uup,vup = self.getUpLimit() ydwn,udwn,vdwn = self.getDownLimit() ''' We convert RGB as BGR because OpenCV with RGB pass to YVU instead of YUV''' yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV) minValues = np.array([ydwn,udwn,vdw...
generate complete python implemenation
def generate(basename, xml): '''generate complete python implemenation''' if basename.endswith('.lua'): filename = basename else: filename = basename + '.lua' msgs = [] enums = [] filelist = [] for x in xml: msgs.extend(x.message) enums.extend(x.enum) ...
handle menu selections
def on_menu(self, event): '''handle menu selections''' state = self.state ret = self.menu.find_selected(event) if ret is None: return ret.call_handler() state.child_pipe_send.send(ret)
Voltage and current sensor data adc121_vspb_volt : Power board voltage sensor reading in volts (float) adc121_cspb_amp : Power board current sensor reading in amps (float) adc121_cs1_amp : Board current sensor 1 reading in amps (float) ...
def sens_power_encode(self, adc121_vspb_volt, adc121_cspb_amp, adc121_cs1_amp, adc121_cs2_amp): ''' Voltage and current sensor data adc121_vspb_volt : Power board voltage sensor reading in volts (float) adc121_cspb_amp : Power board cur...
Voltage and current sensor data adc121_vspb_volt : Power board voltage sensor reading in volts (float) adc121_cspb_amp : Power board current sensor reading in amps (float) adc121_cs1_amp : Board current sensor 1 reading in amps (float) ...
def sens_power_send(self, adc121_vspb_volt, adc121_cspb_amp, adc121_cs1_amp, adc121_cs2_amp, force_mavlink1=False): ''' Voltage and current sensor data adc121_vspb_volt : Power board voltage sensor reading in volts (float) adc121_cspb_amp ...
Maximum Power Point Tracker (MPPT) sensor data for solar module power performance tracking mppt_timestamp : MPPT last timestamp (uint64_t) mppt1_volt : MPPT1 voltage (float) mppt1_amp : MPPT1 current (float) ...
def sens_mppt_encode(self, mppt_timestamp, mppt1_volt, mppt1_amp, mppt1_pwm, mppt1_status, mppt2_volt, mppt2_amp, mppt2_pwm, mppt2_status, mppt3_volt, mppt3_amp, mppt3_pwm, mppt3_status): ''' Maximum Power Point Tracker (MPPT) sensor data for solar module power performanc...
Maximum Power Point Tracker (MPPT) sensor data for solar module power performance tracking mppt_timestamp : MPPT last timestamp (uint64_t) mppt1_volt : MPPT1 voltage (float) mppt1_amp : MPPT1 current (float) ...
def sens_mppt_send(self, mppt_timestamp, mppt1_volt, mppt1_amp, mppt1_pwm, mppt1_status, mppt2_volt, mppt2_amp, mppt2_pwm, mppt2_status, mppt3_volt, mppt3_amp, mppt3_pwm, mppt3_status, force_mavlink1=False): ''' Maximum Power Point Tracker (MPPT) sensor data for solar module power ...
ASL-fixed-wing controller data timestamp : Timestamp (uint64_t) aslctrl_mode : ASLCTRL control-mode (manual, stabilized, auto, etc...) (uint8_t) h : See sourcecode for a description of these values... (float) ...
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): ''' ASL-fixed-wing controller data ...
ASL-fixed-wing controller debug data i32_1 : Debug data (uint32_t) i8_1 : Debug data (uint8_t) i8_2 : Debug data (uint8_t) f_1 : Debug data (float) f_2 ...
def aslctrl_debug_encode(self, i32_1, i8_1, i8_2, f_1, f_2, f_3, f_4, f_5, f_6, f_7, f_8): ''' ASL-fixed-wing controller debug data i32_1 : Debug data (uint32_t) i8_1 : Debug data (uint8_t) i8_2 ...
ASL-fixed-wing controller debug data i32_1 : Debug data (uint32_t) i8_1 : Debug data (uint8_t) i8_2 : Debug data (uint8_t) f_1 : Debug data (float) f_2 ...
def aslctrl_debug_send(self, i32_1, i8_1, i8_2, f_1, f_2, f_3, f_4, f_5, f_6, f_7, f_8, force_mavlink1=False): ''' ASL-fixed-wing controller debug data i32_1 : Debug data (uint32_t) i8_1 : Debug data (uint8_t) ...
Extended state information for ASLUAVs LED_status : Status of the position-indicator LEDs (uint8_t) SATCOM_status : Status of the IRIDIUM satellite communication system (uint8_t) Servo_status : Status vector for up to 8 servos (uin...
def asluav_status_encode(self, LED_status, SATCOM_status, Servo_status, Motor_rpm): ''' Extended state information for ASLUAVs LED_status : Status of the position-indicator LEDs (uint8_t) SATCOM_status : Status of the IRIDIUM sa...
Extended state information for ASLUAVs LED_status : Status of the position-indicator LEDs (uint8_t) SATCOM_status : Status of the IRIDIUM satellite communication system (uint8_t) Servo_status : Status vector for up to 8 servos (uin...
def asluav_status_send(self, LED_status, SATCOM_status, Servo_status, Motor_rpm, force_mavlink1=False): ''' Extended state information for ASLUAVs LED_status : Status of the position-indicator LEDs (uint8_t) SATCOM_status : Stat...
Extended EKF state estimates for ASLUAVs timestamp : Time since system start [us] (uint64_t) Windspeed : Magnitude of wind velocity (in lateral inertial plane) [m/s] (float) WindDir : Wind heading angle from North [rad] (...
def ekf_ext_encode(self, timestamp, Windspeed, WindDir, WindZ, Airspeed, beta, alpha): ''' Extended EKF state estimates for ASLUAVs timestamp : Time since system start [us] (uint64_t) Windspeed : Magnitude of wind velocity ...
Extended EKF state estimates for ASLUAVs timestamp : Time since system start [us] (uint64_t) Windspeed : Magnitude of wind velocity (in lateral inertial plane) [m/s] (float) WindDir : Wind heading angle from North [rad] (...
def ekf_ext_send(self, timestamp, Windspeed, WindDir, WindZ, Airspeed, beta, alpha, force_mavlink1=False): ''' Extended EKF state estimates for ASLUAVs timestamp : Time since system start [us] (uint64_t) Windspeed : Magnitu...
Off-board controls/commands for ASLUAVs timestamp : Time since system start [us] (uint64_t) uElev : Elevator command [~] (float) uThrot : Throttle command [~] (float) uThrot2 : Throt...
def asl_obctrl_encode(self, timestamp, uElev, uThrot, uThrot2, uAilL, uAilR, uRud, obctrl_status): ''' Off-board controls/commands for ASLUAVs timestamp : Time since system start [us] (uint64_t) uElev : Elevator command...
Off-board controls/commands for ASLUAVs timestamp : Time since system start [us] (uint64_t) uElev : Elevator command [~] (float) uThrot : Throttle command [~] (float) uThrot2 : Throt...
def asl_obctrl_send(self, timestamp, uElev, uThrot, uThrot2, uAilL, uAilR, uRud, obctrl_status, force_mavlink1=False): ''' Off-board controls/commands for ASLUAVs timestamp : Time since system start [us] (uint64_t) uElev ...
Atmospheric sensors (temperature, humidity, ...) TempAmbient : Ambient temperature [degrees Celsius] (float) Humidity : Relative humidity [%] (float)
def sens_atmos_send(self, TempAmbient, Humidity, force_mavlink1=False): ''' Atmospheric sensors (temperature, humidity, ...) TempAmbient : Ambient temperature [degrees Celsius] (float) Humidity : Relative humidity [%] (float...
Battery pack monitoring data for Li-Ion batteries temperature : Battery pack temperature in [deg C] (float) voltage : Battery pack voltage in [mV] (uint16_t) current : Battery pack current in [mA] (int16_t) ...
def sens_batmon_encode(self, temperature, voltage, current, SoC, batterystatus, serialnumber, hostfetcontrol, cellvoltage1, cellvoltage2, cellvoltage3, cellvoltage4, cellvoltage5, cellvoltage6): ''' Battery pack monitoring data for Li-Ion batteries temperature ...
Battery pack monitoring data for Li-Ion batteries temperature : Battery pack temperature in [deg C] (float) voltage : Battery pack voltage in [mV] (uint16_t) current : Battery pack current in [mA] (int16_t) ...
def sens_batmon_send(self, temperature, voltage, current, SoC, batterystatus, serialnumber, hostfetcontrol, cellvoltage1, cellvoltage2, cellvoltage3, cellvoltage4, cellvoltage5, cellvoltage6, force_mavlink1=False): ''' Battery pack monitoring data for Li-Ion batteries te...
Fixed-wing soaring (i.e. thermal seeking) data timestamp : Timestamp [ms] (uint64_t) timestampModeChanged : Timestamp since last mode change[ms] (uint64_t) xW : Thermal core updraft strength [m/s] (float) xR ...
def fw_soaring_data_encode(self, timestamp, timestampModeChanged, xW, xR, xLat, xLon, VarW, VarR, VarLat, VarLon, LoiterRadius, LoiterDirection, DistToSoarPoint, vSinkExp, z1_LocalUpdraftSpeed, z2_DeltaRoll, z1_exp, z2_exp, ThermalGSNorth, ThermalGSEast, TSE_dot, DebugVar1, DebugVar2, ControlMode, valid): ...
Monitoring of sensorpod status timestamp : Timestamp in linuxtime [ms] (since 1.1.1970) (uint64_t) visensor_rate_1 : Rate of ROS topic 1 (uint8_t) visensor_rate_2 : Rate of ROS topic 2 (uint8_t) visensor_rate_3 ...
def sensorpod_status_encode(self, timestamp, visensor_rate_1, visensor_rate_2, visensor_rate_3, visensor_rate_4, recording_nodes_count, cpu_temp, free_space): ''' Monitoring of sensorpod status timestamp : Timestamp in linuxtime [ms] (since 1.1.1970) (uin...
Monitoring of sensorpod status timestamp : Timestamp in linuxtime [ms] (since 1.1.1970) (uint64_t) visensor_rate_1 : Rate of ROS topic 1 (uint8_t) visensor_rate_2 : Rate of ROS topic 2 (uint8_t) visensor_rate_3 ...
def sensorpod_status_send(self, timestamp, visensor_rate_1, visensor_rate_2, visensor_rate_3, visensor_rate_4, recording_nodes_count, cpu_temp, free_space, force_mavlink1=False): ''' Monitoring of sensorpod status timestamp : Timestamp in linuxtime [ms] (...
Monitoring of power board status timestamp : Timestamp (uint64_t) pwr_brd_status : Power board status register (uint8_t) pwr_brd_led_status : Power board leds status (uint8_t) pwr_brd_system_volt : Power board syst...
def sens_power_board_encode(self, timestamp, pwr_brd_status, pwr_brd_led_status, pwr_brd_system_volt, pwr_brd_servo_volt, pwr_brd_mot_l_amp, pwr_brd_mot_r_amp, pwr_brd_servo_1_amp, pwr_brd_servo_2_amp, pwr_brd_servo_3_amp, pwr_brd_servo_4_amp, pwr_brd_aux_amp): ''' Monitoring of power bo...
Monitoring of power board status timestamp : Timestamp (uint64_t) pwr_brd_status : Power board status register (uint8_t) pwr_brd_led_status : Power board leds status (uint8_t) pwr_brd_system_volt : Power board syst...
def sens_power_board_send(self, timestamp, pwr_brd_status, pwr_brd_led_status, pwr_brd_system_volt, pwr_brd_servo_volt, pwr_brd_mot_l_amp, pwr_brd_mot_r_amp, pwr_brd_servo_1_amp, pwr_brd_servo_2_amp, pwr_brd_servo_3_amp, pwr_brd_servo_4_amp, pwr_brd_aux_amp, force_mavlink1=False): ''' Mo...
calculate barometric altitude
def altitude(SCALED_PRESSURE, ground_pressure=None, ground_temp=None): '''calculate barometric altitude''' from . import mavutil self = mavutil.mavfile_global if ground_pressure is None: if self.param('GND_ABS_PRESS', None) is None: return 0 ground_pressure = self.param('GND_...
calculate barometric altitude
def altitude2(SCALED_PRESSURE, ground_pressure=None, ground_temp=None): '''calculate barometric altitude''' from . import mavutil self = mavutil.mavfile_global if ground_pressure is None: if self.param('GND_ABS_PRESS', None) is None: return 0 ground_pressure = self.param('GND...
calculate heading from raw magnetometer
def mag_heading(RAW_IMU, ATTITUDE, declination=None, SENSOR_OFFSETS=None, ofs=None): '''calculate heading from raw magnetometer''' if declination is None: import mavutil declination = degrees(mavutil.mavfile_global.param('COMPASS_DEC', 0)) mag_x = RAW_IMU.xmag mag_y = RAW_IMU.ymag ma...
calculate heading from raw magnetometer
def mag_heading_motors(RAW_IMU, ATTITUDE, declination, SENSOR_OFFSETS, ofs, SERVO_OUTPUT_RAW, motor_ofs): '''calculate heading from raw magnetometer''' ofs = get_motor_offsets(SERVO_OUTPUT_RAW, ofs, motor_ofs) if declination is None: import mavutil declination = degrees(mavutil.mavfile_glob...
calculate magnetic field strength from raw magnetometer
def mag_field(RAW_IMU, SENSOR_OFFSETS=None, ofs=None): '''calculate magnetic field strength from raw magnetometer''' mag_x = RAW_IMU.xmag mag_y = RAW_IMU.ymag mag_z = RAW_IMU.zmag if SENSOR_OFFSETS is not None and ofs is not None: mag_x += ofs[0] - SENSOR_OFFSETS.mag_ofs_x mag_y += o...
calculate magnetic field strength from raw magnetometer (dataflash version)
def mag_field_df(MAG, ofs=None): '''calculate magnetic field strength from raw magnetometer (dataflash version)''' mag = Vector3(MAG.MagX, MAG.MagY, MAG.MagZ) offsets = Vector3(MAG.OfsX, MAG.OfsY, MAG.OfsZ) if ofs is not None: mag = (mag - offsets) + Vector3(ofs[0], ofs[1], ofs[2]) return ma...
calculate magnetic field strength from raw magnetometer
def get_motor_offsets(SERVO_OUTPUT_RAW, ofs, motor_ofs): '''calculate magnetic field strength from raw magnetometer''' import mavutil self = mavutil.mavfile_global m = SERVO_OUTPUT_RAW motor_pwm = m.servo1_raw + m.servo2_raw + m.servo3_raw + m.servo4_raw motor_pwm *= 0.25 rc3_min = self.par...
calculate magnetic field strength from raw magnetometer
def mag_field_motors(RAW_IMU, SENSOR_OFFSETS, ofs, SERVO_OUTPUT_RAW, motor_ofs): '''calculate magnetic field strength from raw magnetometer''' mag_x = RAW_IMU.xmag mag_y = RAW_IMU.ymag mag_z = RAW_IMU.zmag ofs = get_motor_offsets(SERVO_OUTPUT_RAW, ofs, motor_ofs) if SENSOR_OFFSETS is not None ...
average over N points
def average(var, key, N): '''average over N points''' 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
5 point 2nd derivative
def second_derivative_5(var, key): '''5 point 2nd derivative''' 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) ...
a simple lowpass filter
def lowpass(var, key, factor): '''a simple lowpass filter''' 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]
calculate differences between values
def diff(var, key): '''calculate differences between values''' 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 slope
def delta(var, key, tusec=None): '''calculate slope''' global last_delta if tusec is not None: tnow = tusec * 1.0e-6 else: import mavutil tnow = mavutil.mavfile_global.timestamp dv = 0 ret = 0 if key in last_delta: (last_v, last_t, last_ret) = last_delta[key] ...
estimate roll from accelerometer
def roll_estimate(RAW_IMU,GPS_RAW_INT=None,ATTITUDE=None,SENSOR_OFFSETS=None, ofs=None, mul=None,smooth=0.7): '''estimate roll from accelerometer''' 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 No...
return the current DCM rotation matrix
def rotation(ATTITUDE): '''return the current DCM rotation matrix''' r = Matrix3() r.from_euler(ATTITUDE.roll, ATTITUDE.pitch, ATTITUDE.yaw) return r
return an attitude rotation matrix that is consistent with the current mag vector
def mag_rotation(RAW_IMU, inclination, declination): '''return an attitude rotation matrix that is consistent with the current mag vector''' 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)...
estimate yaw from mag
def mag_yaw(RAW_IMU, inclination, declination): '''estimate yaw from mag''' m = mag_rotation(RAW_IMU, inclination, declination) (r, p, y) = m.to_euler() y = degrees(y) if y < 0: y += 360 return y
estimate roll from mag
def mag_roll(RAW_IMU, inclination, declination): '''estimate roll from mag''' m = mag_rotation(RAW_IMU, inclination, declination) (r, p, y) = m.to_euler() return degrees(r)
give the magnitude of the discrepancy between observed and expected magnetic field
def mag_discrepancy(RAW_IMU, ATTITUDE, inclination, declination=None): '''give the magnitude of the discrepancy between observed and expected magnetic field''' if declination is None: import mavutil declination = degrees(mavutil.mavfile_global.param('COMPASS_DEC', 0)) expected = expected_mag...
return expected mag vector
def expected_mag(RAW_IMU, ATTITUDE, inclination, declination): '''return expected mag vector''' 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_ea...
give the magnitude of the discrepancy between observed and expected magnetic field
def mag_inclination(RAW_IMU, ATTITUDE, declination=None): '''give the magnitude of the discrepancy between observed and expected magnetic field''' if declination is None: import mavutil declination = degrees(mavutil.mavfile_global.param('COMPASS_DEC', 0)) r = rotation(ATTITUDE) mag1 = Ve...
estimate from mag
def expected_magx(RAW_IMU, ATTITUDE, inclination, declination): '''estimate from mag''' v = expected_mag(RAW_IMU, ATTITUDE, inclination, declination) return v.x
estimate from mag
def expected_magy(RAW_IMU, ATTITUDE, inclination, declination): '''estimate from mag''' v = expected_mag(RAW_IMU, ATTITUDE, inclination, declination) return v.y
estimate from mag
def expected_magz(RAW_IMU, ATTITUDE, inclination, declination): '''estimate from mag''' v = expected_mag(RAW_IMU, ATTITUDE, inclination, declination) return v.z
estimate pitch from accelerometer
def gravity(RAW_IMU, SENSOR_OFFSETS=None, ofs=None, mul=None, smooth=0.7): '''estimate pitch from accelerometer''' 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 ...
estimate pitch from SIMSTATE accels
def pitch_sim(SIMSTATE, GPS_RAW): '''estimate pitch from SIMSTATE accels''' 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(-as...
distance between two points
def distance_two(GPS_RAW1, GPS_RAW2, horizontal=True): '''distance between two points''' if hasattr(GPS_RAW1, 'Lat'): lat1 = radians(GPS_RAW1.Lat) lat2 = radians(GPS_RAW2.Lat) lon1 = radians(GPS_RAW1.Lng) lon2 = radians(GPS_RAW2.Lng) alt1 = GPS_RAW1.Alt alt2 = GPS...
distance from first fix point
def distance_home(GPS_RAW): '''distance from first fix point''' 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...
sawtooth pattern based on uptime
def sawtooth(ATTITUDE, amplitude=2.0, period=5.0): '''sawtooth pattern based on uptime''' 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
return expected rate of turn in degrees/s for given speed in m/s and bank angle in degrees
def rate_of_turn(speed, bank): '''return expected rate of turn in degrees/s for given speed in m/s and bank angle in degrees''' if abs(speed) < 2 or abs(bank) > 80: return 0 ret = degrees(9.81*tan(radians(bank))/speed) return ret
recompute airspeed with a different ARSPD_RATIO
def airspeed(VFR_HUD, ratio=None, used_ratio=None, offset=None): '''recompute airspeed with a different ARSPD_RATIO''' import mavutil mav = mavutil.mavfile_global if ratio is None: ratio = 1.9936 # APM default if used_ratio is None: if 'ARSPD_RATIO' in mav.params: used_ra...
EAS2TAS from ARSP.Temp
def EAS2TAS(ARSP,GPS,BARO,ground_temp=25): '''EAS2TAS from ARSP.Temp''' tempK = ground_temp + 273.15 - 0.0065 * GPS.Alt return sqrt(1.225 / (BARO.Press / (287.26 * tempK)))
recompute airspeed with a different ARSPD_RATIO
def airspeed_ratio(VFR_HUD): '''recompute airspeed with a different ARSPD_RATIO''' import mavutil mav = mavutil.mavfile_global airspeed_pressure = (VFR_HUD.airspeed**2) / ratio airspeed = sqrt(airspeed_pressure * ratio) return airspeed
back-calculate the voltage the airspeed sensor must have seen
def airspeed_voltage(VFR_HUD, ratio=None): '''back-calculate the voltage the airspeed sensor must have seen''' import mavutil mav = mavutil.mavfile_global if ratio is None: ratio = 1.9936 # APM default if 'ARSPD_RATIO' in mav.params: used_ratio = mav.params['ARSPD_RATIO'] else: ...
return angular velocities in earth frame
def earth_rates(ATTITUDE): '''return angular velocities in earth frame''' 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...
return GPS velocity vector
def gps_velocity_old(GPS_RAW_INT): '''return GPS velocity vector''' return 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)), 0)
return GPS velocity vector in body frame
def gps_velocity_body(GPS_RAW_INT, ATTITUDE): '''return GPS velocity vector in body frame''' 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)), ...
return earth frame acceleration vector
def earth_accel(RAW_IMU,ATTITUDE): '''return earth frame acceleration vector''' r = rotation(ATTITUDE) accel = Vector3(RAW_IMU.xacc, RAW_IMU.yacc, RAW_IMU.zacc) * 9.81 * 0.001 return r * accel
return earth frame gyro vector
def earth_gyro(RAW_IMU,ATTITUDE): '''return earth frame gyro vector''' r = rotation(ATTITUDE) accel = Vector3(degrees(RAW_IMU.xgyro), degrees(RAW_IMU.ygyro), degrees(RAW_IMU.zgyro)) * 0.001 return r * accel
return airspeed energy error matching APM internals This is positive when we are going too slow
def airspeed_energy_error(NAV_CONTROLLER_OUTPUT, VFR_HUD): '''return airspeed energy error matching APM internals This is positive when we are going too slow ''' aspeed_cm = VFR_HUD.airspeed*100 target_airspeed = NAV_CONTROLLER_OUTPUT.aspd_error + aspeed_cm airspeed_energy_error = ((target_airsp...
return energy error matching APM internals This is positive when we are too low or going too slow
def energy_error(NAV_CONTROLLER_OUTPUT, VFR_HUD): '''return energy error matching APM internals This is positive when we are too low or going too slow ''' aspeed_energy_error = airspeed_energy_error(NAV_CONTROLLER_OUTPUT, VFR_HUD) alt_error = NAV_CONTROLLER_OUTPUT.alt_error*100 energy_error = as...
return yaw rate in degrees/second given steering_angle and speed
def rover_yaw_rate(VFR_HUD, SERVO_OUTPUT_RAW): '''return yaw rate in degrees/second given steering_angle and speed''' max_wheel_turn=35 speed = VFR_HUD.groundspeed # assume 1100 to 1900 PWM on steering steering_angle = max_wheel_turn * (SERVO_OUTPUT_RAW.servo1_raw - 1500) / 400.0 if abs(steering...
return turning circle (diameter) in meters for steering_angle in degrees
def rover_turn_circle(SERVO_OUTPUT_RAW): '''return turning circle (diameter) in meters for steering_angle in degrees ''' # this matches Toms slash max_wheel_turn = 35 wheelbase = 0.335 wheeltrack = 0.296 steering_angle = max_wheel_turn * (SERVO_OUTPUT_RAW.servo1_raw - 1500) / 400....
return lateral acceleration in m/s/s
def rover_lat_accel(VFR_HUD, SERVO_OUTPUT_RAW): '''return lateral acceleration in m/s/s''' speed = VFR_HUD.groundspeed yaw_rate = rover_yaw_rate(VFR_HUD, SERVO_OUTPUT_RAW) accel = radians(yaw_rate) * speed return accel
de-mix a mixed servo output
def demix1(servo1, servo2, gain=0.5): '''de-mix a mixed servo output''' s1 = servo1 - 1500 s2 = servo2 - 1500 out1 = (s1+s2)*gain out2 = (s1-s2)*gain return out1+1500
de-mix a mixed servo output
def demix2(servo1, servo2, gain=0.5): '''de-mix a mixed servo output''' s1 = servo1 - 1500 s2 = servo2 - 1500 out1 = (s1+s2)*gain out2 = (s1-s2)*gain return out2+1500
mix two servos
def mixer(servo1, servo2, mixtype=1, gain=0.5): '''mix two servos''' 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: ...
de-mix a mixed servo output
def mix1(servo1, servo2, mixtype=1, gain=0.5): '''de-mix a mixed servo output''' (v1,v2) = mixer(servo1, servo2, mixtype=mixtype, gain=gain) return v1
de-mix a mixed servo output
def mix2(servo1, servo2, mixtype=1, gain=0.5): '''de-mix a mixed servo output''' (v1,v2) = mixer(servo1, servo2, mixtype=mixtype, gain=gain) return v2
implement full DCM system
def DCM_update(IMU, ATT, MAG, GPS): '''implement full DCM system''' 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, ...
implement full DCM using PX4 native SD log data
def PX4_update(IMU, ATT): '''implement full DCM using PX4 native SD log data''' 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, IM...
return 1 if armed, 0 if not
def armed(HEARTBEAT): '''return 1 if armed, 0 if not''' 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 the current DCM rotation matrix
def rotation_df(ATT): '''return the current DCM rotation matrix''' r = Matrix3() r.from_euler(radians(ATT.Roll), radians(ATT.Pitch), radians(ATT.Yaw)) return r
return the current DCM rotation matrix
def rotation2(AHRS2): '''return the current DCM rotation matrix''' r = Matrix3() r.from_euler(AHRS2.roll, AHRS2.pitch, AHRS2.yaw) return r
return earth frame acceleration vector from AHRS2
def earth_accel2(RAW_IMU,ATTITUDE): '''return earth frame acceleration vector from AHRS2''' 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 df log
def earth_accel_df(IMU,ATT): '''return earth frame acceleration vector from df log''' r = rotation_df(ATT) accel = Vector3(IMU.AccX, IMU.AccY, IMU.AccZ) return r * accel
return earth frame acceleration vector from df log
def earth_accel2_df(IMU,IMU2,ATT): '''return earth frame acceleration vector from df log''' r = rotation_df(ATT) accel1 = Vector3(IMU.AccX, IMU.AccY, IMU.AccZ) accel2 = Vector3(IMU2.AccX, IMU2.AccY, IMU2.AccZ) accel = 0.5 * (accel1 + accel2) return r * accel
return GPS velocity vector
def gps_velocity_df(GPS): '''return GPS velocity vector''' vx = GPS.Spd * cos(radians(GPS.GCrs)) vy = GPS.Spd * sin(radians(GPS.GCrs)) return Vector3(vx, vy, GPS.VZ)
distance between two points
def distance_gps2(GPS, GPS2): '''distance between two points''' if GPS.TimeMS != GPS2.TimeMS: # reject messages not time aligned return None return distance_two(GPS, GPS2)
calculate EKF position when EKF disabled
def ekf1_pos(EKF1): '''calculate EKF position when EKF disabled''' 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, ...
Returns rotated quaternion :param attitude: quaternion [w, x, y , z] :param roll: rotation in rad :param pitch: rotation in rad :param yaw: rotation in rad :returns: quaternion [w, x, y , z]
def rotate_quat(attitude, roll, pitch, yaw): ''' Returns rotated quaternion :param attitude: quaternion [w, x, y , z] :param roll: rotation in rad :param pitch: rotation in rad :param yaw: rotation in rad :returns: quaternion [w, x, y , z] ''' quat = Quaternion(attitude) rotation = Quaternion([roll,...
take off
def cmd_takeoff(self, args): '''take off''' if ( len(args) != 1): print("Usage: takeoff ALTITUDE_IN_METERS") return if (len(args) == 1): altitude = float(args[0]) print("Take Off started") self.master.mav.command_long_send( ...
parachute control
def cmd_parachute(self, args): '''parachute control''' usage = "Usage: parachute <enable|disable|release>" if len(args) != 1: print(usage) return cmds = { 'enable' : mavutil.mavlink.PARACHUTE_ENABLE, 'disable' : mavutil.mavlink.PARACHUTE_...