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 listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1 value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
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",
"]",
... | 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 | train | 230,200 |
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 | train | 230,201 |
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",
"(",
... | 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 | train | 230,202 |
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",
... | 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 | train | 230,203 |
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 ... | 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 | train | 230,204 |
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 | train | 230,205 |
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",
"("... | 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 | train | 230,206 |
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",
"(",
"... | 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 | train | 230,207 |
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*'",
"]"... | show available ports | [
"show",
"available",
"ports"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_link.py#L148-L152 | train | 230,208 |
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",
"... | 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 | train | 230,209 |
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 | train | 230,210 |
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 | train | 230,211 |
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",
"[",
"servi... | 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 | train | 230,212 |
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 | train | 230,213 |
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",
".",
"_downloa... | 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 | train | 230,214 |
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'",
",",
"'... | 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 | train | 230,215 |
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",
"(",
... | 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 | train | 230,216 |
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\"",
")",
... | show autopilot time | [
"show",
"autopilot",
"time"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py#L128-L134 | train | 230,217 |
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",... | change target altitude | [
"change",
"target",
"altitude"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py#L136-L149 | train | 230,218 |
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",
".",
"ma... | auto land commands | [
"auto",
"land",
"commands"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py#L151-L164 | train | 230,219 |
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",
... | start RC bind | [
"start",
"RC",
"bind"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_misc.py#L174-L183 | train | 230,220 |
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",
"(",
... | 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 | train | 230,221 |
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",
"]",
")",
")",
... | 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 | train | 230,222 |
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",... | 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 | train | 230,223 |
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'",
")",
".",
"... | 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 | train | 230,224 |
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",
"(",
"\"... | 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 | train | 230,225 |
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 | train | 230,226 |
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'... | 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 | train | 230,227 |
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... | 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 | train | 230,228 |
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",
".",
"cl... | 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 | train | 230,229 |
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",
"(",
"filep... | 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 | train | 230,230 |
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",
... | 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 | train | 230,231 |
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",
")",
":",
"br... | 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 | train | 230,232 |
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",
"+",
"de... | 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 | train | 230,233 |
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",
... | 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 | train | 230,234 |
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",
... | 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 | train | 230,235 |
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 | train | 230,236 |
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 | train | 230,237 |
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 | train | 230,238 |
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",
":",
"r... | 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 | train | 230,239 |
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"... | 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 | train | 230,240 |
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\"",
... | 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 | train | 230,241 |
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 | train | 230,242 |
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 | train | 230,243 |
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... | 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 | train | 230,244 |
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",
... | 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 | train | 230,245 |
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 | train | 230,246 |
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",
"(",
"... | 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 | train | 230,247 |
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",
"(",
")",
"st... | 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 | train | 230,248 |
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",
",",
"Airspeed... | 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 | train | 230,249 |
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",
"]",
... | 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 | train | 230,250 |
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",
... | 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 | train | 230,251 |
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",
"*",
... | 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 | train | 230,252 |
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",
"]",
"l... | 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 | train | 230,253 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | roll_estimate | def roll_estimate(RAW_IMU,GPS_RAW_INT=None,ATTITUDE=None,SENSOR_OFFSETS=None, ofs=None, mul=None,smooth=0.7):
'''estimate roll from accelerometer'''
rx = RAW_IMU.xacc * 9.81 / 1000.0
ry = RAW_IMU.yacc * 9.81 / 1000.0
rz = RAW_IMU.zacc * 9.81 / 1000.0
if ATTITUDE is not None and GPS_RAW_INT is not None:
ry -= ATTITUDE.yawspeed * GPS_RAW_INT.vel*0.01
rz += ATTITUDE.pitchspeed * GPS_RAW_INT.vel*0.01
if SENSOR_OFFSETS is not None and ofs is not None:
rx += SENSOR_OFFSETS.accel_cal_x
ry += SENSOR_OFFSETS.accel_cal_y
rz += SENSOR_OFFSETS.accel_cal_z
rx -= ofs[0]
ry -= ofs[1]
rz -= ofs[2]
if mul is not None:
rx *= mul[0]
ry *= mul[1]
rz *= mul[2]
return lowpass(degrees(-asin(ry/sqrt(rx**2+ry**2+rz**2))),'_roll',smooth) | python | def roll_estimate(RAW_IMU,GPS_RAW_INT=None,ATTITUDE=None,SENSOR_OFFSETS=None, ofs=None, mul=None,smooth=0.7):
'''estimate roll from accelerometer'''
rx = RAW_IMU.xacc * 9.81 / 1000.0
ry = RAW_IMU.yacc * 9.81 / 1000.0
rz = RAW_IMU.zacc * 9.81 / 1000.0
if ATTITUDE is not None and GPS_RAW_INT is not None:
ry -= ATTITUDE.yawspeed * GPS_RAW_INT.vel*0.01
rz += ATTITUDE.pitchspeed * GPS_RAW_INT.vel*0.01
if SENSOR_OFFSETS is not None and ofs is not None:
rx += SENSOR_OFFSETS.accel_cal_x
ry += SENSOR_OFFSETS.accel_cal_y
rz += SENSOR_OFFSETS.accel_cal_z
rx -= ofs[0]
ry -= ofs[1]
rz -= ofs[2]
if mul is not None:
rx *= mul[0]
ry *= mul[1]
rz *= mul[2]
return lowpass(degrees(-asin(ry/sqrt(rx**2+ry**2+rz**2))),'_roll',smooth) | [
"def",
"roll_estimate",
"(",
"RAW_IMU",
",",
"GPS_RAW_INT",
"=",
"None",
",",
"ATTITUDE",
"=",
"None",
",",
"SENSOR_OFFSETS",
"=",
"None",
",",
"ofs",
"=",
"None",
",",
"mul",
"=",
"None",
",",
"smooth",
"=",
"0.7",
")",
":",
"rx",
"=",
"RAW_IMU",
".... | estimate roll from accelerometer | [
"estimate",
"roll",
"from",
"accelerometer"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L294-L313 | train | 230,254 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | mag_rotation | def mag_rotation(RAW_IMU, inclination, declination):
'''return an attitude rotation matrix that is consistent with the current mag
vector'''
m_body = Vector3(RAW_IMU.xmag, RAW_IMU.ymag, RAW_IMU.zmag)
m_earth = Vector3(m_body.length(), 0, 0)
r = Matrix3()
r.from_euler(0, -radians(inclination), radians(declination))
m_earth = r * m_earth
r.from_two_vectors(m_earth, m_body)
return r | python | def mag_rotation(RAW_IMU, inclination, declination):
'''return an attitude rotation matrix that is consistent with the current mag
vector'''
m_body = Vector3(RAW_IMU.xmag, RAW_IMU.ymag, RAW_IMU.zmag)
m_earth = Vector3(m_body.length(), 0, 0)
r = Matrix3()
r.from_euler(0, -radians(inclination), radians(declination))
m_earth = r * m_earth
r.from_two_vectors(m_earth, m_body)
return r | [
"def",
"mag_rotation",
"(",
"RAW_IMU",
",",
"inclination",
",",
"declination",
")",
":",
"m_body",
"=",
"Vector3",
"(",
"RAW_IMU",
".",
"xmag",
",",
"RAW_IMU",
".",
"ymag",
",",
"RAW_IMU",
".",
"zmag",
")",
"m_earth",
"=",
"Vector3",
"(",
"m_body",
".",
... | return an attitude rotation matrix that is consistent with the current mag
vector | [
"return",
"an",
"attitude",
"rotation",
"matrix",
"that",
"is",
"consistent",
"with",
"the",
"current",
"mag",
"vector"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L342-L353 | train | 230,255 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | mag_yaw | def mag_yaw(RAW_IMU, inclination, declination):
'''estimate yaw from mag'''
m = mag_rotation(RAW_IMU, inclination, declination)
(r, p, y) = m.to_euler()
y = degrees(y)
if y < 0:
y += 360
return y | python | def mag_yaw(RAW_IMU, inclination, declination):
'''estimate yaw from mag'''
m = mag_rotation(RAW_IMU, inclination, declination)
(r, p, y) = m.to_euler()
y = degrees(y)
if y < 0:
y += 360
return y | [
"def",
"mag_yaw",
"(",
"RAW_IMU",
",",
"inclination",
",",
"declination",
")",
":",
"m",
"=",
"mag_rotation",
"(",
"RAW_IMU",
",",
"inclination",
",",
"declination",
")",
"(",
"r",
",",
"p",
",",
"y",
")",
"=",
"m",
".",
"to_euler",
"(",
")",
"y",
... | estimate yaw from mag | [
"estimate",
"yaw",
"from",
"mag"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L355-L362 | train | 230,256 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | mag_roll | def mag_roll(RAW_IMU, inclination, declination):
'''estimate roll from mag'''
m = mag_rotation(RAW_IMU, inclination, declination)
(r, p, y) = m.to_euler()
return degrees(r) | python | def mag_roll(RAW_IMU, inclination, declination):
'''estimate roll from mag'''
m = mag_rotation(RAW_IMU, inclination, declination)
(r, p, y) = m.to_euler()
return degrees(r) | [
"def",
"mag_roll",
"(",
"RAW_IMU",
",",
"inclination",
",",
"declination",
")",
":",
"m",
"=",
"mag_rotation",
"(",
"RAW_IMU",
",",
"inclination",
",",
"declination",
")",
"(",
"r",
",",
"p",
",",
"y",
")",
"=",
"m",
".",
"to_euler",
"(",
")",
"retur... | estimate roll from mag | [
"estimate",
"roll",
"from",
"mag"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L370-L374 | train | 230,257 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | expected_mag | def expected_mag(RAW_IMU, ATTITUDE, inclination, declination):
'''return expected mag vector'''
m_body = Vector3(RAW_IMU.xmag, RAW_IMU.ymag, RAW_IMU.zmag)
field_strength = m_body.length()
m = rotation(ATTITUDE)
r = Matrix3()
r.from_euler(0, -radians(inclination), radians(declination))
m_earth = r * Vector3(field_strength, 0, 0)
return m.transposed() * m_earth | python | def expected_mag(RAW_IMU, ATTITUDE, inclination, declination):
'''return expected mag vector'''
m_body = Vector3(RAW_IMU.xmag, RAW_IMU.ymag, RAW_IMU.zmag)
field_strength = m_body.length()
m = rotation(ATTITUDE)
r = Matrix3()
r.from_euler(0, -radians(inclination), radians(declination))
m_earth = r * Vector3(field_strength, 0, 0)
return m.transposed() * m_earth | [
"def",
"expected_mag",
"(",
"RAW_IMU",
",",
"ATTITUDE",
",",
"inclination",
",",
"declination",
")",
":",
"m_body",
"=",
"Vector3",
"(",
"RAW_IMU",
".",
"xmag",
",",
"RAW_IMU",
".",
"ymag",
",",
"RAW_IMU",
".",
"zmag",
")",
"field_strength",
"=",
"m_body",... | return expected mag vector | [
"return",
"expected",
"mag",
"vector"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L376-L387 | train | 230,258 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | gravity | def gravity(RAW_IMU, SENSOR_OFFSETS=None, ofs=None, mul=None, smooth=0.7):
'''estimate pitch from accelerometer'''
if hasattr(RAW_IMU, 'xacc'):
rx = RAW_IMU.xacc * 9.81 / 1000.0
ry = RAW_IMU.yacc * 9.81 / 1000.0
rz = RAW_IMU.zacc * 9.81 / 1000.0
else:
rx = RAW_IMU.AccX
ry = RAW_IMU.AccY
rz = RAW_IMU.AccZ
if SENSOR_OFFSETS is not None and ofs is not None:
rx += SENSOR_OFFSETS.accel_cal_x
ry += SENSOR_OFFSETS.accel_cal_y
rz += SENSOR_OFFSETS.accel_cal_z
rx -= ofs[0]
ry -= ofs[1]
rz -= ofs[2]
if mul is not None:
rx *= mul[0]
ry *= mul[1]
rz *= mul[2]
return sqrt(rx**2+ry**2+rz**2) | python | def gravity(RAW_IMU, SENSOR_OFFSETS=None, ofs=None, mul=None, smooth=0.7):
'''estimate pitch from accelerometer'''
if hasattr(RAW_IMU, 'xacc'):
rx = RAW_IMU.xacc * 9.81 / 1000.0
ry = RAW_IMU.yacc * 9.81 / 1000.0
rz = RAW_IMU.zacc * 9.81 / 1000.0
else:
rx = RAW_IMU.AccX
ry = RAW_IMU.AccY
rz = RAW_IMU.AccZ
if SENSOR_OFFSETS is not None and ofs is not None:
rx += SENSOR_OFFSETS.accel_cal_x
ry += SENSOR_OFFSETS.accel_cal_y
rz += SENSOR_OFFSETS.accel_cal_z
rx -= ofs[0]
ry -= ofs[1]
rz -= ofs[2]
if mul is not None:
rx *= mul[0]
ry *= mul[1]
rz *= mul[2]
return sqrt(rx**2+ry**2+rz**2) | [
"def",
"gravity",
"(",
"RAW_IMU",
",",
"SENSOR_OFFSETS",
"=",
"None",
",",
"ofs",
"=",
"None",
",",
"mul",
"=",
"None",
",",
"smooth",
"=",
"0.7",
")",
":",
"if",
"hasattr",
"(",
"RAW_IMU",
",",
"'xacc'",
")",
":",
"rx",
"=",
"RAW_IMU",
".",
"xacc"... | estimate pitch from accelerometer | [
"estimate",
"pitch",
"from",
"accelerometer"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L428-L449 | train | 230,259 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | pitch_sim | def pitch_sim(SIMSTATE, GPS_RAW):
'''estimate pitch from SIMSTATE accels'''
xacc = SIMSTATE.xacc - lowpass(delta(GPS_RAW.v,"v")*6.6, "v", 0.9)
zacc = SIMSTATE.zacc
zacc += SIMSTATE.ygyro * GPS_RAW.v;
if xacc/zacc >= 1:
return 0
if xacc/zacc <= -1:
return -0
return degrees(-asin(xacc/zacc)) | python | def pitch_sim(SIMSTATE, GPS_RAW):
'''estimate pitch from SIMSTATE accels'''
xacc = SIMSTATE.xacc - lowpass(delta(GPS_RAW.v,"v")*6.6, "v", 0.9)
zacc = SIMSTATE.zacc
zacc += SIMSTATE.ygyro * GPS_RAW.v;
if xacc/zacc >= 1:
return 0
if xacc/zacc <= -1:
return -0
return degrees(-asin(xacc/zacc)) | [
"def",
"pitch_sim",
"(",
"SIMSTATE",
",",
"GPS_RAW",
")",
":",
"xacc",
"=",
"SIMSTATE",
".",
"xacc",
"-",
"lowpass",
"(",
"delta",
"(",
"GPS_RAW",
".",
"v",
",",
"\"v\"",
")",
"*",
"6.6",
",",
"\"v\"",
",",
"0.9",
")",
"zacc",
"=",
"SIMSTATE",
".",... | estimate pitch from SIMSTATE accels | [
"estimate",
"pitch",
"from",
"SIMSTATE",
"accels"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L453-L462 | train | 230,260 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | distance_home | def distance_home(GPS_RAW):
'''distance from first fix point'''
global first_fix
if (hasattr(GPS_RAW, 'fix_type') and GPS_RAW.fix_type < 2) or \
(hasattr(GPS_RAW, 'Status') and GPS_RAW.Status < 2):
return 0
if first_fix == None:
first_fix = GPS_RAW
return 0
return distance_two(GPS_RAW, first_fix) | python | def distance_home(GPS_RAW):
'''distance from first fix point'''
global first_fix
if (hasattr(GPS_RAW, 'fix_type') and GPS_RAW.fix_type < 2) or \
(hasattr(GPS_RAW, 'Status') and GPS_RAW.Status < 2):
return 0
if first_fix == None:
first_fix = GPS_RAW
return 0
return distance_two(GPS_RAW, first_fix) | [
"def",
"distance_home",
"(",
"GPS_RAW",
")",
":",
"global",
"first_fix",
"if",
"(",
"hasattr",
"(",
"GPS_RAW",
",",
"'fix_type'",
")",
"and",
"GPS_RAW",
".",
"fix_type",
"<",
"2",
")",
"or",
"(",
"hasattr",
"(",
"GPS_RAW",
",",
"'Status'",
")",
"and",
... | distance from first fix point | [
"distance",
"from",
"first",
"fix",
"point"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L500-L510 | train | 230,261 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | sawtooth | def sawtooth(ATTITUDE, amplitude=2.0, period=5.0):
'''sawtooth pattern based on uptime'''
mins = (ATTITUDE.usec * 1.0e-6)/60
p = fmod(mins, period*2)
if p < period:
return amplitude * (p/period)
return amplitude * (period - (p-period))/period | python | def sawtooth(ATTITUDE, amplitude=2.0, period=5.0):
'''sawtooth pattern based on uptime'''
mins = (ATTITUDE.usec * 1.0e-6)/60
p = fmod(mins, period*2)
if p < period:
return amplitude * (p/period)
return amplitude * (period - (p-period))/period | [
"def",
"sawtooth",
"(",
"ATTITUDE",
",",
"amplitude",
"=",
"2.0",
",",
"period",
"=",
"5.0",
")",
":",
"mins",
"=",
"(",
"ATTITUDE",
".",
"usec",
"*",
"1.0e-6",
")",
"/",
"60",
"p",
"=",
"fmod",
"(",
"mins",
",",
"period",
"*",
"2",
")",
"if",
... | sawtooth pattern based on uptime | [
"sawtooth",
"pattern",
"based",
"on",
"uptime"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L512-L518 | train | 230,262 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | EAS2TAS | def EAS2TAS(ARSP,GPS,BARO,ground_temp=25):
'''EAS2TAS from ARSP.Temp'''
tempK = ground_temp + 273.15 - 0.0065 * GPS.Alt
return sqrt(1.225 / (BARO.Press / (287.26 * tempK))) | python | def EAS2TAS(ARSP,GPS,BARO,ground_temp=25):
'''EAS2TAS from ARSP.Temp'''
tempK = ground_temp + 273.15 - 0.0065 * GPS.Alt
return sqrt(1.225 / (BARO.Press / (287.26 * tempK))) | [
"def",
"EAS2TAS",
"(",
"ARSP",
",",
"GPS",
",",
"BARO",
",",
"ground_temp",
"=",
"25",
")",
":",
"tempK",
"=",
"ground_temp",
"+",
"273.15",
"-",
"0.0065",
"*",
"GPS",
".",
"Alt",
"return",
"sqrt",
"(",
"1.225",
"/",
"(",
"BARO",
".",
"Press",
"/",... | EAS2TAS from ARSP.Temp | [
"EAS2TAS",
"from",
"ARSP",
".",
"Temp"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L556-L559 | train | 230,263 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | airspeed_voltage | def airspeed_voltage(VFR_HUD, ratio=None):
'''back-calculate the voltage the airspeed sensor must have seen'''
import mavutil
mav = mavutil.mavfile_global
if ratio is None:
ratio = 1.9936 # APM default
if 'ARSPD_RATIO' in mav.params:
used_ratio = mav.params['ARSPD_RATIO']
else:
used_ratio = ratio
if 'ARSPD_OFFSET' in mav.params:
offset = mav.params['ARSPD_OFFSET']
else:
return -1
airspeed_pressure = (pow(VFR_HUD.airspeed,2)) / used_ratio
raw = airspeed_pressure + offset
SCALING_OLD_CALIBRATION = 204.8
voltage = 5.0 * raw / 4096
return voltage | python | def airspeed_voltage(VFR_HUD, ratio=None):
'''back-calculate the voltage the airspeed sensor must have seen'''
import mavutil
mav = mavutil.mavfile_global
if ratio is None:
ratio = 1.9936 # APM default
if 'ARSPD_RATIO' in mav.params:
used_ratio = mav.params['ARSPD_RATIO']
else:
used_ratio = ratio
if 'ARSPD_OFFSET' in mav.params:
offset = mav.params['ARSPD_OFFSET']
else:
return -1
airspeed_pressure = (pow(VFR_HUD.airspeed,2)) / used_ratio
raw = airspeed_pressure + offset
SCALING_OLD_CALIBRATION = 204.8
voltage = 5.0 * raw / 4096
return voltage | [
"def",
"airspeed_voltage",
"(",
"VFR_HUD",
",",
"ratio",
"=",
"None",
")",
":",
"import",
"mavutil",
"mav",
"=",
"mavutil",
".",
"mavfile_global",
"if",
"ratio",
"is",
"None",
":",
"ratio",
"=",
"1.9936",
"# APM default",
"if",
"'ARSPD_RATIO'",
"in",
"mav",
... | back-calculate the voltage the airspeed sensor must have seen | [
"back",
"-",
"calculate",
"the",
"voltage",
"the",
"airspeed",
"sensor",
"must",
"have",
"seen"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L570-L588 | train | 230,264 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | earth_rates | def earth_rates(ATTITUDE):
'''return angular velocities in earth frame'''
from math import sin, cos, tan, fabs
p = ATTITUDE.rollspeed
q = ATTITUDE.pitchspeed
r = ATTITUDE.yawspeed
phi = ATTITUDE.roll
theta = ATTITUDE.pitch
psi = ATTITUDE.yaw
phiDot = p + tan(theta)*(q*sin(phi) + r*cos(phi))
thetaDot = q*cos(phi) - r*sin(phi)
if fabs(cos(theta)) < 1.0e-20:
theta += 1.0e-10
psiDot = (q*sin(phi) + r*cos(phi))/cos(theta)
return (phiDot, thetaDot, psiDot) | python | def earth_rates(ATTITUDE):
'''return angular velocities in earth frame'''
from math import sin, cos, tan, fabs
p = ATTITUDE.rollspeed
q = ATTITUDE.pitchspeed
r = ATTITUDE.yawspeed
phi = ATTITUDE.roll
theta = ATTITUDE.pitch
psi = ATTITUDE.yaw
phiDot = p + tan(theta)*(q*sin(phi) + r*cos(phi))
thetaDot = q*cos(phi) - r*sin(phi)
if fabs(cos(theta)) < 1.0e-20:
theta += 1.0e-10
psiDot = (q*sin(phi) + r*cos(phi))/cos(theta)
return (phiDot, thetaDot, psiDot) | [
"def",
"earth_rates",
"(",
"ATTITUDE",
")",
":",
"from",
"math",
"import",
"sin",
",",
"cos",
",",
"tan",
",",
"fabs",
"p",
"=",
"ATTITUDE",
".",
"rollspeed",
"q",
"=",
"ATTITUDE",
".",
"pitchspeed",
"r",
"=",
"ATTITUDE",
".",
"yawspeed",
"phi",
"=",
... | return angular velocities in earth frame | [
"return",
"angular",
"velocities",
"in",
"earth",
"frame"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L591-L607 | train | 230,265 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | gps_velocity_body | def gps_velocity_body(GPS_RAW_INT, ATTITUDE):
'''return GPS velocity vector in body frame'''
r = rotation(ATTITUDE)
return r.transposed() * Vector3(GPS_RAW_INT.vel*0.01*cos(radians(GPS_RAW_INT.cog*0.01)),
GPS_RAW_INT.vel*0.01*sin(radians(GPS_RAW_INT.cog*0.01)),
-tan(ATTITUDE.pitch)*GPS_RAW_INT.vel*0.01) | python | def gps_velocity_body(GPS_RAW_INT, ATTITUDE):
'''return GPS velocity vector in body frame'''
r = rotation(ATTITUDE)
return r.transposed() * Vector3(GPS_RAW_INT.vel*0.01*cos(radians(GPS_RAW_INT.cog*0.01)),
GPS_RAW_INT.vel*0.01*sin(radians(GPS_RAW_INT.cog*0.01)),
-tan(ATTITUDE.pitch)*GPS_RAW_INT.vel*0.01) | [
"def",
"gps_velocity_body",
"(",
"GPS_RAW_INT",
",",
"ATTITUDE",
")",
":",
"r",
"=",
"rotation",
"(",
"ATTITUDE",
")",
"return",
"r",
".",
"transposed",
"(",
")",
"*",
"Vector3",
"(",
"GPS_RAW_INT",
".",
"vel",
"*",
"0.01",
"*",
"cos",
"(",
"radians",
... | return GPS velocity vector in body frame | [
"return",
"GPS",
"velocity",
"vector",
"in",
"body",
"frame"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L635-L640 | train | 230,266 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | earth_accel | def earth_accel(RAW_IMU,ATTITUDE):
'''return earth frame acceleration vector'''
r = rotation(ATTITUDE)
accel = Vector3(RAW_IMU.xacc, RAW_IMU.yacc, RAW_IMU.zacc) * 9.81 * 0.001
return r * accel | python | def earth_accel(RAW_IMU,ATTITUDE):
'''return earth frame acceleration vector'''
r = rotation(ATTITUDE)
accel = Vector3(RAW_IMU.xacc, RAW_IMU.yacc, RAW_IMU.zacc) * 9.81 * 0.001
return r * accel | [
"def",
"earth_accel",
"(",
"RAW_IMU",
",",
"ATTITUDE",
")",
":",
"r",
"=",
"rotation",
"(",
"ATTITUDE",
")",
"accel",
"=",
"Vector3",
"(",
"RAW_IMU",
".",
"xacc",
",",
"RAW_IMU",
".",
"yacc",
",",
"RAW_IMU",
".",
"zacc",
")",
"*",
"9.81",
"*",
"0.001... | return earth frame acceleration vector | [
"return",
"earth",
"frame",
"acceleration",
"vector"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L642-L646 | train | 230,267 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | earth_gyro | def earth_gyro(RAW_IMU,ATTITUDE):
'''return earth frame gyro vector'''
r = rotation(ATTITUDE)
accel = Vector3(degrees(RAW_IMU.xgyro), degrees(RAW_IMU.ygyro), degrees(RAW_IMU.zgyro)) * 0.001
return r * accel | python | def earth_gyro(RAW_IMU,ATTITUDE):
'''return earth frame gyro vector'''
r = rotation(ATTITUDE)
accel = Vector3(degrees(RAW_IMU.xgyro), degrees(RAW_IMU.ygyro), degrees(RAW_IMU.zgyro)) * 0.001
return r * accel | [
"def",
"earth_gyro",
"(",
"RAW_IMU",
",",
"ATTITUDE",
")",
":",
"r",
"=",
"rotation",
"(",
"ATTITUDE",
")",
"accel",
"=",
"Vector3",
"(",
"degrees",
"(",
"RAW_IMU",
".",
"xgyro",
")",
",",
"degrees",
"(",
"RAW_IMU",
".",
"ygyro",
")",
",",
"degrees",
... | return earth frame gyro vector | [
"return",
"earth",
"frame",
"gyro",
"vector"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L648-L652 | train | 230,268 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | airspeed_energy_error | def airspeed_energy_error(NAV_CONTROLLER_OUTPUT, VFR_HUD):
'''return airspeed energy error matching APM internals
This is positive when we are going too slow
'''
aspeed_cm = VFR_HUD.airspeed*100
target_airspeed = NAV_CONTROLLER_OUTPUT.aspd_error + aspeed_cm
airspeed_energy_error = ((target_airspeed*target_airspeed) - (aspeed_cm*aspeed_cm))*0.00005
return airspeed_energy_error | python | def airspeed_energy_error(NAV_CONTROLLER_OUTPUT, VFR_HUD):
'''return airspeed energy error matching APM internals
This is positive when we are going too slow
'''
aspeed_cm = VFR_HUD.airspeed*100
target_airspeed = NAV_CONTROLLER_OUTPUT.aspd_error + aspeed_cm
airspeed_energy_error = ((target_airspeed*target_airspeed) - (aspeed_cm*aspeed_cm))*0.00005
return airspeed_energy_error | [
"def",
"airspeed_energy_error",
"(",
"NAV_CONTROLLER_OUTPUT",
",",
"VFR_HUD",
")",
":",
"aspeed_cm",
"=",
"VFR_HUD",
".",
"airspeed",
"*",
"100",
"target_airspeed",
"=",
"NAV_CONTROLLER_OUTPUT",
".",
"aspd_error",
"+",
"aspeed_cm",
"airspeed_energy_error",
"=",
"(",
... | return airspeed energy error matching APM internals
This is positive when we are going too slow | [
"return",
"airspeed",
"energy",
"error",
"matching",
"APM",
"internals",
"This",
"is",
"positive",
"when",
"we",
"are",
"going",
"too",
"slow"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L654-L661 | train | 230,269 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | energy_error | def energy_error(NAV_CONTROLLER_OUTPUT, VFR_HUD):
'''return energy error matching APM internals
This is positive when we are too low or going too slow
'''
aspeed_energy_error = airspeed_energy_error(NAV_CONTROLLER_OUTPUT, VFR_HUD)
alt_error = NAV_CONTROLLER_OUTPUT.alt_error*100
energy_error = aspeed_energy_error + alt_error*0.098
return energy_error | python | def energy_error(NAV_CONTROLLER_OUTPUT, VFR_HUD):
'''return energy error matching APM internals
This is positive when we are too low or going too slow
'''
aspeed_energy_error = airspeed_energy_error(NAV_CONTROLLER_OUTPUT, VFR_HUD)
alt_error = NAV_CONTROLLER_OUTPUT.alt_error*100
energy_error = aspeed_energy_error + alt_error*0.098
return energy_error | [
"def",
"energy_error",
"(",
"NAV_CONTROLLER_OUTPUT",
",",
"VFR_HUD",
")",
":",
"aspeed_energy_error",
"=",
"airspeed_energy_error",
"(",
"NAV_CONTROLLER_OUTPUT",
",",
"VFR_HUD",
")",
"alt_error",
"=",
"NAV_CONTROLLER_OUTPUT",
".",
"alt_error",
"*",
"100",
"energy_error"... | return energy error matching APM internals
This is positive when we are too low or going too slow | [
"return",
"energy",
"error",
"matching",
"APM",
"internals",
"This",
"is",
"positive",
"when",
"we",
"are",
"too",
"low",
"or",
"going",
"too",
"slow"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L664-L671 | train | 230,270 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | mixer | def mixer(servo1, servo2, mixtype=1, gain=0.5):
'''mix two servos'''
s1 = servo1 - 1500
s2 = servo2 - 1500
v1 = (s1-s2)*gain
v2 = (s1+s2)*gain
if mixtype == 2:
v2 = -v2
elif mixtype == 3:
v1 = -v1
elif mixtype == 4:
v1 = -v1
v2 = -v2
if v1 > 600:
v1 = 600
elif v1 < -600:
v1 = -600
if v2 > 600:
v2 = 600
elif v2 < -600:
v2 = -600
return (1500+v1,1500+v2) | python | def mixer(servo1, servo2, mixtype=1, gain=0.5):
'''mix two servos'''
s1 = servo1 - 1500
s2 = servo2 - 1500
v1 = (s1-s2)*gain
v2 = (s1+s2)*gain
if mixtype == 2:
v2 = -v2
elif mixtype == 3:
v1 = -v1
elif mixtype == 4:
v1 = -v1
v2 = -v2
if v1 > 600:
v1 = 600
elif v1 < -600:
v1 = -600
if v2 > 600:
v2 = 600
elif v2 < -600:
v2 = -600
return (1500+v1,1500+v2) | [
"def",
"mixer",
"(",
"servo1",
",",
"servo2",
",",
"mixtype",
"=",
"1",
",",
"gain",
"=",
"0.5",
")",
":",
"s1",
"=",
"servo1",
"-",
"1500",
"s2",
"=",
"servo2",
"-",
"1500",
"v1",
"=",
"(",
"s1",
"-",
"s2",
")",
"*",
"gain",
"v2",
"=",
"(",
... | mix two servos | [
"mix",
"two",
"servos"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L724-L745 | train | 230,271 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | DCM_update | def DCM_update(IMU, ATT, MAG, GPS):
'''implement full DCM system'''
global dcm_state
if dcm_state is None:
dcm_state = DCM_State(ATT.Roll, ATT.Pitch, ATT.Yaw)
mag = Vector3(MAG.MagX, MAG.MagY, MAG.MagZ)
gyro = Vector3(IMU.GyrX, IMU.GyrY, IMU.GyrZ)
accel = Vector3(IMU.AccX, IMU.AccY, IMU.AccZ)
accel2 = Vector3(IMU.AccX, IMU.AccY, IMU.AccZ)
dcm_state.update(gyro, accel, mag, GPS)
return dcm_state | python | def DCM_update(IMU, ATT, MAG, GPS):
'''implement full DCM system'''
global dcm_state
if dcm_state is None:
dcm_state = DCM_State(ATT.Roll, ATT.Pitch, ATT.Yaw)
mag = Vector3(MAG.MagX, MAG.MagY, MAG.MagZ)
gyro = Vector3(IMU.GyrX, IMU.GyrY, IMU.GyrZ)
accel = Vector3(IMU.AccX, IMU.AccY, IMU.AccZ)
accel2 = Vector3(IMU.AccX, IMU.AccY, IMU.AccZ)
dcm_state.update(gyro, accel, mag, GPS)
return dcm_state | [
"def",
"DCM_update",
"(",
"IMU",
",",
"ATT",
",",
"MAG",
",",
"GPS",
")",
":",
"global",
"dcm_state",
"if",
"dcm_state",
"is",
"None",
":",
"dcm_state",
"=",
"DCM_State",
"(",
"ATT",
".",
"Roll",
",",
"ATT",
".",
"Pitch",
",",
"ATT",
".",
"Yaw",
")... | implement full DCM system | [
"implement",
"full",
"DCM",
"system"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L818-L829 | train | 230,272 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | PX4_update | def PX4_update(IMU, ATT):
'''implement full DCM using PX4 native SD log data'''
global px4_state
if px4_state is None:
px4_state = PX4_State(degrees(ATT.Roll), degrees(ATT.Pitch), degrees(ATT.Yaw), IMU._timestamp)
gyro = Vector3(IMU.GyroX, IMU.GyroY, IMU.GyroZ)
accel = Vector3(IMU.AccX, IMU.AccY, IMU.AccZ)
px4_state.update(gyro, accel, IMU._timestamp)
return px4_state | python | def PX4_update(IMU, ATT):
'''implement full DCM using PX4 native SD log data'''
global px4_state
if px4_state is None:
px4_state = PX4_State(degrees(ATT.Roll), degrees(ATT.Pitch), degrees(ATT.Yaw), IMU._timestamp)
gyro = Vector3(IMU.GyroX, IMU.GyroY, IMU.GyroZ)
accel = Vector3(IMU.AccX, IMU.AccY, IMU.AccZ)
px4_state.update(gyro, accel, IMU._timestamp)
return px4_state | [
"def",
"PX4_update",
"(",
"IMU",
",",
"ATT",
")",
":",
"global",
"px4_state",
"if",
"px4_state",
"is",
"None",
":",
"px4_state",
"=",
"PX4_State",
"(",
"degrees",
"(",
"ATT",
".",
"Roll",
")",
",",
"degrees",
"(",
"ATT",
".",
"Pitch",
")",
",",
"degr... | implement full DCM using PX4 native SD log data | [
"implement",
"full",
"DCM",
"using",
"PX4",
"native",
"SD",
"log",
"data"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L853-L862 | train | 230,273 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | armed | def armed(HEARTBEAT):
'''return 1 if armed, 0 if not'''
from . import mavutil
if HEARTBEAT.type == mavutil.mavlink.MAV_TYPE_GCS:
self = mavutil.mavfile_global
if self.motors_armed():
return 1
return 0
if HEARTBEAT.base_mode & mavutil.mavlink.MAV_MODE_FLAG_SAFETY_ARMED:
return 1
return 0 | python | def armed(HEARTBEAT):
'''return 1 if armed, 0 if not'''
from . import mavutil
if HEARTBEAT.type == mavutil.mavlink.MAV_TYPE_GCS:
self = mavutil.mavfile_global
if self.motors_armed():
return 1
return 0
if HEARTBEAT.base_mode & mavutil.mavlink.MAV_MODE_FLAG_SAFETY_ARMED:
return 1
return 0 | [
"def",
"armed",
"(",
"HEARTBEAT",
")",
":",
"from",
".",
"import",
"mavutil",
"if",
"HEARTBEAT",
".",
"type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_GCS",
":",
"self",
"=",
"mavutil",
".",
"mavfile_global",
"if",
"self",
".",
"motors_armed",
"(",
... | return 1 if armed, 0 if not | [
"return",
"1",
"if",
"armed",
"0",
"if",
"not"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L872-L882 | train | 230,274 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | earth_accel2 | def earth_accel2(RAW_IMU,ATTITUDE):
'''return earth frame acceleration vector from AHRS2'''
r = rotation2(ATTITUDE)
accel = Vector3(RAW_IMU.xacc, RAW_IMU.yacc, RAW_IMU.zacc) * 9.81 * 0.001
return r * accel | python | def earth_accel2(RAW_IMU,ATTITUDE):
'''return earth frame acceleration vector from AHRS2'''
r = rotation2(ATTITUDE)
accel = Vector3(RAW_IMU.xacc, RAW_IMU.yacc, RAW_IMU.zacc) * 9.81 * 0.001
return r * accel | [
"def",
"earth_accel2",
"(",
"RAW_IMU",
",",
"ATTITUDE",
")",
":",
"r",
"=",
"rotation2",
"(",
"ATTITUDE",
")",
"accel",
"=",
"Vector3",
"(",
"RAW_IMU",
".",
"xacc",
",",
"RAW_IMU",
".",
"yacc",
",",
"RAW_IMU",
".",
"zacc",
")",
"*",
"9.81",
"*",
"0.0... | return earth frame acceleration vector from AHRS2 | [
"return",
"earth",
"frame",
"acceleration",
"vector",
"from",
"AHRS2"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L896-L900 | train | 230,275 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | ekf1_pos | def ekf1_pos(EKF1):
'''calculate EKF position when EKF disabled'''
global ekf_home
from . import mavutil
self = mavutil.mavfile_global
if ekf_home is None:
if not 'GPS' in self.messages or self.messages['GPS'].Status != 3:
return None
ekf_home = self.messages['GPS']
(ekf_home.Lat, ekf_home.Lng) = gps_offset(ekf_home.Lat, ekf_home.Lng, -EKF1.PE, -EKF1.PN)
(lat,lon) = gps_offset(ekf_home.Lat, ekf_home.Lng, EKF1.PE, EKF1.PN)
return (lat, lon) | python | def ekf1_pos(EKF1):
'''calculate EKF position when EKF disabled'''
global ekf_home
from . import mavutil
self = mavutil.mavfile_global
if ekf_home is None:
if not 'GPS' in self.messages or self.messages['GPS'].Status != 3:
return None
ekf_home = self.messages['GPS']
(ekf_home.Lat, ekf_home.Lng) = gps_offset(ekf_home.Lat, ekf_home.Lng, -EKF1.PE, -EKF1.PN)
(lat,lon) = gps_offset(ekf_home.Lat, ekf_home.Lng, EKF1.PE, EKF1.PN)
return (lat, lon) | [
"def",
"ekf1_pos",
"(",
"EKF1",
")",
":",
"global",
"ekf_home",
"from",
".",
"import",
"mavutil",
"self",
"=",
"mavutil",
".",
"mavfile_global",
"if",
"ekf_home",
"is",
"None",
":",
"if",
"not",
"'GPS'",
"in",
"self",
".",
"messages",
"or",
"self",
".",
... | calculate EKF position when EKF disabled | [
"calculate",
"EKF",
"position",
"when",
"EKF",
"disabled"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L964-L975 | train | 230,276 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_cmdlong.py | CmdlongModule.cmd_condition_yaw | def cmd_condition_yaw(self, args):
'''yaw angle angular_speed angle_mode'''
if ( len(args) != 3):
print("Usage: yaw ANGLE ANGULAR_SPEED MODE:[0 absolute / 1 relative]")
return
if (len(args) == 3):
angle = float(args[0])
angular_speed = float(args[1])
angle_mode = float(args[2])
print("ANGLE %s" % (str(angle)))
self.master.mav.command_long_send(
self.settings.target_system, # target_system
mavutil.mavlink.MAV_COMP_ID_SYSTEM_CONTROL, # target_component
mavutil.mavlink.MAV_CMD_CONDITION_YAW, # command
0, # confirmation
angle, # param1 (angle value)
angular_speed, # param2 (angular speed value)
0, # param3
angle_mode, # param4 (mode: 0->absolute / 1->relative)
0, # param5
0, # param6
0) | python | def cmd_condition_yaw(self, args):
'''yaw angle angular_speed angle_mode'''
if ( len(args) != 3):
print("Usage: yaw ANGLE ANGULAR_SPEED MODE:[0 absolute / 1 relative]")
return
if (len(args) == 3):
angle = float(args[0])
angular_speed = float(args[1])
angle_mode = float(args[2])
print("ANGLE %s" % (str(angle)))
self.master.mav.command_long_send(
self.settings.target_system, # target_system
mavutil.mavlink.MAV_COMP_ID_SYSTEM_CONTROL, # target_component
mavutil.mavlink.MAV_CMD_CONDITION_YAW, # command
0, # confirmation
angle, # param1 (angle value)
angular_speed, # param2 (angular speed value)
0, # param3
angle_mode, # param4 (mode: 0->absolute / 1->relative)
0, # param5
0, # param6
0) | [
"def",
"cmd_condition_yaw",
"(",
"self",
",",
"args",
")",
":",
"if",
"(",
"len",
"(",
"args",
")",
"!=",
"3",
")",
":",
"print",
"(",
"\"Usage: yaw ANGLE ANGULAR_SPEED MODE:[0 absolute / 1 relative]\"",
")",
"return",
"if",
"(",
"len",
"(",
"args",
")",
"==... | yaw angle angular_speed angle_mode | [
"yaw",
"angle",
"angular_speed",
"angle_mode"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_cmdlong.py#L126-L149 | train | 230,277 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_cmdlong.py | CmdlongModule.cmd_velocity | def cmd_velocity(self, args):
'''velocity x-ms y-ms z-ms'''
if (len(args) != 3):
print("Usage: velocity x y z (m/s)")
return
if (len(args) == 3):
x_mps = float(args[0])
y_mps = float(args[1])
z_mps = float(args[2])
#print("x:%f, y:%f, z:%f" % (x_mps, y_mps, z_mps))
self.master.mav.set_position_target_local_ned_send(
0, # time_boot_ms (not used)
0, 0, # target system, target component
mavutil.mavlink.MAV_FRAME_LOCAL_NED, # frame
0b0000111111000111, # type_mask (only speeds enabled)
0, 0, 0, # x, y, z positions (not used)
x_mps, y_mps, -z_mps, # x, y, z velocity in m/s
0, 0, 0, # x, y, z acceleration (not supported yet, ignored in GCS_Mavlink)
0, 0) | python | def cmd_velocity(self, args):
'''velocity x-ms y-ms z-ms'''
if (len(args) != 3):
print("Usage: velocity x y z (m/s)")
return
if (len(args) == 3):
x_mps = float(args[0])
y_mps = float(args[1])
z_mps = float(args[2])
#print("x:%f, y:%f, z:%f" % (x_mps, y_mps, z_mps))
self.master.mav.set_position_target_local_ned_send(
0, # time_boot_ms (not used)
0, 0, # target system, target component
mavutil.mavlink.MAV_FRAME_LOCAL_NED, # frame
0b0000111111000111, # type_mask (only speeds enabled)
0, 0, 0, # x, y, z positions (not used)
x_mps, y_mps, -z_mps, # x, y, z velocity in m/s
0, 0, 0, # x, y, z acceleration (not supported yet, ignored in GCS_Mavlink)
0, 0) | [
"def",
"cmd_velocity",
"(",
"self",
",",
"args",
")",
":",
"if",
"(",
"len",
"(",
"args",
")",
"!=",
"3",
")",
":",
"print",
"(",
"\"Usage: velocity x y z (m/s)\"",
")",
"return",
"if",
"(",
"len",
"(",
"args",
")",
"==",
"3",
")",
":",
"x_mps",
"=... | velocity x-ms y-ms z-ms | [
"velocity",
"x",
"-",
"ms",
"y",
"-",
"ms",
"z",
"-",
"ms"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_cmdlong.py#L151-L171 | train | 230,278 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_cmdlong.py | CmdlongModule.cmd_position | def cmd_position(self, args):
'''position x-m y-m z-m'''
if (len(args) != 3):
print("Usage: position x y z (meters)")
return
if (len(args) == 3):
x_m = float(args[0])
y_m = float(args[1])
z_m = float(args[2])
print("x:%f, y:%f, z:%f" % (x_m, y_m, z_m))
self.master.mav.set_position_target_local_ned_send(
0, # system time in milliseconds
1, # target system
0, # target component
8, # coordinate frame MAV_FRAME_BODY_NED
3576, # type mask (pos only)
x_m, y_m, z_m, # position x,y,z
0, 0, 0, # velocity x,y,z
0, 0, 0, # accel x,y,z
0, 0) | python | def cmd_position(self, args):
'''position x-m y-m z-m'''
if (len(args) != 3):
print("Usage: position x y z (meters)")
return
if (len(args) == 3):
x_m = float(args[0])
y_m = float(args[1])
z_m = float(args[2])
print("x:%f, y:%f, z:%f" % (x_m, y_m, z_m))
self.master.mav.set_position_target_local_ned_send(
0, # system time in milliseconds
1, # target system
0, # target component
8, # coordinate frame MAV_FRAME_BODY_NED
3576, # type mask (pos only)
x_m, y_m, z_m, # position x,y,z
0, 0, 0, # velocity x,y,z
0, 0, 0, # accel x,y,z
0, 0) | [
"def",
"cmd_position",
"(",
"self",
",",
"args",
")",
":",
"if",
"(",
"len",
"(",
"args",
")",
"!=",
"3",
")",
":",
"print",
"(",
"\"Usage: position x y z (meters)\"",
")",
"return",
"if",
"(",
"len",
"(",
"args",
")",
"==",
"3",
")",
":",
"x_m",
"... | position x-m y-m z-m | [
"position",
"x",
"-",
"m",
"y",
"-",
"m",
"z",
"-",
"m"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_cmdlong.py#L182-L202 | train | 230,279 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_cmdlong.py | CmdlongModule.cmd_attitude | def cmd_attitude(self, args):
'''attitude q0 q1 q2 q3 thrust'''
if len(args) != 5:
print("Usage: attitude q0 q1 q2 q3 thrust (0~1)")
return
if len(args) == 5:
q0 = float(args[0])
q1 = float(args[1])
q2 = float(args[2])
q3 = float(args[3])
thrust = float(args[4])
att_target = [q0, q1, q2, q3]
print("q0:%.3f, q1:%.3f, q2:%.3f q3:%.3f thrust:%.2f" % (q0, q1, q2, q3, thrust))
self.master.mav.set_attitude_target_send(
0, # system time in milliseconds
1, # target system
0, # target component
63, # type mask (ignore all except attitude + thrust)
att_target, # quaternion attitude
0, # body roll rate
0, # body pich rate
0, # body yaw rate
thrust) | python | def cmd_attitude(self, args):
'''attitude q0 q1 q2 q3 thrust'''
if len(args) != 5:
print("Usage: attitude q0 q1 q2 q3 thrust (0~1)")
return
if len(args) == 5:
q0 = float(args[0])
q1 = float(args[1])
q2 = float(args[2])
q3 = float(args[3])
thrust = float(args[4])
att_target = [q0, q1, q2, q3]
print("q0:%.3f, q1:%.3f, q2:%.3f q3:%.3f thrust:%.2f" % (q0, q1, q2, q3, thrust))
self.master.mav.set_attitude_target_send(
0, # system time in milliseconds
1, # target system
0, # target component
63, # type mask (ignore all except attitude + thrust)
att_target, # quaternion attitude
0, # body roll rate
0, # body pich rate
0, # body yaw rate
thrust) | [
"def",
"cmd_attitude",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"!=",
"5",
":",
"print",
"(",
"\"Usage: attitude q0 q1 q2 q3 thrust (0~1)\"",
")",
"return",
"if",
"len",
"(",
"args",
")",
"==",
"5",
":",
"q0",
"=",
"float",
"(... | attitude q0 q1 q2 q3 thrust | [
"attitude",
"q0",
"q1",
"q2",
"q3",
"thrust"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_cmdlong.py#L204-L227 | train | 230,280 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_cmdlong.py | CmdlongModule.cmd_posvel | def cmd_posvel(self, args):
'''posvel mapclick vN vE vD'''
ignoremask = 511
latlon = None
try:
latlon = self.module('map').click_position
except Exception:
pass
if latlon is None:
print ("set latlon to zeros")
latlon = [0, 0]
else:
ignoremask = ignoremask & 504
print ("found latlon", ignoremask)
vN = 0
vE = 0
vD = 0
if (len(args) == 3):
vN = float(args[0])
vE = float(args[1])
vD = float(args[2])
ignoremask = ignoremask & 455
print ("ignoremask",ignoremask)
print (latlon)
self.master.mav.set_position_target_global_int_send(
0, # system time in ms
1, # target system
0, # target component
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT_INT,
ignoremask, # ignore
int(latlon[0] * 1e7),
int(latlon[1] * 1e7),
10,
vN, vE, vD, # velocity
0, 0, 0, # accel x,y,z
0, 0) | python | def cmd_posvel(self, args):
'''posvel mapclick vN vE vD'''
ignoremask = 511
latlon = None
try:
latlon = self.module('map').click_position
except Exception:
pass
if latlon is None:
print ("set latlon to zeros")
latlon = [0, 0]
else:
ignoremask = ignoremask & 504
print ("found latlon", ignoremask)
vN = 0
vE = 0
vD = 0
if (len(args) == 3):
vN = float(args[0])
vE = float(args[1])
vD = float(args[2])
ignoremask = ignoremask & 455
print ("ignoremask",ignoremask)
print (latlon)
self.master.mav.set_position_target_global_int_send(
0, # system time in ms
1, # target system
0, # target component
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT_INT,
ignoremask, # ignore
int(latlon[0] * 1e7),
int(latlon[1] * 1e7),
10,
vN, vE, vD, # velocity
0, 0, 0, # accel x,y,z
0, 0) | [
"def",
"cmd_posvel",
"(",
"self",
",",
"args",
")",
":",
"ignoremask",
"=",
"511",
"latlon",
"=",
"None",
"try",
":",
"latlon",
"=",
"self",
".",
"module",
"(",
"'map'",
")",
".",
"click_position",
"except",
"Exception",
":",
"pass",
"if",
"latlon",
"i... | posvel mapclick vN vE vD | [
"posvel",
"mapclick",
"vN",
"vE",
"vD"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_cmdlong.py#L229-L265 | train | 230,281 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_widgets.py | ImagePanel.on_paint | def on_paint(self, event):
'''repaint the image'''
dc = wx.AutoBufferedPaintDC(self)
dc.DrawBitmap(self._bmp, 0, 0) | python | def on_paint(self, event):
'''repaint the image'''
dc = wx.AutoBufferedPaintDC(self)
dc.DrawBitmap(self._bmp, 0, 0) | [
"def",
"on_paint",
"(",
"self",
",",
"event",
")",
":",
"dc",
"=",
"wx",
".",
"AutoBufferedPaintDC",
"(",
"self",
")",
"dc",
".",
"DrawBitmap",
"(",
"self",
".",
"_bmp",
",",
"0",
",",
"0",
")"
] | repaint the image | [
"repaint",
"the",
"image"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_widgets.py#L19-L22 | train | 230,282 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen.py | mavgen_python_dialect | def mavgen_python_dialect(dialect, wire_protocol):
'''generate the python code on the fly for a MAVLink dialect'''
dialects = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'dialects')
mdef = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', 'message_definitions')
if wire_protocol == mavparse.PROTOCOL_0_9:
py = os.path.join(dialects, 'v09', dialect + '.py')
xml = os.path.join(dialects, 'v09', dialect + '.xml')
if not os.path.exists(xml):
xml = os.path.join(mdef, 'v0.9', dialect + '.xml')
elif wire_protocol == mavparse.PROTOCOL_1_0:
py = os.path.join(dialects, 'v10', dialect + '.py')
xml = os.path.join(dialects, 'v10', dialect + '.xml')
if not os.path.exists(xml):
xml = os.path.join(mdef, 'v1.0', dialect + '.xml')
else:
py = os.path.join(dialects, 'v20', dialect + '.py')
xml = os.path.join(dialects, 'v20', dialect + '.xml')
if not os.path.exists(xml):
xml = os.path.join(mdef, 'v1.0', dialect + '.xml')
opts = Opts(py, wire_protocol)
# Python 2 to 3 compatibility
try:
import StringIO as io
except ImportError:
import io
# throw away stdout while generating
stdout_saved = sys.stdout
sys.stdout = io.StringIO()
try:
xml = os.path.relpath(xml)
if not mavgen(opts, [xml]):
sys.stdout = stdout_saved
return False
except Exception:
sys.stdout = stdout_saved
raise
sys.stdout = stdout_saved
return True | python | def mavgen_python_dialect(dialect, wire_protocol):
'''generate the python code on the fly for a MAVLink dialect'''
dialects = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'dialects')
mdef = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', 'message_definitions')
if wire_protocol == mavparse.PROTOCOL_0_9:
py = os.path.join(dialects, 'v09', dialect + '.py')
xml = os.path.join(dialects, 'v09', dialect + '.xml')
if not os.path.exists(xml):
xml = os.path.join(mdef, 'v0.9', dialect + '.xml')
elif wire_protocol == mavparse.PROTOCOL_1_0:
py = os.path.join(dialects, 'v10', dialect + '.py')
xml = os.path.join(dialects, 'v10', dialect + '.xml')
if not os.path.exists(xml):
xml = os.path.join(mdef, 'v1.0', dialect + '.xml')
else:
py = os.path.join(dialects, 'v20', dialect + '.py')
xml = os.path.join(dialects, 'v20', dialect + '.xml')
if not os.path.exists(xml):
xml = os.path.join(mdef, 'v1.0', dialect + '.xml')
opts = Opts(py, wire_protocol)
# Python 2 to 3 compatibility
try:
import StringIO as io
except ImportError:
import io
# throw away stdout while generating
stdout_saved = sys.stdout
sys.stdout = io.StringIO()
try:
xml = os.path.relpath(xml)
if not mavgen(opts, [xml]):
sys.stdout = stdout_saved
return False
except Exception:
sys.stdout = stdout_saved
raise
sys.stdout = stdout_saved
return True | [
"def",
"mavgen_python_dialect",
"(",
"dialect",
",",
"wire_protocol",
")",
":",
"dialects",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"realpath",
"(",
"__file__",
")",
")",
",",
"'..'",
... | generate the python code on the fly for a MAVLink dialect | [
"generate",
"the",
"python",
"code",
"on",
"the",
"fly",
"for",
"a",
"MAVLink",
"dialect"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen.py#L165-L204 | train | 230,283 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavtomfile.py | process_tlog | def process_tlog(filename):
'''convert a tlog to a .m file'''
print("Processing %s" % filename)
mlog = mavutil.mavlink_connection(filename, dialect=args.dialect, zero_time_base=True)
# first walk the entire file, grabbing all messages into a hash of lists,
#and the first message of each type into a hash
msg_types = {}
msg_lists = {}
types = args.types
if types is not None:
types = types.split(',')
# note that Octave doesn't like any extra '.', '*', '-', characters in the filename
(head, tail) = os.path.split(filename)
basename = '.'.join(tail.split('.')[:-1])
mfilename = re.sub('[\.\-\+\*]','_', basename) + '.m'
# Octave also doesn't like files that don't start with a letter
if (re.match('^[a-zA-z]', mfilename) == None):
mfilename = 'm_' + mfilename
if head is not None:
mfilename = os.path.join(head, mfilename)
print("Creating %s" % mfilename)
f = open(mfilename, "w")
type_counters = {}
while True:
m = mlog.recv_match(condition=args.condition)
if m is None:
break
if types is not None and m.get_type() not in types:
continue
if m.get_type() == 'BAD_DATA':
continue
fieldnames = m._fieldnames
mtype = m.get_type()
if mtype in ['FMT', 'PARM']:
continue
if mtype not in type_counters:
type_counters[mtype] = 0
f.write("%s.columns = {'timestamp'" % mtype)
for field in fieldnames:
val = getattr(m, field)
if not isinstance(val, str):
if type(val) is not list:
f.write(",'%s'" % field)
else:
for i in range(0, len(val)):
f.write(",'%s%d'" % (field, i + 1))
f.write("};\n")
type_counters[mtype] += 1
f.write("%s.data(%u,:) = [%f" % (mtype, type_counters[mtype], m._timestamp))
for field in m._fieldnames:
val = getattr(m, field)
if not isinstance(val, str):
if type(val) is not list:
f.write(",%.20g" % val)
else:
for i in range(0, len(val)):
f.write(",%.20g" % val[i])
f.write("];\n")
f.close() | python | def process_tlog(filename):
'''convert a tlog to a .m file'''
print("Processing %s" % filename)
mlog = mavutil.mavlink_connection(filename, dialect=args.dialect, zero_time_base=True)
# first walk the entire file, grabbing all messages into a hash of lists,
#and the first message of each type into a hash
msg_types = {}
msg_lists = {}
types = args.types
if types is not None:
types = types.split(',')
# note that Octave doesn't like any extra '.', '*', '-', characters in the filename
(head, tail) = os.path.split(filename)
basename = '.'.join(tail.split('.')[:-1])
mfilename = re.sub('[\.\-\+\*]','_', basename) + '.m'
# Octave also doesn't like files that don't start with a letter
if (re.match('^[a-zA-z]', mfilename) == None):
mfilename = 'm_' + mfilename
if head is not None:
mfilename = os.path.join(head, mfilename)
print("Creating %s" % mfilename)
f = open(mfilename, "w")
type_counters = {}
while True:
m = mlog.recv_match(condition=args.condition)
if m is None:
break
if types is not None and m.get_type() not in types:
continue
if m.get_type() == 'BAD_DATA':
continue
fieldnames = m._fieldnames
mtype = m.get_type()
if mtype in ['FMT', 'PARM']:
continue
if mtype not in type_counters:
type_counters[mtype] = 0
f.write("%s.columns = {'timestamp'" % mtype)
for field in fieldnames:
val = getattr(m, field)
if not isinstance(val, str):
if type(val) is not list:
f.write(",'%s'" % field)
else:
for i in range(0, len(val)):
f.write(",'%s%d'" % (field, i + 1))
f.write("};\n")
type_counters[mtype] += 1
f.write("%s.data(%u,:) = [%f" % (mtype, type_counters[mtype], m._timestamp))
for field in m._fieldnames:
val = getattr(m, field)
if not isinstance(val, str):
if type(val) is not list:
f.write(",%.20g" % val)
else:
for i in range(0, len(val)):
f.write(",%.20g" % val[i])
f.write("];\n")
f.close() | [
"def",
"process_tlog",
"(",
"filename",
")",
":",
"print",
"(",
"\"Processing %s\"",
"%",
"filename",
")",
"mlog",
"=",
"mavutil",
".",
"mavlink_connection",
"(",
"filename",
",",
"dialect",
"=",
"args",
".",
"dialect",
",",
"zero_time_base",
"=",
"True",
")... | convert a tlog to a .m file | [
"convert",
"a",
"tlog",
"to",
"a",
".",
"m",
"file"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavtomfile.py#L11-L82 | train | 230,284 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit_motors.py | radius | def radius(d, offsets, motor_ofs):
'''return radius give data point and offsets'''
(mag, motor) = d
return (mag + offsets + motor*motor_ofs).length() | python | def radius(d, offsets, motor_ofs):
'''return radius give data point and offsets'''
(mag, motor) = d
return (mag + offsets + motor*motor_ofs).length() | [
"def",
"radius",
"(",
"d",
",",
"offsets",
",",
"motor_ofs",
")",
":",
"(",
"mag",
",",
"motor",
")",
"=",
"d",
"return",
"(",
"mag",
"+",
"offsets",
"+",
"motor",
"*",
"motor_ofs",
")",
".",
"length",
"(",
")"
] | return radius give data point and offsets | [
"return",
"radius",
"give",
"data",
"point",
"and",
"offsets"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit_motors.py#L44-L47 | train | 230,285 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_objc.py | camel_case_from_underscores | def camel_case_from_underscores(string):
"""generate a CamelCase string from an underscore_string."""
components = string.split('_')
string = ''
for component in components:
string += component[0].upper() + component[1:]
return string | python | def camel_case_from_underscores(string):
"""generate a CamelCase string from an underscore_string."""
components = string.split('_')
string = ''
for component in components:
string += component[0].upper() + component[1:]
return string | [
"def",
"camel_case_from_underscores",
"(",
"string",
")",
":",
"components",
"=",
"string",
".",
"split",
"(",
"'_'",
")",
"string",
"=",
"''",
"for",
"component",
"in",
"components",
":",
"string",
"+=",
"component",
"[",
"0",
"]",
".",
"upper",
"(",
")... | generate a CamelCase string from an underscore_string. | [
"generate",
"a",
"CamelCase",
"string",
"from",
"an",
"underscore_string",
"."
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_objc.py#L311-L317 | train | 230,286 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_objc.py | generate | def generate(basename, xml_list):
'''generate complete MAVLink Objective-C implemenation'''
generate_shared(basename, xml_list)
for xml in xml_list:
generate_message_definitions(basename, xml) | python | def generate(basename, xml_list):
'''generate complete MAVLink Objective-C implemenation'''
generate_shared(basename, xml_list)
for xml in xml_list:
generate_message_definitions(basename, xml) | [
"def",
"generate",
"(",
"basename",
",",
"xml_list",
")",
":",
"generate_shared",
"(",
"basename",
",",
"xml_list",
")",
"for",
"xml",
"in",
"xml_list",
":",
"generate_message_definitions",
"(",
"basename",
",",
"xml",
")"
] | generate complete MAVLink Objective-C implemenation | [
"generate",
"complete",
"MAVLink",
"Objective",
"-",
"C",
"implemenation"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_objc.py#L431-L436 | train | 230,287 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/live_graph.py | LiveGraph.add_values | def add_values(self, values):
'''add some data to the graph'''
if self.child.is_alive():
self.parent_pipe.send(values) | python | def add_values(self, values):
'''add some data to the graph'''
if self.child.is_alive():
self.parent_pipe.send(values) | [
"def",
"add_values",
"(",
"self",
",",
"values",
")",
":",
"if",
"self",
".",
"child",
".",
"is_alive",
"(",
")",
":",
"self",
".",
"parent_pipe",
".",
"send",
"(",
"values",
")"
] | add some data to the graph | [
"add",
"some",
"data",
"to",
"the",
"graph"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/live_graph.py#L57-L60 | train | 230,288 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/live_graph.py | LiveGraph.close | def close(self):
'''close the graph'''
self.close_graph.set()
if self.is_alive():
self.child.join(2) | python | def close(self):
'''close the graph'''
self.close_graph.set()
if self.is_alive():
self.child.join(2) | [
"def",
"close",
"(",
"self",
")",
":",
"self",
".",
"close_graph",
".",
"set",
"(",
")",
"if",
"self",
".",
"is_alive",
"(",
")",
":",
"self",
".",
"child",
".",
"join",
"(",
"2",
")"
] | close the graph | [
"close",
"the",
"graph"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/live_graph.py#L62-L66 | train | 230,289 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_swift.py | get_enum_raw_type | def get_enum_raw_type(enum, msgs):
"""Search appropirate raw type for enums in messages fields"""
for msg in msgs:
for field in msg.fields:
if field.enum == enum.name:
return swift_types[field.type][0]
return "Int" | python | def get_enum_raw_type(enum, msgs):
"""Search appropirate raw type for enums in messages fields"""
for msg in msgs:
for field in msg.fields:
if field.enum == enum.name:
return swift_types[field.type][0]
return "Int" | [
"def",
"get_enum_raw_type",
"(",
"enum",
",",
"msgs",
")",
":",
"for",
"msg",
"in",
"msgs",
":",
"for",
"field",
"in",
"msg",
".",
"fields",
":",
"if",
"field",
".",
"enum",
"==",
"enum",
".",
"name",
":",
"return",
"swift_types",
"[",
"field",
".",
... | Search appropirate raw type for enums in messages fields | [
"Search",
"appropirate",
"raw",
"type",
"for",
"enums",
"in",
"messages",
"fields"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_swift.py#L139-L146 | train | 230,290 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_swift.py | append_static_code | def append_static_code(filename, outf):
"""Open and copy static code from specified file"""
basepath = os.path.dirname(os.path.realpath(__file__))
filepath = os.path.join(basepath, 'swift/%s' % filename)
print("Appending content of %s" % filename)
with open(filepath) as inf:
for line in inf:
outf.write(line) | python | def append_static_code(filename, outf):
"""Open and copy static code from specified file"""
basepath = os.path.dirname(os.path.realpath(__file__))
filepath = os.path.join(basepath, 'swift/%s' % filename)
print("Appending content of %s" % filename)
with open(filepath) as inf:
for line in inf:
outf.write(line) | [
"def",
"append_static_code",
"(",
"filename",
",",
"outf",
")",
":",
"basepath",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"realpath",
"(",
"__file__",
")",
")",
"filepath",
"=",
"os",
".",
"path",
".",
"join",
"(",
"basepa... | Open and copy static code from specified file | [
"Open",
"and",
"copy",
"static",
"code",
"from",
"specified",
"file"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_swift.py#L243-L253 | train | 230,291 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_swift.py | camel_case_from_underscores | def camel_case_from_underscores(string):
"""Generate a CamelCase string from an underscore_string"""
components = string.split('_')
string = ''
for component in components:
if component in abbreviations:
string += component
else:
string += component[0].upper() + component[1:].lower()
return string | python | def camel_case_from_underscores(string):
"""Generate a CamelCase string from an underscore_string"""
components = string.split('_')
string = ''
for component in components:
if component in abbreviations:
string += component
else:
string += component[0].upper() + component[1:].lower()
return string | [
"def",
"camel_case_from_underscores",
"(",
"string",
")",
":",
"components",
"=",
"string",
".",
"split",
"(",
"'_'",
")",
"string",
"=",
"''",
"for",
"component",
"in",
"components",
":",
"if",
"component",
"in",
"abbreviations",
":",
"string",
"+=",
"compo... | Generate a CamelCase string from an underscore_string | [
"Generate",
"a",
"CamelCase",
"string",
"from",
"an",
"underscore_string"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_swift.py#L304-L316 | train | 230,292 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_swift.py | generate_enums_info | def generate_enums_info(enums, msgs):
"""Add camel case swift names for enums an entries, descriptions and sort enums alphabetically"""
for enum in enums:
enum.swift_name = camel_case_from_underscores(enum.name)
enum.raw_value_type = get_enum_raw_type(enum, msgs)
enum.formatted_description = ""
if enum.description:
enum.description = " ".join(enum.description.split())
enum.formatted_description = "\n/**\n %s\n*/\n" % enum.description
all_entities = []
entities_info = []
for entry in enum.entry:
name = entry.name.replace(enum.name + '_', '')
"""Ensure that enums entry name does not start from digit"""
if name[0].isdigit():
name = "MAV_" + name
entry.swift_name = camel_case_from_underscores(name)
entry.formatted_description = ""
if entry.description:
entry.description = " ".join(entry.description.split())
entry.formatted_description = "\n\t/// " + entry.description + "\n"
all_entities.append(entry.swift_name)
entities_info.append('("%s", "%s")' % (entry.name, entry.description.replace('"','\\"')))
enum.all_entities = ", ".join(all_entities)
enum.entities_info = ", ".join(entities_info)
enum.entity_description = enum.description.replace('"','\\"')
enums.sort(key = lambda enum : enum.swift_name) | python | def generate_enums_info(enums, msgs):
"""Add camel case swift names for enums an entries, descriptions and sort enums alphabetically"""
for enum in enums:
enum.swift_name = camel_case_from_underscores(enum.name)
enum.raw_value_type = get_enum_raw_type(enum, msgs)
enum.formatted_description = ""
if enum.description:
enum.description = " ".join(enum.description.split())
enum.formatted_description = "\n/**\n %s\n*/\n" % enum.description
all_entities = []
entities_info = []
for entry in enum.entry:
name = entry.name.replace(enum.name + '_', '')
"""Ensure that enums entry name does not start from digit"""
if name[0].isdigit():
name = "MAV_" + name
entry.swift_name = camel_case_from_underscores(name)
entry.formatted_description = ""
if entry.description:
entry.description = " ".join(entry.description.split())
entry.formatted_description = "\n\t/// " + entry.description + "\n"
all_entities.append(entry.swift_name)
entities_info.append('("%s", "%s")' % (entry.name, entry.description.replace('"','\\"')))
enum.all_entities = ", ".join(all_entities)
enum.entities_info = ", ".join(entities_info)
enum.entity_description = enum.description.replace('"','\\"')
enums.sort(key = lambda enum : enum.swift_name) | [
"def",
"generate_enums_info",
"(",
"enums",
",",
"msgs",
")",
":",
"for",
"enum",
"in",
"enums",
":",
"enum",
".",
"swift_name",
"=",
"camel_case_from_underscores",
"(",
"enum",
".",
"name",
")",
"enum",
".",
"raw_value_type",
"=",
"get_enum_raw_type",
"(",
... | Add camel case swift names for enums an entries, descriptions and sort enums alphabetically | [
"Add",
"camel",
"case",
"swift",
"names",
"for",
"enums",
"an",
"entries",
"descriptions",
"and",
"sort",
"enums",
"alphabetically"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_swift.py#L328-L362 | train | 230,293 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_swift.py | generate_messages_info | def generate_messages_info(msgs):
"""Add proper formated variable names, initializers and type names to use in templates"""
for msg in msgs:
msg.swift_name = camel_case_from_underscores(msg.name)
msg.formatted_description = ""
if msg.description:
msg.description = " ".join(msg.description.split())
msg.formatted_description = "\n/**\n %s\n*/\n" % " ".join(msg.description.split())
msg.message_description = msg.description.replace('"','\\"')
for field in msg.ordered_fields:
field.swift_name = lower_camel_case_from_underscores(field.name)
field.return_type = swift_types[field.type][0]
# configure fields initializers
if field.enum:
# handle enums
field.return_type = camel_case_from_underscores(field.enum)
field.initial_value = "try data.mavEnumeration(offset: %u)" % field.wire_offset
elif field.array_length > 0:
if field.return_type == "String":
# handle strings
field.initial_value = "data." + swift_types[field.type][2] % (field.wire_offset, field.array_length)
else:
# other array types
field.return_type = "[%s]" % field.return_type
field.initial_value = "try data.mavArray(offset: %u, count: %u)" % (field.wire_offset, field.array_length)
else:
# simple type field
field.initial_value = "try data." + swift_types[field.type][2] % field.wire_offset
field.formatted_description = ""
if field.description:
field.description = " ".join(field.description.split())
field.formatted_description = "\n\t/// " + field.description + "\n"
fields_info = map(lambda field: '("%s", %u, "%s", "%s")' % (field.swift_name, field.wire_offset, field.return_type, field.description.replace('"','\\"')), msg.fields)
msg.fields_info = ", ".join(fields_info)
msgs.sort(key = lambda msg : msg.id) | python | def generate_messages_info(msgs):
"""Add proper formated variable names, initializers and type names to use in templates"""
for msg in msgs:
msg.swift_name = camel_case_from_underscores(msg.name)
msg.formatted_description = ""
if msg.description:
msg.description = " ".join(msg.description.split())
msg.formatted_description = "\n/**\n %s\n*/\n" % " ".join(msg.description.split())
msg.message_description = msg.description.replace('"','\\"')
for field in msg.ordered_fields:
field.swift_name = lower_camel_case_from_underscores(field.name)
field.return_type = swift_types[field.type][0]
# configure fields initializers
if field.enum:
# handle enums
field.return_type = camel_case_from_underscores(field.enum)
field.initial_value = "try data.mavEnumeration(offset: %u)" % field.wire_offset
elif field.array_length > 0:
if field.return_type == "String":
# handle strings
field.initial_value = "data." + swift_types[field.type][2] % (field.wire_offset, field.array_length)
else:
# other array types
field.return_type = "[%s]" % field.return_type
field.initial_value = "try data.mavArray(offset: %u, count: %u)" % (field.wire_offset, field.array_length)
else:
# simple type field
field.initial_value = "try data." + swift_types[field.type][2] % field.wire_offset
field.formatted_description = ""
if field.description:
field.description = " ".join(field.description.split())
field.formatted_description = "\n\t/// " + field.description + "\n"
fields_info = map(lambda field: '("%s", %u, "%s", "%s")' % (field.swift_name, field.wire_offset, field.return_type, field.description.replace('"','\\"')), msg.fields)
msg.fields_info = ", ".join(fields_info)
msgs.sort(key = lambda msg : msg.id) | [
"def",
"generate_messages_info",
"(",
"msgs",
")",
":",
"for",
"msg",
"in",
"msgs",
":",
"msg",
".",
"swift_name",
"=",
"camel_case_from_underscores",
"(",
"msg",
".",
"name",
")",
"msg",
".",
"formatted_description",
"=",
"\"\"",
"if",
"msg",
".",
"descript... | Add proper formated variable names, initializers and type names to use in templates | [
"Add",
"proper",
"formated",
"variable",
"names",
"initializers",
"and",
"type",
"names",
"to",
"use",
"in",
"templates"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_swift.py#L364-L405 | train | 230,294 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_swift.py | generate | def generate(basename, xml_list):
"""Generate complete MAVLink Swift implemenation"""
if os.path.isdir(basename):
filename = os.path.join(basename, 'MAVLink.swift')
else:
filename = basename
msgs = []
enums = []
filelist = []
for xml in xml_list:
msgs.extend(xml.message)
enums.extend(xml.enum)
filelist.append(os.path.basename(xml.filename))
outf = open(filename, "w")
generate_header(outf, filelist, xml_list)
generate_enums_info(enums, msgs)
generate_enums(outf, enums, msgs)
generate_messages_info(msgs)
generate_messages(outf, msgs)
append_static_code('Parser.swift', outf)
generate_message_mappings_array(outf, msgs)
generate_message_lengths_array(outf, msgs)
generate_message_crc_extra_array(outf, msgs)
outf.close() | python | def generate(basename, xml_list):
"""Generate complete MAVLink Swift implemenation"""
if os.path.isdir(basename):
filename = os.path.join(basename, 'MAVLink.swift')
else:
filename = basename
msgs = []
enums = []
filelist = []
for xml in xml_list:
msgs.extend(xml.message)
enums.extend(xml.enum)
filelist.append(os.path.basename(xml.filename))
outf = open(filename, "w")
generate_header(outf, filelist, xml_list)
generate_enums_info(enums, msgs)
generate_enums(outf, enums, msgs)
generate_messages_info(msgs)
generate_messages(outf, msgs)
append_static_code('Parser.swift', outf)
generate_message_mappings_array(outf, msgs)
generate_message_lengths_array(outf, msgs)
generate_message_crc_extra_array(outf, msgs)
outf.close() | [
"def",
"generate",
"(",
"basename",
",",
"xml_list",
")",
":",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"basename",
")",
":",
"filename",
"=",
"os",
".",
"path",
".",
"join",
"(",
"basename",
",",
"'MAVLink.swift'",
")",
"else",
":",
"filename",
"... | Generate complete MAVLink Swift implemenation | [
"Generate",
"complete",
"MAVLink",
"Swift",
"implemenation"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_swift.py#L407-L433 | train | 230,295 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVWPLoader.wp_is_loiter | def wp_is_loiter(self, i):
'''return true if waypoint is a loiter waypoint'''
loiter_cmds = [mavutil.mavlink.MAV_CMD_NAV_LOITER_UNLIM,
mavutil.mavlink.MAV_CMD_NAV_LOITER_TURNS,
mavutil.mavlink.MAV_CMD_NAV_LOITER_TIME,
mavutil.mavlink.MAV_CMD_NAV_LOITER_TO_ALT]
if (self.wpoints[i].command in loiter_cmds):
return True
return False | python | def wp_is_loiter(self, i):
'''return true if waypoint is a loiter waypoint'''
loiter_cmds = [mavutil.mavlink.MAV_CMD_NAV_LOITER_UNLIM,
mavutil.mavlink.MAV_CMD_NAV_LOITER_TURNS,
mavutil.mavlink.MAV_CMD_NAV_LOITER_TIME,
mavutil.mavlink.MAV_CMD_NAV_LOITER_TO_ALT]
if (self.wpoints[i].command in loiter_cmds):
return True
return False | [
"def",
"wp_is_loiter",
"(",
"self",
",",
"i",
")",
":",
"loiter_cmds",
"=",
"[",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_NAV_LOITER_UNLIM",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_NAV_LOITER_TURNS",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_NAV_LOITER... | return true if waypoint is a loiter waypoint | [
"return",
"true",
"if",
"waypoint",
"is",
"a",
"loiter",
"waypoint"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L44-L54 | train | 230,296 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVWPLoader.add | def add(self, w, comment=''):
'''add a waypoint'''
w = copy.copy(w)
if comment:
w.comment = comment
w.seq = self.count()
self.wpoints.append(w)
self.last_change = time.time() | python | def add(self, w, comment=''):
'''add a waypoint'''
w = copy.copy(w)
if comment:
w.comment = comment
w.seq = self.count()
self.wpoints.append(w)
self.last_change = time.time() | [
"def",
"add",
"(",
"self",
",",
"w",
",",
"comment",
"=",
"''",
")",
":",
"w",
"=",
"copy",
".",
"copy",
"(",
"w",
")",
"if",
"comment",
":",
"w",
".",
"comment",
"=",
"comment",
"w",
".",
"seq",
"=",
"self",
".",
"count",
"(",
")",
"self",
... | add a waypoint | [
"add",
"a",
"waypoint"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L56-L63 | train | 230,297 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVWPLoader.insert | def insert(self, idx, w, comment=''):
'''insert a waypoint'''
if idx >= self.count():
self.add(w, comment)
return
if idx < 0:
return
w = copy.copy(w)
if comment:
w.comment = comment
w.seq = idx
self.wpoints.insert(idx, w)
self.last_change = time.time()
self.reindex() | python | def insert(self, idx, w, comment=''):
'''insert a waypoint'''
if idx >= self.count():
self.add(w, comment)
return
if idx < 0:
return
w = copy.copy(w)
if comment:
w.comment = comment
w.seq = idx
self.wpoints.insert(idx, w)
self.last_change = time.time()
self.reindex() | [
"def",
"insert",
"(",
"self",
",",
"idx",
",",
"w",
",",
"comment",
"=",
"''",
")",
":",
"if",
"idx",
">=",
"self",
".",
"count",
"(",
")",
":",
"self",
".",
"add",
"(",
"w",
",",
"comment",
")",
"return",
"if",
"idx",
"<",
"0",
":",
"return"... | insert a waypoint | [
"insert",
"a",
"waypoint"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L65-L78 | train | 230,298 |
JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVWPLoader.set | def set(self, w, idx):
'''set a waypoint'''
w.seq = idx
if w.seq == self.count():
return self.add(w)
if self.count() <= idx:
raise MAVWPError('adding waypoint at idx=%u past end of list (count=%u)' % (idx, self.count()))
self.wpoints[idx] = w
self.last_change = time.time() | python | def set(self, w, idx):
'''set a waypoint'''
w.seq = idx
if w.seq == self.count():
return self.add(w)
if self.count() <= idx:
raise MAVWPError('adding waypoint at idx=%u past end of list (count=%u)' % (idx, self.count()))
self.wpoints[idx] = w
self.last_change = time.time() | [
"def",
"set",
"(",
"self",
",",
"w",
",",
"idx",
")",
":",
"w",
".",
"seq",
"=",
"idx",
"if",
"w",
".",
"seq",
"==",
"self",
".",
"count",
"(",
")",
":",
"return",
"self",
".",
"add",
"(",
"w",
")",
"if",
"self",
".",
"count",
"(",
")",
"... | set a waypoint | [
"set",
"a",
"waypoint"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L102-L110 | train | 230,299 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.