INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
called on idle | def idle_task(self):
'''called on idle'''
if self.module('console') is not None and not self.menu_added_console:
self.menu_added_console = True
self.module('console').add_menu(self.menu)
if self.module('map') is not None and not self.menu_added_map:
self.menu_... |
Enable or disable fence | def set_fence_enabled(self, do_enable):
'''Enable or disable fence'''
self.master.mav.command_long_send(
self.target_system,
self.target_component,
mavutil.mavlink.MAV_CMD_DO_FENCE_ENABLE, 0,
do_enable, 0, 0, 0, 0, 0, 0) |
handle fencepoint move | def cmd_fence_move(self, args):
'''handle fencepoint move'''
if len(args) < 1:
print("Usage: fence move FENCEPOINTNUM")
return
if not self.have_list:
print("Please list fence points first")
return
idx = int(args[0])
if idx <= 0 or ... |
handle fencepoint remove | def cmd_fence_remove(self, args):
'''handle fencepoint remove'''
if len(args) < 1:
print("Usage: fence remove FENCEPOINTNUM")
return
if not self.have_list:
print("Please list fence points first")
return
idx = int(args[0])
if idx <=... |
fence commands | def cmd_fence(self, args):
'''fence commands'''
if len(args) < 1:
self.print_usage()
return
if args[0] == "enable":
self.set_fence_enabled(1)
elif args[0] == "disable":
self.set_fence_enabled(0)
elif args[0] == "load":
... |
send fence points from fenceloader | def send_fence(self):
'''send fence points from fenceloader'''
# must disable geo-fencing when loading
self.fenceloader.target_system = self.target_system
self.fenceloader.target_component = self.target_component
self.fenceloader.reindex()
action = self.get_mav_param('FEN... |
fetch one fence point | def fetch_fence_point(self ,i):
'''fetch one fence point'''
self.master.mav.fence_fetch_point_send(self.target_system,
self.target_component, i)
tstart = time.time()
p = None
while time.time() - tstart < 3:
p = self.... |
callback from drawing a fence | def fence_draw_callback(self, points):
'''callback from drawing a fence'''
self.fenceloader.clear()
if len(points) < 3:
return
self.fenceloader.target_system = self.target_system
self.fenceloader.target_component = self.target_component
bounds = mp_util.polygo... |
add a new menu | def add_menu(self, menu):
'''add a new menu'''
self.menu.add(menu)
self.mpstate.console.set_menu(self.menu, self.menu_callback) |
unload module | def unload(self):
'''unload module'''
self.mpstate.console.close()
self.mpstate.console = textconsole.SimpleConsole() |
called on menu selection | def menu_callback(self, m):
'''called on menu selection'''
if m.returnkey.startswith('# '):
cmd = m.returnkey[2:]
if m.handler is not None:
if m.handler_result is None:
return
cmd += m.handler_result
self.mpstate.fun... |
estimate time remaining in mission in seconds | def estimated_time_remaining(self, lat, lon, wpnum, speed):
'''estimate time remaining in mission in seconds'''
idx = wpnum
if wpnum >= self.module('wp').wploader.count():
return 0
distance = 0
done = set()
while idx < self.module('wp').wploader.count():
... |
handle an incoming mavlink packet | def mavlink_packet(self, msg):
'''handle an incoming mavlink packet'''
if not isinstance(self.console, wxconsole.MessageConsole):
return
if not self.console.is_alive():
self.mpstate.console = textconsole.SimpleConsole()
return
type = msg.get_type()
... |
return the angle between this vector and another vector | def angle(self, v):
'''return the angle between this vector and another vector'''
return acos((self * v) / (self.length() * v.length())) |
fill the matrix from Euler angles in radians | def from_euler(self, roll, pitch, yaw):
'''fill the matrix from Euler angles in radians'''
cp = cos(pitch)
sp = sin(pitch)
sr = sin(roll)
cr = cos(roll)
sy = sin(yaw)
cy = cos(yaw)
self.a.x = cp * cy
self.a.y = (sr * sp * cy) - (cr * sy)
s... |
find Euler angles (321 convention) for the matrix | def to_euler(self):
'''find Euler angles (321 convention) for the matrix'''
if self.c.x >= 1.0:
pitch = pi
elif self.c.x <= -1.0:
pitch = -pi
else:
pitch = -asin(self.c.x)
roll = atan2(self.c.y, self.c.z)
yaw = atan2(self.b.x, self.a.x... |
find Euler angles (312 convention) for the matrix.
See http://www.atacolorado.com/eulersequences.doc | def to_euler312(self):
'''find Euler angles (312 convention) for the matrix.
See http://www.atacolorado.com/eulersequences.doc
'''
T21 = self.a.y
T22 = self.b.y
T23 = self.c.y
T13 = self.c.x
T33 = self.c.z
yaw = atan2(-T21, T22)
roll = asin... |
fill the matrix from Euler angles in radians in 312 convention | def from_euler312(self, roll, pitch, yaw):
'''fill the matrix from Euler angles in radians in 312 convention'''
c3 = cos(pitch)
s3 = sin(pitch)
s2 = sin(roll)
c2 = cos(roll)
s1 = sin(yaw)
c1 = cos(yaw)
self.a.x = c1 * c3 - s1 * s2 * s3
self.b.y = ... |
rotate the matrix by a given amount on 3 axes | def rotate(self, g):
'''rotate the matrix by a given amount on 3 axes'''
temp_matrix = Matrix3()
a = self.a
b = self.b
c = self.c
temp_matrix.a.x = a.y * g.z - a.z * g.y
temp_matrix.a.y = a.z * g.x - a.x * g.z
temp_matrix.a.z = a.x * g.y - a.y * g.x
... |
re-normalise a rotation matrix | def normalize(self):
'''re-normalise a rotation matrix'''
error = self.a * self.b
t0 = self.a - (self.b * (0.5 * error))
t1 = self.b - (self.a * (0.5 * error))
t2 = t0 % t1
self.a = t0 * (1.0 / t0.length())
self.b = t1 * (1.0 / t1.length())
self.c = t2 * (... |
the trace of the matrix | def trace(self):
'''the trace of the matrix'''
return self.a.x + self.b.y + self.c.z |
create a rotation matrix from axis and angle | def from_axis_angle(self, axis, angle):
'''create a rotation matrix from axis and angle'''
ux = axis.x
uy = axis.y
uz = axis.z
ct = cos(angle)
st = sin(angle)
self.a.x = ct + (1-ct) * ux**2
self.a.y = ux*uy*(1-ct) - uz*st
self.a.z = ux*uz*(1-ct) + ... |
get a rotation matrix from two vectors.
This returns a rotation matrix which when applied to vec1
will produce a vector pointing in the same direction as vec2 | def from_two_vectors(self, vec1, vec2):
'''get a rotation matrix from two vectors.
This returns a rotation matrix which when applied to vec1
will produce a vector pointing in the same direction as vec2'''
angle = vec1.angle(vec2)
cross = vec1 % vec2
if cross.length(... |
return point where line intersects with a plane | def plane_intersection(self, plane, forward_only=False):
'''return point where line intersects with a plane'''
l_dot_n = self.vector * plane.normal
if l_dot_n == 0.0:
# line is parallel to the plane
return None
d = ((plane.point - self.point) * plane.normal) / l_d... |
Updates Image. | def update(self):
'''
Updates Image.
'''
if self.hasproxy():
img = Rgbd()
data = self.proxy.getData()
img.color.data = np.frombuffer(data.color.pixelData, dtype=np.uint8)
img.color.data.shape = data.color.description.height, data.color.des... |
Returns last Rgbd.
@return last JdeRobotTypes Rgbd saved | def getRgbd(self):
'''
Returns last Rgbd.
@return last JdeRobotTypes Rgbd saved
'''
img = Rgb()
if self.hasproxy():
self.lock.acquire()
img = self.image
self.lock.release()
return img |
called in idle time | def idle_task(self):
'''called in idle time'''
try:
data = self.port.recv(200)
except socket.error as e:
if e.errno in [ errno.EAGAIN, errno.EWOULDBLOCK ]:
return
raise
if len(data) > 110:
print("DGPS data too large: %u byte... |
graph command | def cmd_graph(self, args):
'''graph command'''
if len(args) == 0:
# list current graphs
for i in range(len(self.graphs)):
print("Graph %u: %s" % (i, self.graphs[i].fields))
return
elif args[0] == "help":
print("graph <timespan|tick... |
handle an incoming mavlink packet | def mavlink_packet(self, msg):
'''handle an incoming mavlink packet'''
# check for any closed graphs
for i in range(len(self.graphs) - 1, -1, -1):
if not self.graphs[i].is_alive():
self.graphs[i].close()
self.graphs.pop(i)
# add data to the r... |
add data to the graph | def add_mavlink_packet(self, msg):
'''add data to the graph'''
mtype = msg.get_type()
if mtype not in self.msg_types:
return
for i in range(len(self.fields)):
if mtype not in self.field_types[i]:
continue
f = self.fields[i]
... |
Generate the implementations of the classes representing MAVLink messages. | def generate_classes(outf, msgs):
"""
Generate the implementations of the classes representing MAVLink messages.
"""
print("Generating class definitions")
wrapper = textwrap.TextWrapper(initial_indent="", subsequent_indent="")
outf.write("\nmavlink.messages = {};\n\n");
def field_descripti... |
work out the struct format for a type | def mavfmt(field):
'''work out the struct format for a type'''
map = {
'float' : 'f',
'double' : 'd',
'char' : 'c',
'int8_t' : 'b',
'uint8_t' : 'B',
'uint8_t_mavlink_version' : 'B',
'int16_t' : 'h',
'uint16_t' : 'H',
'int32_t'... |
generate complete javascript implementation | def generate(basename, xml):
'''generate complete javascript implementation'''
if basename.endswith('.js'):
filename = basename
else:
filename = basename + '.js'
msgs = []
enums = []
filelist = []
for x in xml:
msgs.extend(x.message)
enums.extend(x.enum)
... |
child process - this holds GUI elements | def child_task(self, q, l, gq, gl):
'''child process - this holds GUI elements'''
mp_util.child_close_fds()
from ..lib import wx_processguard
from ..lib.wx_loader import wx
from MAVProxy.modules.mavproxy_misseditor import missionEditorFrame
self.app = wx.App(Fal... |
close the Mission Editor window | def close(self):
'''close the Mission Editor window'''
self.close_window.set()
if self.child.is_alive():
self.child.join(1)
self.child.terminate()
self.event_queue_lock.acquire()
self.event_queue.put(MissionEditorEvent(me_event.MEE_TIME_TO_QUIT));
se... |
Trigger Camera | def __vCmdCamTrigger(self, args):
'''Trigger Camera'''
#print(self.camera_list)
for cam in self.camera_list:
cam.take_picture()
print("Trigger Cam %s" % cam) |
ToDo: Validate the argument as a valid port | def __vCmdConnectCameras(self, args):
'''ToDo: Validate the argument as a valid port'''
if len(args) >= 1:
self.WirelessPort = args[0]
print ("Connecting to Cameras on %s" % self.WirelessPort)
self.__vRegisterCameras() |
ToDo: Validate CAM number and Valid Mode Values | def __vCmdSetCamExposureMode(self, args):
'''ToDo: Validate CAM number and Valid Mode Values'''
if len(args) == 1:
for cam in self.camera_list:
cam.boSetExposureMode(args[0])
elif len(args) == 2:
cam = self.camera_list[int(args[1])]
cam.boSetEx... |
ToDo: Validate CAM number and Valid Aperture Value | def __vCmdSetCamAperture(self, args):
'''ToDo: Validate CAM number and Valid Aperture Value'''
if len(args) == 1:
for cam in self.camera_list:
cam.boSetAperture(int(args[0]))
elif len(args) == 2:
cam = self.camera_list[int(args[1])]
cam.boSetAp... |
ToDo: Validate CAM number and Valid Shutter Speed | def __vCmdSetCamShutterSpeed(self, args):
'''ToDo: Validate CAM number and Valid Shutter Speed'''
if len(args) == 1:
for cam in self.camera_list:
cam.boSetShutterSpeed(int(args[0]))
elif len(args) == 2:
cam = self.camera_list[int(args[1])]
cam.... |
ToDo: Validate CAM number and Valid ISO Value | def __vCmdSetCamISO(self, args):
'''ToDo: Validate CAM number and Valid ISO Value'''
if len(args) == 1:
for cam in self.camera_list:
cam.boSetISO(int(args[0]))
elif len(args) == 2:
cam = self.camera_list[int(args[1])]
cam.boSetISO(int(args[0]))... |
Shutter Speed | def __vDecodeDIGICAMConfigure(self, mCommand_Long):
if mCommand_Long.param1 != 0:
print ("Exposure Mode = %d" % mCommand_Long.param1)
if mCommand_Long.param1 == self.ProgramAuto:
self.__vCmdSetCamExposureMode(["Program Auto"])
elif mC... |
Session | def __vDecodeDIGICAMControl(self, mCommand_Long):
'''Session'''
if mCommand_Long.param1 != 0:
print ("Session = %d" % mCommand_Long.param1)
'''Zooming Step Value'''
if mCommand_Long.param2 != 0:
print ("Zooming Step = %d" % mCommand_Long.param2)
... |
handle a mavlink packet | def mavlink_packet(self, m):
'''handle a mavlink packet'''
mtype = m.get_type()
if mtype == "CAMERA_STATUS":
print ("Got Message camera_status")
if mtype == "CAMERA_FEEDBACK":
print ("Got Message camera_feedback")
'''self.__vCmdCamTrigger(m)'''
... |
show flight modes for a log file | def flight_modes(logfile):
'''show flight modes for a log file'''
print("Processing log %s" % filename)
mlog = mavutil.mavlink_connection(filename)
mode = ""
previous_mode = ""
mode_start_timestamp = -1
time_in_mode = {}
previous_percent = -1
seconds_per_percent = -1
filesize =... |
return true if we have a graph of the given name | def have_graph(name):
'''return true if we have a graph of the given name'''
for g in mestate.graphs:
if g.name == name:
return True
return False |
called on menu selection | def menu_callback(m):
'''called on menu selection'''
if m.returnkey.startswith('# '):
cmd = m.returnkey[2:]
if m.handler is not None:
if m.handler_result is None:
return
cmd += m.handler_result
process_stdin(cmd)
elif m.returnkey == 'menuSettin... |
construct flightmode menu | def flightmode_menu():
'''construct flightmode menu'''
modes = mestate.mlog.flightmode_list()
ret = []
idx = 0
for (mode,t1,t2) in modes:
modestr = "%s %us" % (mode, (t2-t1))
ret.append(MPMenuCheckbox(modestr, modestr, 'mode-%u' % idx))
idx += 1
mestate.flightmode_sel... |
return menu tree for graphs (recursive) | def graph_menus():
'''return menu tree for graphs (recursive)'''
ret = MPMenuSubMenu('Graphs', [])
for i in range(len(mestate.graphs)):
g = mestate.graphs[i]
path = g.name.split('/')
name = path[-1]
path = path[:-1]
ret.add_to_submenu(path, MPMenuItem(name, name, '# g... |
setup console menus | def setup_menus():
'''setup console menus'''
menu = MPMenuTop([])
menu.add(MPMenuSubMenu('MAVExplorer',
items=[MPMenuItem('Settings', 'Settings', 'menuSettings'),
MPMenuItem('Map', 'Map', '# map'),
MPMenuItem('Sav... |
return True if an expression is OK with current messages | def expression_ok(expression):
'''return True if an expression is OK with current messages'''
expression_ok = True
fields = expression.split()
for f in fields:
try:
if f.endswith(':2'):
f = f[:-2]
if mavutil.evaluate_expression(f, mestate.status.msgs) is N... |
load a graph from one xml string | def load_graph_xml(xml, filename, load_all=False):
'''load a graph from one xml string'''
ret = []
try:
root = objectify.fromstring(xml)
except Exception:
return []
if root.tag != 'graphs':
return []
if not hasattr(root, 'graph'):
return []
for g in root.graph... |
load graphs from mavgraphs.xml | def load_graphs():
'''load graphs from mavgraphs.xml'''
mestate.graphs = []
gfiles = ['mavgraphs.xml']
if 'HOME' in os.environ:
for dirname, dirnames, filenames in os.walk(os.path.join(os.environ['HOME'], ".mavproxy")):
for filename in filenames:
if f... |
process for a graph | def graph_process(fields):
'''process for a graph'''
mestate.mlog.reduce_by_flightmodes(mestate.flightmode_selections)
mg = grapher.MavGraph()
mg.set_marker(mestate.settings.marker)
mg.set_condition(mestate.settings.condition)
mg.set_xaxis(mestate.settings.xaxis)
mg.set_linestyle(mestat... |
display a graph | def display_graph(graphdef):
'''display a graph'''
mestate.console.write("Expression: %s\n" % ' '.join(graphdef.expression.split()))
child = multiprocessing.Process(target=graph_process, args=[graphdef.expression.split()])
child.start() |
graph command | def cmd_graph(args):
'''graph command'''
usage = "usage: graph <FIELD...>"
if len(args) < 1:
print(usage)
return
if args[0][0] == ':':
i = int(args[0][1:])
g = mestate.graphs[i]
expression = g.expression
args = expression.split()
mestate.console.wr... |
process for a graph | def map_process(args):
'''process for a graph'''
from mavflightview import mavflightview_mav, mavflightview_options
mestate.mlog.reduce_by_flightmodes(mestate.flightmode_selections)
options = mavflightview_options()
options.condition = mestate.settings.condition
if len(args) > 0:
op... |
map command | def cmd_map(args):
'''map command'''
child = multiprocessing.Process(target=map_process, args=[args])
child.start() |
control MAVExporer conditions | def cmd_condition(args):
'''control MAVExporer conditions'''
if len(args) == 0:
print("condition is: %s" % mestate.settings.condition)
return
mestate.settings.condition = ' '.join(args)
if len(mestate.settings.condition) == 0 or mestate.settings.condition == 'clear':
mestate.sett... |
reload graphs | def cmd_reload(args):
'''reload graphs'''
mestate.console.writeln('Reloading graphs', fg='blue')
load_graphs()
setup_menus()
mestate.console.write("Loaded %u graphs\n" % len(mestate.graphs)) |
save a graph as XML | def save_graph(graphdef):
'''save a graph as XML'''
if graphdef.filename is None:
if 'HOME' in os.environ:
dname = os.path.join(os.environ['HOME'], '.mavproxy')
mp_util.mkdir_p(dname)
graphdef.filename = os.path.join(dname, 'mavgraphs.xml')
else:
g... |
callback from save thread | def save_callback(operation, graphdef):
'''callback from save thread'''
if operation == 'test':
for e in graphdef.expressions:
if expression_ok(e):
graphdef.expression = e
display_graph(graphdef)
return
mestate.console.writeln('Invalid ... |
process for saving a graph | def save_process():
'''process for saving a graph'''
from MAVProxy.modules.lib import wx_processguard
from MAVProxy.modules.lib.wx_loader import wx
from MAVProxy.modules.lib.wxgrapheditor import GraphDialog
app = wx.App(False)
frame = GraphDialog('Graph Editor',
mestate.l... |
show parameters | def cmd_param(args):
'''show parameters'''
if len(args) > 0:
wildcard = args[0]
else:
wildcard = '*'
k = sorted(mestate.mlog.params.keys())
for p in k:
if fnmatch.fnmatch(str(p).upper(), wildcard.upper()):
print("%-16.16s %f" % (str(p), mestate.mlog.params[p])) |
main processing loop, display graphs and maps | def main_loop():
'''main processing loop, display graphs and maps'''
while True:
if mestate is None or mestate.exit:
return
while not mestate.input_queue.empty():
line = mestate.input_queue.get()
cmds = line.split(';')
for c in cmds:
... |
Accelerometer and Gyro biases from the navigation filter
usec : Timestamp (microseconds) (uint64_t)
accel_0 : b_f[0] (float)
accel_1 : b_f[1] (float)
accel_2 : b_f[2] (float)
... | def nav_filter_bias_encode(self, usec, accel_0, accel_1, accel_2, gyro_0, gyro_1, gyro_2):
'''
Accelerometer and Gyro biases from the navigation filter
usec : Timestamp (microseconds) (uint64_t)
accel_0 : b_f[0] (flo... |
Accelerometer and Gyro biases from the navigation filter
usec : Timestamp (microseconds) (uint64_t)
accel_0 : b_f[0] (float)
accel_1 : b_f[1] (float)
accel_2 : b_f[2] (float)
... | def nav_filter_bias_send(self, usec, accel_0, accel_1, accel_2, gyro_0, gyro_1, gyro_2, force_mavlink1=False):
'''
Accelerometer and Gyro biases from the navigation filter
usec : Timestamp (microseconds) (uint64_t)
accel_0 ... |
Complete set of calibration parameters for the radio
aileron : Aileron setpoints: left, center, right (uint16_t)
elevator : Elevator setpoints: nose down, center, nose up (uint16_t)
rudder : Rudder setpoints: nose lef... | def radio_calibration_encode(self, aileron, elevator, rudder, gyro, pitch, throttle):
'''
Complete set of calibration parameters for the radio
aileron : Aileron setpoints: left, center, right (uint16_t)
elevator : Elevat... |
Complete set of calibration parameters for the radio
aileron : Aileron setpoints: left, center, right (uint16_t)
elevator : Elevator setpoints: nose down, center, nose up (uint16_t)
rudder : Rudder setpoints: nose lef... | def radio_calibration_send(self, aileron, elevator, rudder, gyro, pitch, throttle, force_mavlink1=False):
'''
Complete set of calibration parameters for the radio
aileron : Aileron setpoints: left, center, right (uint16_t)
elevator ... |
System status specific to ualberta uav
mode : System mode, see UALBERTA_AUTOPILOT_MODE ENUM (uint8_t)
nav_mode : Navigation mode, see UALBERTA_NAV_MODE ENUM (uint8_t)
pilot : Pilot mode, see UALBERTA_PILOT_MODE (u... | def ualberta_sys_status_send(self, mode, nav_mode, pilot, force_mavlink1=False):
'''
System status specific to ualberta uav
mode : System mode, see UALBERTA_AUTOPILOT_MODE ENUM (uint8_t)
nav_mode : Navigation mode, se... |
The RAW values of the servo outputs (for RC input from the remote, use
the RC_CHANNELS messages). The standard PPM modulation
is as follows: 1000 microseconds: 0%, 2000
microseconds: 100%.
time_usec : Timestamp (microseconds since system b... | def servo_output_raw_encode(self, time_usec, port, servo1_raw, servo2_raw, servo3_raw, servo4_raw, servo5_raw, servo6_raw, servo7_raw, servo8_raw, servo9_raw, servo10_raw, servo11_raw, servo12_raw, servo13_raw, servo14_raw, servo15_raw, servo16_raw):
'''
The RAW values of the servo outpu... |
Setup a MAVLink2 signing key. If called with secret_key of all zero
and zero initial_timestamp will disable signing
target_system : system id of the target (uint8_t)
target_component : component ID of the target (uint8_t)
secret_key ... | def setup_signing_encode(self, target_system, target_component, secret_key, initial_timestamp):
'''
Setup a MAVLink2 signing key. If called with secret_key of all zero
and zero initial_timestamp will disable signing
target_system : system id o... |
Setup a MAVLink2 signing key. If called with secret_key of all zero
and zero initial_timestamp will disable signing
target_system : system id of the target (uint8_t)
target_component : component ID of the target (uint8_t)
secret_key ... | def setup_signing_send(self, target_system, target_component, secret_key, initial_timestamp, force_mavlink1=False):
'''
Setup a MAVLink2 signing key. If called with secret_key of all zero
and zero initial_timestamp will disable signing
target_system ... |
Report button state change
time_boot_ms : Timestamp (milliseconds since system boot) (uint32_t)
last_change_ms : Time of last change of button state (uint32_t)
state : Bitmap state of buttons (uint8_t) | def button_change_send(self, time_boot_ms, last_change_ms, state, force_mavlink1=False):
'''
Report button state change
time_boot_ms : Timestamp (milliseconds since system boot) (uint32_t)
last_change_ms : Time of last change of bu... |
Control vehicle tone generation (buzzer)
target_system : System ID (uint8_t)
target_component : Component ID (uint8_t)
tune : tune in board specific format (char) | def play_tune_send(self, target_system, target_component, tune, force_mavlink1=False):
'''
Control vehicle tone generation (buzzer)
target_system : System ID (uint8_t)
target_component : Component ID (uint8_t)
tune ... |
Convert latitude and longitude data to UTM as a list of coordinates.
Input
points: list of points given in decimal degrees (latitude, longitude) or
latitudes: list of latitudes and
longitudes: list of longitudes
false_easting (optional)
false_northing (optional)
Output
points: Lis... | def convert_from_latlon_to_utm(points=None,
latitudes=None,
longitudes=None,
false_easting=None,
false_northing=None):
"""Convert latitude and longitude data to UTM as a list of coordinates.
... |
convert a mavlink log file to a GPX file | def mav_to_gpx(infilename, outfilename):
'''convert a mavlink log file to a GPX file'''
mlog = mavutil.mavlink_connection(infilename)
outf = open(outfilename, mode='w')
def process_packet(timestamp, lat, lon, alt, hdg, v):
t = time.localtime(timestamp)
outf.write('''<trkpt lat="%s" lon... |
Get the quaternion
:returns: array containing the quaternion elements | def q(self):
"""
Get the quaternion
:returns: array containing the quaternion elements
"""
if self._q is None:
if self._euler is not None:
# get q from euler
self._q = self._euler_to_q(self.euler)
elif self._dcm is not None:... |
Set the quaternion
:param q: list or array of quaternion values [w, x, y, z] | def q(self, q):
"""
Set the quaternion
:param q: list or array of quaternion values [w, x, y, z]
"""
self._q = np.array(q)
# mark other representations as outdated, will get generated on next
# read
self._euler = None
self._dcm = None |
Get the euler angles.
The convention is Tait-Bryan (ZY'X'')
:returns: array containing the euler angles [roll, pitch, yaw] | def euler(self):
"""
Get the euler angles.
The convention is Tait-Bryan (ZY'X'')
:returns: array containing the euler angles [roll, pitch, yaw]
"""
if self._euler is None:
if self._q is not None:
# try to get euler angles from q via DCM
... |
Set the euler angles
:param euler: list or array of the euler angles [roll, pitch, yaw] | def euler(self, euler):
"""
Set the euler angles
:param euler: list or array of the euler angles [roll, pitch, yaw]
"""
assert(len(euler) == 3)
self._euler = np.array(euler)
# mark other representations as outdated, will get generated on next
# read
... |
Get the DCM
:returns: 3x3 array | def dcm(self):
"""
Get the DCM
:returns: 3x3 array
"""
if self._dcm is None:
if self._q is not None:
# try to get dcm from q
self._dcm = self._q_to_dcm(self.q)
elif self._euler is not None:
# try to get get ... |
Set the DCM
:param dcm: 3x3 array | def dcm(self, dcm):
"""
Set the DCM
:param dcm: 3x3 array
"""
assert(len(dcm) == 3)
for sub in dcm:
assert(len(sub) == 3)
self._dcm = np.array(dcm)
# mark other representations as outdated, will get generated on next
# read
s... |
Calculates the vector transformed by this quaternion
:param v: array with len 3 to be transformed
:returns: transformed vector | def transform(self, v):
"""
Calculates the vector transformed by this quaternion
:param v: array with len 3 to be transformed
:returns: transformed vector
"""
assert(len(v) == 3)
assert(np.allclose(self.norm, 1))
# perform transformation t = q * [0, v] * q... |
Equality test with tolerance
(same orientation, not necessarily same rotation)
:param other: a QuaternionBase
:returns: true if the quaternions are almost equal | def close(self, other):
"""
Equality test with tolerance
(same orientation, not necessarily same rotation)
:param other: a QuaternionBase
:returns: true if the quaternions are almost equal
"""
if isinstance(other, QuaternionBase):
return np.allclose(... |
Normalizes the list with len 4 so that it can be used as quaternion
:param q: array of len 4
:returns: normalized array | def normalize_array(q):
"""
Normalizes the list with len 4 so that it can be used as quaternion
:param q: array of len 4
:returns: normalized array
"""
assert(len(q) == 4)
q = np.array(q)
n = QuaternionBase.norm_array(q)
return q / n |
Calculate quaternion norm on array q
:param quaternion: array of len 4
:returns: norm (scalar) | def norm_array(q):
"""
Calculate quaternion norm on array q
:param quaternion: array of len 4
:returns: norm (scalar)
"""
assert(len(q) == 4)
return np.sqrt(np.dot(q, q)) |
Performs multiplication of the 2 quaterniona arrays p and q
:param p: array of len 4
:param q: array of len 4
:returns: array of len, result of p * q (with p, q quaternions) | def _mul_array(self, p, q):
"""
Performs multiplication of the 2 quaterniona arrays p and q
:param p: array of len 4
:param q: array of len 4
:returns: array of len, result of p * q (with p, q quaternions)
"""
assert(len(q) == len(p) == 4)
p0 = p[0]
... |
Create q array from euler angles
:param euler: array [roll, pitch, yaw] in rad
:returns: array q which represents a quaternion [w, x, y, z] | def _euler_to_q(self, euler):
"""
Create q array from euler angles
:param euler: array [roll, pitch, yaw] in rad
:returns: array q which represents a quaternion [w, x, y, z]
"""
assert(len(euler) == 3)
phi = euler[0]
theta = euler[1]
psi = euler[2]... |
Create DCM from q
:param q: array q which represents a quaternion [w, x, y, z]
:returns: 3x3 dcm array | def _q_to_dcm(self, q):
"""
Create DCM from q
:param q: array q which represents a quaternion [w, x, y, z]
:returns: 3x3 dcm array
"""
assert(len(q) == 4)
assert(np.allclose(QuaternionBase.norm_array(q), 1))
dcm = np.zeros([3, 3])
a = q[0]
... |
Create q from dcm
Reference:
- Shoemake, Quaternions,
http://www.cs.ucr.edu/~vbz/resources/quatut.pdf
:param dcm: 3x3 dcm array
returns: quaternion array | def _dcm_to_q(self, dcm):
"""
Create q from dcm
Reference:
- Shoemake, Quaternions,
http://www.cs.ucr.edu/~vbz/resources/quatut.pdf
:param dcm: 3x3 dcm array
returns: quaternion array
"""
assert(dcm.shape == (3, 3))
q = np.zeros(4)... |
Create DCM from euler angles
:param euler: array [roll, pitch, yaw] in rad
:returns: 3x3 dcm array | def _euler_to_dcm(self, euler):
"""
Create DCM from euler angles
:param euler: array [roll, pitch, yaw] in rad
:returns: 3x3 dcm array
"""
assert(len(euler) == 3)
phi = euler[0]
theta = euler[1]
psi = euler[2]
dcm = np.zeros([3, 3])
... |
Set the DCM
:param dcm: Matrix3 | def dcm(self, dcm):
"""
Set the DCM
:param dcm: Matrix3
"""
assert(isinstance(dcm, Matrix3))
self._dcm = dcm.copy()
# mark other representations as outdated, will get generated on next
# read
self._q = None
self._euler = None |
Create DCM from euler angles
:param dcm: 3x3 dcm array
:returns: array [roll, pitch, yaw] in rad | def _dcm_to_euler(self, dcm):
"""
Create DCM from euler angles
:param dcm: 3x3 dcm array
:returns: array [roll, pitch, yaw] in rad
"""
assert(dcm.shape == (3, 3))
theta = np.arcsin(min(1, max(-1, -dcm[2][0])))
if abs(theta - np.pi/2) < 1.0e-3:
... |
Calculates the vector transformed by this quaternion
:param v3: Vector3 to be transformed
:returns: transformed vector | def transform(self, v3):
"""
Calculates the vector transformed by this quaternion
:param v3: Vector3 to be transformed
:returns: transformed vector
"""
if isinstance(v3, Vector3):
t = super(Quaternion, self).transform([v3.x, v3.y, v3.z])
return Vec... |
Converts dcm array into Matrix3
:param dcm: 3x3 dcm array
:returns: Matrix3 | def _dcm_array_to_matrix3(self, dcm):
"""
Converts dcm array into Matrix3
:param dcm: 3x3 dcm array
:returns: Matrix3
"""
assert(dcm.shape == (3, 3))
a = Vector3(dcm[0][0], dcm[0][1], dcm[0][2])
b = Vector3(dcm[1][0], dcm[1][1], dcm[1][2])
c = Vect... |
Converts Matrix3 in an array
:param m: Matrix3
:returns: 3x3 array | def _matrix3_to_dcm_array(self, m):
"""
Converts Matrix3 in an array
:param m: Matrix3
:returns: 3x3 array
"""
assert(isinstance(m, Matrix3))
return np.array([[m.a.x, m.a.y, m.a.z],
[m.b.x, m.b.y, m.b.z],
[m.c.x, m... |
Create DCM (Matrix3) from q
:param q: array q which represents a quaternion [w, x, y, z]
:returns: Matrix3 | def _q_to_dcm(self, q):
"""
Create DCM (Matrix3) from q
:param q: array q which represents a quaternion [w, x, y, z]
:returns: Matrix3
"""
assert(len(q) == 4)
arr = super(Quaternion, self)._q_to_dcm(q)
return self._dcm_array_to_matrix3(arr) |
Create q from dcm (Matrix3)
:param dcm: Matrix3
:returns: array q which represents a quaternion [w, x, y, z] | def _dcm_to_q(self, dcm):
"""
Create q from dcm (Matrix3)
:param dcm: Matrix3
:returns: array q which represents a quaternion [w, x, y, z]
"""
assert(isinstance(dcm, Matrix3))
arr = self._matrix3_to_dcm_array(dcm)
return super(Quaternion, self)._dcm_to_q(a... |
Create DCM (Matrix3) from euler angles
:param euler: array [roll, pitch, yaw] in rad
:returns: Matrix3 | def _euler_to_dcm(self, euler):
"""
Create DCM (Matrix3) from euler angles
:param euler: array [roll, pitch, yaw] in rad
:returns: Matrix3
"""
assert(len(euler) == 3)
m = Matrix3()
m.from_euler(*euler)
return m |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.