id
int32 0
252k
| repo
stringlengths 7
55
| path
stringlengths 4
127
| func_name
stringlengths 1
88
| original_string
stringlengths 75
19.8k
| language
stringclasses 1
value | code
stringlengths 75
19.8k
| code_tokens
list | docstring
stringlengths 3
17.3k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 87
242
|
|---|---|---|---|---|---|---|---|---|---|---|---|
235,300
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py
|
WPModule.update_waypoints
|
def update_waypoints(self, filename, wpnum):
'''update waypoints from a file'''
self.wploader.target_system = self.target_system
self.wploader.target_component = self.target_component
try:
self.wploader.load(filename)
except Exception as msg:
print("Unable to load %s - %s" % (filename, msg))
return
if self.wploader.count() == 0:
print("No waypoints found in %s" % filename)
return
if wpnum == -1:
print("Loaded %u updated waypoints from %s" % (self.wploader.count(), filename))
elif wpnum >= self.wploader.count():
print("Invalid waypoint number %u" % wpnum)
return
else:
print("Loaded updated waypoint %u from %s" % (wpnum, filename))
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
if wpnum == -1:
start = 0
end = self.wploader.count()-1
else:
start = wpnum
end = wpnum
self.master.mav.mission_write_partial_list_send(self.target_system,
self.target_component,
start, end)
|
python
|
def update_waypoints(self, filename, wpnum):
'''update waypoints from a file'''
self.wploader.target_system = self.target_system
self.wploader.target_component = self.target_component
try:
self.wploader.load(filename)
except Exception as msg:
print("Unable to load %s - %s" % (filename, msg))
return
if self.wploader.count() == 0:
print("No waypoints found in %s" % filename)
return
if wpnum == -1:
print("Loaded %u updated waypoints from %s" % (self.wploader.count(), filename))
elif wpnum >= self.wploader.count():
print("Invalid waypoint number %u" % wpnum)
return
else:
print("Loaded updated waypoint %u from %s" % (wpnum, filename))
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
if wpnum == -1:
start = 0
end = self.wploader.count()-1
else:
start = wpnum
end = wpnum
self.master.mav.mission_write_partial_list_send(self.target_system,
self.target_component,
start, end)
|
[
"def",
"update_waypoints",
"(",
"self",
",",
"filename",
",",
"wpnum",
")",
":",
"self",
".",
"wploader",
".",
"target_system",
"=",
"self",
".",
"target_system",
"self",
".",
"wploader",
".",
"target_component",
"=",
"self",
".",
"target_component",
"try",
":",
"self",
".",
"wploader",
".",
"load",
"(",
"filename",
")",
"except",
"Exception",
"as",
"msg",
":",
"print",
"(",
"\"Unable to load %s - %s\"",
"%",
"(",
"filename",
",",
"msg",
")",
")",
"return",
"if",
"self",
".",
"wploader",
".",
"count",
"(",
")",
"==",
"0",
":",
"print",
"(",
"\"No waypoints found in %s\"",
"%",
"filename",
")",
"return",
"if",
"wpnum",
"==",
"-",
"1",
":",
"print",
"(",
"\"Loaded %u updated waypoints from %s\"",
"%",
"(",
"self",
".",
"wploader",
".",
"count",
"(",
")",
",",
"filename",
")",
")",
"elif",
"wpnum",
">=",
"self",
".",
"wploader",
".",
"count",
"(",
")",
":",
"print",
"(",
"\"Invalid waypoint number %u\"",
"%",
"wpnum",
")",
"return",
"else",
":",
"print",
"(",
"\"Loaded updated waypoint %u from %s\"",
"%",
"(",
"wpnum",
",",
"filename",
")",
")",
"self",
".",
"loading_waypoints",
"=",
"True",
"self",
".",
"loading_waypoint_lasttime",
"=",
"time",
".",
"time",
"(",
")",
"if",
"wpnum",
"==",
"-",
"1",
":",
"start",
"=",
"0",
"end",
"=",
"self",
".",
"wploader",
".",
"count",
"(",
")",
"-",
"1",
"else",
":",
"start",
"=",
"wpnum",
"end",
"=",
"wpnum",
"self",
".",
"master",
".",
"mav",
".",
"mission_write_partial_list_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"start",
",",
"end",
")"
] |
update waypoints from a file
|
[
"update",
"waypoints",
"from",
"a",
"file"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L161-L191
|
235,301
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py
|
WPModule.get_default_frame
|
def get_default_frame(self):
'''default frame for waypoints'''
if self.settings.terrainalt == 'Auto':
if self.get_mav_param('TERRAIN_FOLLOW',0) == 1:
return mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT
return mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT
if self.settings.terrainalt == 'True':
return mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT
return mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT
|
python
|
def get_default_frame(self):
'''default frame for waypoints'''
if self.settings.terrainalt == 'Auto':
if self.get_mav_param('TERRAIN_FOLLOW',0) == 1:
return mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT
return mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT
if self.settings.terrainalt == 'True':
return mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT
return mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT
|
[
"def",
"get_default_frame",
"(",
"self",
")",
":",
"if",
"self",
".",
"settings",
".",
"terrainalt",
"==",
"'Auto'",
":",
"if",
"self",
".",
"get_mav_param",
"(",
"'TERRAIN_FOLLOW'",
",",
"0",
")",
"==",
"1",
":",
"return",
"mavutil",
".",
"mavlink",
".",
"MAV_FRAME_GLOBAL_TERRAIN_ALT",
"return",
"mavutil",
".",
"mavlink",
".",
"MAV_FRAME_GLOBAL_RELATIVE_ALT",
"if",
"self",
".",
"settings",
".",
"terrainalt",
"==",
"'True'",
":",
"return",
"mavutil",
".",
"mavlink",
".",
"MAV_FRAME_GLOBAL_TERRAIN_ALT",
"return",
"mavutil",
".",
"mavlink",
".",
"MAV_FRAME_GLOBAL_RELATIVE_ALT"
] |
default frame for waypoints
|
[
"default",
"frame",
"for",
"waypoints"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L202-L210
|
235,302
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py
|
WPModule.wp_draw_callback
|
def wp_draw_callback(self, points):
'''callback from drawing waypoints'''
if len(points) < 3:
return
from MAVProxy.modules.lib import mp_util
home = self.wploader.wp(0)
self.wploader.clear()
self.wploader.target_system = self.target_system
self.wploader.target_component = self.target_component
self.wploader.add(home)
if self.get_default_frame() == mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT:
use_terrain = True
else:
use_terrain = False
for p in points:
self.wploader.add_latlonalt(p[0], p[1], self.settings.wpalt, terrain_alt=use_terrain)
self.send_all_waypoints()
|
python
|
def wp_draw_callback(self, points):
'''callback from drawing waypoints'''
if len(points) < 3:
return
from MAVProxy.modules.lib import mp_util
home = self.wploader.wp(0)
self.wploader.clear()
self.wploader.target_system = self.target_system
self.wploader.target_component = self.target_component
self.wploader.add(home)
if self.get_default_frame() == mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT:
use_terrain = True
else:
use_terrain = False
for p in points:
self.wploader.add_latlonalt(p[0], p[1], self.settings.wpalt, terrain_alt=use_terrain)
self.send_all_waypoints()
|
[
"def",
"wp_draw_callback",
"(",
"self",
",",
"points",
")",
":",
"if",
"len",
"(",
"points",
")",
"<",
"3",
":",
"return",
"from",
"MAVProxy",
".",
"modules",
".",
"lib",
"import",
"mp_util",
"home",
"=",
"self",
".",
"wploader",
".",
"wp",
"(",
"0",
")",
"self",
".",
"wploader",
".",
"clear",
"(",
")",
"self",
".",
"wploader",
".",
"target_system",
"=",
"self",
".",
"target_system",
"self",
".",
"wploader",
".",
"target_component",
"=",
"self",
".",
"target_component",
"self",
".",
"wploader",
".",
"add",
"(",
"home",
")",
"if",
"self",
".",
"get_default_frame",
"(",
")",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_FRAME_GLOBAL_TERRAIN_ALT",
":",
"use_terrain",
"=",
"True",
"else",
":",
"use_terrain",
"=",
"False",
"for",
"p",
"in",
"points",
":",
"self",
".",
"wploader",
".",
"add_latlonalt",
"(",
"p",
"[",
"0",
"]",
",",
"p",
"[",
"1",
"]",
",",
"self",
".",
"settings",
".",
"wpalt",
",",
"terrain_alt",
"=",
"use_terrain",
")",
"self",
".",
"send_all_waypoints",
"(",
")"
] |
callback from drawing waypoints
|
[
"callback",
"from",
"drawing",
"waypoints"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L212-L228
|
235,303
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py
|
WPModule.wp_loop
|
def wp_loop(self):
'''close the loop on a mission'''
loader = self.wploader
if loader.count() < 2:
print("Not enough waypoints (%u)" % loader.count())
return
wp = loader.wp(loader.count()-2)
if wp.command == mavutil.mavlink.MAV_CMD_DO_JUMP:
print("Mission is already looped")
return
wp = mavutil.mavlink.MAVLink_mission_item_message(0, 0, 0, 0, mavutil.mavlink.MAV_CMD_DO_JUMP,
0, 1, 1, -1, 0, 0, 0, 0, 0)
loader.add(wp)
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
self.master.waypoint_count_send(self.wploader.count())
print("Closed loop on mission")
|
python
|
def wp_loop(self):
'''close the loop on a mission'''
loader = self.wploader
if loader.count() < 2:
print("Not enough waypoints (%u)" % loader.count())
return
wp = loader.wp(loader.count()-2)
if wp.command == mavutil.mavlink.MAV_CMD_DO_JUMP:
print("Mission is already looped")
return
wp = mavutil.mavlink.MAVLink_mission_item_message(0, 0, 0, 0, mavutil.mavlink.MAV_CMD_DO_JUMP,
0, 1, 1, -1, 0, 0, 0, 0, 0)
loader.add(wp)
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
self.master.waypoint_count_send(self.wploader.count())
print("Closed loop on mission")
|
[
"def",
"wp_loop",
"(",
"self",
")",
":",
"loader",
"=",
"self",
".",
"wploader",
"if",
"loader",
".",
"count",
"(",
")",
"<",
"2",
":",
"print",
"(",
"\"Not enough waypoints (%u)\"",
"%",
"loader",
".",
"count",
"(",
")",
")",
"return",
"wp",
"=",
"loader",
".",
"wp",
"(",
"loader",
".",
"count",
"(",
")",
"-",
"2",
")",
"if",
"wp",
".",
"command",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_DO_JUMP",
":",
"print",
"(",
"\"Mission is already looped\"",
")",
"return",
"wp",
"=",
"mavutil",
".",
"mavlink",
".",
"MAVLink_mission_item_message",
"(",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_DO_JUMP",
",",
"0",
",",
"1",
",",
"1",
",",
"-",
"1",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
"loader",
".",
"add",
"(",
"wp",
")",
"self",
".",
"loading_waypoints",
"=",
"True",
"self",
".",
"loading_waypoint_lasttime",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"master",
".",
"waypoint_count_send",
"(",
"self",
".",
"wploader",
".",
"count",
"(",
")",
")",
"print",
"(",
"\"Closed loop on mission\"",
")"
] |
close the loop on a mission
|
[
"close",
"the",
"loop",
"on",
"a",
"mission"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L230-L246
|
235,304
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py
|
WPModule.set_home_location
|
def set_home_location(self):
'''set home location from last map click'''
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
lat = float(latlon[0])
lon = float(latlon[1])
if self.wploader.count() == 0:
self.wploader.add_latlonalt(lat, lon, 0)
w = self.wploader.wp(0)
w.x = lat
w.y = lon
self.wploader.set(w, 0)
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
self.master.mav.mission_write_partial_list_send(self.target_system,
self.target_component,
0, 0)
|
python
|
def set_home_location(self):
'''set home location from last map click'''
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
lat = float(latlon[0])
lon = float(latlon[1])
if self.wploader.count() == 0:
self.wploader.add_latlonalt(lat, lon, 0)
w = self.wploader.wp(0)
w.x = lat
w.y = lon
self.wploader.set(w, 0)
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
self.master.mav.mission_write_partial_list_send(self.target_system,
self.target_component,
0, 0)
|
[
"def",
"set_home_location",
"(",
"self",
")",
":",
"try",
":",
"latlon",
"=",
"self",
".",
"module",
"(",
"'map'",
")",
".",
"click_position",
"except",
"Exception",
":",
"print",
"(",
"\"No map available\"",
")",
"return",
"lat",
"=",
"float",
"(",
"latlon",
"[",
"0",
"]",
")",
"lon",
"=",
"float",
"(",
"latlon",
"[",
"1",
"]",
")",
"if",
"self",
".",
"wploader",
".",
"count",
"(",
")",
"==",
"0",
":",
"self",
".",
"wploader",
".",
"add_latlonalt",
"(",
"lat",
",",
"lon",
",",
"0",
")",
"w",
"=",
"self",
".",
"wploader",
".",
"wp",
"(",
"0",
")",
"w",
".",
"x",
"=",
"lat",
"w",
".",
"y",
"=",
"lon",
"self",
".",
"wploader",
".",
"set",
"(",
"w",
",",
"0",
")",
"self",
".",
"loading_waypoints",
"=",
"True",
"self",
".",
"loading_waypoint_lasttime",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"master",
".",
"mav",
".",
"mission_write_partial_list_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"0",
",",
"0",
")"
] |
set home location from last map click
|
[
"set",
"home",
"location",
"from",
"last",
"map",
"click"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L248-L267
|
235,305
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py
|
WPModule.cmd_wp_move
|
def cmd_wp_move(self, args):
'''handle wp move'''
if len(args) != 1:
print("usage: wp move WPNUM")
return
idx = int(args[0])
if idx < 1 or idx > self.wploader.count():
print("Invalid wp number %u" % idx)
return
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
if latlon is None:
print("No map click position available")
return
wp = self.wploader.wp(idx)
# setup for undo
self.undo_wp = copy.copy(wp)
self.undo_wp_idx = idx
self.undo_type = "move"
(lat, lon) = latlon
if getattr(self.console, 'ElevationMap', None) is not None and wp.frame != mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT:
alt1 = self.console.ElevationMap.GetElevation(lat, lon)
alt2 = self.console.ElevationMap.GetElevation(wp.x, wp.y)
if alt1 is not None and alt2 is not None:
wp.z += alt1 - alt2
wp.x = lat
wp.y = lon
wp.target_system = self.target_system
wp.target_component = self.target_component
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
self.master.mav.mission_write_partial_list_send(self.target_system,
self.target_component,
idx, idx)
self.wploader.set(wp, idx)
print("Moved WP %u to %f, %f at %.1fm" % (idx, lat, lon, wp.z))
|
python
|
def cmd_wp_move(self, args):
'''handle wp move'''
if len(args) != 1:
print("usage: wp move WPNUM")
return
idx = int(args[0])
if idx < 1 or idx > self.wploader.count():
print("Invalid wp number %u" % idx)
return
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
if latlon is None:
print("No map click position available")
return
wp = self.wploader.wp(idx)
# setup for undo
self.undo_wp = copy.copy(wp)
self.undo_wp_idx = idx
self.undo_type = "move"
(lat, lon) = latlon
if getattr(self.console, 'ElevationMap', None) is not None and wp.frame != mavutil.mavlink.MAV_FRAME_GLOBAL_TERRAIN_ALT:
alt1 = self.console.ElevationMap.GetElevation(lat, lon)
alt2 = self.console.ElevationMap.GetElevation(wp.x, wp.y)
if alt1 is not None and alt2 is not None:
wp.z += alt1 - alt2
wp.x = lat
wp.y = lon
wp.target_system = self.target_system
wp.target_component = self.target_component
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
self.master.mav.mission_write_partial_list_send(self.target_system,
self.target_component,
idx, idx)
self.wploader.set(wp, idx)
print("Moved WP %u to %f, %f at %.1fm" % (idx, lat, lon, wp.z))
|
[
"def",
"cmd_wp_move",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"!=",
"1",
":",
"print",
"(",
"\"usage: wp move WPNUM\"",
")",
"return",
"idx",
"=",
"int",
"(",
"args",
"[",
"0",
"]",
")",
"if",
"idx",
"<",
"1",
"or",
"idx",
">",
"self",
".",
"wploader",
".",
"count",
"(",
")",
":",
"print",
"(",
"\"Invalid wp number %u\"",
"%",
"idx",
")",
"return",
"try",
":",
"latlon",
"=",
"self",
".",
"module",
"(",
"'map'",
")",
".",
"click_position",
"except",
"Exception",
":",
"print",
"(",
"\"No map available\"",
")",
"return",
"if",
"latlon",
"is",
"None",
":",
"print",
"(",
"\"No map click position available\"",
")",
"return",
"wp",
"=",
"self",
".",
"wploader",
".",
"wp",
"(",
"idx",
")",
"# setup for undo",
"self",
".",
"undo_wp",
"=",
"copy",
".",
"copy",
"(",
"wp",
")",
"self",
".",
"undo_wp_idx",
"=",
"idx",
"self",
".",
"undo_type",
"=",
"\"move\"",
"(",
"lat",
",",
"lon",
")",
"=",
"latlon",
"if",
"getattr",
"(",
"self",
".",
"console",
",",
"'ElevationMap'",
",",
"None",
")",
"is",
"not",
"None",
"and",
"wp",
".",
"frame",
"!=",
"mavutil",
".",
"mavlink",
".",
"MAV_FRAME_GLOBAL_TERRAIN_ALT",
":",
"alt1",
"=",
"self",
".",
"console",
".",
"ElevationMap",
".",
"GetElevation",
"(",
"lat",
",",
"lon",
")",
"alt2",
"=",
"self",
".",
"console",
".",
"ElevationMap",
".",
"GetElevation",
"(",
"wp",
".",
"x",
",",
"wp",
".",
"y",
")",
"if",
"alt1",
"is",
"not",
"None",
"and",
"alt2",
"is",
"not",
"None",
":",
"wp",
".",
"z",
"+=",
"alt1",
"-",
"alt2",
"wp",
".",
"x",
"=",
"lat",
"wp",
".",
"y",
"=",
"lon",
"wp",
".",
"target_system",
"=",
"self",
".",
"target_system",
"wp",
".",
"target_component",
"=",
"self",
".",
"target_component",
"self",
".",
"loading_waypoints",
"=",
"True",
"self",
".",
"loading_waypoint_lasttime",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"master",
".",
"mav",
".",
"mission_write_partial_list_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"idx",
",",
"idx",
")",
"self",
".",
"wploader",
".",
"set",
"(",
"wp",
",",
"idx",
")",
"print",
"(",
"\"Moved WP %u to %f, %f at %.1fm\"",
"%",
"(",
"idx",
",",
"lat",
",",
"lon",
",",
"wp",
".",
"z",
")",
")"
] |
handle wp move
|
[
"handle",
"wp",
"move"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L270-L311
|
235,306
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py
|
WPModule.cmd_wp_param
|
def cmd_wp_param(self, args):
'''handle wp parameter change'''
if len(args) < 2:
print("usage: wp param WPNUM PNUM <VALUE>")
return
idx = int(args[0])
if idx < 1 or idx > self.wploader.count():
print("Invalid wp number %u" % idx)
return
wp = self.wploader.wp(idx)
param = [wp.param1, wp.param2, wp.param3, wp.param4]
pnum = int(args[1])
if pnum < 1 or pnum > 4:
print("Invalid param number %u" % pnum)
return
if len(args) == 2:
print("Param %u: %f" % (pnum, param[pnum-1]))
return
param[pnum-1] = float(args[2])
wp.param1 = param[0]
wp.param2 = param[1]
wp.param3 = param[2]
wp.param4 = param[3]
wp.target_system = self.target_system
wp.target_component = self.target_component
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
self.master.mav.mission_write_partial_list_send(self.target_system,
self.target_component,
idx, idx)
self.wploader.set(wp, idx)
print("Set param %u for %u to %f" % (pnum, idx, param[pnum-1]))
|
python
|
def cmd_wp_param(self, args):
'''handle wp parameter change'''
if len(args) < 2:
print("usage: wp param WPNUM PNUM <VALUE>")
return
idx = int(args[0])
if idx < 1 or idx > self.wploader.count():
print("Invalid wp number %u" % idx)
return
wp = self.wploader.wp(idx)
param = [wp.param1, wp.param2, wp.param3, wp.param4]
pnum = int(args[1])
if pnum < 1 or pnum > 4:
print("Invalid param number %u" % pnum)
return
if len(args) == 2:
print("Param %u: %f" % (pnum, param[pnum-1]))
return
param[pnum-1] = float(args[2])
wp.param1 = param[0]
wp.param2 = param[1]
wp.param3 = param[2]
wp.param4 = param[3]
wp.target_system = self.target_system
wp.target_component = self.target_component
self.loading_waypoints = True
self.loading_waypoint_lasttime = time.time()
self.master.mav.mission_write_partial_list_send(self.target_system,
self.target_component,
idx, idx)
self.wploader.set(wp, idx)
print("Set param %u for %u to %f" % (pnum, idx, param[pnum-1]))
|
[
"def",
"cmd_wp_param",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"2",
":",
"print",
"(",
"\"usage: wp param WPNUM PNUM <VALUE>\"",
")",
"return",
"idx",
"=",
"int",
"(",
"args",
"[",
"0",
"]",
")",
"if",
"idx",
"<",
"1",
"or",
"idx",
">",
"self",
".",
"wploader",
".",
"count",
"(",
")",
":",
"print",
"(",
"\"Invalid wp number %u\"",
"%",
"idx",
")",
"return",
"wp",
"=",
"self",
".",
"wploader",
".",
"wp",
"(",
"idx",
")",
"param",
"=",
"[",
"wp",
".",
"param1",
",",
"wp",
".",
"param2",
",",
"wp",
".",
"param3",
",",
"wp",
".",
"param4",
"]",
"pnum",
"=",
"int",
"(",
"args",
"[",
"1",
"]",
")",
"if",
"pnum",
"<",
"1",
"or",
"pnum",
">",
"4",
":",
"print",
"(",
"\"Invalid param number %u\"",
"%",
"pnum",
")",
"return",
"if",
"len",
"(",
"args",
")",
"==",
"2",
":",
"print",
"(",
"\"Param %u: %f\"",
"%",
"(",
"pnum",
",",
"param",
"[",
"pnum",
"-",
"1",
"]",
")",
")",
"return",
"param",
"[",
"pnum",
"-",
"1",
"]",
"=",
"float",
"(",
"args",
"[",
"2",
"]",
")",
"wp",
".",
"param1",
"=",
"param",
"[",
"0",
"]",
"wp",
".",
"param2",
"=",
"param",
"[",
"1",
"]",
"wp",
".",
"param3",
"=",
"param",
"[",
"2",
"]",
"wp",
".",
"param4",
"=",
"param",
"[",
"3",
"]",
"wp",
".",
"target_system",
"=",
"self",
".",
"target_system",
"wp",
".",
"target_component",
"=",
"self",
".",
"target_component",
"self",
".",
"loading_waypoints",
"=",
"True",
"self",
".",
"loading_waypoint_lasttime",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"master",
".",
"mav",
".",
"mission_write_partial_list_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"idx",
",",
"idx",
")",
"self",
".",
"wploader",
".",
"set",
"(",
"wp",
",",
"idx",
")",
"print",
"(",
"\"Set param %u for %u to %f\"",
"%",
"(",
"pnum",
",",
"idx",
",",
"param",
"[",
"pnum",
"-",
"1",
"]",
")",
")"
] |
handle wp parameter change
|
[
"handle",
"wp",
"parameter",
"change"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_wp.py#L432-L466
|
235,307
|
JdeRobot/base
|
src/libs/comm_py/comm/ros/listenerCamera.py
|
depthToRGB8
|
def depthToRGB8(float_img_buff, encoding):
'''
Translates from Distance Image format to RGB. Inf values are represented by NaN, when converting to RGB, NaN passed to 0
@param float_img_buff: ROS Image to translate
@type img: ros image
@return a Opencv RGB image
'''
gray_image = None
if (encoding[-3:-2]== "U"):
gray_image = float_img_buff
else:
float_img = np.zeros((float_img_buff.shape[0], float_img_buff.shape[1], 1), dtype = "float32")
float_img.data = float_img_buff.data
gray_image=cv2.convertScaleAbs(float_img, alpha=255/MAXRANGE)
cv_image = cv2.cvtColor(gray_image, cv2.COLOR_GRAY2RGB)
return cv_image
|
python
|
def depthToRGB8(float_img_buff, encoding):
'''
Translates from Distance Image format to RGB. Inf values are represented by NaN, when converting to RGB, NaN passed to 0
@param float_img_buff: ROS Image to translate
@type img: ros image
@return a Opencv RGB image
'''
gray_image = None
if (encoding[-3:-2]== "U"):
gray_image = float_img_buff
else:
float_img = np.zeros((float_img_buff.shape[0], float_img_buff.shape[1], 1), dtype = "float32")
float_img.data = float_img_buff.data
gray_image=cv2.convertScaleAbs(float_img, alpha=255/MAXRANGE)
cv_image = cv2.cvtColor(gray_image, cv2.COLOR_GRAY2RGB)
return cv_image
|
[
"def",
"depthToRGB8",
"(",
"float_img_buff",
",",
"encoding",
")",
":",
"gray_image",
"=",
"None",
"if",
"(",
"encoding",
"[",
"-",
"3",
":",
"-",
"2",
"]",
"==",
"\"U\"",
")",
":",
"gray_image",
"=",
"float_img_buff",
"else",
":",
"float_img",
"=",
"np",
".",
"zeros",
"(",
"(",
"float_img_buff",
".",
"shape",
"[",
"0",
"]",
",",
"float_img_buff",
".",
"shape",
"[",
"1",
"]",
",",
"1",
")",
",",
"dtype",
"=",
"\"float32\"",
")",
"float_img",
".",
"data",
"=",
"float_img_buff",
".",
"data",
"gray_image",
"=",
"cv2",
".",
"convertScaleAbs",
"(",
"float_img",
",",
"alpha",
"=",
"255",
"/",
"MAXRANGE",
")",
"cv_image",
"=",
"cv2",
".",
"cvtColor",
"(",
"gray_image",
",",
"cv2",
".",
"COLOR_GRAY2RGB",
")",
"return",
"cv_image"
] |
Translates from Distance Image format to RGB. Inf values are represented by NaN, when converting to RGB, NaN passed to 0
@param float_img_buff: ROS Image to translate
@type img: ros image
@return a Opencv RGB image
|
[
"Translates",
"from",
"Distance",
"Image",
"format",
"to",
"RGB",
".",
"Inf",
"values",
"are",
"represented",
"by",
"NaN",
"when",
"converting",
"to",
"RGB",
"NaN",
"passed",
"to",
"0"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/libs/comm_py/comm/ros/listenerCamera.py#L15-L37
|
235,308
|
JdeRobot/base
|
src/libs/comm_py/comm/ros/listenerCamera.py
|
ListenerCamera.__callback
|
def __callback (self, img):
'''
Callback function to receive and save Images.
@param img: ROS Image received
@type img: sensor_msgs.msg.Image
'''
image = imageMsg2Image(img, self.bridge)
self.lock.acquire()
self.data = image
self.lock.release()
|
python
|
def __callback (self, img):
'''
Callback function to receive and save Images.
@param img: ROS Image received
@type img: sensor_msgs.msg.Image
'''
image = imageMsg2Image(img, self.bridge)
self.lock.acquire()
self.data = image
self.lock.release()
|
[
"def",
"__callback",
"(",
"self",
",",
"img",
")",
":",
"image",
"=",
"imageMsg2Image",
"(",
"img",
",",
"self",
".",
"bridge",
")",
"self",
".",
"lock",
".",
"acquire",
"(",
")",
"self",
".",
"data",
"=",
"image",
"self",
".",
"lock",
".",
"release",
"(",
")"
] |
Callback function to receive and save Images.
@param img: ROS Image received
@type img: sensor_msgs.msg.Image
|
[
"Callback",
"function",
"to",
"receive",
"and",
"save",
"Images",
"."
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/libs/comm_py/comm/ros/listenerCamera.py#L89-L102
|
235,309
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit_delta.py
|
noise
|
def noise():
'''a noise vector'''
from random import gauss
v = Vector3(gauss(0, 1), gauss(0, 1), gauss(0, 1))
v.normalize()
return v * args.noise
|
python
|
def noise():
'''a noise vector'''
from random import gauss
v = Vector3(gauss(0, 1), gauss(0, 1), gauss(0, 1))
v.normalize()
return v * args.noise
|
[
"def",
"noise",
"(",
")",
":",
"from",
"random",
"import",
"gauss",
"v",
"=",
"Vector3",
"(",
"gauss",
"(",
"0",
",",
"1",
")",
",",
"gauss",
"(",
"0",
",",
"1",
")",
",",
"gauss",
"(",
"0",
",",
"1",
")",
")",
"v",
".",
"normalize",
"(",
")",
"return",
"v",
"*",
"args",
".",
"noise"
] |
a noise vector
|
[
"a",
"noise",
"vector"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit_delta.py#L30-L35
|
235,310
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit_delta.py
|
find_offsets
|
def find_offsets(data, ofs):
'''find mag offsets by applying Bills "offsets revisited" algorithm
on the data
This is an implementation of the algorithm from:
http://gentlenav.googlecode.com/files/MagnetometerOffsetNullingRevisited.pdf
'''
# a limit on the maximum change in each step
max_change = args.max_change
# the gain factor for the algorithm
gain = args.gain
data2 = []
for d in data:
d = d.copy() + noise()
d.x = float(int(d.x + 0.5))
d.y = float(int(d.y + 0.5))
d.z = float(int(d.z + 0.5))
data2.append(d)
data = data2
history_idx = 0
mag_history = data[0:args.history]
for i in range(args.history, len(data)):
B1 = mag_history[history_idx] + ofs
B2 = data[i] + ofs
diff = B2 - B1
diff_length = diff.length()
if diff_length <= args.min_diff:
# the mag vector hasn't changed enough - we don't get any
# information from this
history_idx = (history_idx+1) % args.history
continue
mag_history[history_idx] = data[i]
history_idx = (history_idx+1) % args.history
# equation 6 of Bills paper
delta = diff * (gain * (B2.length() - B1.length()) / diff_length)
# limit the change from any one reading. This is to prevent
# single crazy readings from throwing off the offsets for a long
# time
delta_length = delta.length()
if max_change != 0 and delta_length > max_change:
delta *= max_change / delta_length
# set the new offsets
ofs = ofs - delta
if args.verbose:
print(ofs)
return ofs
|
python
|
def find_offsets(data, ofs):
'''find mag offsets by applying Bills "offsets revisited" algorithm
on the data
This is an implementation of the algorithm from:
http://gentlenav.googlecode.com/files/MagnetometerOffsetNullingRevisited.pdf
'''
# a limit on the maximum change in each step
max_change = args.max_change
# the gain factor for the algorithm
gain = args.gain
data2 = []
for d in data:
d = d.copy() + noise()
d.x = float(int(d.x + 0.5))
d.y = float(int(d.y + 0.5))
d.z = float(int(d.z + 0.5))
data2.append(d)
data = data2
history_idx = 0
mag_history = data[0:args.history]
for i in range(args.history, len(data)):
B1 = mag_history[history_idx] + ofs
B2 = data[i] + ofs
diff = B2 - B1
diff_length = diff.length()
if diff_length <= args.min_diff:
# the mag vector hasn't changed enough - we don't get any
# information from this
history_idx = (history_idx+1) % args.history
continue
mag_history[history_idx] = data[i]
history_idx = (history_idx+1) % args.history
# equation 6 of Bills paper
delta = diff * (gain * (B2.length() - B1.length()) / diff_length)
# limit the change from any one reading. This is to prevent
# single crazy readings from throwing off the offsets for a long
# time
delta_length = delta.length()
if max_change != 0 and delta_length > max_change:
delta *= max_change / delta_length
# set the new offsets
ofs = ofs - delta
if args.verbose:
print(ofs)
return ofs
|
[
"def",
"find_offsets",
"(",
"data",
",",
"ofs",
")",
":",
"# a limit on the maximum change in each step",
"max_change",
"=",
"args",
".",
"max_change",
"# the gain factor for the algorithm",
"gain",
"=",
"args",
".",
"gain",
"data2",
"=",
"[",
"]",
"for",
"d",
"in",
"data",
":",
"d",
"=",
"d",
".",
"copy",
"(",
")",
"+",
"noise",
"(",
")",
"d",
".",
"x",
"=",
"float",
"(",
"int",
"(",
"d",
".",
"x",
"+",
"0.5",
")",
")",
"d",
".",
"y",
"=",
"float",
"(",
"int",
"(",
"d",
".",
"y",
"+",
"0.5",
")",
")",
"d",
".",
"z",
"=",
"float",
"(",
"int",
"(",
"d",
".",
"z",
"+",
"0.5",
")",
")",
"data2",
".",
"append",
"(",
"d",
")",
"data",
"=",
"data2",
"history_idx",
"=",
"0",
"mag_history",
"=",
"data",
"[",
"0",
":",
"args",
".",
"history",
"]",
"for",
"i",
"in",
"range",
"(",
"args",
".",
"history",
",",
"len",
"(",
"data",
")",
")",
":",
"B1",
"=",
"mag_history",
"[",
"history_idx",
"]",
"+",
"ofs",
"B2",
"=",
"data",
"[",
"i",
"]",
"+",
"ofs",
"diff",
"=",
"B2",
"-",
"B1",
"diff_length",
"=",
"diff",
".",
"length",
"(",
")",
"if",
"diff_length",
"<=",
"args",
".",
"min_diff",
":",
"# the mag vector hasn't changed enough - we don't get any",
"# information from this",
"history_idx",
"=",
"(",
"history_idx",
"+",
"1",
")",
"%",
"args",
".",
"history",
"continue",
"mag_history",
"[",
"history_idx",
"]",
"=",
"data",
"[",
"i",
"]",
"history_idx",
"=",
"(",
"history_idx",
"+",
"1",
")",
"%",
"args",
".",
"history",
"# equation 6 of Bills paper",
"delta",
"=",
"diff",
"*",
"(",
"gain",
"*",
"(",
"B2",
".",
"length",
"(",
")",
"-",
"B1",
".",
"length",
"(",
")",
")",
"/",
"diff_length",
")",
"# limit the change from any one reading. This is to prevent",
"# single crazy readings from throwing off the offsets for a long",
"# time",
"delta_length",
"=",
"delta",
".",
"length",
"(",
")",
"if",
"max_change",
"!=",
"0",
"and",
"delta_length",
">",
"max_change",
":",
"delta",
"*=",
"max_change",
"/",
"delta_length",
"# set the new offsets",
"ofs",
"=",
"ofs",
"-",
"delta",
"if",
"args",
".",
"verbose",
":",
"print",
"(",
"ofs",
")",
"return",
"ofs"
] |
find mag offsets by applying Bills "offsets revisited" algorithm
on the data
This is an implementation of the algorithm from:
http://gentlenav.googlecode.com/files/MagnetometerOffsetNullingRevisited.pdf
|
[
"find",
"mag",
"offsets",
"by",
"applying",
"Bills",
"offsets",
"revisited",
"algorithm",
"on",
"the",
"data"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit_delta.py#L37-L93
|
235,311
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py
|
MPImage.set_menu
|
def set_menu(self, menu):
'''set a MPTopMenu on the frame'''
self.menu = menu
self.in_queue.put(MPImageMenu(menu))
|
python
|
def set_menu(self, menu):
'''set a MPTopMenu on the frame'''
self.menu = menu
self.in_queue.put(MPImageMenu(menu))
|
[
"def",
"set_menu",
"(",
"self",
",",
"menu",
")",
":",
"self",
".",
"menu",
"=",
"menu",
"self",
".",
"in_queue",
".",
"put",
"(",
"MPImageMenu",
"(",
"menu",
")",
")"
] |
set a MPTopMenu on the frame
|
[
"set",
"a",
"MPTopMenu",
"on",
"the",
"frame"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L145-L148
|
235,312
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py
|
MPImage.set_popup_menu
|
def set_popup_menu(self, menu):
'''set a popup menu on the frame'''
self.popup_menu = menu
self.in_queue.put(MPImagePopupMenu(menu))
|
python
|
def set_popup_menu(self, menu):
'''set a popup menu on the frame'''
self.popup_menu = menu
self.in_queue.put(MPImagePopupMenu(menu))
|
[
"def",
"set_popup_menu",
"(",
"self",
",",
"menu",
")",
":",
"self",
".",
"popup_menu",
"=",
"menu",
"self",
".",
"in_queue",
".",
"put",
"(",
"MPImagePopupMenu",
"(",
"menu",
")",
")"
] |
set a popup menu on the frame
|
[
"set",
"a",
"popup",
"menu",
"on",
"the",
"frame"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L150-L153
|
235,313
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py
|
MPImagePanel.image_coordinates
|
def image_coordinates(self, point):
'''given a point in window coordinates, calculate image coordinates'''
# the dragpos is the top left position in image coordinates
ret = wx.Point(int(self.dragpos.x + point.x/self.zoom),
int(self.dragpos.y + point.y/self.zoom))
return ret
|
python
|
def image_coordinates(self, point):
'''given a point in window coordinates, calculate image coordinates'''
# the dragpos is the top left position in image coordinates
ret = wx.Point(int(self.dragpos.x + point.x/self.zoom),
int(self.dragpos.y + point.y/self.zoom))
return ret
|
[
"def",
"image_coordinates",
"(",
"self",
",",
"point",
")",
":",
"# the dragpos is the top left position in image coordinates",
"ret",
"=",
"wx",
".",
"Point",
"(",
"int",
"(",
"self",
".",
"dragpos",
".",
"x",
"+",
"point",
".",
"x",
"/",
"self",
".",
"zoom",
")",
",",
"int",
"(",
"self",
".",
"dragpos",
".",
"y",
"+",
"point",
".",
"y",
"/",
"self",
".",
"zoom",
")",
")",
"return",
"ret"
] |
given a point in window coordinates, calculate image coordinates
|
[
"given",
"a",
"point",
"in",
"window",
"coordinates",
"calculate",
"image",
"coordinates"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L254-L259
|
235,314
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py
|
MPImagePanel.redraw
|
def redraw(self):
'''redraw the image with current settings'''
state = self.state
if self.img is None:
self.mainSizer.Fit(self)
self.Refresh()
state.frame.Refresh()
self.SetFocus()
return
# get the current size of the containing window frame
size = self.frame.GetSize()
(width, height) = (self.img.GetWidth(), self.img.GetHeight())
rect = wx.Rect(self.dragpos.x, self.dragpos.y, int(size.x/self.zoom), int(size.y/self.zoom))
#print("redraw", self.zoom, self.dragpos, size, rect);
if rect.x > width-1:
rect.x = width-1
if rect.y > height-1:
rect.y = height-1
if rect.width > width - rect.x:
rect.width = width - rect.x
if rect.height > height - rect.y:
rect.height = height - rect.y
scaled_image = self.img.Copy()
scaled_image = scaled_image.GetSubImage(rect);
scaled_image = scaled_image.Rescale(int(rect.width*self.zoom), int(rect.height*self.zoom))
if state.brightness != 1.0:
try:
from PIL import Image
pimg = mp_util.wxToPIL(scaled_image)
pimg = Image.eval(pimg, lambda x: int(x * state.brightness))
scaled_image = mp_util.PILTowx(pimg)
except Exception:
if not self.done_PIL_warning:
print("Please install PIL for brightness control")
self.done_PIL_warning = True
# ignore lack of PIL library
pass
self.imagePanel.set_image(scaled_image)
self.need_redraw = False
self.mainSizer.Fit(self)
self.Refresh()
state.frame.Refresh()
self.SetFocus()
'''
from guppy import hpy
h = hpy()
print h.heap()
'''
|
python
|
def redraw(self):
'''redraw the image with current settings'''
state = self.state
if self.img is None:
self.mainSizer.Fit(self)
self.Refresh()
state.frame.Refresh()
self.SetFocus()
return
# get the current size of the containing window frame
size = self.frame.GetSize()
(width, height) = (self.img.GetWidth(), self.img.GetHeight())
rect = wx.Rect(self.dragpos.x, self.dragpos.y, int(size.x/self.zoom), int(size.y/self.zoom))
#print("redraw", self.zoom, self.dragpos, size, rect);
if rect.x > width-1:
rect.x = width-1
if rect.y > height-1:
rect.y = height-1
if rect.width > width - rect.x:
rect.width = width - rect.x
if rect.height > height - rect.y:
rect.height = height - rect.y
scaled_image = self.img.Copy()
scaled_image = scaled_image.GetSubImage(rect);
scaled_image = scaled_image.Rescale(int(rect.width*self.zoom), int(rect.height*self.zoom))
if state.brightness != 1.0:
try:
from PIL import Image
pimg = mp_util.wxToPIL(scaled_image)
pimg = Image.eval(pimg, lambda x: int(x * state.brightness))
scaled_image = mp_util.PILTowx(pimg)
except Exception:
if not self.done_PIL_warning:
print("Please install PIL for brightness control")
self.done_PIL_warning = True
# ignore lack of PIL library
pass
self.imagePanel.set_image(scaled_image)
self.need_redraw = False
self.mainSizer.Fit(self)
self.Refresh()
state.frame.Refresh()
self.SetFocus()
'''
from guppy import hpy
h = hpy()
print h.heap()
'''
|
[
"def",
"redraw",
"(",
"self",
")",
":",
"state",
"=",
"self",
".",
"state",
"if",
"self",
".",
"img",
"is",
"None",
":",
"self",
".",
"mainSizer",
".",
"Fit",
"(",
"self",
")",
"self",
".",
"Refresh",
"(",
")",
"state",
".",
"frame",
".",
"Refresh",
"(",
")",
"self",
".",
"SetFocus",
"(",
")",
"return",
"# get the current size of the containing window frame",
"size",
"=",
"self",
".",
"frame",
".",
"GetSize",
"(",
")",
"(",
"width",
",",
"height",
")",
"=",
"(",
"self",
".",
"img",
".",
"GetWidth",
"(",
")",
",",
"self",
".",
"img",
".",
"GetHeight",
"(",
")",
")",
"rect",
"=",
"wx",
".",
"Rect",
"(",
"self",
".",
"dragpos",
".",
"x",
",",
"self",
".",
"dragpos",
".",
"y",
",",
"int",
"(",
"size",
".",
"x",
"/",
"self",
".",
"zoom",
")",
",",
"int",
"(",
"size",
".",
"y",
"/",
"self",
".",
"zoom",
")",
")",
"#print(\"redraw\", self.zoom, self.dragpos, size, rect);",
"if",
"rect",
".",
"x",
">",
"width",
"-",
"1",
":",
"rect",
".",
"x",
"=",
"width",
"-",
"1",
"if",
"rect",
".",
"y",
">",
"height",
"-",
"1",
":",
"rect",
".",
"y",
"=",
"height",
"-",
"1",
"if",
"rect",
".",
"width",
">",
"width",
"-",
"rect",
".",
"x",
":",
"rect",
".",
"width",
"=",
"width",
"-",
"rect",
".",
"x",
"if",
"rect",
".",
"height",
">",
"height",
"-",
"rect",
".",
"y",
":",
"rect",
".",
"height",
"=",
"height",
"-",
"rect",
".",
"y",
"scaled_image",
"=",
"self",
".",
"img",
".",
"Copy",
"(",
")",
"scaled_image",
"=",
"scaled_image",
".",
"GetSubImage",
"(",
"rect",
")",
"scaled_image",
"=",
"scaled_image",
".",
"Rescale",
"(",
"int",
"(",
"rect",
".",
"width",
"*",
"self",
".",
"zoom",
")",
",",
"int",
"(",
"rect",
".",
"height",
"*",
"self",
".",
"zoom",
")",
")",
"if",
"state",
".",
"brightness",
"!=",
"1.0",
":",
"try",
":",
"from",
"PIL",
"import",
"Image",
"pimg",
"=",
"mp_util",
".",
"wxToPIL",
"(",
"scaled_image",
")",
"pimg",
"=",
"Image",
".",
"eval",
"(",
"pimg",
",",
"lambda",
"x",
":",
"int",
"(",
"x",
"*",
"state",
".",
"brightness",
")",
")",
"scaled_image",
"=",
"mp_util",
".",
"PILTowx",
"(",
"pimg",
")",
"except",
"Exception",
":",
"if",
"not",
"self",
".",
"done_PIL_warning",
":",
"print",
"(",
"\"Please install PIL for brightness control\"",
")",
"self",
".",
"done_PIL_warning",
"=",
"True",
"# ignore lack of PIL library",
"pass",
"self",
".",
"imagePanel",
".",
"set_image",
"(",
"scaled_image",
")",
"self",
".",
"need_redraw",
"=",
"False",
"self",
".",
"mainSizer",
".",
"Fit",
"(",
"self",
")",
"self",
".",
"Refresh",
"(",
")",
"state",
".",
"frame",
".",
"Refresh",
"(",
")",
"self",
".",
"SetFocus",
"(",
")",
"'''\n from guppy import hpy\n h = hpy()\n print h.heap()\n '''"
] |
redraw the image with current settings
|
[
"redraw",
"the",
"image",
"with",
"current",
"settings"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L261-L315
|
235,315
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py
|
MPImagePanel.limit_dragpos
|
def limit_dragpos(self):
'''limit dragpos to sane values'''
if self.dragpos.x < 0:
self.dragpos.x = 0
if self.dragpos.y < 0:
self.dragpos.y = 0
if self.img is None:
return
if self.dragpos.x >= self.img.GetWidth():
self.dragpos.x = self.img.GetWidth()-1
if self.dragpos.y >= self.img.GetHeight():
self.dragpos.y = self.img.GetHeight()-1
|
python
|
def limit_dragpos(self):
'''limit dragpos to sane values'''
if self.dragpos.x < 0:
self.dragpos.x = 0
if self.dragpos.y < 0:
self.dragpos.y = 0
if self.img is None:
return
if self.dragpos.x >= self.img.GetWidth():
self.dragpos.x = self.img.GetWidth()-1
if self.dragpos.y >= self.img.GetHeight():
self.dragpos.y = self.img.GetHeight()-1
|
[
"def",
"limit_dragpos",
"(",
"self",
")",
":",
"if",
"self",
".",
"dragpos",
".",
"x",
"<",
"0",
":",
"self",
".",
"dragpos",
".",
"x",
"=",
"0",
"if",
"self",
".",
"dragpos",
".",
"y",
"<",
"0",
":",
"self",
".",
"dragpos",
".",
"y",
"=",
"0",
"if",
"self",
".",
"img",
"is",
"None",
":",
"return",
"if",
"self",
".",
"dragpos",
".",
"x",
">=",
"self",
".",
"img",
".",
"GetWidth",
"(",
")",
":",
"self",
".",
"dragpos",
".",
"x",
"=",
"self",
".",
"img",
".",
"GetWidth",
"(",
")",
"-",
"1",
"if",
"self",
".",
"dragpos",
".",
"y",
">=",
"self",
".",
"img",
".",
"GetHeight",
"(",
")",
":",
"self",
".",
"dragpos",
".",
"y",
"=",
"self",
".",
"img",
".",
"GetHeight",
"(",
")",
"-",
"1"
] |
limit dragpos to sane values
|
[
"limit",
"dragpos",
"to",
"sane",
"values"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L362-L373
|
235,316
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py
|
MPImagePanel.on_drag_event
|
def on_drag_event(self, event):
'''handle mouse drags'''
state = self.state
if not state.can_drag:
return
newpos = self.image_coordinates(event.GetPosition())
dx = -(newpos.x - self.mouse_down.x)
dy = -(newpos.y - self.mouse_down.y)
self.dragpos = wx.Point(self.dragpos.x+dx,self.dragpos.y+dy)
self.limit_dragpos()
self.mouse_down = newpos
self.need_redraw = True
self.redraw()
|
python
|
def on_drag_event(self, event):
'''handle mouse drags'''
state = self.state
if not state.can_drag:
return
newpos = self.image_coordinates(event.GetPosition())
dx = -(newpos.x - self.mouse_down.x)
dy = -(newpos.y - self.mouse_down.y)
self.dragpos = wx.Point(self.dragpos.x+dx,self.dragpos.y+dy)
self.limit_dragpos()
self.mouse_down = newpos
self.need_redraw = True
self.redraw()
|
[
"def",
"on_drag_event",
"(",
"self",
",",
"event",
")",
":",
"state",
"=",
"self",
".",
"state",
"if",
"not",
"state",
".",
"can_drag",
":",
"return",
"newpos",
"=",
"self",
".",
"image_coordinates",
"(",
"event",
".",
"GetPosition",
"(",
")",
")",
"dx",
"=",
"-",
"(",
"newpos",
".",
"x",
"-",
"self",
".",
"mouse_down",
".",
"x",
")",
"dy",
"=",
"-",
"(",
"newpos",
".",
"y",
"-",
"self",
".",
"mouse_down",
".",
"y",
")",
"self",
".",
"dragpos",
"=",
"wx",
".",
"Point",
"(",
"self",
".",
"dragpos",
".",
"x",
"+",
"dx",
",",
"self",
".",
"dragpos",
".",
"y",
"+",
"dy",
")",
"self",
".",
"limit_dragpos",
"(",
")",
"self",
".",
"mouse_down",
"=",
"newpos",
"self",
".",
"need_redraw",
"=",
"True",
"self",
".",
"redraw",
"(",
")"
] |
handle mouse drags
|
[
"handle",
"mouse",
"drags"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L401-L413
|
235,317
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py
|
MPImagePanel.show_popup_menu
|
def show_popup_menu(self, pos):
'''show a popup menu'''
self.popup_pos = self.image_coordinates(pos)
self.frame.PopupMenu(self.wx_popup_menu, pos)
|
python
|
def show_popup_menu(self, pos):
'''show a popup menu'''
self.popup_pos = self.image_coordinates(pos)
self.frame.PopupMenu(self.wx_popup_menu, pos)
|
[
"def",
"show_popup_menu",
"(",
"self",
",",
"pos",
")",
":",
"self",
".",
"popup_pos",
"=",
"self",
".",
"image_coordinates",
"(",
"pos",
")",
"self",
".",
"frame",
".",
"PopupMenu",
"(",
"self",
".",
"wx_popup_menu",
",",
"pos",
")"
] |
show a popup menu
|
[
"show",
"a",
"popup",
"menu"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L415-L418
|
235,318
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py
|
MPImagePanel.on_key_event
|
def on_key_event(self, event):
'''handle key events'''
keycode = event.GetKeyCode()
if keycode == wx.WXK_HOME:
self.zoom = 1.0
self.dragpos = wx.Point(0, 0)
self.need_redraw = True
|
python
|
def on_key_event(self, event):
'''handle key events'''
keycode = event.GetKeyCode()
if keycode == wx.WXK_HOME:
self.zoom = 1.0
self.dragpos = wx.Point(0, 0)
self.need_redraw = True
|
[
"def",
"on_key_event",
"(",
"self",
",",
"event",
")",
":",
"keycode",
"=",
"event",
".",
"GetKeyCode",
"(",
")",
"if",
"keycode",
"==",
"wx",
".",
"WXK_HOME",
":",
"self",
".",
"zoom",
"=",
"1.0",
"self",
".",
"dragpos",
"=",
"wx",
".",
"Point",
"(",
"0",
",",
"0",
")",
"self",
".",
"need_redraw",
"=",
"True"
] |
handle key events
|
[
"handle",
"key",
"events"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L436-L442
|
235,319
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py
|
MPImagePanel.on_event
|
def on_event(self, event):
'''pass events to the parent'''
state = self.state
if isinstance(event, wx.MouseEvent):
self.on_mouse_event(event)
if isinstance(event, wx.KeyEvent):
self.on_key_event(event)
if (isinstance(event, wx.MouseEvent) and
not event.ButtonIsDown(wx.MOUSE_BTN_ANY) and
event.GetWheelRotation() == 0):
# don't flood the queue with mouse movement
return
evt = mp_util.object_container(event)
pt = self.image_coordinates(wx.Point(evt.X,evt.Y))
evt.X = pt.x
evt.Y = pt.y
state.out_queue.put(evt)
|
python
|
def on_event(self, event):
'''pass events to the parent'''
state = self.state
if isinstance(event, wx.MouseEvent):
self.on_mouse_event(event)
if isinstance(event, wx.KeyEvent):
self.on_key_event(event)
if (isinstance(event, wx.MouseEvent) and
not event.ButtonIsDown(wx.MOUSE_BTN_ANY) and
event.GetWheelRotation() == 0):
# don't flood the queue with mouse movement
return
evt = mp_util.object_container(event)
pt = self.image_coordinates(wx.Point(evt.X,evt.Y))
evt.X = pt.x
evt.Y = pt.y
state.out_queue.put(evt)
|
[
"def",
"on_event",
"(",
"self",
",",
"event",
")",
":",
"state",
"=",
"self",
".",
"state",
"if",
"isinstance",
"(",
"event",
",",
"wx",
".",
"MouseEvent",
")",
":",
"self",
".",
"on_mouse_event",
"(",
"event",
")",
"if",
"isinstance",
"(",
"event",
",",
"wx",
".",
"KeyEvent",
")",
":",
"self",
".",
"on_key_event",
"(",
"event",
")",
"if",
"(",
"isinstance",
"(",
"event",
",",
"wx",
".",
"MouseEvent",
")",
"and",
"not",
"event",
".",
"ButtonIsDown",
"(",
"wx",
".",
"MOUSE_BTN_ANY",
")",
"and",
"event",
".",
"GetWheelRotation",
"(",
")",
"==",
"0",
")",
":",
"# don't flood the queue with mouse movement",
"return",
"evt",
"=",
"mp_util",
".",
"object_container",
"(",
"event",
")",
"pt",
"=",
"self",
".",
"image_coordinates",
"(",
"wx",
".",
"Point",
"(",
"evt",
".",
"X",
",",
"evt",
".",
"Y",
")",
")",
"evt",
".",
"X",
"=",
"pt",
".",
"x",
"evt",
".",
"Y",
"=",
"pt",
".",
"y",
"state",
".",
"out_queue",
".",
"put",
"(",
"evt",
")"
] |
pass events to the parent
|
[
"pass",
"events",
"to",
"the",
"parent"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L444-L460
|
235,320
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py
|
MPImagePanel.on_menu
|
def on_menu(self, event):
'''called on menu event'''
state = self.state
if self.popup_menu is not None:
ret = self.popup_menu.find_selected(event)
if ret is not None:
ret.popup_pos = self.popup_pos
if ret.returnkey == 'fitWindow':
self.fit_to_window()
elif ret.returnkey == 'fullSize':
self.full_size()
else:
state.out_queue.put(ret)
return
if self.menu is not None:
ret = self.menu.find_selected(event)
if ret is not None:
state.out_queue.put(ret)
return
|
python
|
def on_menu(self, event):
'''called on menu event'''
state = self.state
if self.popup_menu is not None:
ret = self.popup_menu.find_selected(event)
if ret is not None:
ret.popup_pos = self.popup_pos
if ret.returnkey == 'fitWindow':
self.fit_to_window()
elif ret.returnkey == 'fullSize':
self.full_size()
else:
state.out_queue.put(ret)
return
if self.menu is not None:
ret = self.menu.find_selected(event)
if ret is not None:
state.out_queue.put(ret)
return
|
[
"def",
"on_menu",
"(",
"self",
",",
"event",
")",
":",
"state",
"=",
"self",
".",
"state",
"if",
"self",
".",
"popup_menu",
"is",
"not",
"None",
":",
"ret",
"=",
"self",
".",
"popup_menu",
".",
"find_selected",
"(",
"event",
")",
"if",
"ret",
"is",
"not",
"None",
":",
"ret",
".",
"popup_pos",
"=",
"self",
".",
"popup_pos",
"if",
"ret",
".",
"returnkey",
"==",
"'fitWindow'",
":",
"self",
".",
"fit_to_window",
"(",
")",
"elif",
"ret",
".",
"returnkey",
"==",
"'fullSize'",
":",
"self",
".",
"full_size",
"(",
")",
"else",
":",
"state",
".",
"out_queue",
".",
"put",
"(",
"ret",
")",
"return",
"if",
"self",
".",
"menu",
"is",
"not",
"None",
":",
"ret",
"=",
"self",
".",
"menu",
".",
"find_selected",
"(",
"event",
")",
"if",
"ret",
"is",
"not",
"None",
":",
"state",
".",
"out_queue",
".",
"put",
"(",
"ret",
")",
"return"
] |
called on menu event
|
[
"called",
"on",
"menu",
"event"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L462-L480
|
235,321
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py
|
MPImagePanel.set_menu
|
def set_menu(self, menu):
'''add a menu from the parent'''
self.menu = menu
wx_menu = menu.wx_menu()
self.frame.SetMenuBar(wx_menu)
self.frame.Bind(wx.EVT_MENU, self.on_menu)
|
python
|
def set_menu(self, menu):
'''add a menu from the parent'''
self.menu = menu
wx_menu = menu.wx_menu()
self.frame.SetMenuBar(wx_menu)
self.frame.Bind(wx.EVT_MENU, self.on_menu)
|
[
"def",
"set_menu",
"(",
"self",
",",
"menu",
")",
":",
"self",
".",
"menu",
"=",
"menu",
"wx_menu",
"=",
"menu",
".",
"wx_menu",
"(",
")",
"self",
".",
"frame",
".",
"SetMenuBar",
"(",
"wx_menu",
")",
"self",
".",
"frame",
".",
"Bind",
"(",
"wx",
".",
"EVT_MENU",
",",
"self",
".",
"on_menu",
")"
] |
add a menu from the parent
|
[
"add",
"a",
"menu",
"from",
"the",
"parent"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L482-L487
|
235,322
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py
|
MPImagePanel.set_popup_menu
|
def set_popup_menu(self, menu):
'''add a popup menu from the parent'''
self.popup_menu = menu
if menu is None:
self.wx_popup_menu = None
else:
self.wx_popup_menu = menu.wx_menu()
self.frame.Bind(wx.EVT_MENU, self.on_menu)
|
python
|
def set_popup_menu(self, menu):
'''add a popup menu from the parent'''
self.popup_menu = menu
if menu is None:
self.wx_popup_menu = None
else:
self.wx_popup_menu = menu.wx_menu()
self.frame.Bind(wx.EVT_MENU, self.on_menu)
|
[
"def",
"set_popup_menu",
"(",
"self",
",",
"menu",
")",
":",
"self",
".",
"popup_menu",
"=",
"menu",
"if",
"menu",
"is",
"None",
":",
"self",
".",
"wx_popup_menu",
"=",
"None",
"else",
":",
"self",
".",
"wx_popup_menu",
"=",
"menu",
".",
"wx_menu",
"(",
")",
"self",
".",
"frame",
".",
"Bind",
"(",
"wx",
".",
"EVT_MENU",
",",
"self",
".",
"on_menu",
")"
] |
add a popup menu from the parent
|
[
"add",
"a",
"popup",
"menu",
"from",
"the",
"parent"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L489-L496
|
235,323
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py
|
MPImagePanel.fit_to_window
|
def fit_to_window(self):
'''fit image to window'''
state = self.state
self.dragpos = wx.Point(0, 0)
client_area = state.frame.GetClientSize()
self.zoom = min(float(client_area.x) / self.img.GetWidth(),
float(client_area.y) / self.img.GetHeight())
self.need_redraw = True
|
python
|
def fit_to_window(self):
'''fit image to window'''
state = self.state
self.dragpos = wx.Point(0, 0)
client_area = state.frame.GetClientSize()
self.zoom = min(float(client_area.x) / self.img.GetWidth(),
float(client_area.y) / self.img.GetHeight())
self.need_redraw = True
|
[
"def",
"fit_to_window",
"(",
"self",
")",
":",
"state",
"=",
"self",
".",
"state",
"self",
".",
"dragpos",
"=",
"wx",
".",
"Point",
"(",
"0",
",",
"0",
")",
"client_area",
"=",
"state",
".",
"frame",
".",
"GetClientSize",
"(",
")",
"self",
".",
"zoom",
"=",
"min",
"(",
"float",
"(",
"client_area",
".",
"x",
")",
"/",
"self",
".",
"img",
".",
"GetWidth",
"(",
")",
",",
"float",
"(",
"client_area",
".",
"y",
")",
"/",
"self",
".",
"img",
".",
"GetHeight",
"(",
")",
")",
"self",
".",
"need_redraw",
"=",
"True"
] |
fit image to window
|
[
"fit",
"image",
"to",
"window"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L498-L505
|
235,324
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py
|
MPImagePanel.full_size
|
def full_size(self):
'''show image at full size'''
self.dragpos = wx.Point(0, 0)
self.zoom = 1.0
self.need_redraw = True
|
python
|
def full_size(self):
'''show image at full size'''
self.dragpos = wx.Point(0, 0)
self.zoom = 1.0
self.need_redraw = True
|
[
"def",
"full_size",
"(",
"self",
")",
":",
"self",
".",
"dragpos",
"=",
"wx",
".",
"Point",
"(",
"0",
",",
"0",
")",
"self",
".",
"zoom",
"=",
"1.0",
"self",
".",
"need_redraw",
"=",
"True"
] |
show image at full size
|
[
"show",
"image",
"at",
"full",
"size"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_image.py#L507-L511
|
235,325
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavmission.py
|
mavmission
|
def mavmission(logfile):
'''extract mavlink mission'''
mlog = mavutil.mavlink_connection(filename)
wp = mavwp.MAVWPLoader()
while True:
m = mlog.recv_match(type=['MISSION_ITEM','CMD','WAYPOINT'])
if m is None:
break
if m.get_type() == 'CMD':
m = mavutil.mavlink.MAVLink_mission_item_message(0,
0,
m.CNum,
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
m.CId,
0, 1,
m.Prm1, m.Prm2, m.Prm3, m.Prm4,
m.Lat, m.Lng, m.Alt)
if m.current >= 2:
continue
while m.seq > wp.count():
print("Adding dummy WP %u" % wp.count())
wp.set(m, wp.count())
wp.set(m, m.seq)
wp.save(args.output)
print("Saved %u waypoints to %s" % (wp.count(), args.output))
|
python
|
def mavmission(logfile):
'''extract mavlink mission'''
mlog = mavutil.mavlink_connection(filename)
wp = mavwp.MAVWPLoader()
while True:
m = mlog.recv_match(type=['MISSION_ITEM','CMD','WAYPOINT'])
if m is None:
break
if m.get_type() == 'CMD':
m = mavutil.mavlink.MAVLink_mission_item_message(0,
0,
m.CNum,
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
m.CId,
0, 1,
m.Prm1, m.Prm2, m.Prm3, m.Prm4,
m.Lat, m.Lng, m.Alt)
if m.current >= 2:
continue
while m.seq > wp.count():
print("Adding dummy WP %u" % wp.count())
wp.set(m, wp.count())
wp.set(m, m.seq)
wp.save(args.output)
print("Saved %u waypoints to %s" % (wp.count(), args.output))
|
[
"def",
"mavmission",
"(",
"logfile",
")",
":",
"mlog",
"=",
"mavutil",
".",
"mavlink_connection",
"(",
"filename",
")",
"wp",
"=",
"mavwp",
".",
"MAVWPLoader",
"(",
")",
"while",
"True",
":",
"m",
"=",
"mlog",
".",
"recv_match",
"(",
"type",
"=",
"[",
"'MISSION_ITEM'",
",",
"'CMD'",
",",
"'WAYPOINT'",
"]",
")",
"if",
"m",
"is",
"None",
":",
"break",
"if",
"m",
".",
"get_type",
"(",
")",
"==",
"'CMD'",
":",
"m",
"=",
"mavutil",
".",
"mavlink",
".",
"MAVLink_mission_item_message",
"(",
"0",
",",
"0",
",",
"m",
".",
"CNum",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_FRAME_GLOBAL_RELATIVE_ALT",
",",
"m",
".",
"CId",
",",
"0",
",",
"1",
",",
"m",
".",
"Prm1",
",",
"m",
".",
"Prm2",
",",
"m",
".",
"Prm3",
",",
"m",
".",
"Prm4",
",",
"m",
".",
"Lat",
",",
"m",
".",
"Lng",
",",
"m",
".",
"Alt",
")",
"if",
"m",
".",
"current",
">=",
"2",
":",
"continue",
"while",
"m",
".",
"seq",
">",
"wp",
".",
"count",
"(",
")",
":",
"print",
"(",
"\"Adding dummy WP %u\"",
"%",
"wp",
".",
"count",
"(",
")",
")",
"wp",
".",
"set",
"(",
"m",
",",
"wp",
".",
"count",
"(",
")",
")",
"wp",
".",
"set",
"(",
"m",
",",
"m",
".",
"seq",
")",
"wp",
".",
"save",
"(",
"args",
".",
"output",
")",
"print",
"(",
"\"Saved %u waypoints to %s\"",
"%",
"(",
"wp",
".",
"count",
"(",
")",
",",
"args",
".",
"output",
")",
")"
] |
extract mavlink mission
|
[
"extract",
"mavlink",
"mission"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavmission.py#L20-L47
|
235,326
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py
|
message_checksum
|
def message_checksum(msg):
'''calculate a 8-bit checksum of the key fields of a message, so we
can detect incompatible XML changes'''
from .mavcrc import x25crc
crc = x25crc()
crc.accumulate_str(msg.name + ' ')
# in order to allow for extensions the crc does not include
# any field extensions
crc_end = msg.base_fields()
for i in range(crc_end):
f = msg.ordered_fields[i]
crc.accumulate_str(f.type + ' ')
crc.accumulate_str(f.name + ' ')
if f.array_length:
crc.accumulate([f.array_length])
return (crc.crc&0xFF) ^ (crc.crc>>8)
|
python
|
def message_checksum(msg):
'''calculate a 8-bit checksum of the key fields of a message, so we
can detect incompatible XML changes'''
from .mavcrc import x25crc
crc = x25crc()
crc.accumulate_str(msg.name + ' ')
# in order to allow for extensions the crc does not include
# any field extensions
crc_end = msg.base_fields()
for i in range(crc_end):
f = msg.ordered_fields[i]
crc.accumulate_str(f.type + ' ')
crc.accumulate_str(f.name + ' ')
if f.array_length:
crc.accumulate([f.array_length])
return (crc.crc&0xFF) ^ (crc.crc>>8)
|
[
"def",
"message_checksum",
"(",
"msg",
")",
":",
"from",
".",
"mavcrc",
"import",
"x25crc",
"crc",
"=",
"x25crc",
"(",
")",
"crc",
".",
"accumulate_str",
"(",
"msg",
".",
"name",
"+",
"' '",
")",
"# in order to allow for extensions the crc does not include",
"# any field extensions",
"crc_end",
"=",
"msg",
".",
"base_fields",
"(",
")",
"for",
"i",
"in",
"range",
"(",
"crc_end",
")",
":",
"f",
"=",
"msg",
".",
"ordered_fields",
"[",
"i",
"]",
"crc",
".",
"accumulate_str",
"(",
"f",
".",
"type",
"+",
"' '",
")",
"crc",
".",
"accumulate_str",
"(",
"f",
".",
"name",
"+",
"' '",
")",
"if",
"f",
".",
"array_length",
":",
"crc",
".",
"accumulate",
"(",
"[",
"f",
".",
"array_length",
"]",
")",
"return",
"(",
"crc",
".",
"crc",
"&",
"0xFF",
")",
"^",
"(",
"crc",
".",
"crc",
">>",
"8",
")"
] |
calculate a 8-bit checksum of the key fields of a message, so we
can detect incompatible XML changes
|
[
"calculate",
"a",
"8",
"-",
"bit",
"checksum",
"of",
"the",
"key",
"fields",
"of",
"a",
"message",
"so",
"we",
"can",
"detect",
"incompatible",
"XML",
"changes"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py#L379-L394
|
235,327
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py
|
merge_enums
|
def merge_enums(xml):
'''merge enums between XML files'''
emap = {}
for x in xml:
newenums = []
for enum in x.enum:
if enum.name in emap:
emapitem = emap[enum.name]
# check for possible conflicting auto-assigned values after merge
if (emapitem.start_value <= enum.highest_value and emapitem.highest_value >= enum.start_value):
for entry in emapitem.entry:
# correct the value if necessary, but only if it was auto-assigned to begin with
if entry.value <= enum.highest_value and entry.autovalue == True:
entry.value = enum.highest_value + 1
enum.highest_value = entry.value
# merge the entries
emapitem.entry.extend(enum.entry)
if not emapitem.description:
emapitem.description = enum.description
print("Merged enum %s" % enum.name)
else:
newenums.append(enum)
emap[enum.name] = enum
x.enum = newenums
for e in emap:
# sort by value
emap[e].entry = sorted(emap[e].entry,
key=operator.attrgetter('value'),
reverse=False)
# add a ENUM_END
emap[e].entry.append(MAVEnumEntry("%s_ENUM_END" % emap[e].name,
emap[e].entry[-1].value+1, end_marker=True))
|
python
|
def merge_enums(xml):
'''merge enums between XML files'''
emap = {}
for x in xml:
newenums = []
for enum in x.enum:
if enum.name in emap:
emapitem = emap[enum.name]
# check for possible conflicting auto-assigned values after merge
if (emapitem.start_value <= enum.highest_value and emapitem.highest_value >= enum.start_value):
for entry in emapitem.entry:
# correct the value if necessary, but only if it was auto-assigned to begin with
if entry.value <= enum.highest_value and entry.autovalue == True:
entry.value = enum.highest_value + 1
enum.highest_value = entry.value
# merge the entries
emapitem.entry.extend(enum.entry)
if not emapitem.description:
emapitem.description = enum.description
print("Merged enum %s" % enum.name)
else:
newenums.append(enum)
emap[enum.name] = enum
x.enum = newenums
for e in emap:
# sort by value
emap[e].entry = sorted(emap[e].entry,
key=operator.attrgetter('value'),
reverse=False)
# add a ENUM_END
emap[e].entry.append(MAVEnumEntry("%s_ENUM_END" % emap[e].name,
emap[e].entry[-1].value+1, end_marker=True))
|
[
"def",
"merge_enums",
"(",
"xml",
")",
":",
"emap",
"=",
"{",
"}",
"for",
"x",
"in",
"xml",
":",
"newenums",
"=",
"[",
"]",
"for",
"enum",
"in",
"x",
".",
"enum",
":",
"if",
"enum",
".",
"name",
"in",
"emap",
":",
"emapitem",
"=",
"emap",
"[",
"enum",
".",
"name",
"]",
"# check for possible conflicting auto-assigned values after merge",
"if",
"(",
"emapitem",
".",
"start_value",
"<=",
"enum",
".",
"highest_value",
"and",
"emapitem",
".",
"highest_value",
">=",
"enum",
".",
"start_value",
")",
":",
"for",
"entry",
"in",
"emapitem",
".",
"entry",
":",
"# correct the value if necessary, but only if it was auto-assigned to begin with",
"if",
"entry",
".",
"value",
"<=",
"enum",
".",
"highest_value",
"and",
"entry",
".",
"autovalue",
"==",
"True",
":",
"entry",
".",
"value",
"=",
"enum",
".",
"highest_value",
"+",
"1",
"enum",
".",
"highest_value",
"=",
"entry",
".",
"value",
"# merge the entries",
"emapitem",
".",
"entry",
".",
"extend",
"(",
"enum",
".",
"entry",
")",
"if",
"not",
"emapitem",
".",
"description",
":",
"emapitem",
".",
"description",
"=",
"enum",
".",
"description",
"print",
"(",
"\"Merged enum %s\"",
"%",
"enum",
".",
"name",
")",
"else",
":",
"newenums",
".",
"append",
"(",
"enum",
")",
"emap",
"[",
"enum",
".",
"name",
"]",
"=",
"enum",
"x",
".",
"enum",
"=",
"newenums",
"for",
"e",
"in",
"emap",
":",
"# sort by value",
"emap",
"[",
"e",
"]",
".",
"entry",
"=",
"sorted",
"(",
"emap",
"[",
"e",
"]",
".",
"entry",
",",
"key",
"=",
"operator",
".",
"attrgetter",
"(",
"'value'",
")",
",",
"reverse",
"=",
"False",
")",
"# add a ENUM_END",
"emap",
"[",
"e",
"]",
".",
"entry",
".",
"append",
"(",
"MAVEnumEntry",
"(",
"\"%s_ENUM_END\"",
"%",
"emap",
"[",
"e",
"]",
".",
"name",
",",
"emap",
"[",
"e",
"]",
".",
"entry",
"[",
"-",
"1",
"]",
".",
"value",
"+",
"1",
",",
"end_marker",
"=",
"True",
")",
")"
] |
merge enums between XML files
|
[
"merge",
"enums",
"between",
"XML",
"files"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py#L396-L427
|
235,328
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py
|
check_duplicates
|
def check_duplicates(xml):
'''check for duplicate message IDs'''
merge_enums(xml)
msgmap = {}
enummap = {}
for x in xml:
for m in x.message:
key = m.id
if key in msgmap:
print("ERROR: Duplicate message id %u for %s (%s:%u) also used by %s" % (
m.id,
m.name,
x.filename, m.linenumber,
msgmap[key]))
return True
fieldset = set()
for f in m.fields:
if f.name in fieldset:
print("ERROR: Duplicate field %s in message %s (%s:%u)" % (
f.name, m.name,
x.filename, m.linenumber))
return True
fieldset.add(f.name)
msgmap[key] = '%s (%s:%u)' % (m.name, x.filename, m.linenumber)
for enum in x.enum:
for entry in enum.entry:
if entry.autovalue == True and "common.xml" not in entry.origin_file:
print("Note: An enum value was auto-generated: %s = %u" % (entry.name, entry.value))
s1 = "%s.%s" % (enum.name, entry.name)
s2 = "%s.%s" % (enum.name, entry.value)
if s1 in enummap or s2 in enummap:
print("ERROR: Duplicate enum %s:\n\t%s = %s @ %s:%u\n\t%s" % (
"names" if s1 in enummap else "values",
s1, entry.value, entry.origin_file, entry.origin_line,
enummap.get(s1) or enummap.get(s2)))
return True
enummap[s1] = enummap[s2] = "%s.%s = %s @ %s:%u" % (enum.name, entry.name, entry.value, entry.origin_file, entry.origin_line)
return False
|
python
|
def check_duplicates(xml):
'''check for duplicate message IDs'''
merge_enums(xml)
msgmap = {}
enummap = {}
for x in xml:
for m in x.message:
key = m.id
if key in msgmap:
print("ERROR: Duplicate message id %u for %s (%s:%u) also used by %s" % (
m.id,
m.name,
x.filename, m.linenumber,
msgmap[key]))
return True
fieldset = set()
for f in m.fields:
if f.name in fieldset:
print("ERROR: Duplicate field %s in message %s (%s:%u)" % (
f.name, m.name,
x.filename, m.linenumber))
return True
fieldset.add(f.name)
msgmap[key] = '%s (%s:%u)' % (m.name, x.filename, m.linenumber)
for enum in x.enum:
for entry in enum.entry:
if entry.autovalue == True and "common.xml" not in entry.origin_file:
print("Note: An enum value was auto-generated: %s = %u" % (entry.name, entry.value))
s1 = "%s.%s" % (enum.name, entry.name)
s2 = "%s.%s" % (enum.name, entry.value)
if s1 in enummap or s2 in enummap:
print("ERROR: Duplicate enum %s:\n\t%s = %s @ %s:%u\n\t%s" % (
"names" if s1 in enummap else "values",
s1, entry.value, entry.origin_file, entry.origin_line,
enummap.get(s1) or enummap.get(s2)))
return True
enummap[s1] = enummap[s2] = "%s.%s = %s @ %s:%u" % (enum.name, entry.name, entry.value, entry.origin_file, entry.origin_line)
return False
|
[
"def",
"check_duplicates",
"(",
"xml",
")",
":",
"merge_enums",
"(",
"xml",
")",
"msgmap",
"=",
"{",
"}",
"enummap",
"=",
"{",
"}",
"for",
"x",
"in",
"xml",
":",
"for",
"m",
"in",
"x",
".",
"message",
":",
"key",
"=",
"m",
".",
"id",
"if",
"key",
"in",
"msgmap",
":",
"print",
"(",
"\"ERROR: Duplicate message id %u for %s (%s:%u) also used by %s\"",
"%",
"(",
"m",
".",
"id",
",",
"m",
".",
"name",
",",
"x",
".",
"filename",
",",
"m",
".",
"linenumber",
",",
"msgmap",
"[",
"key",
"]",
")",
")",
"return",
"True",
"fieldset",
"=",
"set",
"(",
")",
"for",
"f",
"in",
"m",
".",
"fields",
":",
"if",
"f",
".",
"name",
"in",
"fieldset",
":",
"print",
"(",
"\"ERROR: Duplicate field %s in message %s (%s:%u)\"",
"%",
"(",
"f",
".",
"name",
",",
"m",
".",
"name",
",",
"x",
".",
"filename",
",",
"m",
".",
"linenumber",
")",
")",
"return",
"True",
"fieldset",
".",
"add",
"(",
"f",
".",
"name",
")",
"msgmap",
"[",
"key",
"]",
"=",
"'%s (%s:%u)'",
"%",
"(",
"m",
".",
"name",
",",
"x",
".",
"filename",
",",
"m",
".",
"linenumber",
")",
"for",
"enum",
"in",
"x",
".",
"enum",
":",
"for",
"entry",
"in",
"enum",
".",
"entry",
":",
"if",
"entry",
".",
"autovalue",
"==",
"True",
"and",
"\"common.xml\"",
"not",
"in",
"entry",
".",
"origin_file",
":",
"print",
"(",
"\"Note: An enum value was auto-generated: %s = %u\"",
"%",
"(",
"entry",
".",
"name",
",",
"entry",
".",
"value",
")",
")",
"s1",
"=",
"\"%s.%s\"",
"%",
"(",
"enum",
".",
"name",
",",
"entry",
".",
"name",
")",
"s2",
"=",
"\"%s.%s\"",
"%",
"(",
"enum",
".",
"name",
",",
"entry",
".",
"value",
")",
"if",
"s1",
"in",
"enummap",
"or",
"s2",
"in",
"enummap",
":",
"print",
"(",
"\"ERROR: Duplicate enum %s:\\n\\t%s = %s @ %s:%u\\n\\t%s\"",
"%",
"(",
"\"names\"",
"if",
"s1",
"in",
"enummap",
"else",
"\"values\"",
",",
"s1",
",",
"entry",
".",
"value",
",",
"entry",
".",
"origin_file",
",",
"entry",
".",
"origin_line",
",",
"enummap",
".",
"get",
"(",
"s1",
")",
"or",
"enummap",
".",
"get",
"(",
"s2",
")",
")",
")",
"return",
"True",
"enummap",
"[",
"s1",
"]",
"=",
"enummap",
"[",
"s2",
"]",
"=",
"\"%s.%s = %s @ %s:%u\"",
"%",
"(",
"enum",
".",
"name",
",",
"entry",
".",
"name",
",",
"entry",
".",
"value",
",",
"entry",
".",
"origin_file",
",",
"entry",
".",
"origin_line",
")",
"return",
"False"
] |
check for duplicate message IDs
|
[
"check",
"for",
"duplicate",
"message",
"IDs"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py#L429-L469
|
235,329
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py
|
total_msgs
|
def total_msgs(xml):
'''count total number of msgs'''
count = 0
for x in xml:
count += len(x.message)
return count
|
python
|
def total_msgs(xml):
'''count total number of msgs'''
count = 0
for x in xml:
count += len(x.message)
return count
|
[
"def",
"total_msgs",
"(",
"xml",
")",
":",
"count",
"=",
"0",
"for",
"x",
"in",
"xml",
":",
"count",
"+=",
"len",
"(",
"x",
".",
"message",
")",
"return",
"count"
] |
count total number of msgs
|
[
"count",
"total",
"number",
"of",
"msgs"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py#L473-L478
|
235,330
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py
|
MAVType.base_fields
|
def base_fields(self):
'''return number of non-extended fields'''
if self.extensions_start is None:
return len(self.fields)
return len(self.fields[:self.extensions_start])
|
python
|
def base_fields(self):
'''return number of non-extended fields'''
if self.extensions_start is None:
return len(self.fields)
return len(self.fields[:self.extensions_start])
|
[
"def",
"base_fields",
"(",
"self",
")",
":",
"if",
"self",
".",
"extensions_start",
"is",
"None",
":",
"return",
"len",
"(",
"self",
".",
"fields",
")",
"return",
"len",
"(",
"self",
".",
"fields",
"[",
":",
"self",
".",
"extensions_start",
"]",
")"
] |
return number of non-extended fields
|
[
"return",
"number",
"of",
"non",
"-",
"extended",
"fields"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavparse.py#L125-L129
|
235,331
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py
|
dataflash_logger._dataflash_dir
|
def _dataflash_dir(self, mpstate):
'''returns directory path to store DF logs in. May be relative'''
if mpstate.settings.state_basedir is None:
ret = 'dataflash'
else:
ret = os.path.join(mpstate.settings.state_basedir,'dataflash')
try:
os.makedirs(ret)
except OSError as e:
if e.errno != errno.EEXIST:
print("DFLogger: OSError making (%s): %s" % (ret, str(e)))
except Exception as e:
print("DFLogger: Unknown exception making (%s): %s" % (ret, str(e)))
return ret
|
python
|
def _dataflash_dir(self, mpstate):
'''returns directory path to store DF logs in. May be relative'''
if mpstate.settings.state_basedir is None:
ret = 'dataflash'
else:
ret = os.path.join(mpstate.settings.state_basedir,'dataflash')
try:
os.makedirs(ret)
except OSError as e:
if e.errno != errno.EEXIST:
print("DFLogger: OSError making (%s): %s" % (ret, str(e)))
except Exception as e:
print("DFLogger: Unknown exception making (%s): %s" % (ret, str(e)))
return ret
|
[
"def",
"_dataflash_dir",
"(",
"self",
",",
"mpstate",
")",
":",
"if",
"mpstate",
".",
"settings",
".",
"state_basedir",
"is",
"None",
":",
"ret",
"=",
"'dataflash'",
"else",
":",
"ret",
"=",
"os",
".",
"path",
".",
"join",
"(",
"mpstate",
".",
"settings",
".",
"state_basedir",
",",
"'dataflash'",
")",
"try",
":",
"os",
".",
"makedirs",
"(",
"ret",
")",
"except",
"OSError",
"as",
"e",
":",
"if",
"e",
".",
"errno",
"!=",
"errno",
".",
"EEXIST",
":",
"print",
"(",
"\"DFLogger: OSError making (%s): %s\"",
"%",
"(",
"ret",
",",
"str",
"(",
"e",
")",
")",
")",
"except",
"Exception",
"as",
"e",
":",
"print",
"(",
"\"DFLogger: Unknown exception making (%s): %s\"",
"%",
"(",
"ret",
",",
"str",
"(",
"e",
")",
")",
")",
"return",
"ret"
] |
returns directory path to store DF logs in. May be relative
|
[
"returns",
"directory",
"path",
"to",
"store",
"DF",
"logs",
"in",
".",
"May",
"be",
"relative"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py#L65-L80
|
235,332
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py
|
dataflash_logger.new_log_filepath
|
def new_log_filepath(self):
'''returns a filepath to a log which does not currently exist and is suitable for DF logging'''
lastlog_filename = os.path.join(self.dataflash_dir,'LASTLOG.TXT')
if os.path.exists(lastlog_filename) and os.stat(lastlog_filename).st_size != 0:
fh = open(lastlog_filename,'rb')
log_cnt = int(fh.read()) + 1
fh.close()
else:
log_cnt = 1
self.lastlog_file = open(lastlog_filename,'w+b')
self.lastlog_file.write(log_cnt.__str__())
self.lastlog_file.close()
return os.path.join(self.dataflash_dir, '%u.BIN' % (log_cnt,));
|
python
|
def new_log_filepath(self):
'''returns a filepath to a log which does not currently exist and is suitable for DF logging'''
lastlog_filename = os.path.join(self.dataflash_dir,'LASTLOG.TXT')
if os.path.exists(lastlog_filename) and os.stat(lastlog_filename).st_size != 0:
fh = open(lastlog_filename,'rb')
log_cnt = int(fh.read()) + 1
fh.close()
else:
log_cnt = 1
self.lastlog_file = open(lastlog_filename,'w+b')
self.lastlog_file.write(log_cnt.__str__())
self.lastlog_file.close()
return os.path.join(self.dataflash_dir, '%u.BIN' % (log_cnt,));
|
[
"def",
"new_log_filepath",
"(",
"self",
")",
":",
"lastlog_filename",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"dataflash_dir",
",",
"'LASTLOG.TXT'",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"lastlog_filename",
")",
"and",
"os",
".",
"stat",
"(",
"lastlog_filename",
")",
".",
"st_size",
"!=",
"0",
":",
"fh",
"=",
"open",
"(",
"lastlog_filename",
",",
"'rb'",
")",
"log_cnt",
"=",
"int",
"(",
"fh",
".",
"read",
"(",
")",
")",
"+",
"1",
"fh",
".",
"close",
"(",
")",
"else",
":",
"log_cnt",
"=",
"1",
"self",
".",
"lastlog_file",
"=",
"open",
"(",
"lastlog_filename",
",",
"'w+b'",
")",
"self",
".",
"lastlog_file",
".",
"write",
"(",
"log_cnt",
".",
"__str__",
"(",
")",
")",
"self",
".",
"lastlog_file",
".",
"close",
"(",
")",
"return",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"dataflash_dir",
",",
"'%u.BIN'",
"%",
"(",
"log_cnt",
",",
")",
")"
] |
returns a filepath to a log which does not currently exist and is suitable for DF logging
|
[
"returns",
"a",
"filepath",
"to",
"a",
"log",
"which",
"does",
"not",
"currently",
"exist",
"and",
"is",
"suitable",
"for",
"DF",
"logging"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py#L82-L96
|
235,333
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py
|
dataflash_logger.start_new_log
|
def start_new_log(self):
'''open a new dataflash log, reset state'''
filename = self.new_log_filepath()
self.block_cnt = 0
self.logfile = open(filename, 'w+b')
print("DFLogger: logging started (%s)" % (filename))
self.prev_cnt = 0
self.download = 0
self.prev_download = 0
self.last_idle_status_printed_time = time.time()
self.last_status_time = time.time()
self.missing_blocks = {}
self.acking_blocks = {}
self.blocks_to_ack_and_nack = []
self.missing_found = 0
self.abandoned = 0
|
python
|
def start_new_log(self):
'''open a new dataflash log, reset state'''
filename = self.new_log_filepath()
self.block_cnt = 0
self.logfile = open(filename, 'w+b')
print("DFLogger: logging started (%s)" % (filename))
self.prev_cnt = 0
self.download = 0
self.prev_download = 0
self.last_idle_status_printed_time = time.time()
self.last_status_time = time.time()
self.missing_blocks = {}
self.acking_blocks = {}
self.blocks_to_ack_and_nack = []
self.missing_found = 0
self.abandoned = 0
|
[
"def",
"start_new_log",
"(",
"self",
")",
":",
"filename",
"=",
"self",
".",
"new_log_filepath",
"(",
")",
"self",
".",
"block_cnt",
"=",
"0",
"self",
".",
"logfile",
"=",
"open",
"(",
"filename",
",",
"'w+b'",
")",
"print",
"(",
"\"DFLogger: logging started (%s)\"",
"%",
"(",
"filename",
")",
")",
"self",
".",
"prev_cnt",
"=",
"0",
"self",
".",
"download",
"=",
"0",
"self",
".",
"prev_download",
"=",
"0",
"self",
".",
"last_idle_status_printed_time",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"last_status_time",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"missing_blocks",
"=",
"{",
"}",
"self",
".",
"acking_blocks",
"=",
"{",
"}",
"self",
".",
"blocks_to_ack_and_nack",
"=",
"[",
"]",
"self",
".",
"missing_found",
"=",
"0",
"self",
".",
"abandoned",
"=",
"0"
] |
open a new dataflash log, reset state
|
[
"open",
"a",
"new",
"dataflash",
"log",
"reset",
"state"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py#L98-L114
|
235,334
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py
|
dataflash_logger.mavlink_packet
|
def mavlink_packet(self, m):
'''handle REMOTE_LOG_DATA_BLOCK packets'''
now = time.time()
if m.get_type() == 'REMOTE_LOG_DATA_BLOCK':
if self.stopped:
# send a stop packet every second until the other end gets the idea:
if now - self.time_last_stop_packet_sent > 1:
if self.log_settings.verbose:
print("DFLogger: Sending stop packet")
self.master.mav.remote_log_block_status_send(mavutil.mavlink.MAV_REMOTE_LOG_DATA_BLOCK_STOP,1)
return
# if random.random() < 0.1: # drop 1 packet in 10
# return
if not self.new_log_started:
if self.log_settings.verbose:
print("DFLogger: Received data packet - starting new log")
self.start_new_log()
self.new_log_started = True
if self.new_log_started == True:
size = m.block_size
data = ''.join(str(chr(x)) for x in m.data[:size])
ofs = size*(m.block_cnt)
self.logfile.seek(ofs)
self.logfile.write(data)
if m.block_cnt in self.missing_blocks:
if self.log_settings.verbose:
print("DFLogger: Received missing block: %d" % (m.block_cnt,))
del self.missing_blocks[m.block_cnt]
self.missing_found += 1
self.blocks_to_ack_and_nack.append([self.master,m.block_cnt,1,now,None])
self.acking_blocks[m.block_cnt] = 1
# print("DFLogger: missing blocks: %s" % (str(self.missing_blocks),))
else:
# ACK the block we just got:
if m.block_cnt in self.acking_blocks:
# already acking this one; we probably sent
# multiple nacks and received this one
# multiple times
pass
else:
self.blocks_to_ack_and_nack.append([self.master,m.block_cnt,1,now,None])
self.acking_blocks[m.block_cnt] = 1
# NACK any blocks we haven't seen and should have:
if(m.block_cnt - self.block_cnt > 1):
for block in range(self.block_cnt+1, m.block_cnt):
if block not in self.missing_blocks and \
block not in self.acking_blocks:
self.missing_blocks[block] = 1
if self.log_settings.verbose:
print ("DFLogger: setting %d for nacking" % (block,))
self.blocks_to_ack_and_nack.append([self.master,block,0,now,None])
#print "\nmissed blocks: ",self.missing_blocks
if self.block_cnt < m.block_cnt:
self.block_cnt = m.block_cnt
self.download += size
elif not self.new_log_started and not self.stopped:
# send a start packet every second until the other end gets the idea:
if now - self.time_last_start_packet_sent > 1:
if self.log_settings.verbose:
print("DFLogger: Sending start packet")
self.master.mav.remote_log_block_status_send(mavutil.mavlink.MAV_REMOTE_LOG_DATA_BLOCK_START,1)
self.time_last_start_packet_sent = now
|
python
|
def mavlink_packet(self, m):
'''handle REMOTE_LOG_DATA_BLOCK packets'''
now = time.time()
if m.get_type() == 'REMOTE_LOG_DATA_BLOCK':
if self.stopped:
# send a stop packet every second until the other end gets the idea:
if now - self.time_last_stop_packet_sent > 1:
if self.log_settings.verbose:
print("DFLogger: Sending stop packet")
self.master.mav.remote_log_block_status_send(mavutil.mavlink.MAV_REMOTE_LOG_DATA_BLOCK_STOP,1)
return
# if random.random() < 0.1: # drop 1 packet in 10
# return
if not self.new_log_started:
if self.log_settings.verbose:
print("DFLogger: Received data packet - starting new log")
self.start_new_log()
self.new_log_started = True
if self.new_log_started == True:
size = m.block_size
data = ''.join(str(chr(x)) for x in m.data[:size])
ofs = size*(m.block_cnt)
self.logfile.seek(ofs)
self.logfile.write(data)
if m.block_cnt in self.missing_blocks:
if self.log_settings.verbose:
print("DFLogger: Received missing block: %d" % (m.block_cnt,))
del self.missing_blocks[m.block_cnt]
self.missing_found += 1
self.blocks_to_ack_and_nack.append([self.master,m.block_cnt,1,now,None])
self.acking_blocks[m.block_cnt] = 1
# print("DFLogger: missing blocks: %s" % (str(self.missing_blocks),))
else:
# ACK the block we just got:
if m.block_cnt in self.acking_blocks:
# already acking this one; we probably sent
# multiple nacks and received this one
# multiple times
pass
else:
self.blocks_to_ack_and_nack.append([self.master,m.block_cnt,1,now,None])
self.acking_blocks[m.block_cnt] = 1
# NACK any blocks we haven't seen and should have:
if(m.block_cnt - self.block_cnt > 1):
for block in range(self.block_cnt+1, m.block_cnt):
if block not in self.missing_blocks and \
block not in self.acking_blocks:
self.missing_blocks[block] = 1
if self.log_settings.verbose:
print ("DFLogger: setting %d for nacking" % (block,))
self.blocks_to_ack_and_nack.append([self.master,block,0,now,None])
#print "\nmissed blocks: ",self.missing_blocks
if self.block_cnt < m.block_cnt:
self.block_cnt = m.block_cnt
self.download += size
elif not self.new_log_started and not self.stopped:
# send a start packet every second until the other end gets the idea:
if now - self.time_last_start_packet_sent > 1:
if self.log_settings.verbose:
print("DFLogger: Sending start packet")
self.master.mav.remote_log_block_status_send(mavutil.mavlink.MAV_REMOTE_LOG_DATA_BLOCK_START,1)
self.time_last_start_packet_sent = now
|
[
"def",
"mavlink_packet",
"(",
"self",
",",
"m",
")",
":",
"now",
"=",
"time",
".",
"time",
"(",
")",
"if",
"m",
".",
"get_type",
"(",
")",
"==",
"'REMOTE_LOG_DATA_BLOCK'",
":",
"if",
"self",
".",
"stopped",
":",
"# send a stop packet every second until the other end gets the idea:",
"if",
"now",
"-",
"self",
".",
"time_last_stop_packet_sent",
">",
"1",
":",
"if",
"self",
".",
"log_settings",
".",
"verbose",
":",
"print",
"(",
"\"DFLogger: Sending stop packet\"",
")",
"self",
".",
"master",
".",
"mav",
".",
"remote_log_block_status_send",
"(",
"mavutil",
".",
"mavlink",
".",
"MAV_REMOTE_LOG_DATA_BLOCK_STOP",
",",
"1",
")",
"return",
"# if random.random() < 0.1: # drop 1 packet in 10",
"# return",
"if",
"not",
"self",
".",
"new_log_started",
":",
"if",
"self",
".",
"log_settings",
".",
"verbose",
":",
"print",
"(",
"\"DFLogger: Received data packet - starting new log\"",
")",
"self",
".",
"start_new_log",
"(",
")",
"self",
".",
"new_log_started",
"=",
"True",
"if",
"self",
".",
"new_log_started",
"==",
"True",
":",
"size",
"=",
"m",
".",
"block_size",
"data",
"=",
"''",
".",
"join",
"(",
"str",
"(",
"chr",
"(",
"x",
")",
")",
"for",
"x",
"in",
"m",
".",
"data",
"[",
":",
"size",
"]",
")",
"ofs",
"=",
"size",
"*",
"(",
"m",
".",
"block_cnt",
")",
"self",
".",
"logfile",
".",
"seek",
"(",
"ofs",
")",
"self",
".",
"logfile",
".",
"write",
"(",
"data",
")",
"if",
"m",
".",
"block_cnt",
"in",
"self",
".",
"missing_blocks",
":",
"if",
"self",
".",
"log_settings",
".",
"verbose",
":",
"print",
"(",
"\"DFLogger: Received missing block: %d\"",
"%",
"(",
"m",
".",
"block_cnt",
",",
")",
")",
"del",
"self",
".",
"missing_blocks",
"[",
"m",
".",
"block_cnt",
"]",
"self",
".",
"missing_found",
"+=",
"1",
"self",
".",
"blocks_to_ack_and_nack",
".",
"append",
"(",
"[",
"self",
".",
"master",
",",
"m",
".",
"block_cnt",
",",
"1",
",",
"now",
",",
"None",
"]",
")",
"self",
".",
"acking_blocks",
"[",
"m",
".",
"block_cnt",
"]",
"=",
"1",
"# print(\"DFLogger: missing blocks: %s\" % (str(self.missing_blocks),))",
"else",
":",
"# ACK the block we just got:",
"if",
"m",
".",
"block_cnt",
"in",
"self",
".",
"acking_blocks",
":",
"# already acking this one; we probably sent",
"# multiple nacks and received this one",
"# multiple times",
"pass",
"else",
":",
"self",
".",
"blocks_to_ack_and_nack",
".",
"append",
"(",
"[",
"self",
".",
"master",
",",
"m",
".",
"block_cnt",
",",
"1",
",",
"now",
",",
"None",
"]",
")",
"self",
".",
"acking_blocks",
"[",
"m",
".",
"block_cnt",
"]",
"=",
"1",
"# NACK any blocks we haven't seen and should have:",
"if",
"(",
"m",
".",
"block_cnt",
"-",
"self",
".",
"block_cnt",
">",
"1",
")",
":",
"for",
"block",
"in",
"range",
"(",
"self",
".",
"block_cnt",
"+",
"1",
",",
"m",
".",
"block_cnt",
")",
":",
"if",
"block",
"not",
"in",
"self",
".",
"missing_blocks",
"and",
"block",
"not",
"in",
"self",
".",
"acking_blocks",
":",
"self",
".",
"missing_blocks",
"[",
"block",
"]",
"=",
"1",
"if",
"self",
".",
"log_settings",
".",
"verbose",
":",
"print",
"(",
"\"DFLogger: setting %d for nacking\"",
"%",
"(",
"block",
",",
")",
")",
"self",
".",
"blocks_to_ack_and_nack",
".",
"append",
"(",
"[",
"self",
".",
"master",
",",
"block",
",",
"0",
",",
"now",
",",
"None",
"]",
")",
"#print \"\\nmissed blocks: \",self.missing_blocks",
"if",
"self",
".",
"block_cnt",
"<",
"m",
".",
"block_cnt",
":",
"self",
".",
"block_cnt",
"=",
"m",
".",
"block_cnt",
"self",
".",
"download",
"+=",
"size",
"elif",
"not",
"self",
".",
"new_log_started",
"and",
"not",
"self",
".",
"stopped",
":",
"# send a start packet every second until the other end gets the idea:",
"if",
"now",
"-",
"self",
".",
"time_last_start_packet_sent",
">",
"1",
":",
"if",
"self",
".",
"log_settings",
".",
"verbose",
":",
"print",
"(",
"\"DFLogger: Sending start packet\"",
")",
"self",
".",
"master",
".",
"mav",
".",
"remote_log_block_status_send",
"(",
"mavutil",
".",
"mavlink",
".",
"MAV_REMOTE_LOG_DATA_BLOCK_START",
",",
"1",
")",
"self",
".",
"time_last_start_packet_sent",
"=",
"now"
] |
handle REMOTE_LOG_DATA_BLOCK packets
|
[
"handle",
"REMOTE_LOG_DATA_BLOCK",
"packets"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_dataflash_logger.py#L194-L259
|
235,335
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/dialects/v10/ardupilotmega.py
|
MAVLink.meminfo_send
|
def meminfo_send(self, brkval, freemem, force_mavlink1=False):
'''
state of APM memory
brkval : heap top (uint16_t)
freemem : free memory (uint16_t)
'''
return self.send(self.meminfo_encode(brkval, freemem), force_mavlink1=force_mavlink1)
|
python
|
def meminfo_send(self, brkval, freemem, force_mavlink1=False):
'''
state of APM memory
brkval : heap top (uint16_t)
freemem : free memory (uint16_t)
'''
return self.send(self.meminfo_encode(brkval, freemem), force_mavlink1=force_mavlink1)
|
[
"def",
"meminfo_send",
"(",
"self",
",",
"brkval",
",",
"freemem",
",",
"force_mavlink1",
"=",
"False",
")",
":",
"return",
"self",
".",
"send",
"(",
"self",
".",
"meminfo_encode",
"(",
"brkval",
",",
"freemem",
")",
",",
"force_mavlink1",
"=",
"force_mavlink1",
")"
] |
state of APM memory
brkval : heap top (uint16_t)
freemem : free memory (uint16_t)
|
[
"state",
"of",
"APM",
"memory"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/dialects/v10/ardupilotmega.py#L9577-L9585
|
235,336
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavextract.py
|
older_message
|
def older_message(m, lastm):
'''return true if m is older than lastm by timestamp'''
atts = {'time_boot_ms' : 1.0e-3,
'time_unix_usec' : 1.0e-6,
'time_usec' : 1.0e-6}
for a in atts.keys():
if hasattr(m, a):
mul = atts[a]
t1 = m.getattr(a) * mul
t2 = lastm.getattr(a) * mul
if t2 >= t1 and t2 - t1 < 60:
return True
return False
|
python
|
def older_message(m, lastm):
'''return true if m is older than lastm by timestamp'''
atts = {'time_boot_ms' : 1.0e-3,
'time_unix_usec' : 1.0e-6,
'time_usec' : 1.0e-6}
for a in atts.keys():
if hasattr(m, a):
mul = atts[a]
t1 = m.getattr(a) * mul
t2 = lastm.getattr(a) * mul
if t2 >= t1 and t2 - t1 < 60:
return True
return False
|
[
"def",
"older_message",
"(",
"m",
",",
"lastm",
")",
":",
"atts",
"=",
"{",
"'time_boot_ms'",
":",
"1.0e-3",
",",
"'time_unix_usec'",
":",
"1.0e-6",
",",
"'time_usec'",
":",
"1.0e-6",
"}",
"for",
"a",
"in",
"atts",
".",
"keys",
"(",
")",
":",
"if",
"hasattr",
"(",
"m",
",",
"a",
")",
":",
"mul",
"=",
"atts",
"[",
"a",
"]",
"t1",
"=",
"m",
".",
"getattr",
"(",
"a",
")",
"*",
"mul",
"t2",
"=",
"lastm",
".",
"getattr",
"(",
"a",
")",
"*",
"mul",
"if",
"t2",
">=",
"t1",
"and",
"t2",
"-",
"t1",
"<",
"60",
":",
"return",
"True",
"return",
"False"
] |
return true if m is older than lastm by timestamp
|
[
"return",
"true",
"if",
"m",
"is",
"older",
"than",
"lastm",
"by",
"timestamp"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavextract.py#L22-L34
|
235,337
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavextract.py
|
process
|
def process(filename):
'''process one logfile'''
print("Processing %s" % filename)
mlog = mavutil.mavlink_connection(filename, notimestamps=args.notimestamps,
robust_parsing=args.robust)
ext = os.path.splitext(filename)[1]
isbin = ext in ['.bin', '.BIN']
islog = ext in ['.log', '.LOG']
output = None
count = 1
dirname = os.path.dirname(filename)
if isbin or islog:
extension = "bin"
else:
extension = "tlog"
file_header = ''
messages = []
# we allow a list of modes that map to one mode number. This allows for --mode=AUTO,RTL and consider the RTL as part of AUTO
modes = args.mode.upper().split(',')
flightmode = None
while True:
m = mlog.recv_match()
if m is None:
break
if args.link is not None and m._link != args.link:
continue
mtype = m.get_type()
if mtype in messages:
if older_message(m, messages[mtype]):
continue
# we don't use mlog.flightmode as that can be wrong if we are extracting a single link
if mtype == 'HEARTBEAT' and m.get_srcComponent() != mavutil.mavlink.MAV_COMP_ID_GIMBAL and m.type != mavutil.mavlink.MAV_TYPE_GCS:
flightmode = mavutil.mode_string_v10(m).upper()
if mtype == 'MODE':
flightmode = mlog.flightmode
if (isbin or islog) and m.get_type() in ["FMT", "PARM", "CMD"]:
file_header += m.get_msgbuf()
if (isbin or islog) and m.get_type() == 'MSG' and m.Message.startswith("Ardu"):
file_header += m.get_msgbuf()
if m.get_type() in ['PARAM_VALUE','MISSION_ITEM']:
timestamp = getattr(m, '_timestamp', None)
file_header += struct.pack('>Q', timestamp*1.0e6) + m.get_msgbuf()
if not mavutil.evaluate_condition(args.condition, mlog.messages):
continue
if flightmode in modes:
if output is None:
path = os.path.join(dirname, "%s%u.%s" % (modes[0], count, extension))
count += 1
print("Creating %s" % path)
output = open(path, mode='wb')
output.write(file_header)
else:
if output is not None:
output.close()
output = None
if output and m.get_type() != 'BAD_DATA':
timestamp = getattr(m, '_timestamp', None)
if not isbin:
output.write(struct.pack('>Q', timestamp*1.0e6))
output.write(m.get_msgbuf())
|
python
|
def process(filename):
'''process one logfile'''
print("Processing %s" % filename)
mlog = mavutil.mavlink_connection(filename, notimestamps=args.notimestamps,
robust_parsing=args.robust)
ext = os.path.splitext(filename)[1]
isbin = ext in ['.bin', '.BIN']
islog = ext in ['.log', '.LOG']
output = None
count = 1
dirname = os.path.dirname(filename)
if isbin or islog:
extension = "bin"
else:
extension = "tlog"
file_header = ''
messages = []
# we allow a list of modes that map to one mode number. This allows for --mode=AUTO,RTL and consider the RTL as part of AUTO
modes = args.mode.upper().split(',')
flightmode = None
while True:
m = mlog.recv_match()
if m is None:
break
if args.link is not None and m._link != args.link:
continue
mtype = m.get_type()
if mtype in messages:
if older_message(m, messages[mtype]):
continue
# we don't use mlog.flightmode as that can be wrong if we are extracting a single link
if mtype == 'HEARTBEAT' and m.get_srcComponent() != mavutil.mavlink.MAV_COMP_ID_GIMBAL and m.type != mavutil.mavlink.MAV_TYPE_GCS:
flightmode = mavutil.mode_string_v10(m).upper()
if mtype == 'MODE':
flightmode = mlog.flightmode
if (isbin or islog) and m.get_type() in ["FMT", "PARM", "CMD"]:
file_header += m.get_msgbuf()
if (isbin or islog) and m.get_type() == 'MSG' and m.Message.startswith("Ardu"):
file_header += m.get_msgbuf()
if m.get_type() in ['PARAM_VALUE','MISSION_ITEM']:
timestamp = getattr(m, '_timestamp', None)
file_header += struct.pack('>Q', timestamp*1.0e6) + m.get_msgbuf()
if not mavutil.evaluate_condition(args.condition, mlog.messages):
continue
if flightmode in modes:
if output is None:
path = os.path.join(dirname, "%s%u.%s" % (modes[0], count, extension))
count += 1
print("Creating %s" % path)
output = open(path, mode='wb')
output.write(file_header)
else:
if output is not None:
output.close()
output = None
if output and m.get_type() != 'BAD_DATA':
timestamp = getattr(m, '_timestamp', None)
if not isbin:
output.write(struct.pack('>Q', timestamp*1.0e6))
output.write(m.get_msgbuf())
|
[
"def",
"process",
"(",
"filename",
")",
":",
"print",
"(",
"\"Processing %s\"",
"%",
"filename",
")",
"mlog",
"=",
"mavutil",
".",
"mavlink_connection",
"(",
"filename",
",",
"notimestamps",
"=",
"args",
".",
"notimestamps",
",",
"robust_parsing",
"=",
"args",
".",
"robust",
")",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"filename",
")",
"[",
"1",
"]",
"isbin",
"=",
"ext",
"in",
"[",
"'.bin'",
",",
"'.BIN'",
"]",
"islog",
"=",
"ext",
"in",
"[",
"'.log'",
",",
"'.LOG'",
"]",
"output",
"=",
"None",
"count",
"=",
"1",
"dirname",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"filename",
")",
"if",
"isbin",
"or",
"islog",
":",
"extension",
"=",
"\"bin\"",
"else",
":",
"extension",
"=",
"\"tlog\"",
"file_header",
"=",
"''",
"messages",
"=",
"[",
"]",
"# we allow a list of modes that map to one mode number. This allows for --mode=AUTO,RTL and consider the RTL as part of AUTO",
"modes",
"=",
"args",
".",
"mode",
".",
"upper",
"(",
")",
".",
"split",
"(",
"','",
")",
"flightmode",
"=",
"None",
"while",
"True",
":",
"m",
"=",
"mlog",
".",
"recv_match",
"(",
")",
"if",
"m",
"is",
"None",
":",
"break",
"if",
"args",
".",
"link",
"is",
"not",
"None",
"and",
"m",
".",
"_link",
"!=",
"args",
".",
"link",
":",
"continue",
"mtype",
"=",
"m",
".",
"get_type",
"(",
")",
"if",
"mtype",
"in",
"messages",
":",
"if",
"older_message",
"(",
"m",
",",
"messages",
"[",
"mtype",
"]",
")",
":",
"continue",
"# we don't use mlog.flightmode as that can be wrong if we are extracting a single link",
"if",
"mtype",
"==",
"'HEARTBEAT'",
"and",
"m",
".",
"get_srcComponent",
"(",
")",
"!=",
"mavutil",
".",
"mavlink",
".",
"MAV_COMP_ID_GIMBAL",
"and",
"m",
".",
"type",
"!=",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_GCS",
":",
"flightmode",
"=",
"mavutil",
".",
"mode_string_v10",
"(",
"m",
")",
".",
"upper",
"(",
")",
"if",
"mtype",
"==",
"'MODE'",
":",
"flightmode",
"=",
"mlog",
".",
"flightmode",
"if",
"(",
"isbin",
"or",
"islog",
")",
"and",
"m",
".",
"get_type",
"(",
")",
"in",
"[",
"\"FMT\"",
",",
"\"PARM\"",
",",
"\"CMD\"",
"]",
":",
"file_header",
"+=",
"m",
".",
"get_msgbuf",
"(",
")",
"if",
"(",
"isbin",
"or",
"islog",
")",
"and",
"m",
".",
"get_type",
"(",
")",
"==",
"'MSG'",
"and",
"m",
".",
"Message",
".",
"startswith",
"(",
"\"Ardu\"",
")",
":",
"file_header",
"+=",
"m",
".",
"get_msgbuf",
"(",
")",
"if",
"m",
".",
"get_type",
"(",
")",
"in",
"[",
"'PARAM_VALUE'",
",",
"'MISSION_ITEM'",
"]",
":",
"timestamp",
"=",
"getattr",
"(",
"m",
",",
"'_timestamp'",
",",
"None",
")",
"file_header",
"+=",
"struct",
".",
"pack",
"(",
"'>Q'",
",",
"timestamp",
"*",
"1.0e6",
")",
"+",
"m",
".",
"get_msgbuf",
"(",
")",
"if",
"not",
"mavutil",
".",
"evaluate_condition",
"(",
"args",
".",
"condition",
",",
"mlog",
".",
"messages",
")",
":",
"continue",
"if",
"flightmode",
"in",
"modes",
":",
"if",
"output",
"is",
"None",
":",
"path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"dirname",
",",
"\"%s%u.%s\"",
"%",
"(",
"modes",
"[",
"0",
"]",
",",
"count",
",",
"extension",
")",
")",
"count",
"+=",
"1",
"print",
"(",
"\"Creating %s\"",
"%",
"path",
")",
"output",
"=",
"open",
"(",
"path",
",",
"mode",
"=",
"'wb'",
")",
"output",
".",
"write",
"(",
"file_header",
")",
"else",
":",
"if",
"output",
"is",
"not",
"None",
":",
"output",
".",
"close",
"(",
")",
"output",
"=",
"None",
"if",
"output",
"and",
"m",
".",
"get_type",
"(",
")",
"!=",
"'BAD_DATA'",
":",
"timestamp",
"=",
"getattr",
"(",
"m",
",",
"'_timestamp'",
",",
"None",
")",
"if",
"not",
"isbin",
":",
"output",
".",
"write",
"(",
"struct",
".",
"pack",
"(",
"'>Q'",
",",
"timestamp",
"*",
"1.0e6",
")",
")",
"output",
".",
"write",
"(",
"m",
".",
"get_msgbuf",
"(",
")",
")"
] |
process one logfile
|
[
"process",
"one",
"logfile"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavextract.py#L36-L108
|
235,338
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py
|
LogModule.handle_log_entry
|
def handle_log_entry(self, m):
'''handling incoming log entry'''
if m.time_utc == 0:
tstring = ''
else:
tstring = time.ctime(m.time_utc)
self.entries[m.id] = m
print("Log %u numLogs %u lastLog %u size %u %s" % (m.id, m.num_logs, m.last_log_num, m.size, tstring))
|
python
|
def handle_log_entry(self, m):
'''handling incoming log entry'''
if m.time_utc == 0:
tstring = ''
else:
tstring = time.ctime(m.time_utc)
self.entries[m.id] = m
print("Log %u numLogs %u lastLog %u size %u %s" % (m.id, m.num_logs, m.last_log_num, m.size, tstring))
|
[
"def",
"handle_log_entry",
"(",
"self",
",",
"m",
")",
":",
"if",
"m",
".",
"time_utc",
"==",
"0",
":",
"tstring",
"=",
"''",
"else",
":",
"tstring",
"=",
"time",
".",
"ctime",
"(",
"m",
".",
"time_utc",
")",
"self",
".",
"entries",
"[",
"m",
".",
"id",
"]",
"=",
"m",
"print",
"(",
"\"Log %u numLogs %u lastLog %u size %u %s\"",
"%",
"(",
"m",
".",
"id",
",",
"m",
".",
"num_logs",
",",
"m",
".",
"last_log_num",
",",
"m",
".",
"size",
",",
"tstring",
")",
")"
] |
handling incoming log entry
|
[
"handling",
"incoming",
"log",
"entry"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py#L32-L39
|
235,339
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py
|
LogModule.handle_log_data_missing
|
def handle_log_data_missing(self):
'''handling missing incoming log data'''
if len(self.download_set) == 0:
return
highest = max(self.download_set)
diff = set(range(highest)).difference(self.download_set)
if len(diff) == 0:
self.master.mav.log_request_data_send(self.target_system,
self.target_component,
self.download_lognum, (1 + highest) * 90, 0xffffffff)
self.retries += 1
else:
num_requests = 0
while num_requests < 20:
start = min(diff)
diff.remove(start)
end = start
while end + 1 in diff:
end += 1
diff.remove(end)
self.master.mav.log_request_data_send(self.target_system,
self.target_component,
self.download_lognum, start * 90, (end + 1 - start) * 90)
num_requests += 1
self.retries += 1
if len(diff) == 0:
break
|
python
|
def handle_log_data_missing(self):
'''handling missing incoming log data'''
if len(self.download_set) == 0:
return
highest = max(self.download_set)
diff = set(range(highest)).difference(self.download_set)
if len(diff) == 0:
self.master.mav.log_request_data_send(self.target_system,
self.target_component,
self.download_lognum, (1 + highest) * 90, 0xffffffff)
self.retries += 1
else:
num_requests = 0
while num_requests < 20:
start = min(diff)
diff.remove(start)
end = start
while end + 1 in diff:
end += 1
diff.remove(end)
self.master.mav.log_request_data_send(self.target_system,
self.target_component,
self.download_lognum, start * 90, (end + 1 - start) * 90)
num_requests += 1
self.retries += 1
if len(diff) == 0:
break
|
[
"def",
"handle_log_data_missing",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"download_set",
")",
"==",
"0",
":",
"return",
"highest",
"=",
"max",
"(",
"self",
".",
"download_set",
")",
"diff",
"=",
"set",
"(",
"range",
"(",
"highest",
")",
")",
".",
"difference",
"(",
"self",
".",
"download_set",
")",
"if",
"len",
"(",
"diff",
")",
"==",
"0",
":",
"self",
".",
"master",
".",
"mav",
".",
"log_request_data_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"self",
".",
"download_lognum",
",",
"(",
"1",
"+",
"highest",
")",
"*",
"90",
",",
"0xffffffff",
")",
"self",
".",
"retries",
"+=",
"1",
"else",
":",
"num_requests",
"=",
"0",
"while",
"num_requests",
"<",
"20",
":",
"start",
"=",
"min",
"(",
"diff",
")",
"diff",
".",
"remove",
"(",
"start",
")",
"end",
"=",
"start",
"while",
"end",
"+",
"1",
"in",
"diff",
":",
"end",
"+=",
"1",
"diff",
".",
"remove",
"(",
"end",
")",
"self",
".",
"master",
".",
"mav",
".",
"log_request_data_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"self",
".",
"download_lognum",
",",
"start",
"*",
"90",
",",
"(",
"end",
"+",
"1",
"-",
"start",
")",
"*",
"90",
")",
"num_requests",
"+=",
"1",
"self",
".",
"retries",
"+=",
"1",
"if",
"len",
"(",
"diff",
")",
"==",
"0",
":",
"break"
] |
handling missing incoming log data
|
[
"handling",
"missing",
"incoming",
"log",
"data"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py#L75-L101
|
235,340
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py
|
LogModule.log_status
|
def log_status(self):
'''show download status'''
if self.download_filename is None:
print("No download")
return
dt = time.time() - self.download_start
speed = os.path.getsize(self.download_filename) / (1000.0 * dt)
m = self.entries.get(self.download_lognum, None)
if m is None:
size = 0
else:
size = m.size
highest = max(self.download_set)
diff = set(range(highest)).difference(self.download_set)
print("Downloading %s - %u/%u bytes %.1f kbyte/s (%u retries %u missing)" % (self.download_filename,
os.path.getsize(self.download_filename),
size,
speed,
self.retries,
len(diff)))
|
python
|
def log_status(self):
'''show download status'''
if self.download_filename is None:
print("No download")
return
dt = time.time() - self.download_start
speed = os.path.getsize(self.download_filename) / (1000.0 * dt)
m = self.entries.get(self.download_lognum, None)
if m is None:
size = 0
else:
size = m.size
highest = max(self.download_set)
diff = set(range(highest)).difference(self.download_set)
print("Downloading %s - %u/%u bytes %.1f kbyte/s (%u retries %u missing)" % (self.download_filename,
os.path.getsize(self.download_filename),
size,
speed,
self.retries,
len(diff)))
|
[
"def",
"log_status",
"(",
"self",
")",
":",
"if",
"self",
".",
"download_filename",
"is",
"None",
":",
"print",
"(",
"\"No download\"",
")",
"return",
"dt",
"=",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"download_start",
"speed",
"=",
"os",
".",
"path",
".",
"getsize",
"(",
"self",
".",
"download_filename",
")",
"/",
"(",
"1000.0",
"*",
"dt",
")",
"m",
"=",
"self",
".",
"entries",
".",
"get",
"(",
"self",
".",
"download_lognum",
",",
"None",
")",
"if",
"m",
"is",
"None",
":",
"size",
"=",
"0",
"else",
":",
"size",
"=",
"m",
".",
"size",
"highest",
"=",
"max",
"(",
"self",
".",
"download_set",
")",
"diff",
"=",
"set",
"(",
"range",
"(",
"highest",
")",
")",
".",
"difference",
"(",
"self",
".",
"download_set",
")",
"print",
"(",
"\"Downloading %s - %u/%u bytes %.1f kbyte/s (%u retries %u missing)\"",
"%",
"(",
"self",
".",
"download_filename",
",",
"os",
".",
"path",
".",
"getsize",
"(",
"self",
".",
"download_filename",
")",
",",
"size",
",",
"speed",
",",
"self",
".",
"retries",
",",
"len",
"(",
"diff",
")",
")",
")"
] |
show download status
|
[
"show",
"download",
"status"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py#L104-L123
|
235,341
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py
|
LogModule.log_download
|
def log_download(self, log_num, filename):
'''download a log file'''
print("Downloading log %u as %s" % (log_num, filename))
self.download_lognum = log_num
self.download_file = open(filename, "wb")
self.master.mav.log_request_data_send(self.target_system,
self.target_component,
log_num, 0, 0xFFFFFFFF)
self.download_filename = filename
self.download_set = set()
self.download_start = time.time()
self.download_last_timestamp = time.time()
self.download_ofs = 0
self.retries = 0
|
python
|
def log_download(self, log_num, filename):
'''download a log file'''
print("Downloading log %u as %s" % (log_num, filename))
self.download_lognum = log_num
self.download_file = open(filename, "wb")
self.master.mav.log_request_data_send(self.target_system,
self.target_component,
log_num, 0, 0xFFFFFFFF)
self.download_filename = filename
self.download_set = set()
self.download_start = time.time()
self.download_last_timestamp = time.time()
self.download_ofs = 0
self.retries = 0
|
[
"def",
"log_download",
"(",
"self",
",",
"log_num",
",",
"filename",
")",
":",
"print",
"(",
"\"Downloading log %u as %s\"",
"%",
"(",
"log_num",
",",
"filename",
")",
")",
"self",
".",
"download_lognum",
"=",
"log_num",
"self",
".",
"download_file",
"=",
"open",
"(",
"filename",
",",
"\"wb\"",
")",
"self",
".",
"master",
".",
"mav",
".",
"log_request_data_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"log_num",
",",
"0",
",",
"0xFFFFFFFF",
")",
"self",
".",
"download_filename",
"=",
"filename",
"self",
".",
"download_set",
"=",
"set",
"(",
")",
"self",
".",
"download_start",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"download_last_timestamp",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"download_ofs",
"=",
"0",
"self",
".",
"retries",
"=",
"0"
] |
download a log file
|
[
"download",
"a",
"log",
"file"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py#L125-L138
|
235,342
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py
|
LogModule.idle_task
|
def idle_task(self):
'''handle missing log data'''
if self.download_last_timestamp is not None and time.time() - self.download_last_timestamp > 0.7:
self.download_last_timestamp = time.time()
self.handle_log_data_missing()
|
python
|
def idle_task(self):
'''handle missing log data'''
if self.download_last_timestamp is not None and time.time() - self.download_last_timestamp > 0.7:
self.download_last_timestamp = time.time()
self.handle_log_data_missing()
|
[
"def",
"idle_task",
"(",
"self",
")",
":",
"if",
"self",
".",
"download_last_timestamp",
"is",
"not",
"None",
"and",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"download_last_timestamp",
">",
"0.7",
":",
"self",
".",
"download_last_timestamp",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"handle_log_data_missing",
"(",
")"
] |
handle missing log data
|
[
"handle",
"missing",
"log",
"data"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_log.py#L185-L189
|
235,343
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py
|
complete_modules
|
def complete_modules(text):
'''complete mavproxy module names'''
import MAVProxy.modules, pkgutil
modlist = [x[1] for x in pkgutil.iter_modules(MAVProxy.modules.__path__)]
ret = []
loaded = set(complete_loadedmodules(''))
for m in modlist:
if not m.startswith("mavproxy_"):
continue
name = m[9:]
if not name in loaded:
ret.append(name)
return ret
|
python
|
def complete_modules(text):
'''complete mavproxy module names'''
import MAVProxy.modules, pkgutil
modlist = [x[1] for x in pkgutil.iter_modules(MAVProxy.modules.__path__)]
ret = []
loaded = set(complete_loadedmodules(''))
for m in modlist:
if not m.startswith("mavproxy_"):
continue
name = m[9:]
if not name in loaded:
ret.append(name)
return ret
|
[
"def",
"complete_modules",
"(",
"text",
")",
":",
"import",
"MAVProxy",
".",
"modules",
",",
"pkgutil",
"modlist",
"=",
"[",
"x",
"[",
"1",
"]",
"for",
"x",
"in",
"pkgutil",
".",
"iter_modules",
"(",
"MAVProxy",
".",
"modules",
".",
"__path__",
")",
"]",
"ret",
"=",
"[",
"]",
"loaded",
"=",
"set",
"(",
"complete_loadedmodules",
"(",
"''",
")",
")",
"for",
"m",
"in",
"modlist",
":",
"if",
"not",
"m",
".",
"startswith",
"(",
"\"mavproxy_\"",
")",
":",
"continue",
"name",
"=",
"m",
"[",
"9",
":",
"]",
"if",
"not",
"name",
"in",
"loaded",
":",
"ret",
".",
"append",
"(",
"name",
")",
"return",
"ret"
] |
complete mavproxy module names
|
[
"complete",
"mavproxy",
"module",
"names"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py#L63-L75
|
235,344
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py
|
complete_filename
|
def complete_filename(text):
'''complete a filename'''
#ensure directories have trailing slashes:
list = glob.glob(text+'*')
for idx, val in enumerate(list):
if os.path.isdir(val):
list[idx] = (val + os.path.sep)
return list
|
python
|
def complete_filename(text):
'''complete a filename'''
#ensure directories have trailing slashes:
list = glob.glob(text+'*')
for idx, val in enumerate(list):
if os.path.isdir(val):
list[idx] = (val + os.path.sep)
return list
|
[
"def",
"complete_filename",
"(",
"text",
")",
":",
"#ensure directories have trailing slashes:",
"list",
"=",
"glob",
".",
"glob",
"(",
"text",
"+",
"'*'",
")",
"for",
"idx",
",",
"val",
"in",
"enumerate",
"(",
"list",
")",
":",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"val",
")",
":",
"list",
"[",
"idx",
"]",
"=",
"(",
"val",
"+",
"os",
".",
"path",
".",
"sep",
")",
"return",
"list"
] |
complete a filename
|
[
"complete",
"a",
"filename"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py#L77-L86
|
235,345
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py
|
complete_variable
|
def complete_variable(text):
'''complete a MAVLink variable'''
if text.find('.') != -1:
var = text.split('.')[0]
if var in rline_mpstate.status.msgs:
ret = []
for f in rline_mpstate.status.msgs[var].get_fieldnames():
ret.append(var + '.' + f)
return ret
return []
return rline_mpstate.status.msgs.keys()
|
python
|
def complete_variable(text):
'''complete a MAVLink variable'''
if text.find('.') != -1:
var = text.split('.')[0]
if var in rline_mpstate.status.msgs:
ret = []
for f in rline_mpstate.status.msgs[var].get_fieldnames():
ret.append(var + '.' + f)
return ret
return []
return rline_mpstate.status.msgs.keys()
|
[
"def",
"complete_variable",
"(",
"text",
")",
":",
"if",
"text",
".",
"find",
"(",
"'.'",
")",
"!=",
"-",
"1",
":",
"var",
"=",
"text",
".",
"split",
"(",
"'.'",
")",
"[",
"0",
"]",
"if",
"var",
"in",
"rline_mpstate",
".",
"status",
".",
"msgs",
":",
"ret",
"=",
"[",
"]",
"for",
"f",
"in",
"rline_mpstate",
".",
"status",
".",
"msgs",
"[",
"var",
"]",
".",
"get_fieldnames",
"(",
")",
":",
"ret",
".",
"append",
"(",
"var",
"+",
"'.'",
"+",
"f",
")",
"return",
"ret",
"return",
"[",
"]",
"return",
"rline_mpstate",
".",
"status",
".",
"msgs",
".",
"keys",
"(",
")"
] |
complete a MAVLink variable
|
[
"complete",
"a",
"MAVLink",
"variable"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py#L92-L102
|
235,346
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py
|
rule_expand
|
def rule_expand(component, text):
'''expand one rule component'''
global rline_mpstate
if component[0] == '<' and component[-1] == '>':
return component[1:-1].split('|')
if component in rline_mpstate.completion_functions:
return rline_mpstate.completion_functions[component](text)
return [component]
|
python
|
def rule_expand(component, text):
'''expand one rule component'''
global rline_mpstate
if component[0] == '<' and component[-1] == '>':
return component[1:-1].split('|')
if component in rline_mpstate.completion_functions:
return rline_mpstate.completion_functions[component](text)
return [component]
|
[
"def",
"rule_expand",
"(",
"component",
",",
"text",
")",
":",
"global",
"rline_mpstate",
"if",
"component",
"[",
"0",
"]",
"==",
"'<'",
"and",
"component",
"[",
"-",
"1",
"]",
"==",
"'>'",
":",
"return",
"component",
"[",
"1",
":",
"-",
"1",
"]",
".",
"split",
"(",
"'|'",
")",
"if",
"component",
"in",
"rline_mpstate",
".",
"completion_functions",
":",
"return",
"rline_mpstate",
".",
"completion_functions",
"[",
"component",
"]",
"(",
"text",
")",
"return",
"[",
"component",
"]"
] |
expand one rule component
|
[
"expand",
"one",
"rule",
"component"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py#L104-L111
|
235,347
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py
|
rule_match
|
def rule_match(component, cmd):
'''see if one rule component matches'''
if component == cmd:
return True
expanded = rule_expand(component, cmd)
if cmd in expanded:
return True
return False
|
python
|
def rule_match(component, cmd):
'''see if one rule component matches'''
if component == cmd:
return True
expanded = rule_expand(component, cmd)
if cmd in expanded:
return True
return False
|
[
"def",
"rule_match",
"(",
"component",
",",
"cmd",
")",
":",
"if",
"component",
"==",
"cmd",
":",
"return",
"True",
"expanded",
"=",
"rule_expand",
"(",
"component",
",",
"cmd",
")",
"if",
"cmd",
"in",
"expanded",
":",
"return",
"True",
"return",
"False"
] |
see if one rule component matches
|
[
"see",
"if",
"one",
"rule",
"component",
"matches"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py#L113-L120
|
235,348
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py
|
complete_rules
|
def complete_rules(rules, cmd):
'''complete using a list of completion rules'''
if not isinstance(rules, list):
rules = [rules]
ret = []
for r in rules:
ret += complete_rule(r, cmd)
return ret
|
python
|
def complete_rules(rules, cmd):
'''complete using a list of completion rules'''
if not isinstance(rules, list):
rules = [rules]
ret = []
for r in rules:
ret += complete_rule(r, cmd)
return ret
|
[
"def",
"complete_rules",
"(",
"rules",
",",
"cmd",
")",
":",
"if",
"not",
"isinstance",
"(",
"rules",
",",
"list",
")",
":",
"rules",
"=",
"[",
"rules",
"]",
"ret",
"=",
"[",
"]",
"for",
"r",
"in",
"rules",
":",
"ret",
"+=",
"complete_rule",
"(",
"r",
",",
"cmd",
")",
"return",
"ret"
] |
complete using a list of completion rules
|
[
"complete",
"using",
"a",
"list",
"of",
"completion",
"rules"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py#L137-L144
|
235,349
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py
|
complete
|
def complete(text, state):
'''completion routine for when user presses tab'''
global last_clist
global rline_mpstate
if state != 0 and last_clist is not None:
return last_clist[state]
# split the command so far
cmd = readline.get_line_buffer().split()
if len(cmd) == 1:
# if on first part then complete on commands and aliases
last_clist = complete_command(text) + complete_alias(text)
elif cmd[0] in rline_mpstate.completions:
# we have a completion rule for this command
last_clist = complete_rules(rline_mpstate.completions[cmd[0]], cmd[1:])
else:
# assume completion by filename
last_clist = glob.glob(text+'*')
ret = []
for c in last_clist:
if c.startswith(text) or c.startswith(text.upper()):
ret.append(c)
if len(ret) == 0:
# if we had no matches then try case insensitively
text = text.lower()
for c in last_clist:
if c.lower().startswith(text):
ret.append(c)
ret.append(None)
last_clist = ret
return last_clist[state]
|
python
|
def complete(text, state):
'''completion routine for when user presses tab'''
global last_clist
global rline_mpstate
if state != 0 and last_clist is not None:
return last_clist[state]
# split the command so far
cmd = readline.get_line_buffer().split()
if len(cmd) == 1:
# if on first part then complete on commands and aliases
last_clist = complete_command(text) + complete_alias(text)
elif cmd[0] in rline_mpstate.completions:
# we have a completion rule for this command
last_clist = complete_rules(rline_mpstate.completions[cmd[0]], cmd[1:])
else:
# assume completion by filename
last_clist = glob.glob(text+'*')
ret = []
for c in last_clist:
if c.startswith(text) or c.startswith(text.upper()):
ret.append(c)
if len(ret) == 0:
# if we had no matches then try case insensitively
text = text.lower()
for c in last_clist:
if c.lower().startswith(text):
ret.append(c)
ret.append(None)
last_clist = ret
return last_clist[state]
|
[
"def",
"complete",
"(",
"text",
",",
"state",
")",
":",
"global",
"last_clist",
"global",
"rline_mpstate",
"if",
"state",
"!=",
"0",
"and",
"last_clist",
"is",
"not",
"None",
":",
"return",
"last_clist",
"[",
"state",
"]",
"# split the command so far",
"cmd",
"=",
"readline",
".",
"get_line_buffer",
"(",
")",
".",
"split",
"(",
")",
"if",
"len",
"(",
"cmd",
")",
"==",
"1",
":",
"# if on first part then complete on commands and aliases",
"last_clist",
"=",
"complete_command",
"(",
"text",
")",
"+",
"complete_alias",
"(",
"text",
")",
"elif",
"cmd",
"[",
"0",
"]",
"in",
"rline_mpstate",
".",
"completions",
":",
"# we have a completion rule for this command",
"last_clist",
"=",
"complete_rules",
"(",
"rline_mpstate",
".",
"completions",
"[",
"cmd",
"[",
"0",
"]",
"]",
",",
"cmd",
"[",
"1",
":",
"]",
")",
"else",
":",
"# assume completion by filename",
"last_clist",
"=",
"glob",
".",
"glob",
"(",
"text",
"+",
"'*'",
")",
"ret",
"=",
"[",
"]",
"for",
"c",
"in",
"last_clist",
":",
"if",
"c",
".",
"startswith",
"(",
"text",
")",
"or",
"c",
".",
"startswith",
"(",
"text",
".",
"upper",
"(",
")",
")",
":",
"ret",
".",
"append",
"(",
"c",
")",
"if",
"len",
"(",
"ret",
")",
"==",
"0",
":",
"# if we had no matches then try case insensitively",
"text",
"=",
"text",
".",
"lower",
"(",
")",
"for",
"c",
"in",
"last_clist",
":",
"if",
"c",
".",
"lower",
"(",
")",
".",
"startswith",
"(",
"text",
")",
":",
"ret",
".",
"append",
"(",
"c",
")",
"ret",
".",
"append",
"(",
"None",
")",
"last_clist",
"=",
"ret",
"return",
"last_clist",
"[",
"state",
"]"
] |
completion routine for when user presses tab
|
[
"completion",
"routine",
"for",
"when",
"user",
"presses",
"tab"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/rline.py#L149-L180
|
235,350
|
JdeRobot/base
|
src/libs/comm_py/comm/ros/listenerLaser.py
|
laserScan2LaserData
|
def laserScan2LaserData(scan):
'''
Translates from ROS LaserScan to JderobotTypes LaserData.
@param scan: ROS LaserScan to translate
@type scan: LaserScan
@return a LaserData translated from scan
'''
laser = LaserData()
laser.values = scan.ranges
'''
ROS Angle Map JdeRobot Angle Map
0 PI/2
| |
| |
PI/2 --------- -PI/2 PI --------- 0
| |
| |
'''
laser.minAngle = scan.angle_min + PI/2
laser.maxAngle = scan.angle_max + PI/2
laser.maxRange = scan.range_max
laser.minRange = scan.range_min
laser.timeStamp = scan.header.stamp.secs + (scan.header.stamp.nsecs *1e-9)
return laser
|
python
|
def laserScan2LaserData(scan):
'''
Translates from ROS LaserScan to JderobotTypes LaserData.
@param scan: ROS LaserScan to translate
@type scan: LaserScan
@return a LaserData translated from scan
'''
laser = LaserData()
laser.values = scan.ranges
'''
ROS Angle Map JdeRobot Angle Map
0 PI/2
| |
| |
PI/2 --------- -PI/2 PI --------- 0
| |
| |
'''
laser.minAngle = scan.angle_min + PI/2
laser.maxAngle = scan.angle_max + PI/2
laser.maxRange = scan.range_max
laser.minRange = scan.range_min
laser.timeStamp = scan.header.stamp.secs + (scan.header.stamp.nsecs *1e-9)
return laser
|
[
"def",
"laserScan2LaserData",
"(",
"scan",
")",
":",
"laser",
"=",
"LaserData",
"(",
")",
"laser",
".",
"values",
"=",
"scan",
".",
"ranges",
"''' \n ROS Angle Map JdeRobot Angle Map\n 0 PI/2\n | |\n | |\n PI/2 --------- -PI/2 PI --------- 0\n | |\n | |\n '''",
"laser",
".",
"minAngle",
"=",
"scan",
".",
"angle_min",
"+",
"PI",
"/",
"2",
"laser",
".",
"maxAngle",
"=",
"scan",
".",
"angle_max",
"+",
"PI",
"/",
"2",
"laser",
".",
"maxRange",
"=",
"scan",
".",
"range_max",
"laser",
".",
"minRange",
"=",
"scan",
".",
"range_min",
"laser",
".",
"timeStamp",
"=",
"scan",
".",
"header",
".",
"stamp",
".",
"secs",
"+",
"(",
"scan",
".",
"header",
".",
"stamp",
".",
"nsecs",
"*",
"1e-9",
")",
"return",
"laser"
] |
Translates from ROS LaserScan to JderobotTypes LaserData.
@param scan: ROS LaserScan to translate
@type scan: LaserScan
@return a LaserData translated from scan
|
[
"Translates",
"from",
"ROS",
"LaserScan",
"to",
"JderobotTypes",
"LaserData",
"."
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/libs/comm_py/comm/ros/listenerLaser.py#L9-L36
|
235,351
|
JdeRobot/base
|
src/libs/comm_py/comm/ros/listenerLaser.py
|
ListenerLaser.__callback
|
def __callback (self, scan):
'''
Callback function to receive and save Laser Scans.
@param scan: ROS LaserScan received
@type scan: LaserScan
'''
laser = laserScan2LaserData(scan)
self.lock.acquire()
self.data = laser
self.lock.release()
|
python
|
def __callback (self, scan):
'''
Callback function to receive and save Laser Scans.
@param scan: ROS LaserScan received
@type scan: LaserScan
'''
laser = laserScan2LaserData(scan)
self.lock.acquire()
self.data = laser
self.lock.release()
|
[
"def",
"__callback",
"(",
"self",
",",
"scan",
")",
":",
"laser",
"=",
"laserScan2LaserData",
"(",
"scan",
")",
"self",
".",
"lock",
".",
"acquire",
"(",
")",
"self",
".",
"data",
"=",
"laser",
"self",
".",
"lock",
".",
"release",
"(",
")"
] |
Callback function to receive and save Laser Scans.
@param scan: ROS LaserScan received
@type scan: LaserScan
|
[
"Callback",
"function",
"to",
"receive",
"and",
"save",
"Laser",
"Scans",
"."
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/libs/comm_py/comm/ros/listenerLaser.py#L57-L70
|
235,352
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavkml.py
|
add_to_linestring
|
def add_to_linestring(position_data, kml_linestring):
'''add a point to the kml file'''
global kml
# add altitude offset
position_data[2] += float(args.aoff)
kml_linestring.coords.addcoordinates([position_data])
|
python
|
def add_to_linestring(position_data, kml_linestring):
'''add a point to the kml file'''
global kml
# add altitude offset
position_data[2] += float(args.aoff)
kml_linestring.coords.addcoordinates([position_data])
|
[
"def",
"add_to_linestring",
"(",
"position_data",
",",
"kml_linestring",
")",
":",
"global",
"kml",
"# add altitude offset",
"position_data",
"[",
"2",
"]",
"+=",
"float",
"(",
"args",
".",
"aoff",
")",
"kml_linestring",
".",
"coords",
".",
"addcoordinates",
"(",
"[",
"position_data",
"]",
")"
] |
add a point to the kml file
|
[
"add",
"a",
"point",
"to",
"the",
"kml",
"file"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavkml.py#L30-L36
|
235,353
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavkml.py
|
sniff_field_spelling
|
def sniff_field_spelling(mlog, source):
'''attempt to detect whether APM or PX4 attributes names are in use'''
position_field_type_default = position_field_types[0] # Default to PX4 spelling
msg = mlog.recv_match(source)
mlog._rewind() # Unfortunately it's either call this or return a mutated object
position_field_selection = [spelling for spelling in position_field_types if hasattr(msg, spelling[0])]
return position_field_selection[0] if position_field_selection else position_field_type_default
|
python
|
def sniff_field_spelling(mlog, source):
'''attempt to detect whether APM or PX4 attributes names are in use'''
position_field_type_default = position_field_types[0] # Default to PX4 spelling
msg = mlog.recv_match(source)
mlog._rewind() # Unfortunately it's either call this or return a mutated object
position_field_selection = [spelling for spelling in position_field_types if hasattr(msg, spelling[0])]
return position_field_selection[0] if position_field_selection else position_field_type_default
|
[
"def",
"sniff_field_spelling",
"(",
"mlog",
",",
"source",
")",
":",
"position_field_type_default",
"=",
"position_field_types",
"[",
"0",
"]",
"# Default to PX4 spelling",
"msg",
"=",
"mlog",
".",
"recv_match",
"(",
"source",
")",
"mlog",
".",
"_rewind",
"(",
")",
"# Unfortunately it's either call this or return a mutated object",
"position_field_selection",
"=",
"[",
"spelling",
"for",
"spelling",
"in",
"position_field_types",
"if",
"hasattr",
"(",
"msg",
",",
"spelling",
"[",
"0",
"]",
")",
"]",
"return",
"position_field_selection",
"[",
"0",
"]",
"if",
"position_field_selection",
"else",
"position_field_type_default"
] |
attempt to detect whether APM or PX4 attributes names are in use
|
[
"attempt",
"to",
"detect",
"whether",
"APM",
"or",
"PX4",
"attributes",
"names",
"are",
"in",
"use"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavkml.py#L153-L162
|
235,354
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_link.py
|
LinkModule.cmd_link_ports
|
def cmd_link_ports(self):
'''show available ports'''
ports = mavutil.auto_detect_serial(preferred_list=['*FTDI*',"*Arduino_Mega_2560*", "*3D_Robotics*", "*USB_to_UART*", '*PX4*', '*FMU*'])
for p in ports:
print("%s : %s : %s" % (p.device, p.description, p.hwid))
|
python
|
def cmd_link_ports(self):
'''show available ports'''
ports = mavutil.auto_detect_serial(preferred_list=['*FTDI*',"*Arduino_Mega_2560*", "*3D_Robotics*", "*USB_to_UART*", '*PX4*', '*FMU*'])
for p in ports:
print("%s : %s : %s" % (p.device, p.description, p.hwid))
|
[
"def",
"cmd_link_ports",
"(",
"self",
")",
":",
"ports",
"=",
"mavutil",
".",
"auto_detect_serial",
"(",
"preferred_list",
"=",
"[",
"'*FTDI*'",
",",
"\"*Arduino_Mega_2560*\"",
",",
"\"*3D_Robotics*\"",
",",
"\"*USB_to_UART*\"",
",",
"'*PX4*'",
",",
"'*FMU*'",
"]",
")",
"for",
"p",
"in",
"ports",
":",
"print",
"(",
"\"%s : %s : %s\"",
"%",
"(",
"p",
".",
"device",
",",
"p",
".",
"description",
",",
"p",
".",
"hwid",
")",
")"
] |
show available ports
|
[
"show",
"available",
"ports"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_link.py#L148-L152
|
235,355
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/textconsole.py
|
SimpleConsole.writeln
|
def writeln(self, text, fg='black', bg='white'):
'''write to the console with linefeed'''
if not isinstance(text, str):
text = str(text)
self.write(text + '\n', fg=fg, bg=bg)
|
python
|
def writeln(self, text, fg='black', bg='white'):
'''write to the console with linefeed'''
if not isinstance(text, str):
text = str(text)
self.write(text + '\n', fg=fg, bg=bg)
|
[
"def",
"writeln",
"(",
"self",
",",
"text",
",",
"fg",
"=",
"'black'",
",",
"bg",
"=",
"'white'",
")",
":",
"if",
"not",
"isinstance",
"(",
"text",
",",
"str",
")",
":",
"text",
"=",
"str",
"(",
"text",
")",
"self",
".",
"write",
"(",
"text",
"+",
"'\\n'",
",",
"fg",
"=",
"fg",
",",
"bg",
"=",
"bg",
")"
] |
write to the console with linefeed
|
[
"write",
"to",
"the",
"console",
"with",
"linefeed"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/textconsole.py#L29-L33
|
235,356
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/MPU6KSearch.py
|
match_extension
|
def match_extension(f):
'''see if the path matches a extension'''
(root,ext) = os.path.splitext(f)
return ext.lower() in extensions
|
python
|
def match_extension(f):
'''see if the path matches a extension'''
(root,ext) = os.path.splitext(f)
return ext.lower() in extensions
|
[
"def",
"match_extension",
"(",
"f",
")",
":",
"(",
"root",
",",
"ext",
")",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"f",
")",
"return",
"ext",
".",
"lower",
"(",
")",
"in",
"extensions"
] |
see if the path matches a extension
|
[
"see",
"if",
"the",
"path",
"matches",
"a",
"extension"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/MPU6KSearch.py#L139-L142
|
235,357
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_tile.py
|
TileInfo.path
|
def path(self):
'''return relative path of tile image'''
(x, y) = self.tile
return os.path.join('%u' % self.zoom,
'%u' % y,
'%u.img' % x)
|
python
|
def path(self):
'''return relative path of tile image'''
(x, y) = self.tile
return os.path.join('%u' % self.zoom,
'%u' % y,
'%u.img' % x)
|
[
"def",
"path",
"(",
"self",
")",
":",
"(",
"x",
",",
"y",
")",
"=",
"self",
".",
"tile",
"return",
"os",
".",
"path",
".",
"join",
"(",
"'%u'",
"%",
"self",
".",
"zoom",
",",
"'%u'",
"%",
"y",
",",
"'%u.img'",
"%",
"x",
")"
] |
return relative path of tile image
|
[
"return",
"relative",
"path",
"of",
"tile",
"image"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_tile.py#L133-L138
|
235,358
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_tile.py
|
TileInfo.url
|
def url(self, service):
'''return URL for a tile'''
if service not in TILE_SERVICES:
raise TileException('unknown tile service %s' % service)
url = string.Template(TILE_SERVICES[service])
(x,y) = self.tile
tile_info = TileServiceInfo(x, y, self.zoom)
return url.substitute(tile_info)
|
python
|
def url(self, service):
'''return URL for a tile'''
if service not in TILE_SERVICES:
raise TileException('unknown tile service %s' % service)
url = string.Template(TILE_SERVICES[service])
(x,y) = self.tile
tile_info = TileServiceInfo(x, y, self.zoom)
return url.substitute(tile_info)
|
[
"def",
"url",
"(",
"self",
",",
"service",
")",
":",
"if",
"service",
"not",
"in",
"TILE_SERVICES",
":",
"raise",
"TileException",
"(",
"'unknown tile service %s'",
"%",
"service",
")",
"url",
"=",
"string",
".",
"Template",
"(",
"TILE_SERVICES",
"[",
"service",
"]",
")",
"(",
"x",
",",
"y",
")",
"=",
"self",
".",
"tile",
"tile_info",
"=",
"TileServiceInfo",
"(",
"x",
",",
"y",
",",
"self",
".",
"zoom",
")",
"return",
"url",
".",
"substitute",
"(",
"tile_info",
")"
] |
return URL for a tile
|
[
"return",
"URL",
"for",
"a",
"tile"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_tile.py#L140-L147
|
235,359
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_tile.py
|
MPTile.tile_to_path
|
def tile_to_path(self, tile):
'''return full path to a tile'''
return os.path.join(self.cache_path, self.service, tile.path())
|
python
|
def tile_to_path(self, tile):
'''return full path to a tile'''
return os.path.join(self.cache_path, self.service, tile.path())
|
[
"def",
"tile_to_path",
"(",
"self",
",",
"tile",
")",
":",
"return",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"cache_path",
",",
"self",
".",
"service",
",",
"tile",
".",
"path",
"(",
")",
")"
] |
return full path to a tile
|
[
"return",
"full",
"path",
"to",
"a",
"tile"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_tile.py#L227-L229
|
235,360
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_tile.py
|
MPTile.start_download_thread
|
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
|
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()
|
[
"def",
"start_download_thread",
"(",
"self",
")",
":",
"if",
"self",
".",
"_download_thread",
":",
"return",
"t",
"=",
"threading",
".",
"Thread",
"(",
"target",
"=",
"self",
".",
"downloader",
")",
"t",
".",
"daemon",
"=",
"True",
"self",
".",
"_download_thread",
"=",
"t",
"t",
".",
"start",
"(",
")"
] |
start the downloader
|
[
"start",
"the",
"downloader"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_tile.py#L307-L314
|
235,361
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py
|
MiscModule.qnh_estimate
|
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_temp + 273.15
pressure1 = pressure2 / math.exp(math.log(1.0 - (alt_gps / (153.8462 * temp))) / 0.190259)
return pressure1
|
python
|
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_temp + 273.15
pressure1 = pressure2 / math.exp(math.log(1.0 - (alt_gps / (153.8462 * temp))) / 0.190259)
return pressure1
|
[
"def",
"qnh_estimate",
"(",
"self",
")",
":",
"alt_gps",
"=",
"self",
".",
"master",
".",
"field",
"(",
"'GPS_RAW_INT'",
",",
"'alt'",
",",
"0",
")",
"*",
"0.001",
"pressure2",
"=",
"self",
".",
"master",
".",
"field",
"(",
"'SCALED_PRESSURE'",
",",
"'press_abs'",
",",
"0",
")",
"ground_temp",
"=",
"self",
".",
"get_mav_param",
"(",
"'GND_TEMP'",
",",
"21",
")",
"temp",
"=",
"ground_temp",
"+",
"273.15",
"pressure1",
"=",
"pressure2",
"/",
"math",
".",
"exp",
"(",
"math",
".",
"log",
"(",
"1.0",
"-",
"(",
"alt_gps",
"/",
"(",
"153.8462",
"*",
"temp",
")",
")",
")",
"/",
"0.190259",
")",
"return",
"pressure1"
] |
estimate QNH pressure from GPS altitude and scaled pressure
|
[
"estimate",
"QNH",
"pressure",
"from",
"GPS",
"altitude",
"and",
"scaled",
"pressure"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py#L83-L90
|
235,362
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py
|
MiscModule.cmd_up
|
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!")
return
new_trim = int(old_trim + (adjust*100))
if math.fabs(new_trim - old_trim) > 1000:
print("Adjustment by %d too large (from %d to %d)" % (adjust*100, old_trim, new_trim))
return
print("Adjusting TRIM_PITCH_CD from %d to %d" % (old_trim, new_trim))
self.param_set('TRIM_PITCH_CD', new_trim)
|
python
|
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!")
return
new_trim = int(old_trim + (adjust*100))
if math.fabs(new_trim - old_trim) > 1000:
print("Adjustment by %d too large (from %d to %d)" % (adjust*100, old_trim, new_trim))
return
print("Adjusting TRIM_PITCH_CD from %d to %d" % (old_trim, new_trim))
self.param_set('TRIM_PITCH_CD', new_trim)
|
[
"def",
"cmd_up",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"adjust",
"=",
"5.0",
"else",
":",
"adjust",
"=",
"float",
"(",
"args",
"[",
"0",
"]",
")",
"old_trim",
"=",
"self",
".",
"get_mav_param",
"(",
"'TRIM_PITCH_CD'",
",",
"None",
")",
"if",
"old_trim",
"is",
"None",
":",
"print",
"(",
"\"Existing trim value unknown!\"",
")",
"return",
"new_trim",
"=",
"int",
"(",
"old_trim",
"+",
"(",
"adjust",
"*",
"100",
")",
")",
"if",
"math",
".",
"fabs",
"(",
"new_trim",
"-",
"old_trim",
")",
">",
"1000",
":",
"print",
"(",
"\"Adjustment by %d too large (from %d to %d)\"",
"%",
"(",
"adjust",
"*",
"100",
",",
"old_trim",
",",
"new_trim",
")",
")",
"return",
"print",
"(",
"\"Adjusting TRIM_PITCH_CD from %d to %d\"",
"%",
"(",
"old_trim",
",",
"new_trim",
")",
")",
"self",
".",
"param_set",
"(",
"'TRIM_PITCH_CD'",
",",
"new_trim",
")"
] |
adjust TRIM_PITCH_CD up by 5 degrees
|
[
"adjust",
"TRIM_PITCH_CD",
"up",
"by",
"5",
"degrees"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py#L107-L122
|
235,363
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py
|
MiscModule.cmd_time
|
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
|
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()))
|
[
"def",
"cmd_time",
"(",
"self",
",",
"args",
")",
":",
"tusec",
"=",
"self",
".",
"master",
".",
"field",
"(",
"'SYSTEM_TIME'",
",",
"'time_unix_usec'",
",",
"0",
")",
"if",
"tusec",
"==",
"0",
":",
"print",
"(",
"\"No SYSTEM_TIME time available\"",
")",
"return",
"print",
"(",
"\"%s (%s)\\n\"",
"%",
"(",
"time",
".",
"ctime",
"(",
"tusec",
"*",
"1.0e-6",
")",
",",
"time",
".",
"ctime",
"(",
")",
")",
")"
] |
show autopilot time
|
[
"show",
"autopilot",
"time"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py#L128-L134
|
235,364
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py
|
MiscModule.cmd_changealt
|
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.settings.target_component,
0,
3,
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
3, 1, 0, 0, 0, 0,
0, 0, relalt)
print("Sent change altitude command for %.1f meters" % relalt)
|
python
|
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.settings.target_component,
0,
3,
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
3, 1, 0, 0, 0, 0,
0, 0, relalt)
print("Sent change altitude command for %.1f meters" % relalt)
|
[
"def",
"cmd_changealt",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"1",
":",
"print",
"(",
"\"usage: changealt <relaltitude>\"",
")",
"return",
"relalt",
"=",
"float",
"(",
"args",
"[",
"0",
"]",
")",
"self",
".",
"master",
".",
"mav",
".",
"mission_item_send",
"(",
"self",
".",
"settings",
".",
"target_system",
",",
"self",
".",
"settings",
".",
"target_component",
",",
"0",
",",
"3",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_NAV_WAYPOINT",
",",
"3",
",",
"1",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"relalt",
")",
"print",
"(",
"\"Sent change altitude command for %.1f meters\"",
"%",
"relalt",
")"
] |
change target altitude
|
[
"change",
"target",
"altitude"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py#L136-L149
|
235,365
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py
|
MiscModule.cmd_land
|
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,
0, 0, 0, 0, 0, 0, 0, 0)
elif args[0] == 'abort':
self.master.mav.command_long_send(self.settings.target_system,
0,
mavutil.mavlink.MAV_CMD_DO_GO_AROUND,
0, 0, 0, 0, 0, 0, 0, 0)
else:
print("Usage: land [abort]")
|
python
|
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,
0, 0, 0, 0, 0, 0, 0, 0)
elif args[0] == 'abort':
self.master.mav.command_long_send(self.settings.target_system,
0,
mavutil.mavlink.MAV_CMD_DO_GO_AROUND,
0, 0, 0, 0, 0, 0, 0, 0)
else:
print("Usage: land [abort]")
|
[
"def",
"cmd_land",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"1",
":",
"self",
".",
"master",
".",
"mav",
".",
"command_long_send",
"(",
"self",
".",
"settings",
".",
"target_system",
",",
"0",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_DO_LAND_START",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"'abort'",
":",
"self",
".",
"master",
".",
"mav",
".",
"command_long_send",
"(",
"self",
".",
"settings",
".",
"target_system",
",",
"0",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_DO_GO_AROUND",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
"else",
":",
"print",
"(",
"\"Usage: land [abort]\"",
")"
] |
auto land commands
|
[
"auto",
"land",
"commands"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py#L151-L164
|
235,366
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py
|
MiscModule.cmd_rcbind
|
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,
mavutil.mavlink.MAV_CMD_START_RX_PAIR,
0,
float(args[0]), 0, 0, 0, 0, 0, 0)
|
python
|
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,
mavutil.mavlink.MAV_CMD_START_RX_PAIR,
0,
float(args[0]), 0, 0, 0, 0, 0, 0)
|
[
"def",
"cmd_rcbind",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"1",
":",
"print",
"(",
"\"Usage: rcbind <dsmmode>\"",
")",
"return",
"self",
".",
"master",
".",
"mav",
".",
"command_long_send",
"(",
"self",
".",
"settings",
".",
"target_system",
",",
"self",
".",
"settings",
".",
"target_component",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_START_RX_PAIR",
",",
"0",
",",
"float",
"(",
"args",
"[",
"0",
"]",
")",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
")"
] |
start RC bind
|
[
"start",
"RC",
"bind"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py#L174-L183
|
235,367
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py
|
MiscModule.cmd_repeat
|
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]))
return
if args[0] == 'add':
if len(args) < 3:
print("Usage: repeat add PERIOD CMD")
return
self.repeats.append(RepeatCommand(float(args[1]), " ".join(args[2:])))
elif args[0] == 'remove':
if len(args) < 2:
print("Usage: repeat remove INDEX")
return
i = int(args[1])
if i < 0 or i >= len(self.repeats):
print("Invalid index %d" % i)
return
self.repeats.pop(i)
return
elif args[0] == 'clean':
self.repeats = []
else:
print("Usage: repeat <add|remove|clean>")
|
python
|
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]))
return
if args[0] == 'add':
if len(args) < 3:
print("Usage: repeat add PERIOD CMD")
return
self.repeats.append(RepeatCommand(float(args[1]), " ".join(args[2:])))
elif args[0] == 'remove':
if len(args) < 2:
print("Usage: repeat remove INDEX")
return
i = int(args[1])
if i < 0 or i >= len(self.repeats):
print("Invalid index %d" % i)
return
self.repeats.pop(i)
return
elif args[0] == 'clean':
self.repeats = []
else:
print("Usage: repeat <add|remove|clean>")
|
[
"def",
"cmd_repeat",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"if",
"len",
"(",
"self",
".",
"repeats",
")",
"==",
"0",
":",
"print",
"(",
"\"No repeats\"",
")",
"return",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"repeats",
")",
")",
":",
"print",
"(",
"\"%u: %s\"",
"%",
"(",
"i",
",",
"self",
".",
"repeats",
"[",
"i",
"]",
")",
")",
"return",
"if",
"args",
"[",
"0",
"]",
"==",
"'add'",
":",
"if",
"len",
"(",
"args",
")",
"<",
"3",
":",
"print",
"(",
"\"Usage: repeat add PERIOD CMD\"",
")",
"return",
"self",
".",
"repeats",
".",
"append",
"(",
"RepeatCommand",
"(",
"float",
"(",
"args",
"[",
"1",
"]",
")",
",",
"\" \"",
".",
"join",
"(",
"args",
"[",
"2",
":",
"]",
")",
")",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"'remove'",
":",
"if",
"len",
"(",
"args",
")",
"<",
"2",
":",
"print",
"(",
"\"Usage: repeat remove INDEX\"",
")",
"return",
"i",
"=",
"int",
"(",
"args",
"[",
"1",
"]",
")",
"if",
"i",
"<",
"0",
"or",
"i",
">=",
"len",
"(",
"self",
".",
"repeats",
")",
":",
"print",
"(",
"\"Invalid index %d\"",
"%",
"i",
")",
"return",
"self",
".",
"repeats",
".",
"pop",
"(",
"i",
")",
"return",
"elif",
"args",
"[",
"0",
"]",
"==",
"'clean'",
":",
"self",
".",
"repeats",
"=",
"[",
"]",
"else",
":",
"print",
"(",
"\"Usage: repeat <add|remove|clean>\"",
")"
] |
repeat a command at regular intervals
|
[
"repeat",
"a",
"command",
"at",
"regular",
"intervals"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py#L185-L212
|
235,368
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py
|
MapModule.show_position
|
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" % (dms[0], dms[1])
msg += "Grid: %s\n" % mp_util.latlon_to_grid(pos)
if self.logdir:
logf = open(os.path.join(self.logdir, "positions.txt"), "a")
logf.write("Position: %.6f %.6f at %s\n" % (pos[0], pos[1], time.ctime()))
logf.close()
posbox = MPMenuChildMessageDialog('Position', msg, font_size=32)
posbox.show()
|
python
|
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" % (dms[0], dms[1])
msg += "Grid: %s\n" % mp_util.latlon_to_grid(pos)
if self.logdir:
logf = open(os.path.join(self.logdir, "positions.txt"), "a")
logf.write("Position: %.6f %.6f at %s\n" % (pos[0], pos[1], time.ctime()))
logf.close()
posbox = MPMenuChildMessageDialog('Position', msg, font_size=32)
posbox.show()
|
[
"def",
"show_position",
"(",
"self",
")",
":",
"pos",
"=",
"self",
".",
"click_position",
"dms",
"=",
"(",
"mp_util",
".",
"degrees_to_dms",
"(",
"pos",
"[",
"0",
"]",
")",
",",
"mp_util",
".",
"degrees_to_dms",
"(",
"pos",
"[",
"1",
"]",
")",
")",
"msg",
"=",
"\"Coordinates in WGS84\\n\"",
"msg",
"+=",
"\"Decimal: %.6f %.6f\\n\"",
"%",
"(",
"pos",
"[",
"0",
"]",
",",
"pos",
"[",
"1",
"]",
")",
"msg",
"+=",
"\"DMS: %s %s\\n\"",
"%",
"(",
"dms",
"[",
"0",
"]",
",",
"dms",
"[",
"1",
"]",
")",
"msg",
"+=",
"\"Grid: %s\\n\"",
"%",
"mp_util",
".",
"latlon_to_grid",
"(",
"pos",
")",
"if",
"self",
".",
"logdir",
":",
"logf",
"=",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"logdir",
",",
"\"positions.txt\"",
")",
",",
"\"a\"",
")",
"logf",
".",
"write",
"(",
"\"Position: %.6f %.6f at %s\\n\"",
"%",
"(",
"pos",
"[",
"0",
"]",
",",
"pos",
"[",
"1",
"]",
",",
"time",
".",
"ctime",
"(",
")",
")",
")",
"logf",
".",
"close",
"(",
")",
"posbox",
"=",
"MPMenuChildMessageDialog",
"(",
"'Position'",
",",
"msg",
",",
"font_size",
"=",
"32",
")",
"posbox",
".",
"show",
"(",
")"
] |
show map position click information
|
[
"show",
"map",
"position",
"click",
"information"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py#L79-L92
|
235,369
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py
|
MapModule.display_fence
|
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('Fence'))
if len(points) > 1:
popup = MPMenuSubMenu('Popup',
items=[MPMenuItem('FencePoint Remove', returnkey='popupFenceRemove'),
MPMenuItem('FencePoint Move', returnkey='popupFenceMove')])
self.mpstate.map.add_object(mp_slipmap.SlipPolygon('Fence', points, layer=1,
linewidth=2, colour=(0,255,0), popup_menu=popup))
|
python
|
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('Fence'))
if len(points) > 1:
popup = MPMenuSubMenu('Popup',
items=[MPMenuItem('FencePoint Remove', returnkey='popupFenceRemove'),
MPMenuItem('FencePoint Move', returnkey='popupFenceMove')])
self.mpstate.map.add_object(mp_slipmap.SlipPolygon('Fence', points, layer=1,
linewidth=2, colour=(0,255,0), popup_menu=popup))
|
[
"def",
"display_fence",
"(",
"self",
")",
":",
"from",
"MAVProxy",
".",
"modules",
".",
"mavproxy_map",
"import",
"mp_slipmap",
"self",
".",
"fence_change_time",
"=",
"self",
".",
"module",
"(",
"'fence'",
")",
".",
"fenceloader",
".",
"last_change",
"points",
"=",
"self",
".",
"module",
"(",
"'fence'",
")",
".",
"fenceloader",
".",
"polygon",
"(",
")",
"self",
".",
"mpstate",
".",
"map",
".",
"add_object",
"(",
"mp_slipmap",
".",
"SlipClearLayer",
"(",
"'Fence'",
")",
")",
"if",
"len",
"(",
"points",
")",
">",
"1",
":",
"popup",
"=",
"MPMenuSubMenu",
"(",
"'Popup'",
",",
"items",
"=",
"[",
"MPMenuItem",
"(",
"'FencePoint Remove'",
",",
"returnkey",
"=",
"'popupFenceRemove'",
")",
",",
"MPMenuItem",
"(",
"'FencePoint Move'",
",",
"returnkey",
"=",
"'popupFenceMove'",
")",
"]",
")",
"self",
".",
"mpstate",
".",
"map",
".",
"add_object",
"(",
"mp_slipmap",
".",
"SlipPolygon",
"(",
"'Fence'",
",",
"points",
",",
"layer",
"=",
"1",
",",
"linewidth",
"=",
"2",
",",
"colour",
"=",
"(",
"0",
",",
"255",
",",
"0",
")",
",",
"popup_menu",
"=",
"popup",
")",
")"
] |
display the fence
|
[
"display",
"the",
"fence"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py#L152-L163
|
235,370
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py
|
MapModule.closest_waypoint
|
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, lon, w.x, w.y)
if best_distance == -1 or distance < best_distance:
best_distance = distance
closest = i
if best_distance < 20:
return closest
else:
return -1
|
python
|
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, lon, w.x, w.y)
if best_distance == -1 or distance < best_distance:
best_distance = distance
closest = i
if best_distance < 20:
return closest
else:
return -1
|
[
"def",
"closest_waypoint",
"(",
"self",
",",
"latlon",
")",
":",
"(",
"lat",
",",
"lon",
")",
"=",
"latlon",
"best_distance",
"=",
"-",
"1",
"closest",
"=",
"-",
"1",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"module",
"(",
"'wp'",
")",
".",
"wploader",
".",
"count",
"(",
")",
")",
":",
"w",
"=",
"self",
".",
"module",
"(",
"'wp'",
")",
".",
"wploader",
".",
"wp",
"(",
"i",
")",
"distance",
"=",
"mp_util",
".",
"gps_distance",
"(",
"lat",
",",
"lon",
",",
"w",
".",
"x",
",",
"w",
".",
"y",
")",
"if",
"best_distance",
"==",
"-",
"1",
"or",
"distance",
"<",
"best_distance",
":",
"best_distance",
"=",
"distance",
"closest",
"=",
"i",
"if",
"best_distance",
"<",
"20",
":",
"return",
"closest",
"else",
":",
"return",
"-",
"1"
] |
find closest waypoint to a position
|
[
"find",
"closest",
"waypoint",
"to",
"a",
"position"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py#L166-L180
|
235,371
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py
|
MapModule.selection_index_to_idx
|
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(self.mission_list):
print("Bad mission index %s" % key)
return None
mlist = self.mission_list[midx]
if selection_index < 0 or selection_index >= len(mlist):
print("Bad mission polygon %s" % selection_index)
return None
idx = mlist[selection_index]
return idx
|
python
|
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(self.mission_list):
print("Bad mission index %s" % key)
return None
mlist = self.mission_list[midx]
if selection_index < 0 or selection_index >= len(mlist):
print("Bad mission polygon %s" % selection_index)
return None
idx = mlist[selection_index]
return idx
|
[
"def",
"selection_index_to_idx",
"(",
"self",
",",
"key",
",",
"selection_index",
")",
":",
"a",
"=",
"key",
".",
"split",
"(",
"' '",
")",
"if",
"a",
"[",
"0",
"]",
"!=",
"'mission'",
"or",
"len",
"(",
"a",
")",
"!=",
"2",
":",
"print",
"(",
"\"Bad mission object %s\"",
"%",
"key",
")",
"return",
"None",
"midx",
"=",
"int",
"(",
"a",
"[",
"1",
"]",
")",
"if",
"midx",
"<",
"0",
"or",
"midx",
">=",
"len",
"(",
"self",
".",
"mission_list",
")",
":",
"print",
"(",
"\"Bad mission index %s\"",
"%",
"key",
")",
"return",
"None",
"mlist",
"=",
"self",
".",
"mission_list",
"[",
"midx",
"]",
"if",
"selection_index",
"<",
"0",
"or",
"selection_index",
">=",
"len",
"(",
"mlist",
")",
":",
"print",
"(",
"\"Bad mission polygon %s\"",
"%",
"selection_index",
")",
"return",
"None",
"idx",
"=",
"mlist",
"[",
"selection_index",
"]",
"return",
"idx"
] |
return a mission idx from a selection_index
|
[
"return",
"a",
"mission",
"idx",
"from",
"a",
"selection_index"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py#L200-L215
|
235,372
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py
|
MapModule.move_mission
|
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
|
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)
|
[
"def",
"move_mission",
"(",
"self",
",",
"key",
",",
"selection_index",
")",
":",
"idx",
"=",
"self",
".",
"selection_index_to_idx",
"(",
"key",
",",
"selection_index",
")",
"self",
".",
"moving_wp",
"=",
"idx",
"print",
"(",
"\"Moving wp %u\"",
"%",
"idx",
")"
] |
move a mission point
|
[
"move",
"a",
"mission",
"point"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py#L217-L221
|
235,373
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py
|
MapModule.remove_mission
|
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
|
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)
|
[
"def",
"remove_mission",
"(",
"self",
",",
"key",
",",
"selection_index",
")",
":",
"idx",
"=",
"self",
".",
"selection_index_to_idx",
"(",
"key",
",",
"selection_index",
")",
"self",
".",
"mpstate",
".",
"functions",
".",
"process_stdin",
"(",
"'wp remove %u'",
"%",
"idx",
")"
] |
remove a mission point
|
[
"remove",
"a",
"mission",
"point"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py#L223-L226
|
235,374
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py
|
MapModule.create_vehicle_icon
|
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[name] == vehicle_type:
return
self.have_vehicle[name] = vehicle_type
icon = self.mpstate.map.icon(colour + vehicle_type + '.png')
self.mpstate.map.add_object(mp_slipmap.SlipIcon(name, (0,0), icon, layer=3, rotation=0, follow=follow,
trail=mp_slipmap.SlipTrail()))
|
python
|
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[name] == vehicle_type:
return
self.have_vehicle[name] = vehicle_type
icon = self.mpstate.map.icon(colour + vehicle_type + '.png')
self.mpstate.map.add_object(mp_slipmap.SlipIcon(name, (0,0), icon, layer=3, rotation=0, follow=follow,
trail=mp_slipmap.SlipTrail()))
|
[
"def",
"create_vehicle_icon",
"(",
"self",
",",
"name",
",",
"colour",
",",
"follow",
"=",
"False",
",",
"vehicle_type",
"=",
"None",
")",
":",
"from",
"MAVProxy",
".",
"modules",
".",
"mavproxy_map",
"import",
"mp_slipmap",
"if",
"vehicle_type",
"is",
"None",
":",
"vehicle_type",
"=",
"self",
".",
"vehicle_type_name",
"if",
"name",
"in",
"self",
".",
"have_vehicle",
"and",
"self",
".",
"have_vehicle",
"[",
"name",
"]",
"==",
"vehicle_type",
":",
"return",
"self",
".",
"have_vehicle",
"[",
"name",
"]",
"=",
"vehicle_type",
"icon",
"=",
"self",
".",
"mpstate",
".",
"map",
".",
"icon",
"(",
"colour",
"+",
"vehicle_type",
"+",
"'.png'",
")",
"self",
".",
"mpstate",
".",
"map",
".",
"add_object",
"(",
"mp_slipmap",
".",
"SlipIcon",
"(",
"name",
",",
"(",
"0",
",",
"0",
")",
",",
"icon",
",",
"layer",
"=",
"3",
",",
"rotation",
"=",
"0",
",",
"follow",
"=",
"follow",
",",
"trail",
"=",
"mp_slipmap",
".",
"SlipTrail",
"(",
")",
")",
")"
] |
add a vehicle to the map
|
[
"add",
"a",
"vehicle",
"to",
"the",
"map"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py#L338-L348
|
235,375
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py
|
MapModule.drawing_update
|
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.SlipPolygon('drawing', self.draw_line,
layer='Drawing', linewidth=2, colour=(128,128,255)))
|
python
|
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.SlipPolygon('drawing', self.draw_line,
layer='Drawing', linewidth=2, colour=(128,128,255)))
|
[
"def",
"drawing_update",
"(",
"self",
")",
":",
"from",
"MAVProxy",
".",
"modules",
".",
"mavproxy_map",
"import",
"mp_slipmap",
"if",
"self",
".",
"draw_callback",
"is",
"None",
":",
"return",
"self",
".",
"draw_line",
".",
"append",
"(",
"self",
".",
"click_position",
")",
"if",
"len",
"(",
"self",
".",
"draw_line",
")",
">",
"1",
":",
"self",
".",
"mpstate",
".",
"map",
".",
"add_object",
"(",
"mp_slipmap",
".",
"SlipPolygon",
"(",
"'drawing'",
",",
"self",
".",
"draw_line",
",",
"layer",
"=",
"'Drawing'",
",",
"linewidth",
"=",
"2",
",",
"colour",
"=",
"(",
"128",
",",
"128",
",",
"255",
")",
")",
")"
] |
update line drawing
|
[
"update",
"line",
"drawing"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/__init__.py#L350-L358
|
235,376
|
JdeRobot/base
|
src/libs/config_py/config/config.py
|
load
|
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))
with open(filepath, 'r') as stream:
cfg=yaml.load(stream)
prop = Properties(cfg)
else:
msg = "Ice.Config file '%s' could not being found" % (filename)
raise ValueError(msg)
return prop
|
python
|
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))
with open(filepath, 'r') as stream:
cfg=yaml.load(stream)
prop = Properties(cfg)
else:
msg = "Ice.Config file '%s' could not being found" % (filename)
raise ValueError(msg)
return prop
|
[
"def",
"load",
"(",
"filename",
")",
":",
"filepath",
"=",
"findConfigFile",
"(",
"filename",
")",
"prop",
"=",
"None",
"if",
"(",
"filepath",
")",
":",
"print",
"(",
"'loading Config file %s'",
"%",
"(",
"filepath",
")",
")",
"with",
"open",
"(",
"filepath",
",",
"'r'",
")",
"as",
"stream",
":",
"cfg",
"=",
"yaml",
".",
"load",
"(",
"stream",
")",
"prop",
"=",
"Properties",
"(",
"cfg",
")",
"else",
":",
"msg",
"=",
"\"Ice.Config file '%s' could not being found\"",
"%",
"(",
"filename",
")",
"raise",
"ValueError",
"(",
"msg",
")",
"return",
"prop"
] |
Returns the configuration as dict
@param filename: Name of the file
@type filename: String
@return a dict with propierties reader from file
|
[
"Returns",
"the",
"configuration",
"as",
"dict"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/libs/config_py/config/config.py#L50-L73
|
235,377
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_param.py
|
ParamState.fetch_check
|
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(self.mav_param_set) != self.mav_param_count:
if master.time_since('PARAM_VALUE') >= 1:
diff = set(range(self.mav_param_count)).difference(self.mav_param_set)
count = 0
while len(diff) > 0 and count < 10:
idx = diff.pop()
master.param_fetch_one(idx)
count += 1
|
python
|
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(self.mav_param_set) != self.mav_param_count:
if master.time_since('PARAM_VALUE') >= 1:
diff = set(range(self.mav_param_count)).difference(self.mav_param_set)
count = 0
while len(diff) > 0 and count < 10:
idx = diff.pop()
master.param_fetch_one(idx)
count += 1
|
[
"def",
"fetch_check",
"(",
"self",
",",
"master",
")",
":",
"if",
"self",
".",
"param_period",
".",
"trigger",
"(",
")",
":",
"if",
"master",
"is",
"None",
":",
"return",
"if",
"len",
"(",
"self",
".",
"mav_param_set",
")",
"==",
"0",
":",
"master",
".",
"param_fetch_all",
"(",
")",
"elif",
"self",
".",
"mav_param_count",
"!=",
"0",
"and",
"len",
"(",
"self",
".",
"mav_param_set",
")",
"!=",
"self",
".",
"mav_param_count",
":",
"if",
"master",
".",
"time_since",
"(",
"'PARAM_VALUE'",
")",
">=",
"1",
":",
"diff",
"=",
"set",
"(",
"range",
"(",
"self",
".",
"mav_param_count",
")",
")",
".",
"difference",
"(",
"self",
".",
"mav_param_set",
")",
"count",
"=",
"0",
"while",
"len",
"(",
"diff",
")",
">",
"0",
"and",
"count",
"<",
"10",
":",
"idx",
"=",
"diff",
".",
"pop",
"(",
")",
"master",
".",
"param_fetch_one",
"(",
"idx",
")",
"count",
"+=",
"1"
] |
check for missing parameters periodically
|
[
"check",
"for",
"missing",
"parameters",
"periodically"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_param.py#L46-L60
|
235,378
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/wxsettings.py
|
WXSettings.watch_thread
|
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, setting.value)
except Exception:
print("Unable to set %s to %s" % (setting.name, setting.value))
|
python
|
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, setting.value)
except Exception:
print("Unable to set %s to %s" % (setting.name, setting.value))
|
[
"def",
"watch_thread",
"(",
"self",
")",
":",
"from",
"mp_settings",
"import",
"MPSetting",
"while",
"True",
":",
"setting",
"=",
"self",
".",
"child_pipe",
".",
"recv",
"(",
")",
"if",
"not",
"isinstance",
"(",
"setting",
",",
"MPSetting",
")",
":",
"break",
"try",
":",
"self",
".",
"settings",
".",
"set",
"(",
"setting",
".",
"name",
",",
"setting",
".",
"value",
")",
"except",
"Exception",
":",
"print",
"(",
"\"Unable to set %s to %s\"",
"%",
"(",
"setting",
".",
"name",
",",
"setting",
".",
"value",
")",
")"
] |
watch for settings changes from child
|
[
"watch",
"for",
"settings",
"changes",
"from",
"child"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/wxsettings.py#L36-L46
|
235,379
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_sensors.py
|
SensorsModule.report
|
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 = ok
if not r.ok:
self.say(msg)
|
python
|
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 = ok
if not r.ok:
self.say(msg)
|
[
"def",
"report",
"(",
"self",
",",
"name",
",",
"ok",
",",
"msg",
"=",
"None",
",",
"deltat",
"=",
"20",
")",
":",
"r",
"=",
"self",
".",
"reports",
"[",
"name",
"]",
"if",
"time",
".",
"time",
"(",
")",
"<",
"r",
".",
"last_report",
"+",
"deltat",
":",
"r",
".",
"ok",
"=",
"ok",
"return",
"r",
".",
"last_report",
"=",
"time",
".",
"time",
"(",
")",
"if",
"ok",
"and",
"not",
"r",
".",
"ok",
":",
"self",
".",
"say",
"(",
"\"%s OK\"",
"%",
"name",
")",
"r",
".",
"ok",
"=",
"ok",
"if",
"not",
"r",
".",
"ok",
":",
"self",
".",
"say",
"(",
"msg",
")"
] |
report a sensor error
|
[
"report",
"a",
"sensor",
"error"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_sensors.py#L82-L93
|
235,380
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_sensors.py
|
SensorsModule.report_change
|
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 = value
self.say("%s %u" % (name, value))
|
python
|
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 = value
self.say("%s %u" % (name, value))
|
[
"def",
"report_change",
"(",
"self",
",",
"name",
",",
"value",
",",
"maxdiff",
"=",
"1",
",",
"deltat",
"=",
"10",
")",
":",
"r",
"=",
"self",
".",
"reports",
"[",
"name",
"]",
"if",
"time",
".",
"time",
"(",
")",
"<",
"r",
".",
"last_report",
"+",
"deltat",
":",
"return",
"r",
".",
"last_report",
"=",
"time",
".",
"time",
"(",
")",
"if",
"math",
".",
"fabs",
"(",
"r",
".",
"value",
"-",
"value",
")",
"<",
"maxdiff",
":",
"return",
"r",
".",
"value",
"=",
"value",
"self",
".",
"say",
"(",
"\"%s %u\"",
"%",
"(",
"name",
",",
"value",
")",
")"
] |
report a sensor change
|
[
"report",
"a",
"sensor",
"change"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_sensors.py#L95-L104
|
235,381
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_slipmap.py
|
MPSlipMap.close
|
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
|
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()
|
[
"def",
"close",
"(",
"self",
")",
":",
"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",
"(",
")"
] |
close the window
|
[
"close",
"the",
"window"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_slipmap.py#L97-L108
|
235,382
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_slipmap.py
|
MPSlipMap.hide_object
|
def hide_object(self, key, hide=True):
'''hide an object on the map by key'''
self.object_queue.put(SlipHideObject(key, hide))
|
python
|
def hide_object(self, key, hide=True):
'''hide an object on the map by key'''
self.object_queue.put(SlipHideObject(key, hide))
|
[
"def",
"hide_object",
"(",
"self",
",",
"key",
",",
"hide",
"=",
"True",
")",
":",
"self",
".",
"object_queue",
".",
"put",
"(",
"SlipHideObject",
"(",
"key",
",",
"hide",
")",
")"
] |
hide an object on the map by key
|
[
"hide",
"an",
"object",
"on",
"the",
"map",
"by",
"key"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_slipmap.py#L122-L124
|
235,383
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_slipmap.py
|
MPSlipMap.set_position
|
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
|
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))
|
[
"def",
"set_position",
"(",
"self",
",",
"key",
",",
"latlon",
",",
"layer",
"=",
"None",
",",
"rotation",
"=",
"0",
")",
":",
"self",
".",
"object_queue",
".",
"put",
"(",
"SlipPosition",
"(",
"key",
",",
"latlon",
",",
"layer",
",",
"rotation",
")",
")"
] |
move an object on the map
|
[
"move",
"an",
"object",
"on",
"the",
"map"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_slipmap.py#L126-L128
|
235,384
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_slipmap.py
|
MPSlipMap.check_events
|
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
|
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)
|
[
"def",
"check_events",
"(",
"self",
")",
":",
"while",
"self",
".",
"event_count",
"(",
")",
">",
"0",
":",
"event",
"=",
"self",
".",
"get_event",
"(",
")",
"for",
"callback",
"in",
"self",
".",
"_callbacks",
":",
"callback",
"(",
"event",
")"
] |
check for events, calling registered callbacks as needed
|
[
"check",
"for",
"events",
"calling",
"registered",
"callbacks",
"as",
"needed"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/mp_slipmap.py#L144-L149
|
235,385
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit.py
|
radius_cmp
|
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
|
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
|
[
"def",
"radius_cmp",
"(",
"a",
",",
"b",
",",
"offsets",
")",
":",
"diff",
"=",
"radius",
"(",
"a",
",",
"offsets",
")",
"-",
"radius",
"(",
"b",
",",
"offsets",
")",
"if",
"diff",
">",
"0",
":",
"return",
"1",
"if",
"diff",
"<",
"0",
":",
"return",
"-",
"1",
"return",
"0"
] |
return +1 or -1 for for sorting
|
[
"return",
"+",
"1",
"or",
"-",
"1",
"for",
"for",
"sorting"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit.py#L51-L58
|
235,386
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit.py
|
plot_data
|
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 dd ]
ys = [ d.y for d in dd ]
zs = [ d.z for d in dd ]
ax.scatter(xs, ys, zs, c=c, marker='o')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()
|
python
|
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 dd ]
ys = [ d.y for d in dd ]
zs = [ d.z for d in dd ]
ax.scatter(xs, ys, zs, c=c, marker='o')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()
|
[
"def",
"plot_data",
"(",
"orig_data",
",",
"data",
")",
":",
"import",
"numpy",
"as",
"np",
"from",
"mpl_toolkits",
".",
"mplot3d",
"import",
"Axes3D",
"import",
"matplotlib",
".",
"pyplot",
"as",
"plt",
"for",
"dd",
",",
"c",
"in",
"[",
"(",
"orig_data",
",",
"'r'",
")",
",",
"(",
"data",
",",
"'b'",
")",
"]",
":",
"fig",
"=",
"plt",
".",
"figure",
"(",
")",
"ax",
"=",
"fig",
".",
"add_subplot",
"(",
"111",
",",
"projection",
"=",
"'3d'",
")",
"xs",
"=",
"[",
"d",
".",
"x",
"for",
"d",
"in",
"dd",
"]",
"ys",
"=",
"[",
"d",
".",
"y",
"for",
"d",
"in",
"dd",
"]",
"zs",
"=",
"[",
"d",
".",
"z",
"for",
"d",
"in",
"dd",
"]",
"ax",
".",
"scatter",
"(",
"xs",
",",
"ys",
",",
"zs",
",",
"c",
"=",
"c",
",",
"marker",
"=",
"'o'",
")",
"ax",
".",
"set_xlabel",
"(",
"'X Label'",
")",
"ax",
".",
"set_ylabel",
"(",
"'Y Label'",
")",
"ax",
".",
"set_zlabel",
"(",
"'Z Label'",
")",
"plt",
".",
"show",
"(",
")"
] |
plot data in 3D
|
[
"plot",
"data",
"in",
"3D"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit.py#L154-L172
|
235,387
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavtemplate.py
|
MAVTemplate.find_end
|
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_token)
nesting = 1
while nesting > 0:
idx1 = text[offset:].find(start_token)
idx2 = text[offset:].find(end_token)
# Check for false positives due to another similar token
# For example, make sure idx2 points to the second '}' in ${{field: ${name}}}
if ignore_end_token:
combined_token = ignore_end_token + end_token
if text[offset+idx2:offset+idx2+len(combined_token)] == combined_token:
idx2 += len(ignore_end_token)
if idx1 == -1 and idx2 == -1:
raise MAVParseError("token nesting error")
if idx1 == -1 or idx1 > idx2:
offset += idx2 + len(end_token)
nesting -= 1
else:
offset += idx1 + len(start_token)
nesting += 1
return offset
|
python
|
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_token)
nesting = 1
while nesting > 0:
idx1 = text[offset:].find(start_token)
idx2 = text[offset:].find(end_token)
# Check for false positives due to another similar token
# For example, make sure idx2 points to the second '}' in ${{field: ${name}}}
if ignore_end_token:
combined_token = ignore_end_token + end_token
if text[offset+idx2:offset+idx2+len(combined_token)] == combined_token:
idx2 += len(ignore_end_token)
if idx1 == -1 and idx2 == -1:
raise MAVParseError("token nesting error")
if idx1 == -1 or idx1 > idx2:
offset += idx2 + len(end_token)
nesting -= 1
else:
offset += idx1 + len(start_token)
nesting += 1
return offset
|
[
"def",
"find_end",
"(",
"self",
",",
"text",
",",
"start_token",
",",
"end_token",
",",
"ignore_end_token",
"=",
"None",
")",
":",
"if",
"not",
"text",
".",
"startswith",
"(",
"start_token",
")",
":",
"raise",
"MAVParseError",
"(",
"\"invalid token start\"",
")",
"offset",
"=",
"len",
"(",
"start_token",
")",
"nesting",
"=",
"1",
"while",
"nesting",
">",
"0",
":",
"idx1",
"=",
"text",
"[",
"offset",
":",
"]",
".",
"find",
"(",
"start_token",
")",
"idx2",
"=",
"text",
"[",
"offset",
":",
"]",
".",
"find",
"(",
"end_token",
")",
"# Check for false positives due to another similar token",
"# For example, make sure idx2 points to the second '}' in ${{field: ${name}}}",
"if",
"ignore_end_token",
":",
"combined_token",
"=",
"ignore_end_token",
"+",
"end_token",
"if",
"text",
"[",
"offset",
"+",
"idx2",
":",
"offset",
"+",
"idx2",
"+",
"len",
"(",
"combined_token",
")",
"]",
"==",
"combined_token",
":",
"idx2",
"+=",
"len",
"(",
"ignore_end_token",
")",
"if",
"idx1",
"==",
"-",
"1",
"and",
"idx2",
"==",
"-",
"1",
":",
"raise",
"MAVParseError",
"(",
"\"token nesting error\"",
")",
"if",
"idx1",
"==",
"-",
"1",
"or",
"idx1",
">",
"idx2",
":",
"offset",
"+=",
"idx2",
"+",
"len",
"(",
"end_token",
")",
"nesting",
"-=",
"1",
"else",
":",
"offset",
"+=",
"idx1",
"+",
"len",
"(",
"start_token",
")",
"nesting",
"+=",
"1",
"return",
"offset"
] |
find the of a token.
Returns the offset in the string immediately after the matching end_token
|
[
"find",
"the",
"of",
"a",
"token",
".",
"Returns",
"the",
"offset",
"in",
"the",
"string",
"immediately",
"after",
"the",
"matching",
"end_token"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavtemplate.py#L27-L51
|
235,388
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavtemplate.py
|
MAVTemplate.find_var_end
|
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
|
def find_var_end(self, text):
'''find the of a variable'''
return self.find_end(text, self.start_var_token, self.end_var_token)
|
[
"def",
"find_var_end",
"(",
"self",
",",
"text",
")",
":",
"return",
"self",
".",
"find_end",
"(",
"text",
",",
"self",
".",
"start_var_token",
",",
"self",
".",
"end_var_token",
")"
] |
find the of a variable
|
[
"find",
"the",
"of",
"a",
"variable"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavtemplate.py#L53-L55
|
235,389
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavtemplate.py
|
MAVTemplate.find_rep_end
|
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
|
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)
|
[
"def",
"find_rep_end",
"(",
"self",
",",
"text",
")",
":",
"return",
"self",
".",
"find_end",
"(",
"text",
",",
"self",
".",
"start_rep_token",
",",
"self",
".",
"end_rep_token",
",",
"ignore_end_token",
"=",
"self",
".",
"end_var_token",
")"
] |
find the of a repitition
|
[
"find",
"the",
"of",
"a",
"repitition"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavtemplate.py#L57-L59
|
235,390
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavtemplate.py
|
MAVTemplate.write
|
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
|
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))
|
[
"def",
"write",
"(",
"self",
",",
"file",
",",
"text",
",",
"subvars",
"=",
"{",
"}",
",",
"trim_leading_lf",
"=",
"True",
")",
":",
"file",
".",
"write",
"(",
"self",
".",
"substitute",
"(",
"text",
",",
"subvars",
"=",
"subvars",
",",
"trim_leading_lf",
"=",
"trim_leading_lf",
")",
")"
] |
write to a file with variable substitution
|
[
"write",
"to",
"a",
"file",
"with",
"variable",
"substitution"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavtemplate.py#L129-L131
|
235,391
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavflighttime.py
|
flight_time
|
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:
m = mlog.recv_match(type=['GPS','GPS_RAW_INT'], condition=args.condition)
if m is None:
if in_air:
total_time += time.mktime(t) - start_time
if total_time > 0:
print("Flight time : %u:%02u" % (int(total_time)/60, int(total_time)%60))
return (total_time, total_dist)
if m.get_type() == 'GPS_RAW_INT':
groundspeed = m.vel*0.01
status = m.fix_type
time_usec = m.time_usec
else:
groundspeed = m.Spd
status = m.Status
time_usec = m.TimeUS
if status < 3:
continue
t = time.localtime(m._timestamp)
if groundspeed > args.groundspeed and not in_air:
print("In air at %s (percent %.0f%% groundspeed %.1f)" % (time.asctime(t), mlog.percent, groundspeed))
in_air = True
start_time = time.mktime(t)
elif groundspeed < args.groundspeed and in_air:
print("On ground at %s (percent %.1f%% groundspeed %.1f time=%.1f seconds)" % (
time.asctime(t), mlog.percent, groundspeed, time.mktime(t) - start_time))
in_air = False
total_time += time.mktime(t) - start_time
if last_msg is None or time_usec > last_time_usec or time_usec+30e6 < last_time_usec:
if last_msg is not None:
total_dist += distance_two(last_msg, m)
last_msg = m
last_time_usec = time_usec
return (total_time, total_dist)
|
python
|
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:
m = mlog.recv_match(type=['GPS','GPS_RAW_INT'], condition=args.condition)
if m is None:
if in_air:
total_time += time.mktime(t) - start_time
if total_time > 0:
print("Flight time : %u:%02u" % (int(total_time)/60, int(total_time)%60))
return (total_time, total_dist)
if m.get_type() == 'GPS_RAW_INT':
groundspeed = m.vel*0.01
status = m.fix_type
time_usec = m.time_usec
else:
groundspeed = m.Spd
status = m.Status
time_usec = m.TimeUS
if status < 3:
continue
t = time.localtime(m._timestamp)
if groundspeed > args.groundspeed and not in_air:
print("In air at %s (percent %.0f%% groundspeed %.1f)" % (time.asctime(t), mlog.percent, groundspeed))
in_air = True
start_time = time.mktime(t)
elif groundspeed < args.groundspeed and in_air:
print("On ground at %s (percent %.1f%% groundspeed %.1f time=%.1f seconds)" % (
time.asctime(t), mlog.percent, groundspeed, time.mktime(t) - start_time))
in_air = False
total_time += time.mktime(t) - start_time
if last_msg is None or time_usec > last_time_usec or time_usec+30e6 < last_time_usec:
if last_msg is not None:
total_dist += distance_two(last_msg, m)
last_msg = m
last_time_usec = time_usec
return (total_time, total_dist)
|
[
"def",
"flight_time",
"(",
"logfile",
")",
":",
"print",
"(",
"\"Processing log %s\"",
"%",
"filename",
")",
"mlog",
"=",
"mavutil",
".",
"mavlink_connection",
"(",
"filename",
")",
"in_air",
"=",
"False",
"start_time",
"=",
"0.0",
"total_time",
"=",
"0.0",
"total_dist",
"=",
"0.0",
"t",
"=",
"None",
"last_msg",
"=",
"None",
"last_time_usec",
"=",
"None",
"while",
"True",
":",
"m",
"=",
"mlog",
".",
"recv_match",
"(",
"type",
"=",
"[",
"'GPS'",
",",
"'GPS_RAW_INT'",
"]",
",",
"condition",
"=",
"args",
".",
"condition",
")",
"if",
"m",
"is",
"None",
":",
"if",
"in_air",
":",
"total_time",
"+=",
"time",
".",
"mktime",
"(",
"t",
")",
"-",
"start_time",
"if",
"total_time",
">",
"0",
":",
"print",
"(",
"\"Flight time : %u:%02u\"",
"%",
"(",
"int",
"(",
"total_time",
")",
"/",
"60",
",",
"int",
"(",
"total_time",
")",
"%",
"60",
")",
")",
"return",
"(",
"total_time",
",",
"total_dist",
")",
"if",
"m",
".",
"get_type",
"(",
")",
"==",
"'GPS_RAW_INT'",
":",
"groundspeed",
"=",
"m",
".",
"vel",
"*",
"0.01",
"status",
"=",
"m",
".",
"fix_type",
"time_usec",
"=",
"m",
".",
"time_usec",
"else",
":",
"groundspeed",
"=",
"m",
".",
"Spd",
"status",
"=",
"m",
".",
"Status",
"time_usec",
"=",
"m",
".",
"TimeUS",
"if",
"status",
"<",
"3",
":",
"continue",
"t",
"=",
"time",
".",
"localtime",
"(",
"m",
".",
"_timestamp",
")",
"if",
"groundspeed",
">",
"args",
".",
"groundspeed",
"and",
"not",
"in_air",
":",
"print",
"(",
"\"In air at %s (percent %.0f%% groundspeed %.1f)\"",
"%",
"(",
"time",
".",
"asctime",
"(",
"t",
")",
",",
"mlog",
".",
"percent",
",",
"groundspeed",
")",
")",
"in_air",
"=",
"True",
"start_time",
"=",
"time",
".",
"mktime",
"(",
"t",
")",
"elif",
"groundspeed",
"<",
"args",
".",
"groundspeed",
"and",
"in_air",
":",
"print",
"(",
"\"On ground at %s (percent %.1f%% groundspeed %.1f time=%.1f seconds)\"",
"%",
"(",
"time",
".",
"asctime",
"(",
"t",
")",
",",
"mlog",
".",
"percent",
",",
"groundspeed",
",",
"time",
".",
"mktime",
"(",
"t",
")",
"-",
"start_time",
")",
")",
"in_air",
"=",
"False",
"total_time",
"+=",
"time",
".",
"mktime",
"(",
"t",
")",
"-",
"start_time",
"if",
"last_msg",
"is",
"None",
"or",
"time_usec",
">",
"last_time_usec",
"or",
"time_usec",
"+",
"30e6",
"<",
"last_time_usec",
":",
"if",
"last_msg",
"is",
"not",
"None",
":",
"total_dist",
"+=",
"distance_two",
"(",
"last_msg",
",",
"m",
")",
"last_msg",
"=",
"m",
"last_time_usec",
"=",
"time_usec",
"return",
"(",
"total_time",
",",
"total_dist",
")"
] |
work out flight time for a log file
|
[
"work",
"out",
"flight",
"time",
"for",
"a",
"log",
"file"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavflighttime.py#L21-L68
|
235,392
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavlogdump.py
|
match_type
|
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
|
def match_type(mtype, patterns):
'''return True if mtype matches pattern'''
for p in patterns:
if fnmatch.fnmatch(mtype, p):
return True
return False
|
[
"def",
"match_type",
"(",
"mtype",
",",
"patterns",
")",
":",
"for",
"p",
"in",
"patterns",
":",
"if",
"fnmatch",
".",
"fnmatch",
"(",
"mtype",
",",
"p",
")",
":",
"return",
"True",
"return",
"False"
] |
return True if mtype matches pattern
|
[
"return",
"True",
"if",
"mtype",
"matches",
"pattern"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavlogdump.py#L74-L79
|
235,393
|
JdeRobot/base
|
src/tools/colorTuner_py/filters/yuvFilter.py
|
YuvFilter.apply
|
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,vdwn],dtype=np.uint8)
maxValues = np.array([yup,uup,vup], dtype=np.uint8)
mask = cv2.inRange(yuv, minValues, maxValues)
res = cv2.bitwise_and(img,img, mask= mask)
return res
|
python
|
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,vdwn],dtype=np.uint8)
maxValues = np.array([yup,uup,vup], dtype=np.uint8)
mask = cv2.inRange(yuv, minValues, maxValues)
res = cv2.bitwise_and(img,img, mask= mask)
return res
|
[
"def",
"apply",
"(",
"self",
",",
"img",
")",
":",
"yup",
",",
"uup",
",",
"vup",
"=",
"self",
".",
"getUpLimit",
"(",
")",
"ydwn",
",",
"udwn",
",",
"vdwn",
"=",
"self",
".",
"getDownLimit",
"(",
")",
"yuv",
"=",
"cv2",
".",
"cvtColor",
"(",
"img",
",",
"cv2",
".",
"COLOR_BGR2YUV",
")",
"minValues",
"=",
"np",
".",
"array",
"(",
"[",
"ydwn",
",",
"udwn",
",",
"vdwn",
"]",
",",
"dtype",
"=",
"np",
".",
"uint8",
")",
"maxValues",
"=",
"np",
".",
"array",
"(",
"[",
"yup",
",",
"uup",
",",
"vup",
"]",
",",
"dtype",
"=",
"np",
".",
"uint8",
")",
"mask",
"=",
"cv2",
".",
"inRange",
"(",
"yuv",
",",
"minValues",
",",
"maxValues",
")",
"res",
"=",
"cv2",
".",
"bitwise_and",
"(",
"img",
",",
"img",
",",
"mask",
"=",
"mask",
")",
"return",
"res"
] |
We convert RGB as BGR because OpenCV
with RGB pass to YVU instead of YUV
|
[
"We",
"convert",
"RGB",
"as",
"BGR",
"because",
"OpenCV",
"with",
"RGB",
"pass",
"to",
"YVU",
"instead",
"of",
"YUV"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/tools/colorTuner_py/filters/yuvFilter.py#L57-L76
|
235,394
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/modules/lib/wxconsole_ui.py
|
ConsoleFrame.on_menu
|
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
|
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)
|
[
"def",
"on_menu",
"(",
"self",
",",
"event",
")",
":",
"state",
"=",
"self",
".",
"state",
"ret",
"=",
"self",
".",
"menu",
".",
"find_selected",
"(",
"event",
")",
"if",
"ret",
"is",
"None",
":",
"return",
"ret",
".",
"call_handler",
"(",
")",
"state",
".",
"child_pipe_send",
".",
"send",
"(",
"ret",
")"
] |
handle menu selections
|
[
"handle",
"menu",
"selections"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/wxconsole_ui.py#L43-L50
|
235,395
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/dialects/v10/ASLUAV.py
|
MAVLink.aslctrl_data_encode
|
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
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)
hRef : (float)
hRef_t : (float)
PitchAngle : Pitch angle [deg] (float)
PitchAngleRef : Pitch angle reference[deg] (float)
q : (float)
qRef : (float)
uElev : (float)
uThrot : (float)
uThrot2 : (float)
nZ : (float)
AirspeedRef : Airspeed reference [m/s] (float)
SpoilersEngaged : (uint8_t)
YawAngle : Yaw angle [deg] (float)
YawAngleRef : Yaw angle reference[deg] (float)
RollAngle : Roll angle [deg] (float)
RollAngleRef : Roll angle reference[deg] (float)
p : (float)
pRef : (float)
r : (float)
rRef : (float)
uAil : (float)
uRud : (float)
'''
return MAVLink_aslctrl_data_message(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)
|
python
|
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
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)
hRef : (float)
hRef_t : (float)
PitchAngle : Pitch angle [deg] (float)
PitchAngleRef : Pitch angle reference[deg] (float)
q : (float)
qRef : (float)
uElev : (float)
uThrot : (float)
uThrot2 : (float)
nZ : (float)
AirspeedRef : Airspeed reference [m/s] (float)
SpoilersEngaged : (uint8_t)
YawAngle : Yaw angle [deg] (float)
YawAngleRef : Yaw angle reference[deg] (float)
RollAngle : Roll angle [deg] (float)
RollAngleRef : Roll angle reference[deg] (float)
p : (float)
pRef : (float)
r : (float)
rRef : (float)
uAil : (float)
uRud : (float)
'''
return MAVLink_aslctrl_data_message(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)
|
[
"def",
"aslctrl_data_encode",
"(",
"self",
",",
"timestamp",
",",
"aslctrl_mode",
",",
"h",
",",
"hRef",
",",
"hRef_t",
",",
"PitchAngle",
",",
"PitchAngleRef",
",",
"q",
",",
"qRef",
",",
"uElev",
",",
"uThrot",
",",
"uThrot2",
",",
"nZ",
",",
"AirspeedRef",
",",
"SpoilersEngaged",
",",
"YawAngle",
",",
"YawAngleRef",
",",
"RollAngle",
",",
"RollAngleRef",
",",
"p",
",",
"pRef",
",",
"r",
",",
"rRef",
",",
"uAil",
",",
"uRud",
")",
":",
"return",
"MAVLink_aslctrl_data_message",
"(",
"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
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)
hRef : (float)
hRef_t : (float)
PitchAngle : Pitch angle [deg] (float)
PitchAngleRef : Pitch angle reference[deg] (float)
q : (float)
qRef : (float)
uElev : (float)
uThrot : (float)
uThrot2 : (float)
nZ : (float)
AirspeedRef : Airspeed reference [m/s] (float)
SpoilersEngaged : (uint8_t)
YawAngle : Yaw angle [deg] (float)
YawAngleRef : Yaw angle reference[deg] (float)
RollAngle : Roll angle [deg] (float)
RollAngleRef : Roll angle reference[deg] (float)
p : (float)
pRef : (float)
r : (float)
rRef : (float)
uAil : (float)
uRud : (float)
|
[
"ASL",
"-",
"fixed",
"-",
"wing",
"controller",
"data"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/dialects/v10/ASLUAV.py#L7653-L7684
|
235,396
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py
|
average
|
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
|
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
|
[
"def",
"average",
"(",
"var",
",",
"key",
",",
"N",
")",
":",
"global",
"average_data",
"if",
"not",
"key",
"in",
"average_data",
":",
"average_data",
"[",
"key",
"]",
"=",
"[",
"var",
"]",
"*",
"N",
"return",
"var",
"average_data",
"[",
"key",
"]",
".",
"pop",
"(",
"0",
")",
"average_data",
"[",
"key",
"]",
".",
"append",
"(",
"var",
")",
"return",
"sum",
"(",
"average_data",
"[",
"key",
"]",
")",
"/",
"N"
] |
average over N points
|
[
"average",
"over",
"N",
"points"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L170-L178
|
235,397
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py
|
second_derivative_5
|
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)
data.append(var)
derivative_data[key] = (tnow, data)
h = (tnow - last_time)
# N=5 2nd derivative from
# http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/smooth-low-noise-differentiators/
ret = ((data[4] + data[0]) - 2*data[2]) / (4*h**2)
return ret
|
python
|
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)
data.append(var)
derivative_data[key] = (tnow, data)
h = (tnow - last_time)
# N=5 2nd derivative from
# http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/smooth-low-noise-differentiators/
ret = ((data[4] + data[0]) - 2*data[2]) / (4*h**2)
return ret
|
[
"def",
"second_derivative_5",
"(",
"var",
",",
"key",
")",
":",
"global",
"derivative_data",
"import",
"mavutil",
"tnow",
"=",
"mavutil",
".",
"mavfile_global",
".",
"timestamp",
"if",
"not",
"key",
"in",
"derivative_data",
":",
"derivative_data",
"[",
"key",
"]",
"=",
"(",
"tnow",
",",
"[",
"var",
"]",
"*",
"5",
")",
"return",
"0",
"(",
"last_time",
",",
"data",
")",
"=",
"derivative_data",
"[",
"key",
"]",
"data",
".",
"pop",
"(",
"0",
")",
"data",
".",
"append",
"(",
"var",
")",
"derivative_data",
"[",
"key",
"]",
"=",
"(",
"tnow",
",",
"data",
")",
"h",
"=",
"(",
"tnow",
"-",
"last_time",
")",
"# N=5 2nd derivative from",
"# http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/smooth-low-noise-differentiators/",
"ret",
"=",
"(",
"(",
"data",
"[",
"4",
"]",
"+",
"data",
"[",
"0",
"]",
")",
"-",
"2",
"*",
"data",
"[",
"2",
"]",
")",
"/",
"(",
"4",
"*",
"h",
"**",
"2",
")",
"return",
"ret"
] |
5 point 2nd derivative
|
[
"5",
"point",
"2nd",
"derivative"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L182-L199
|
235,398
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py
|
lowpass
|
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
|
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]
|
[
"def",
"lowpass",
"(",
"var",
",",
"key",
",",
"factor",
")",
":",
"global",
"lowpass_data",
"if",
"not",
"key",
"in",
"lowpass_data",
":",
"lowpass_data",
"[",
"key",
"]",
"=",
"var",
"else",
":",
"lowpass_data",
"[",
"key",
"]",
"=",
"factor",
"*",
"lowpass_data",
"[",
"key",
"]",
"+",
"(",
"1.0",
"-",
"factor",
")",
"*",
"var",
"return",
"lowpass_data",
"[",
"key",
"]"
] |
a simple lowpass filter
|
[
"a",
"simple",
"lowpass",
"filter"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L223-L230
|
235,399
|
JdeRobot/base
|
src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py
|
diff
|
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
|
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
|
[
"def",
"diff",
"(",
"var",
",",
"key",
")",
":",
"global",
"last_diff",
"ret",
"=",
"0",
"if",
"not",
"key",
"in",
"last_diff",
":",
"last_diff",
"[",
"key",
"]",
"=",
"var",
"return",
"0",
"ret",
"=",
"var",
"-",
"last_diff",
"[",
"key",
"]",
"last_diff",
"[",
"key",
"]",
"=",
"var",
"return",
"ret"
] |
calculate differences between values
|
[
"calculate",
"differences",
"between",
"values"
] |
303b18992785b2fe802212f2d758a60873007f1f
|
https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L234-L243
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.