_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q230700 | MPTile.start_download_thread | train | def start_download_thread(self):
'''start the downloader'''
if self._download_thread:
return
t = threading.Thread(target=self.downloader)
t.daemon = True
self._download_thread = t
t.start() | python | {
"resource": ""
} |
q230701 | MiscModule.qnh_estimate | train | def qnh_estimate(self):
'''estimate QNH pressure from GPS altitude and scaled pressure'''
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_t... | python | {
"resource": ""
} |
q230702 | MiscModule.cmd_up | train | def cmd_up(self, args):
'''adjust TRIM_PITCH_CD up by 5 degrees'''
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!")
... | python | {
"resource": ""
} |
q230703 | MiscModule.cmd_time | train | def cmd_time(self, args):
'''show autopilot time'''
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())) | python | {
"resource": ""
} |
q230704 | MiscModule.cmd_changealt | train | def cmd_changealt(self, args):
'''change target altitude'''
if len(args) < 1:
print("usage: changealt <relaltitude>")
return
relalt = float(args[0])
self.master.mav.mission_item_send(self.settings.target_system,
self.setti... | python | {
"resource": ""
} |
q230705 | MiscModule.cmd_land | train | def cmd_land(self, args):
'''auto land commands'''
if len(args) < 1:
self.master.mav.command_long_send(self.settings.target_system,
0,
mavutil.mavlink.MAV_CMD_DO_LAND_START,
... | python | {
"resource": ""
} |
q230706 | MiscModule.cmd_rcbind | train | def cmd_rcbind(self, args):
'''start RC bind'''
if len(args) < 1:
print("Usage: rcbind <dsmmode>")
return
self.master.mav.command_long_send(self.settings.target_system,
self.settings.target_component,
... | python | {
"resource": ""
} |
q230707 | MiscModule.cmd_repeat | train | def cmd_repeat(self, args):
'''repeat a command at regular intervals'''
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]))
r... | python | {
"resource": ""
} |
q230708 | MapModule.show_position | train | def show_position(self):
'''show map position click information'''
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" %... | python | {
"resource": ""
} |
q230709 | MapModule.display_fence | train | def display_fence(self):
'''display the fence'''
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('F... | python | {
"resource": ""
} |
q230710 | MapModule.closest_waypoint | train | def closest_waypoint(self, latlon):
'''find closest waypoint to a position'''
(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, ... | python | {
"resource": ""
} |
q230711 | MapModule.selection_index_to_idx | train | def selection_index_to_idx(self, key, selection_index):
'''return a mission idx from a 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(s... | python | {
"resource": ""
} |
q230712 | MapModule.move_mission | train | def move_mission(self, key, selection_index):
'''move a mission point'''
idx = self.selection_index_to_idx(key, selection_index)
self.moving_wp = idx
print("Moving wp %u" % idx) | python | {
"resource": ""
} |
q230713 | MapModule.remove_mission | train | def remove_mission(self, key, selection_index):
'''remove a mission point'''
idx = self.selection_index_to_idx(key, selection_index)
self.mpstate.functions.process_stdin('wp remove %u' % idx) | python | {
"resource": ""
} |
q230714 | MapModule.create_vehicle_icon | train | def create_vehicle_icon(self, name, colour, follow=False, vehicle_type=None):
'''add a vehicle to the map'''
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[... | python | {
"resource": ""
} |
q230715 | MapModule.drawing_update | train | def drawing_update(self):
'''update line drawing'''
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.Sli... | python | {
"resource": ""
} |
q230716 | load | train | def load(filename):
'''
Returns the configuration as dict
@param filename: Name of the file
@type filename: String
@return a dict with propierties reader from file
'''
filepath = findConfigFile(filename)
prop= None
if (filepath):
print ('loading Config file %s' %(filepath... | python | {
"resource": ""
} |
q230717 | ParamState.fetch_check | train | def fetch_check(self, master):
'''check for missing parameters periodically'''
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(se... | python | {
"resource": ""
} |
q230718 | WXSettings.watch_thread | train | def watch_thread(self):
'''watch for settings changes from child'''
from mp_settings import MPSetting
while True:
setting = self.child_pipe.recv()
if not isinstance(setting, MPSetting):
break
try:
self.settings.set(setting.name,... | python | {
"resource": ""
} |
q230719 | SensorsModule.report | train | def report(self, name, ok, msg=None, deltat=20):
'''report a sensor error'''
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 ... | python | {
"resource": ""
} |
q230720 | SensorsModule.report_change | train | def report_change(self, name, value, maxdiff=1, deltat=10):
'''report a sensor change'''
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 = va... | python | {
"resource": ""
} |
q230721 | MPSlipMap.close | train | def close(self):
'''close the window'''
self.close_window.release()
count=0
while self.child.is_alive() and count < 30: # 3 seconds to die...
time.sleep(0.1) #?
count+=1
if self.child.is_alive():
self.child.terminate()
self.child.join... | python | {
"resource": ""
} |
q230722 | MPSlipMap.hide_object | train | def hide_object(self, key, hide=True):
'''hide an object on the map by key'''
self.object_queue.put(SlipHideObject(key, hide)) | python | {
"resource": ""
} |
q230723 | MPSlipMap.set_position | train | def set_position(self, key, latlon, layer=None, rotation=0):
'''move an object on the map'''
self.object_queue.put(SlipPosition(key, latlon, layer, rotation)) | python | {
"resource": ""
} |
q230724 | MPSlipMap.check_events | train | 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) | python | {
"resource": ""
} |
q230725 | radius_cmp | train | 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 | python | {
"resource": ""
} |
q230726 | plot_data | train | 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... | python | {
"resource": ""
} |
q230727 | MAVTemplate.find_end | train | 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... | python | {
"resource": ""
} |
q230728 | MAVTemplate.find_var_end | train | def find_var_end(self, text):
'''find the of a variable'''
return self.find_end(text, self.start_var_token, self.end_var_token) | python | {
"resource": ""
} |
q230729 | MAVTemplate.find_rep_end | train | 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) | python | {
"resource": ""
} |
q230730 | MAVTemplate.write | train | 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)) | python | {
"resource": ""
} |
q230731 | flight_time | train | 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:... | python | {
"resource": ""
} |
q230732 | match_type | train | def match_type(mtype, patterns):
'''return True if mtype matches pattern'''
for p in patterns:
if fnmatch.fnmatch(mtype, p):
return True
return False | python | {
"resource": ""
} |
q230733 | YuvFilter.apply | train | 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... | python | {
"resource": ""
} |
q230734 | ConsoleFrame.on_menu | train | 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) | python | {
"resource": ""
} |
q230735 | MAVLink.aslctrl_data_encode | train | 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
... | python | {
"resource": ""
} |
q230736 | average | train | 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 | python | {
"resource": ""
} |
q230737 | second_derivative_5 | train | 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)
... | python | {
"resource": ""
} |
q230738 | lowpass | train | 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] | python | {
"resource": ""
} |
q230739 | diff | train | 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 | python | {
"resource": ""
} |
q230740 | roll_estimate | train | 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... | python | {
"resource": ""
} |
q230741 | mag_rotation | train | 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)... | python | {
"resource": ""
} |
q230742 | mag_yaw | train | 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 | python | {
"resource": ""
} |
q230743 | mag_roll | train | 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) | python | {
"resource": ""
} |
q230744 | expected_mag | train | 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... | python | {
"resource": ""
} |
q230745 | gravity | train | 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
... | python | {
"resource": ""
} |
q230746 | pitch_sim | train | 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... | python | {
"resource": ""
} |
q230747 | distance_home | train | 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... | python | {
"resource": ""
} |
q230748 | sawtooth | train | 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 | python | {
"resource": ""
} |
q230749 | EAS2TAS | train | 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))) | python | {
"resource": ""
} |
q230750 | airspeed_voltage | train | 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:
... | python | {
"resource": ""
} |
q230751 | earth_rates | train | 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... | python | {
"resource": ""
} |
q230752 | gps_velocity_body | train | 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)),
... | python | {
"resource": ""
} |
q230753 | earth_accel | train | 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 | python | {
"resource": ""
} |
q230754 | earth_gyro | train | 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 | python | {
"resource": ""
} |
q230755 | airspeed_energy_error | train | 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... | python | {
"resource": ""
} |
q230756 | energy_error | train | 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... | python | {
"resource": ""
} |
q230757 | mixer | train | 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:
... | python | {
"resource": ""
} |
q230758 | DCM_update | train | 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, ... | python | {
"resource": ""
} |
q230759 | PX4_update | train | 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... | python | {
"resource": ""
} |
q230760 | armed | train | 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... | python | {
"resource": ""
} |
q230761 | earth_accel2 | train | 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 | python | {
"resource": ""
} |
q230762 | ekf1_pos | train | 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, ... | python | {
"resource": ""
} |
q230763 | CmdlongModule.cmd_condition_yaw | train | def cmd_condition_yaw(self, args):
'''yaw angle angular_speed angle_mode'''
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[... | python | {
"resource": ""
} |
q230764 | CmdlongModule.cmd_velocity | train | def cmd_velocity(self, args):
'''velocity x-ms y-ms z-ms'''
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])
#print("... | python | {
"resource": ""
} |
q230765 | CmdlongModule.cmd_position | train | def cmd_position(self, args):
'''position x-m y-m z-m'''
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... | python | {
"resource": ""
} |
q230766 | CmdlongModule.cmd_attitude | train | def cmd_attitude(self, args):
'''attitude q0 q1 q2 q3 thrust'''
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 =... | python | {
"resource": ""
} |
q230767 | CmdlongModule.cmd_posvel | train | def cmd_posvel(self, args):
'''posvel mapclick vN vE vD'''
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... | python | {
"resource": ""
} |
q230768 | ImagePanel.on_paint | train | def on_paint(self, event):
'''repaint the image'''
dc = wx.AutoBufferedPaintDC(self)
dc.DrawBitmap(self._bmp, 0, 0) | python | {
"resource": ""
} |
q230769 | mavgen_python_dialect | train | def mavgen_python_dialect(dialect, wire_protocol):
'''generate the python code on the fly for a MAVLink dialect'''
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... | python | {
"resource": ""
} |
q230770 | process_tlog | train | def process_tlog(filename):
'''convert a tlog to a .m file'''
print("Processing %s" % filename)
mlog = mavutil.mavlink_connection(filename, dialect=args.dialect, zero_time_base=True)
# first walk the entire file, grabbing all messages into a hash of lists,
#and the first message of each type into... | python | {
"resource": ""
} |
q230771 | radius | train | def radius(d, offsets, motor_ofs):
'''return radius give data point and offsets'''
(mag, motor) = d
return (mag + offsets + motor*motor_ofs).length() | python | {
"resource": ""
} |
q230772 | camel_case_from_underscores | train | def camel_case_from_underscores(string):
"""generate a CamelCase string from an underscore_string."""
components = string.split('_')
string = ''
for component in components:
string += component[0].upper() + component[1:]
return string | python | {
"resource": ""
} |
q230773 | generate | train | def generate(basename, xml_list):
'''generate complete MAVLink Objective-C implemenation'''
generate_shared(basename, xml_list)
for xml in xml_list:
generate_message_definitions(basename, xml) | python | {
"resource": ""
} |
q230774 | LiveGraph.add_values | train | def add_values(self, values):
'''add some data to the graph'''
if self.child.is_alive():
self.parent_pipe.send(values) | python | {
"resource": ""
} |
q230775 | LiveGraph.close | train | def close(self):
'''close the graph'''
self.close_graph.set()
if self.is_alive():
self.child.join(2) | python | {
"resource": ""
} |
q230776 | get_enum_raw_type | train | def get_enum_raw_type(enum, msgs):
"""Search appropirate raw type for enums in messages fields"""
for msg in msgs:
for field in msg.fields:
if field.enum == enum.name:
return swift_types[field.type][0]
return "Int" | python | {
"resource": ""
} |
q230777 | append_static_code | train | def append_static_code(filename, outf):
"""Open and copy static code from specified file"""
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 l... | python | {
"resource": ""
} |
q230778 | camel_case_from_underscores | train | def camel_case_from_underscores(string):
"""Generate a CamelCase string from an underscore_string"""
components = string.split('_')
string = ''
for component in components:
if component in abbreviations:
string += component
else:
string += component[0].upper() +... | python | {
"resource": ""
} |
q230779 | generate_enums_info | train | def generate_enums_info(enums, msgs):
"""Add camel case swift names for enums an entries, descriptions and sort enums alphabetically"""
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_descrip... | python | {
"resource": ""
} |
q230780 | generate_messages_info | train | def generate_messages_info(msgs):
"""Add proper formated variable names, initializers and type names to use in templates"""
for msg in msgs:
msg.swift_name = camel_case_from_underscores(msg.name)
msg.formatted_description = ""
if msg.description:
msg.description = " ".join(... | python | {
"resource": ""
} |
q230781 | generate | train | def generate(basename, xml_list):
"""Generate complete MAVLink Swift implemenation"""
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.mes... | python | {
"resource": ""
} |
q230782 | MAVWPLoader.wp_is_loiter | train | def wp_is_loiter(self, i):
'''return true if waypoint is a loiter waypoint'''
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_... | python | {
"resource": ""
} |
q230783 | MAVWPLoader.add | train | def add(self, w, comment=''):
'''add a waypoint'''
w = copy.copy(w)
if comment:
w.comment = comment
w.seq = self.count()
self.wpoints.append(w)
self.last_change = time.time() | python | {
"resource": ""
} |
q230784 | MAVWPLoader.insert | train | def insert(self, idx, w, comment=''):
'''insert a waypoint'''
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(id... | python | {
"resource": ""
} |
q230785 | MAVWPLoader.set | train | def set(self, w, idx):
'''set a waypoint'''
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.... | python | {
"resource": ""
} |
q230786 | MAVWPLoader.remove | train | def remove(self, w):
'''remove a waypoint'''
self.wpoints.remove(w)
self.last_change = time.time()
self.reindex() | python | {
"resource": ""
} |
q230787 | MAVWPLoader._read_waypoints_v100 | train | def _read_waypoints_v100(self, file):
'''read a version 100 waypoint'''
cmdmap = {
2 : mavutil.mavlink.MAV_CMD_NAV_TAKEOFF,
3 : mavutil.mavlink.MAV_CMD_NAV_RETURN_TO_LAUNCH,
4 : mavutil.mavlink.MAV_CMD_NAV_LAND,
24: mavutil.mavlink.MAV_CMD_NAV_TAKEOFF,
... | python | {
"resource": ""
} |
q230788 | MAVWPLoader._read_waypoints_v110 | train | def _read_waypoints_v110(self, file):
'''read a version 110 waypoint'''
comment = ''
for line in file:
if line.startswith('#'):
comment = line[1:].lstrip()
continue
line = line.strip()
if not line:
continue
... | python | {
"resource": ""
} |
q230789 | MAVWPLoader.load | train | def load(self, filename):
'''load waypoints from a file.
returns number of waypoints loaded'''
f = open(filename, mode='r')
version_line = f.readline().strip()
if version_line == "QGC WPL 100":
readfn = self._read_waypoints_v100
elif version_line == "QGC WPL 1... | python | {
"resource": ""
} |
q230790 | MAVWPLoader.view_indexes | train | def view_indexes(self, done=None):
'''return a list waypoint indexes in view order'''
ret = []
if done is None:
done = set()
idx = 0
# find first point not done yet
while idx < self.count():
if not idx in done:
break
id... | python | {
"resource": ""
} |
q230791 | MAVWPLoader.polygon | train | def polygon(self, done=None):
'''return a polygon for the waypoints'''
indexes = self.view_indexes(done)
points = []
for idx in indexes:
w = self.wp(idx)
points.append((w.x, w.y))
return points | python | {
"resource": ""
} |
q230792 | MAVWPLoader.polygon_list | train | def polygon_list(self):
'''return a list of polygons for the waypoints'''
done = set()
ret = []
while len(done) != self.count():
p = self.polygon(done)
if len(p) > 0:
ret.append(p)
return ret | python | {
"resource": ""
} |
q230793 | MAVWPLoader.view_list | train | def view_list(self):
'''return a list of polygon indexes lists for the waypoints'''
done = set()
ret = []
while len(done) != self.count():
p = self.view_indexes(done)
if len(p) > 0:
ret.append(p)
return ret | python | {
"resource": ""
} |
q230794 | MAVRallyLoader.reindex | train | def reindex(self):
'''reset counters and indexes'''
for i in range(self.rally_count()):
self.rally_points[i].count = self.rally_count()
self.rally_points[i].idx = i
self.last_change = time.time() | python | {
"resource": ""
} |
q230795 | MAVRallyLoader.append_rally_point | train | def append_rally_point(self, p):
'''add rallypoint to end of list'''
if (self.rally_count() > 9):
print("Can't have more than 10 rally points, not adding.")
return
self.rally_points.append(p)
self.reindex() | python | {
"resource": ""
} |
q230796 | MAVRallyLoader.load | train | def load(self, filename):
'''load rally and rally_land points from a file.
returns number of points loaded'''
f = open(filename, mode='r')
self.clear()
for line in f:
if line.startswith('#'):
continue
line = line.strip()
if not... | python | {
"resource": ""
} |
q230797 | MAVFenceLoader.load | train | def load(self, filename):
'''load points from a file.
returns number of points loaded'''
f = open(filename, mode='r')
self.clear()
for line in f:
if line.startswith('#'):
continue
line = line.strip()
if not line:
... | python | {
"resource": ""
} |
q230798 | MAVFenceLoader.move | train | def move(self, i, lat, lng, change_time=True):
'''move a fence point'''
if i < 0 or i >= self.count():
print("Invalid fence point number %u" % i)
self.points[i].lat = lat
self.points[i].lng = lng
# ensure we close the polygon
if i == 1:
self.po... | python | {
"resource": ""
} |
q230799 | MAVFenceLoader.remove | train | def remove(self, i, change_time=True):
'''remove a fence point'''
if i < 0 or i >= self.count():
print("Invalid fence point number %u" % i)
self.points.pop(i)
# ensure we close the polygon
if i == 1:
self.points[self.count()-1].lat = self.points[1].la... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.