id
int32 0
252k
| repo
stringlengths 7
55
| path
stringlengths 4
127
| func_name
stringlengths 1
88
| original_string
stringlengths 75
19.8k
| language
stringclasses 1
value | code
stringlengths 51
19.8k
| code_tokens
sequence | docstring
stringlengths 3
17.3k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 87
242
|
---|---|---|---|---|---|---|---|---|---|---|---|
249,200 | 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 |
249,201 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit.py | radius_cmp | def radius_cmp(a, b, offsets):
'''return +1 or -1 for for sorting'''
diff = radius(a, offsets) - radius(b, offsets)
if diff > 0:
return 1
if diff < 0:
return -1
return 0 | python | def radius_cmp(a, b, offsets):
'''return +1 or -1 for for sorting'''
diff = radius(a, offsets) - radius(b, offsets)
if diff > 0:
return 1
if diff < 0:
return -1
return 0 | [
"def",
"radius_cmp",
"(",
"a",
",",
"b",
",",
"offsets",
")",
":",
"diff",
"=",
"radius",
"(",
"a",
",",
"offsets",
")",
"-",
"radius",
"(",
"b",
",",
"offsets",
")",
"if",
"diff",
">",
"0",
":",
"return",
"1",
"if",
"diff",
"<",
"0",
":",
"return",
"-",
"1",
"return",
"0"
] | return +1 or -1 for for sorting | [
"return",
"+",
"1",
"or",
"-",
"1",
"for",
"for",
"sorting"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit.py#L51-L58 |
249,202 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit.py | plot_data | def plot_data(orig_data, data):
'''plot data in 3D'''
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
for dd, c in [(orig_data, 'r'), (data, 'b')]:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
xs = [ d.x for d in dd ]
ys = [ d.y for d in dd ]
zs = [ d.z for d in dd ]
ax.scatter(xs, ys, zs, c=c, marker='o')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show() | python | def plot_data(orig_data, data):
'''plot data in 3D'''
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
for dd, c in [(orig_data, 'r'), (data, 'b')]:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
xs = [ d.x for d in dd ]
ys = [ d.y for d in dd ]
zs = [ d.z for d in dd ]
ax.scatter(xs, ys, zs, c=c, marker='o')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show() | [
"def",
"plot_data",
"(",
"orig_data",
",",
"data",
")",
":",
"import",
"numpy",
"as",
"np",
"from",
"mpl_toolkits",
".",
"mplot3d",
"import",
"Axes3D",
"import",
"matplotlib",
".",
"pyplot",
"as",
"plt",
"for",
"dd",
",",
"c",
"in",
"[",
"(",
"orig_data",
",",
"'r'",
")",
",",
"(",
"data",
",",
"'b'",
")",
"]",
":",
"fig",
"=",
"plt",
".",
"figure",
"(",
")",
"ax",
"=",
"fig",
".",
"add_subplot",
"(",
"111",
",",
"projection",
"=",
"'3d'",
")",
"xs",
"=",
"[",
"d",
".",
"x",
"for",
"d",
"in",
"dd",
"]",
"ys",
"=",
"[",
"d",
".",
"y",
"for",
"d",
"in",
"dd",
"]",
"zs",
"=",
"[",
"d",
".",
"z",
"for",
"d",
"in",
"dd",
"]",
"ax",
".",
"scatter",
"(",
"xs",
",",
"ys",
",",
"zs",
",",
"c",
"=",
"c",
",",
"marker",
"=",
"'o'",
")",
"ax",
".",
"set_xlabel",
"(",
"'X Label'",
")",
"ax",
".",
"set_ylabel",
"(",
"'Y Label'",
")",
"ax",
".",
"set_zlabel",
"(",
"'Z Label'",
")",
"plt",
".",
"show",
"(",
")"
] | plot data in 3D | [
"plot",
"data",
"in",
"3D"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/magfit.py#L154-L172 |
249,203 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavtemplate.py | MAVTemplate.find_end | def find_end(self, text, start_token, end_token, ignore_end_token=None):
'''find the of a token.
Returns the offset in the string immediately after the matching end_token'''
if not text.startswith(start_token):
raise MAVParseError("invalid token start")
offset = len(start_token)
nesting = 1
while nesting > 0:
idx1 = text[offset:].find(start_token)
idx2 = text[offset:].find(end_token)
# Check for false positives due to another similar token
# For example, make sure idx2 points to the second '}' in ${{field: ${name}}}
if ignore_end_token:
combined_token = ignore_end_token + end_token
if text[offset+idx2:offset+idx2+len(combined_token)] == combined_token:
idx2 += len(ignore_end_token)
if idx1 == -1 and idx2 == -1:
raise MAVParseError("token nesting error")
if idx1 == -1 or idx1 > idx2:
offset += idx2 + len(end_token)
nesting -= 1
else:
offset += idx1 + len(start_token)
nesting += 1
return offset | python | def find_end(self, text, start_token, end_token, ignore_end_token=None):
'''find the of a token.
Returns the offset in the string immediately after the matching end_token'''
if not text.startswith(start_token):
raise MAVParseError("invalid token start")
offset = len(start_token)
nesting = 1
while nesting > 0:
idx1 = text[offset:].find(start_token)
idx2 = text[offset:].find(end_token)
# Check for false positives due to another similar token
# For example, make sure idx2 points to the second '}' in ${{field: ${name}}}
if ignore_end_token:
combined_token = ignore_end_token + end_token
if text[offset+idx2:offset+idx2+len(combined_token)] == combined_token:
idx2 += len(ignore_end_token)
if idx1 == -1 and idx2 == -1:
raise MAVParseError("token nesting error")
if idx1 == -1 or idx1 > idx2:
offset += idx2 + len(end_token)
nesting -= 1
else:
offset += idx1 + len(start_token)
nesting += 1
return offset | [
"def",
"find_end",
"(",
"self",
",",
"text",
",",
"start_token",
",",
"end_token",
",",
"ignore_end_token",
"=",
"None",
")",
":",
"if",
"not",
"text",
".",
"startswith",
"(",
"start_token",
")",
":",
"raise",
"MAVParseError",
"(",
"\"invalid token start\"",
")",
"offset",
"=",
"len",
"(",
"start_token",
")",
"nesting",
"=",
"1",
"while",
"nesting",
">",
"0",
":",
"idx1",
"=",
"text",
"[",
"offset",
":",
"]",
".",
"find",
"(",
"start_token",
")",
"idx2",
"=",
"text",
"[",
"offset",
":",
"]",
".",
"find",
"(",
"end_token",
")",
"# Check for false positives due to another similar token",
"# For example, make sure idx2 points to the second '}' in ${{field: ${name}}}",
"if",
"ignore_end_token",
":",
"combined_token",
"=",
"ignore_end_token",
"+",
"end_token",
"if",
"text",
"[",
"offset",
"+",
"idx2",
":",
"offset",
"+",
"idx2",
"+",
"len",
"(",
"combined_token",
")",
"]",
"==",
"combined_token",
":",
"idx2",
"+=",
"len",
"(",
"ignore_end_token",
")",
"if",
"idx1",
"==",
"-",
"1",
"and",
"idx2",
"==",
"-",
"1",
":",
"raise",
"MAVParseError",
"(",
"\"token nesting error\"",
")",
"if",
"idx1",
"==",
"-",
"1",
"or",
"idx1",
">",
"idx2",
":",
"offset",
"+=",
"idx2",
"+",
"len",
"(",
"end_token",
")",
"nesting",
"-=",
"1",
"else",
":",
"offset",
"+=",
"idx1",
"+",
"len",
"(",
"start_token",
")",
"nesting",
"+=",
"1",
"return",
"offset"
] | find the of a token.
Returns the offset in the string immediately after the matching end_token | [
"find",
"the",
"of",
"a",
"token",
".",
"Returns",
"the",
"offset",
"in",
"the",
"string",
"immediately",
"after",
"the",
"matching",
"end_token"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavtemplate.py#L27-L51 |
249,204 | 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 |
249,205 | 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 |
249,206 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavtemplate.py | MAVTemplate.write | def write(self, file, text, subvars={}, trim_leading_lf=True):
'''write to a file with variable substitution'''
file.write(self.substitute(text, subvars=subvars, trim_leading_lf=trim_leading_lf)) | python | def write(self, file, text, subvars={}, trim_leading_lf=True):
'''write to a file with variable substitution'''
file.write(self.substitute(text, subvars=subvars, trim_leading_lf=trim_leading_lf)) | [
"def",
"write",
"(",
"self",
",",
"file",
",",
"text",
",",
"subvars",
"=",
"{",
"}",
",",
"trim_leading_lf",
"=",
"True",
")",
":",
"file",
".",
"write",
"(",
"self",
".",
"substitute",
"(",
"text",
",",
"subvars",
"=",
"subvars",
",",
"trim_leading_lf",
"=",
"trim_leading_lf",
")",
")"
] | write to a file with variable substitution | [
"write",
"to",
"a",
"file",
"with",
"variable",
"substitution"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavtemplate.py#L129-L131 |
249,207 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavflighttime.py | flight_time | def flight_time(logfile):
'''work out flight time for a log file'''
print("Processing log %s" % filename)
mlog = mavutil.mavlink_connection(filename)
in_air = False
start_time = 0.0
total_time = 0.0
total_dist = 0.0
t = None
last_msg = None
last_time_usec = None
while True:
m = mlog.recv_match(type=['GPS','GPS_RAW_INT'], condition=args.condition)
if m is None:
if in_air:
total_time += time.mktime(t) - start_time
if total_time > 0:
print("Flight time : %u:%02u" % (int(total_time)/60, int(total_time)%60))
return (total_time, total_dist)
if m.get_type() == 'GPS_RAW_INT':
groundspeed = m.vel*0.01
status = m.fix_type
time_usec = m.time_usec
else:
groundspeed = m.Spd
status = m.Status
time_usec = m.TimeUS
if status < 3:
continue
t = time.localtime(m._timestamp)
if groundspeed > args.groundspeed and not in_air:
print("In air at %s (percent %.0f%% groundspeed %.1f)" % (time.asctime(t), mlog.percent, groundspeed))
in_air = True
start_time = time.mktime(t)
elif groundspeed < args.groundspeed and in_air:
print("On ground at %s (percent %.1f%% groundspeed %.1f time=%.1f seconds)" % (
time.asctime(t), mlog.percent, groundspeed, time.mktime(t) - start_time))
in_air = False
total_time += time.mktime(t) - start_time
if last_msg is None or time_usec > last_time_usec or time_usec+30e6 < last_time_usec:
if last_msg is not None:
total_dist += distance_two(last_msg, m)
last_msg = m
last_time_usec = time_usec
return (total_time, total_dist) | python | def flight_time(logfile):
'''work out flight time for a log file'''
print("Processing log %s" % filename)
mlog = mavutil.mavlink_connection(filename)
in_air = False
start_time = 0.0
total_time = 0.0
total_dist = 0.0
t = None
last_msg = None
last_time_usec = None
while True:
m = mlog.recv_match(type=['GPS','GPS_RAW_INT'], condition=args.condition)
if m is None:
if in_air:
total_time += time.mktime(t) - start_time
if total_time > 0:
print("Flight time : %u:%02u" % (int(total_time)/60, int(total_time)%60))
return (total_time, total_dist)
if m.get_type() == 'GPS_RAW_INT':
groundspeed = m.vel*0.01
status = m.fix_type
time_usec = m.time_usec
else:
groundspeed = m.Spd
status = m.Status
time_usec = m.TimeUS
if status < 3:
continue
t = time.localtime(m._timestamp)
if groundspeed > args.groundspeed and not in_air:
print("In air at %s (percent %.0f%% groundspeed %.1f)" % (time.asctime(t), mlog.percent, groundspeed))
in_air = True
start_time = time.mktime(t)
elif groundspeed < args.groundspeed and in_air:
print("On ground at %s (percent %.1f%% groundspeed %.1f time=%.1f seconds)" % (
time.asctime(t), mlog.percent, groundspeed, time.mktime(t) - start_time))
in_air = False
total_time += time.mktime(t) - start_time
if last_msg is None or time_usec > last_time_usec or time_usec+30e6 < last_time_usec:
if last_msg is not None:
total_dist += distance_two(last_msg, m)
last_msg = m
last_time_usec = time_usec
return (total_time, total_dist) | [
"def",
"flight_time",
"(",
"logfile",
")",
":",
"print",
"(",
"\"Processing log %s\"",
"%",
"filename",
")",
"mlog",
"=",
"mavutil",
".",
"mavlink_connection",
"(",
"filename",
")",
"in_air",
"=",
"False",
"start_time",
"=",
"0.0",
"total_time",
"=",
"0.0",
"total_dist",
"=",
"0.0",
"t",
"=",
"None",
"last_msg",
"=",
"None",
"last_time_usec",
"=",
"None",
"while",
"True",
":",
"m",
"=",
"mlog",
".",
"recv_match",
"(",
"type",
"=",
"[",
"'GPS'",
",",
"'GPS_RAW_INT'",
"]",
",",
"condition",
"=",
"args",
".",
"condition",
")",
"if",
"m",
"is",
"None",
":",
"if",
"in_air",
":",
"total_time",
"+=",
"time",
".",
"mktime",
"(",
"t",
")",
"-",
"start_time",
"if",
"total_time",
">",
"0",
":",
"print",
"(",
"\"Flight time : %u:%02u\"",
"%",
"(",
"int",
"(",
"total_time",
")",
"/",
"60",
",",
"int",
"(",
"total_time",
")",
"%",
"60",
")",
")",
"return",
"(",
"total_time",
",",
"total_dist",
")",
"if",
"m",
".",
"get_type",
"(",
")",
"==",
"'GPS_RAW_INT'",
":",
"groundspeed",
"=",
"m",
".",
"vel",
"*",
"0.01",
"status",
"=",
"m",
".",
"fix_type",
"time_usec",
"=",
"m",
".",
"time_usec",
"else",
":",
"groundspeed",
"=",
"m",
".",
"Spd",
"status",
"=",
"m",
".",
"Status",
"time_usec",
"=",
"m",
".",
"TimeUS",
"if",
"status",
"<",
"3",
":",
"continue",
"t",
"=",
"time",
".",
"localtime",
"(",
"m",
".",
"_timestamp",
")",
"if",
"groundspeed",
">",
"args",
".",
"groundspeed",
"and",
"not",
"in_air",
":",
"print",
"(",
"\"In air at %s (percent %.0f%% groundspeed %.1f)\"",
"%",
"(",
"time",
".",
"asctime",
"(",
"t",
")",
",",
"mlog",
".",
"percent",
",",
"groundspeed",
")",
")",
"in_air",
"=",
"True",
"start_time",
"=",
"time",
".",
"mktime",
"(",
"t",
")",
"elif",
"groundspeed",
"<",
"args",
".",
"groundspeed",
"and",
"in_air",
":",
"print",
"(",
"\"On ground at %s (percent %.1f%% groundspeed %.1f time=%.1f seconds)\"",
"%",
"(",
"time",
".",
"asctime",
"(",
"t",
")",
",",
"mlog",
".",
"percent",
",",
"groundspeed",
",",
"time",
".",
"mktime",
"(",
"t",
")",
"-",
"start_time",
")",
")",
"in_air",
"=",
"False",
"total_time",
"+=",
"time",
".",
"mktime",
"(",
"t",
")",
"-",
"start_time",
"if",
"last_msg",
"is",
"None",
"or",
"time_usec",
">",
"last_time_usec",
"or",
"time_usec",
"+",
"30e6",
"<",
"last_time_usec",
":",
"if",
"last_msg",
"is",
"not",
"None",
":",
"total_dist",
"+=",
"distance_two",
"(",
"last_msg",
",",
"m",
")",
"last_msg",
"=",
"m",
"last_time_usec",
"=",
"time_usec",
"return",
"(",
"total_time",
",",
"total_dist",
")"
] | work out flight time for a log file | [
"work",
"out",
"flight",
"time",
"for",
"a",
"log",
"file"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/tools/mavflighttime.py#L21-L68 |
249,208 | 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 |
249,209 | JdeRobot/base | src/tools/colorTuner_py/filters/yuvFilter.py | YuvFilter.apply | def apply (self, img):
yup,uup,vup = self.getUpLimit()
ydwn,udwn,vdwn = self.getDownLimit()
''' We convert RGB as BGR because OpenCV
with RGB pass to YVU instead of YUV'''
yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
minValues = np.array([ydwn,udwn,vdwn],dtype=np.uint8)
maxValues = np.array([yup,uup,vup], dtype=np.uint8)
mask = cv2.inRange(yuv, minValues, maxValues)
res = cv2.bitwise_and(img,img, mask= mask)
return res | python | def apply (self, img):
yup,uup,vup = self.getUpLimit()
ydwn,udwn,vdwn = self.getDownLimit()
''' We convert RGB as BGR because OpenCV
with RGB pass to YVU instead of YUV'''
yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
minValues = np.array([ydwn,udwn,vdwn],dtype=np.uint8)
maxValues = np.array([yup,uup,vup], dtype=np.uint8)
mask = cv2.inRange(yuv, minValues, maxValues)
res = cv2.bitwise_and(img,img, mask= mask)
return res | [
"def",
"apply",
"(",
"self",
",",
"img",
")",
":",
"yup",
",",
"uup",
",",
"vup",
"=",
"self",
".",
"getUpLimit",
"(",
")",
"ydwn",
",",
"udwn",
",",
"vdwn",
"=",
"self",
".",
"getDownLimit",
"(",
")",
"yuv",
"=",
"cv2",
".",
"cvtColor",
"(",
"img",
",",
"cv2",
".",
"COLOR_BGR2YUV",
")",
"minValues",
"=",
"np",
".",
"array",
"(",
"[",
"ydwn",
",",
"udwn",
",",
"vdwn",
"]",
",",
"dtype",
"=",
"np",
".",
"uint8",
")",
"maxValues",
"=",
"np",
".",
"array",
"(",
"[",
"yup",
",",
"uup",
",",
"vup",
"]",
",",
"dtype",
"=",
"np",
".",
"uint8",
")",
"mask",
"=",
"cv2",
".",
"inRange",
"(",
"yuv",
",",
"minValues",
",",
"maxValues",
")",
"res",
"=",
"cv2",
".",
"bitwise_and",
"(",
"img",
",",
"img",
",",
"mask",
"=",
"mask",
")",
"return",
"res"
] | We convert RGB as BGR because OpenCV
with RGB pass to YVU instead of YUV | [
"We",
"convert",
"RGB",
"as",
"BGR",
"because",
"OpenCV",
"with",
"RGB",
"pass",
"to",
"YVU",
"instead",
"of",
"YUV"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/tools/colorTuner_py/filters/yuvFilter.py#L57-L76 |
249,210 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/wxconsole_ui.py | ConsoleFrame.on_menu | def on_menu(self, event):
'''handle menu selections'''
state = self.state
ret = self.menu.find_selected(event)
if ret is None:
return
ret.call_handler()
state.child_pipe_send.send(ret) | python | def on_menu(self, event):
'''handle menu selections'''
state = self.state
ret = self.menu.find_selected(event)
if ret is None:
return
ret.call_handler()
state.child_pipe_send.send(ret) | [
"def",
"on_menu",
"(",
"self",
",",
"event",
")",
":",
"state",
"=",
"self",
".",
"state",
"ret",
"=",
"self",
".",
"menu",
".",
"find_selected",
"(",
"event",
")",
"if",
"ret",
"is",
"None",
":",
"return",
"ret",
".",
"call_handler",
"(",
")",
"state",
".",
"child_pipe_send",
".",
"send",
"(",
"ret",
")"
] | handle menu selections | [
"handle",
"menu",
"selections"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/wxconsole_ui.py#L43-L50 |
249,211 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/dialects/v10/ASLUAV.py | MAVLink.aslctrl_data_encode | def aslctrl_data_encode(self, timestamp, aslctrl_mode, h, hRef, hRef_t, PitchAngle, PitchAngleRef, q, qRef, uElev, uThrot, uThrot2, nZ, AirspeedRef, SpoilersEngaged, YawAngle, YawAngleRef, RollAngle, RollAngleRef, p, pRef, r, rRef, uAil, uRud):
'''
ASL-fixed-wing controller data
timestamp : Timestamp (uint64_t)
aslctrl_mode : ASLCTRL control-mode (manual, stabilized, auto, etc...) (uint8_t)
h : See sourcecode for a description of these values... (float)
hRef : (float)
hRef_t : (float)
PitchAngle : Pitch angle [deg] (float)
PitchAngleRef : Pitch angle reference[deg] (float)
q : (float)
qRef : (float)
uElev : (float)
uThrot : (float)
uThrot2 : (float)
nZ : (float)
AirspeedRef : Airspeed reference [m/s] (float)
SpoilersEngaged : (uint8_t)
YawAngle : Yaw angle [deg] (float)
YawAngleRef : Yaw angle reference[deg] (float)
RollAngle : Roll angle [deg] (float)
RollAngleRef : Roll angle reference[deg] (float)
p : (float)
pRef : (float)
r : (float)
rRef : (float)
uAil : (float)
uRud : (float)
'''
return MAVLink_aslctrl_data_message(timestamp, aslctrl_mode, h, hRef, hRef_t, PitchAngle, PitchAngleRef, q, qRef, uElev, uThrot, uThrot2, nZ, AirspeedRef, SpoilersEngaged, YawAngle, YawAngleRef, RollAngle, RollAngleRef, p, pRef, r, rRef, uAil, uRud) | python | def aslctrl_data_encode(self, timestamp, aslctrl_mode, h, hRef, hRef_t, PitchAngle, PitchAngleRef, q, qRef, uElev, uThrot, uThrot2, nZ, AirspeedRef, SpoilersEngaged, YawAngle, YawAngleRef, RollAngle, RollAngleRef, p, pRef, r, rRef, uAil, uRud):
'''
ASL-fixed-wing controller data
timestamp : Timestamp (uint64_t)
aslctrl_mode : ASLCTRL control-mode (manual, stabilized, auto, etc...) (uint8_t)
h : See sourcecode for a description of these values... (float)
hRef : (float)
hRef_t : (float)
PitchAngle : Pitch angle [deg] (float)
PitchAngleRef : Pitch angle reference[deg] (float)
q : (float)
qRef : (float)
uElev : (float)
uThrot : (float)
uThrot2 : (float)
nZ : (float)
AirspeedRef : Airspeed reference [m/s] (float)
SpoilersEngaged : (uint8_t)
YawAngle : Yaw angle [deg] (float)
YawAngleRef : Yaw angle reference[deg] (float)
RollAngle : Roll angle [deg] (float)
RollAngleRef : Roll angle reference[deg] (float)
p : (float)
pRef : (float)
r : (float)
rRef : (float)
uAil : (float)
uRud : (float)
'''
return MAVLink_aslctrl_data_message(timestamp, aslctrl_mode, h, hRef, hRef_t, PitchAngle, PitchAngleRef, q, qRef, uElev, uThrot, uThrot2, nZ, AirspeedRef, SpoilersEngaged, YawAngle, YawAngleRef, RollAngle, RollAngleRef, p, pRef, r, rRef, uAil, uRud) | [
"def",
"aslctrl_data_encode",
"(",
"self",
",",
"timestamp",
",",
"aslctrl_mode",
",",
"h",
",",
"hRef",
",",
"hRef_t",
",",
"PitchAngle",
",",
"PitchAngleRef",
",",
"q",
",",
"qRef",
",",
"uElev",
",",
"uThrot",
",",
"uThrot2",
",",
"nZ",
",",
"AirspeedRef",
",",
"SpoilersEngaged",
",",
"YawAngle",
",",
"YawAngleRef",
",",
"RollAngle",
",",
"RollAngleRef",
",",
"p",
",",
"pRef",
",",
"r",
",",
"rRef",
",",
"uAil",
",",
"uRud",
")",
":",
"return",
"MAVLink_aslctrl_data_message",
"(",
"timestamp",
",",
"aslctrl_mode",
",",
"h",
",",
"hRef",
",",
"hRef_t",
",",
"PitchAngle",
",",
"PitchAngleRef",
",",
"q",
",",
"qRef",
",",
"uElev",
",",
"uThrot",
",",
"uThrot2",
",",
"nZ",
",",
"AirspeedRef",
",",
"SpoilersEngaged",
",",
"YawAngle",
",",
"YawAngleRef",
",",
"RollAngle",
",",
"RollAngleRef",
",",
"p",
",",
"pRef",
",",
"r",
",",
"rRef",
",",
"uAil",
",",
"uRud",
")"
] | ASL-fixed-wing controller data
timestamp : Timestamp (uint64_t)
aslctrl_mode : ASLCTRL control-mode (manual, stabilized, auto, etc...) (uint8_t)
h : See sourcecode for a description of these values... (float)
hRef : (float)
hRef_t : (float)
PitchAngle : Pitch angle [deg] (float)
PitchAngleRef : Pitch angle reference[deg] (float)
q : (float)
qRef : (float)
uElev : (float)
uThrot : (float)
uThrot2 : (float)
nZ : (float)
AirspeedRef : Airspeed reference [m/s] (float)
SpoilersEngaged : (uint8_t)
YawAngle : Yaw angle [deg] (float)
YawAngleRef : Yaw angle reference[deg] (float)
RollAngle : Roll angle [deg] (float)
RollAngleRef : Roll angle reference[deg] (float)
p : (float)
pRef : (float)
r : (float)
rRef : (float)
uAil : (float)
uRud : (float) | [
"ASL",
"-",
"fixed",
"-",
"wing",
"controller",
"data"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/dialects/v10/ASLUAV.py#L7653-L7684 |
249,212 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | average | def average(var, key, N):
'''average over N points'''
global average_data
if not key in average_data:
average_data[key] = [var]*N
return var
average_data[key].pop(0)
average_data[key].append(var)
return sum(average_data[key])/N | python | def average(var, key, N):
'''average over N points'''
global average_data
if not key in average_data:
average_data[key] = [var]*N
return var
average_data[key].pop(0)
average_data[key].append(var)
return sum(average_data[key])/N | [
"def",
"average",
"(",
"var",
",",
"key",
",",
"N",
")",
":",
"global",
"average_data",
"if",
"not",
"key",
"in",
"average_data",
":",
"average_data",
"[",
"key",
"]",
"=",
"[",
"var",
"]",
"*",
"N",
"return",
"var",
"average_data",
"[",
"key",
"]",
".",
"pop",
"(",
"0",
")",
"average_data",
"[",
"key",
"]",
".",
"append",
"(",
"var",
")",
"return",
"sum",
"(",
"average_data",
"[",
"key",
"]",
")",
"/",
"N"
] | average over N points | [
"average",
"over",
"N",
"points"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L170-L178 |
249,213 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | second_derivative_5 | def second_derivative_5(var, key):
'''5 point 2nd derivative'''
global derivative_data
import mavutil
tnow = mavutil.mavfile_global.timestamp
if not key in derivative_data:
derivative_data[key] = (tnow, [var]*5)
return 0
(last_time, data) = derivative_data[key]
data.pop(0)
data.append(var)
derivative_data[key] = (tnow, data)
h = (tnow - last_time)
# N=5 2nd derivative from
# http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/smooth-low-noise-differentiators/
ret = ((data[4] + data[0]) - 2*data[2]) / (4*h**2)
return ret | python | def second_derivative_5(var, key):
'''5 point 2nd derivative'''
global derivative_data
import mavutil
tnow = mavutil.mavfile_global.timestamp
if not key in derivative_data:
derivative_data[key] = (tnow, [var]*5)
return 0
(last_time, data) = derivative_data[key]
data.pop(0)
data.append(var)
derivative_data[key] = (tnow, data)
h = (tnow - last_time)
# N=5 2nd derivative from
# http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/smooth-low-noise-differentiators/
ret = ((data[4] + data[0]) - 2*data[2]) / (4*h**2)
return ret | [
"def",
"second_derivative_5",
"(",
"var",
",",
"key",
")",
":",
"global",
"derivative_data",
"import",
"mavutil",
"tnow",
"=",
"mavutil",
".",
"mavfile_global",
".",
"timestamp",
"if",
"not",
"key",
"in",
"derivative_data",
":",
"derivative_data",
"[",
"key",
"]",
"=",
"(",
"tnow",
",",
"[",
"var",
"]",
"*",
"5",
")",
"return",
"0",
"(",
"last_time",
",",
"data",
")",
"=",
"derivative_data",
"[",
"key",
"]",
"data",
".",
"pop",
"(",
"0",
")",
"data",
".",
"append",
"(",
"var",
")",
"derivative_data",
"[",
"key",
"]",
"=",
"(",
"tnow",
",",
"data",
")",
"h",
"=",
"(",
"tnow",
"-",
"last_time",
")",
"# N=5 2nd derivative from",
"# http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/smooth-low-noise-differentiators/",
"ret",
"=",
"(",
"(",
"data",
"[",
"4",
"]",
"+",
"data",
"[",
"0",
"]",
")",
"-",
"2",
"*",
"data",
"[",
"2",
"]",
")",
"/",
"(",
"4",
"*",
"h",
"**",
"2",
")",
"return",
"ret"
] | 5 point 2nd derivative | [
"5",
"point",
"2nd",
"derivative"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L182-L199 |
249,214 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | lowpass | def lowpass(var, key, factor):
'''a simple lowpass filter'''
global lowpass_data
if not key in lowpass_data:
lowpass_data[key] = var
else:
lowpass_data[key] = factor*lowpass_data[key] + (1.0 - factor)*var
return lowpass_data[key] | python | def lowpass(var, key, factor):
'''a simple lowpass filter'''
global lowpass_data
if not key in lowpass_data:
lowpass_data[key] = var
else:
lowpass_data[key] = factor*lowpass_data[key] + (1.0 - factor)*var
return lowpass_data[key] | [
"def",
"lowpass",
"(",
"var",
",",
"key",
",",
"factor",
")",
":",
"global",
"lowpass_data",
"if",
"not",
"key",
"in",
"lowpass_data",
":",
"lowpass_data",
"[",
"key",
"]",
"=",
"var",
"else",
":",
"lowpass_data",
"[",
"key",
"]",
"=",
"factor",
"*",
"lowpass_data",
"[",
"key",
"]",
"+",
"(",
"1.0",
"-",
"factor",
")",
"*",
"var",
"return",
"lowpass_data",
"[",
"key",
"]"
] | a simple lowpass filter | [
"a",
"simple",
"lowpass",
"filter"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L223-L230 |
249,215 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py | diff | def diff(var, key):
'''calculate differences between values'''
global last_diff
ret = 0
if not key in last_diff:
last_diff[key] = var
return 0
ret = var - last_diff[key]
last_diff[key] = var
return ret | python | def diff(var, key):
'''calculate differences between values'''
global last_diff
ret = 0
if not key in last_diff:
last_diff[key] = var
return 0
ret = var - last_diff[key]
last_diff[key] = var
return ret | [
"def",
"diff",
"(",
"var",
",",
"key",
")",
":",
"global",
"last_diff",
"ret",
"=",
"0",
"if",
"not",
"key",
"in",
"last_diff",
":",
"last_diff",
"[",
"key",
"]",
"=",
"var",
"return",
"0",
"ret",
"=",
"var",
"-",
"last_diff",
"[",
"key",
"]",
"last_diff",
"[",
"key",
"]",
"=",
"var",
"return",
"ret"
] | calculate differences between values | [
"calculate",
"differences",
"between",
"values"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L234-L243 |
249,216 | 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",
".",
"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",
")"
] | 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 |
249,217 | 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",
".",
"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"
] | 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 |
249,218 | 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",
"=",
"degrees",
"(",
"y",
")",
"if",
"y",
"<",
"0",
":",
"y",
"+=",
"360",
"return",
"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 |
249,219 | 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",
"(",
")",
"return",
"degrees",
"(",
"r",
")"
] | 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 |
249,220 | 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",
".",
"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"
] | 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 |
249,221 | 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",
"*",
"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",
")"
] | 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 |
249,222 | 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",
".",
"zacc",
"zacc",
"+=",
"SIMSTATE",
".",
"ygyro",
"*",
"GPS_RAW",
".",
"v",
"if",
"xacc",
"/",
"zacc",
">=",
"1",
":",
"return",
"0",
"if",
"xacc",
"/",
"zacc",
"<=",
"-",
"1",
":",
"return",
"-",
"0",
"return",
"degrees",
"(",
"-",
"asin",
"(",
"xacc",
"/",
"zacc",
")",
")"
] | 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 |
249,223 | 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",
"GPS_RAW",
".",
"Status",
"<",
"2",
")",
":",
"return",
"0",
"if",
"first_fix",
"==",
"None",
":",
"first_fix",
"=",
"GPS_RAW",
"return",
"0",
"return",
"distance_two",
"(",
"GPS_RAW",
",",
"first_fix",
")"
] | 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 |
249,224 | 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",
"p",
"<",
"period",
":",
"return",
"amplitude",
"*",
"(",
"p",
"/",
"period",
")",
"return",
"amplitude",
"*",
"(",
"period",
"-",
"(",
"p",
"-",
"period",
")",
")",
"/",
"period"
] | 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 |
249,225 | 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",
"/",
"(",
"287.26",
"*",
"tempK",
")",
")",
")"
] | 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 |
249,226 | 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",
".",
"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"
] | 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 |
249,227 | 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",
"=",
"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",
")"
] | 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 |
249,228 | 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",
"(",
"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",
")"
] | 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 |
249,229 | 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",
"r",
"*",
"accel"
] | 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 |
249,230 | 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",
"(",
"RAW_IMU",
".",
"zgyro",
")",
")",
"*",
"0.001",
"return",
"r",
"*",
"accel"
] | 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 |
249,231 | 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",
"=",
"(",
"(",
"target_airspeed",
"*",
"target_airspeed",
")",
"-",
"(",
"aspeed_cm",
"*",
"aspeed_cm",
")",
")",
"*",
"0.00005",
"return",
"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 |
249,232 | 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",
"=",
"aspeed_energy_error",
"+",
"alt_error",
"*",
"0.098",
"return",
"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 |
249,233 | 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",
"=",
"(",
"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",
")"
] | mix two servos | [
"mix",
"two",
"servos"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavextra.py#L724-L745 |
249,234 | 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",
")",
"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"
] | 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 |
249,235 | 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",
")",
",",
"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"
] | 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 |
249,236 | 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",
"return",
"0",
"if",
"HEARTBEAT",
".",
"base_mode",
"&",
"mavutil",
".",
"mavlink",
".",
"MAV_MODE_FLAG_SAFETY_ARMED",
":",
"return",
"1",
"return",
"0"
] | 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 |
249,237 | 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.001",
"return",
"r",
"*",
"accel"
] | 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 |
249,238 | 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",
".",
"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",
")"
] | 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 |
249,239 | 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",
")",
"==",
"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",
")"
] | 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 |
249,240 | 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",
"=",
"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",
")"
] | 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 |
249,241 | 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",
"=",
"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",
")"
] | 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 |
249,242 | 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",
"(",
"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",
")"
] | 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 |
249,243 | 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",
"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",
")"
] | 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 |
249,244 | 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 |
249,245 | 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__",
")",
")",
",",
"'..'",
",",
"'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"
] | 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 |
249,246 | 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",
")",
"# 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",
"(",
")"
] | 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 |
249,247 | 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 |
249,248 | 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):
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",
"(",
")",
"+",
"component",
"[",
"1",
":",
"]",
"return",
"string"
] | 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 |
249,249 | 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 |
249,250 | 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 |
249,251 | 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 |
249,252 | 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):
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",
".",
"type",
"]",
"[",
"0",
"]",
"return",
"\"Int\""
] | 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 |
249,253 | 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):
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",
"(",
"basepath",
",",
"'swift/%s'",
"%",
"filename",
")",
"print",
"(",
"\"Appending content of %s\"",
"%",
"filename",
")",
"with",
"open",
"(",
"filepath",
")",
"as",
"inf",
":",
"for",
"line",
"in",
"inf",
":",
"outf",
".",
"write",
"(",
"line",
")"
] | 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 |
249,254 | 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):
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",
"+=",
"component",
"else",
":",
"string",
"+=",
"component",
"[",
"0",
"]",
".",
"upper",
"(",
")",
"+",
"component",
"[",
"1",
":",
"]",
".",
"lower",
"(",
")",
"return",
"string"
] | 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 |
249,255 | 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):
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",
"(",
"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",
")"
] | 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 |
249,256 | 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):
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",
".",
"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",
")"
] | 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 |
249,257 | 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):
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",
"=",
"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",
"(",
")"
] | 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 |
249,258 | 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_TIME",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_NAV_LOITER_TO_ALT",
"]",
"if",
"(",
"self",
".",
"wpoints",
"[",
"i",
"]",
".",
"command",
"in",
"loiter_cmds",
")",
":",
"return",
"True",
"return",
"False"
] | 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 |
249,259 | 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",
".",
"wpoints",
".",
"append",
"(",
"w",
")",
"self",
".",
"last_change",
"=",
"time",
".",
"time",
"(",
")"
] | add a waypoint | [
"add",
"a",
"waypoint"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L56-L63 |
249,260 | 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",
"w",
"=",
"copy",
".",
"copy",
"(",
"w",
")",
"if",
"comment",
":",
"w",
".",
"comment",
"=",
"comment",
"w",
".",
"seq",
"=",
"idx",
"self",
".",
"wpoints",
".",
"insert",
"(",
"idx",
",",
"w",
")",
"self",
".",
"last_change",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"reindex",
"(",
")"
] | insert a waypoint | [
"insert",
"a",
"waypoint"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L65-L78 |
249,261 | 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",
"(",
")",
"<=",
"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",
"(",
")"
] | set a waypoint | [
"set",
"a",
"waypoint"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L102-L110 |
249,262 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVWPLoader.remove | def remove(self, w):
'''remove a waypoint'''
self.wpoints.remove(w)
self.last_change = time.time()
self.reindex() | python | def remove(self, w):
'''remove a waypoint'''
self.wpoints.remove(w)
self.last_change = time.time()
self.reindex() | [
"def",
"remove",
"(",
"self",
",",
"w",
")",
":",
"self",
".",
"wpoints",
".",
"remove",
"(",
"w",
")",
"self",
".",
"last_change",
"=",
"time",
".",
"time",
"(",
")",
"self",
".",
"reindex",
"(",
")"
] | remove a waypoint | [
"remove",
"a",
"waypoint"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L112-L116 |
249,263 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVWPLoader._read_waypoints_v100 | def _read_waypoints_v100(self, file):
'''read a version 100 waypoint'''
cmdmap = {
2 : mavutil.mavlink.MAV_CMD_NAV_TAKEOFF,
3 : mavutil.mavlink.MAV_CMD_NAV_RETURN_TO_LAUNCH,
4 : mavutil.mavlink.MAV_CMD_NAV_LAND,
24: mavutil.mavlink.MAV_CMD_NAV_TAKEOFF,
26: mavutil.mavlink.MAV_CMD_NAV_LAND,
25: mavutil.mavlink.MAV_CMD_NAV_WAYPOINT ,
27: mavutil.mavlink.MAV_CMD_NAV_LOITER_UNLIM
}
comment = ''
for line in file:
if line.startswith('#'):
comment = line[1:].lstrip()
continue
line = line.strip()
if not line:
continue
a = line.split()
if len(a) != 13:
raise MAVWPError("invalid waypoint line with %u values" % len(a))
if mavutil.mavlink10():
fn = mavutil.mavlink.MAVLink_mission_item_message
else:
fn = mavutil.mavlink.MAVLink_waypoint_message
w = fn(self.target_system, self.target_component,
int(a[0]), # seq
int(a[1]), # frame
int(a[2]), # action
int(a[7]), # current
int(a[12]), # autocontinue
float(a[5]), # param1,
float(a[6]), # param2,
float(a[3]), # param3
float(a[4]), # param4
float(a[9]), # x, latitude
float(a[8]), # y, longitude
float(a[10]) # z
)
if not w.command in cmdmap:
raise MAVWPError("Unknown v100 waypoint action %u" % w.command)
w.command = cmdmap[w.command]
self.add(w, comment)
comment = '' | python | def _read_waypoints_v100(self, file):
'''read a version 100 waypoint'''
cmdmap = {
2 : mavutil.mavlink.MAV_CMD_NAV_TAKEOFF,
3 : mavutil.mavlink.MAV_CMD_NAV_RETURN_TO_LAUNCH,
4 : mavutil.mavlink.MAV_CMD_NAV_LAND,
24: mavutil.mavlink.MAV_CMD_NAV_TAKEOFF,
26: mavutil.mavlink.MAV_CMD_NAV_LAND,
25: mavutil.mavlink.MAV_CMD_NAV_WAYPOINT ,
27: mavutil.mavlink.MAV_CMD_NAV_LOITER_UNLIM
}
comment = ''
for line in file:
if line.startswith('#'):
comment = line[1:].lstrip()
continue
line = line.strip()
if not line:
continue
a = line.split()
if len(a) != 13:
raise MAVWPError("invalid waypoint line with %u values" % len(a))
if mavutil.mavlink10():
fn = mavutil.mavlink.MAVLink_mission_item_message
else:
fn = mavutil.mavlink.MAVLink_waypoint_message
w = fn(self.target_system, self.target_component,
int(a[0]), # seq
int(a[1]), # frame
int(a[2]), # action
int(a[7]), # current
int(a[12]), # autocontinue
float(a[5]), # param1,
float(a[6]), # param2,
float(a[3]), # param3
float(a[4]), # param4
float(a[9]), # x, latitude
float(a[8]), # y, longitude
float(a[10]) # z
)
if not w.command in cmdmap:
raise MAVWPError("Unknown v100 waypoint action %u" % w.command)
w.command = cmdmap[w.command]
self.add(w, comment)
comment = '' | [
"def",
"_read_waypoints_v100",
"(",
"self",
",",
"file",
")",
":",
"cmdmap",
"=",
"{",
"2",
":",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_NAV_TAKEOFF",
",",
"3",
":",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_NAV_RETURN_TO_LAUNCH",
",",
"4",
":",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_NAV_LAND",
",",
"24",
":",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_NAV_TAKEOFF",
",",
"26",
":",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_NAV_LAND",
",",
"25",
":",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_NAV_WAYPOINT",
",",
"27",
":",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_NAV_LOITER_UNLIM",
"}",
"comment",
"=",
"''",
"for",
"line",
"in",
"file",
":",
"if",
"line",
".",
"startswith",
"(",
"'#'",
")",
":",
"comment",
"=",
"line",
"[",
"1",
":",
"]",
".",
"lstrip",
"(",
")",
"continue",
"line",
"=",
"line",
".",
"strip",
"(",
")",
"if",
"not",
"line",
":",
"continue",
"a",
"=",
"line",
".",
"split",
"(",
")",
"if",
"len",
"(",
"a",
")",
"!=",
"13",
":",
"raise",
"MAVWPError",
"(",
"\"invalid waypoint line with %u values\"",
"%",
"len",
"(",
"a",
")",
")",
"if",
"mavutil",
".",
"mavlink10",
"(",
")",
":",
"fn",
"=",
"mavutil",
".",
"mavlink",
".",
"MAVLink_mission_item_message",
"else",
":",
"fn",
"=",
"mavutil",
".",
"mavlink",
".",
"MAVLink_waypoint_message",
"w",
"=",
"fn",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"int",
"(",
"a",
"[",
"0",
"]",
")",
",",
"# seq",
"int",
"(",
"a",
"[",
"1",
"]",
")",
",",
"# frame",
"int",
"(",
"a",
"[",
"2",
"]",
")",
",",
"# action",
"int",
"(",
"a",
"[",
"7",
"]",
")",
",",
"# current",
"int",
"(",
"a",
"[",
"12",
"]",
")",
",",
"# autocontinue",
"float",
"(",
"a",
"[",
"5",
"]",
")",
",",
"# param1,",
"float",
"(",
"a",
"[",
"6",
"]",
")",
",",
"# param2,",
"float",
"(",
"a",
"[",
"3",
"]",
")",
",",
"# param3",
"float",
"(",
"a",
"[",
"4",
"]",
")",
",",
"# param4",
"float",
"(",
"a",
"[",
"9",
"]",
")",
",",
"# x, latitude",
"float",
"(",
"a",
"[",
"8",
"]",
")",
",",
"# y, longitude",
"float",
"(",
"a",
"[",
"10",
"]",
")",
"# z",
")",
"if",
"not",
"w",
".",
"command",
"in",
"cmdmap",
":",
"raise",
"MAVWPError",
"(",
"\"Unknown v100 waypoint action %u\"",
"%",
"w",
".",
"command",
")",
"w",
".",
"command",
"=",
"cmdmap",
"[",
"w",
".",
"command",
"]",
"self",
".",
"add",
"(",
"w",
",",
"comment",
")",
"comment",
"=",
"''"
] | read a version 100 waypoint | [
"read",
"a",
"version",
"100",
"waypoint"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L123-L168 |
249,264 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVWPLoader._read_waypoints_v110 | def _read_waypoints_v110(self, file):
'''read a version 110 waypoint'''
comment = ''
for line in file:
if line.startswith('#'):
comment = line[1:].lstrip()
continue
line = line.strip()
if not line:
continue
a = line.split()
if len(a) != 12:
raise MAVWPError("invalid waypoint line with %u values" % len(a))
if mavutil.mavlink10():
fn = mavutil.mavlink.MAVLink_mission_item_message
else:
fn = mavutil.mavlink.MAVLink_waypoint_message
w = fn(self.target_system, self.target_component,
int(a[0]), # seq
int(a[2]), # frame
int(a[3]), # command
int(a[1]), # current
int(a[11]), # autocontinue
float(a[4]), # param1,
float(a[5]), # param2,
float(a[6]), # param3
float(a[7]), # param4
float(a[8]), # x (latitude)
float(a[9]), # y (longitude)
float(a[10]) # z (altitude)
)
if w.command == 0 and w.seq == 0 and self.count() == 0:
# special handling for Mission Planner created home wp
w.command = mavutil.mavlink.MAV_CMD_NAV_WAYPOINT
self.add(w, comment)
comment = '' | python | def _read_waypoints_v110(self, file):
'''read a version 110 waypoint'''
comment = ''
for line in file:
if line.startswith('#'):
comment = line[1:].lstrip()
continue
line = line.strip()
if not line:
continue
a = line.split()
if len(a) != 12:
raise MAVWPError("invalid waypoint line with %u values" % len(a))
if mavutil.mavlink10():
fn = mavutil.mavlink.MAVLink_mission_item_message
else:
fn = mavutil.mavlink.MAVLink_waypoint_message
w = fn(self.target_system, self.target_component,
int(a[0]), # seq
int(a[2]), # frame
int(a[3]), # command
int(a[1]), # current
int(a[11]), # autocontinue
float(a[4]), # param1,
float(a[5]), # param2,
float(a[6]), # param3
float(a[7]), # param4
float(a[8]), # x (latitude)
float(a[9]), # y (longitude)
float(a[10]) # z (altitude)
)
if w.command == 0 and w.seq == 0 and self.count() == 0:
# special handling for Mission Planner created home wp
w.command = mavutil.mavlink.MAV_CMD_NAV_WAYPOINT
self.add(w, comment)
comment = '' | [
"def",
"_read_waypoints_v110",
"(",
"self",
",",
"file",
")",
":",
"comment",
"=",
"''",
"for",
"line",
"in",
"file",
":",
"if",
"line",
".",
"startswith",
"(",
"'#'",
")",
":",
"comment",
"=",
"line",
"[",
"1",
":",
"]",
".",
"lstrip",
"(",
")",
"continue",
"line",
"=",
"line",
".",
"strip",
"(",
")",
"if",
"not",
"line",
":",
"continue",
"a",
"=",
"line",
".",
"split",
"(",
")",
"if",
"len",
"(",
"a",
")",
"!=",
"12",
":",
"raise",
"MAVWPError",
"(",
"\"invalid waypoint line with %u values\"",
"%",
"len",
"(",
"a",
")",
")",
"if",
"mavutil",
".",
"mavlink10",
"(",
")",
":",
"fn",
"=",
"mavutil",
".",
"mavlink",
".",
"MAVLink_mission_item_message",
"else",
":",
"fn",
"=",
"mavutil",
".",
"mavlink",
".",
"MAVLink_waypoint_message",
"w",
"=",
"fn",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"int",
"(",
"a",
"[",
"0",
"]",
")",
",",
"# seq",
"int",
"(",
"a",
"[",
"2",
"]",
")",
",",
"# frame",
"int",
"(",
"a",
"[",
"3",
"]",
")",
",",
"# command",
"int",
"(",
"a",
"[",
"1",
"]",
")",
",",
"# current",
"int",
"(",
"a",
"[",
"11",
"]",
")",
",",
"# autocontinue",
"float",
"(",
"a",
"[",
"4",
"]",
")",
",",
"# param1,",
"float",
"(",
"a",
"[",
"5",
"]",
")",
",",
"# param2,",
"float",
"(",
"a",
"[",
"6",
"]",
")",
",",
"# param3",
"float",
"(",
"a",
"[",
"7",
"]",
")",
",",
"# param4",
"float",
"(",
"a",
"[",
"8",
"]",
")",
",",
"# x (latitude)",
"float",
"(",
"a",
"[",
"9",
"]",
")",
",",
"# y (longitude)",
"float",
"(",
"a",
"[",
"10",
"]",
")",
"# z (altitude)",
")",
"if",
"w",
".",
"command",
"==",
"0",
"and",
"w",
".",
"seq",
"==",
"0",
"and",
"self",
".",
"count",
"(",
")",
"==",
"0",
":",
"# special handling for Mission Planner created home wp",
"w",
".",
"command",
"=",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_NAV_WAYPOINT",
"self",
".",
"add",
"(",
"w",
",",
"comment",
")",
"comment",
"=",
"''"
] | read a version 110 waypoint | [
"read",
"a",
"version",
"110",
"waypoint"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L170-L205 |
249,265 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVWPLoader.load | def load(self, filename):
'''load waypoints from a file.
returns number of waypoints loaded'''
f = open(filename, mode='r')
version_line = f.readline().strip()
if version_line == "QGC WPL 100":
readfn = self._read_waypoints_v100
elif version_line == "QGC WPL 110":
readfn = self._read_waypoints_v110
elif version_line == "QGC WPL PB 110":
readfn = self._read_waypoints_pb_110
else:
f.close()
raise MAVWPError("Unsupported waypoint format '%s'" % version_line)
self.clear()
readfn(f)
f.close()
return len(self.wpoints) | python | def load(self, filename):
'''load waypoints from a file.
returns number of waypoints loaded'''
f = open(filename, mode='r')
version_line = f.readline().strip()
if version_line == "QGC WPL 100":
readfn = self._read_waypoints_v100
elif version_line == "QGC WPL 110":
readfn = self._read_waypoints_v110
elif version_line == "QGC WPL PB 110":
readfn = self._read_waypoints_pb_110
else:
f.close()
raise MAVWPError("Unsupported waypoint format '%s'" % version_line)
self.clear()
readfn(f)
f.close()
return len(self.wpoints) | [
"def",
"load",
"(",
"self",
",",
"filename",
")",
":",
"f",
"=",
"open",
"(",
"filename",
",",
"mode",
"=",
"'r'",
")",
"version_line",
"=",
"f",
".",
"readline",
"(",
")",
".",
"strip",
"(",
")",
"if",
"version_line",
"==",
"\"QGC WPL 100\"",
":",
"readfn",
"=",
"self",
".",
"_read_waypoints_v100",
"elif",
"version_line",
"==",
"\"QGC WPL 110\"",
":",
"readfn",
"=",
"self",
".",
"_read_waypoints_v110",
"elif",
"version_line",
"==",
"\"QGC WPL PB 110\"",
":",
"readfn",
"=",
"self",
".",
"_read_waypoints_pb_110",
"else",
":",
"f",
".",
"close",
"(",
")",
"raise",
"MAVWPError",
"(",
"\"Unsupported waypoint format '%s'\"",
"%",
"version_line",
")",
"self",
".",
"clear",
"(",
")",
"readfn",
"(",
"f",
")",
"f",
".",
"close",
"(",
")",
"return",
"len",
"(",
"self",
".",
"wpoints",
")"
] | load waypoints from a file.
returns number of waypoints loaded | [
"load",
"waypoints",
"from",
"a",
"file",
".",
"returns",
"number",
"of",
"waypoints",
"loaded"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L263-L282 |
249,266 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVWPLoader.view_indexes | def view_indexes(self, done=None):
'''return a list waypoint indexes in view order'''
ret = []
if done is None:
done = set()
idx = 0
# find first point not done yet
while idx < self.count():
if not idx in done:
break
idx += 1
while idx < self.count():
w = self.wp(idx)
if idx in done:
if w.x != 0 or w.y != 0:
ret.append(idx)
break
done.add(idx)
if w.command == mavutil.mavlink.MAV_CMD_DO_JUMP:
idx = int(w.param1)
w = self.wp(idx)
if w.x != 0 or w.y != 0:
ret.append(idx)
continue
if (w.x != 0 or w.y != 0) and self.is_location_command(w.command):
ret.append(idx)
idx += 1
return ret | python | def view_indexes(self, done=None):
'''return a list waypoint indexes in view order'''
ret = []
if done is None:
done = set()
idx = 0
# find first point not done yet
while idx < self.count():
if not idx in done:
break
idx += 1
while idx < self.count():
w = self.wp(idx)
if idx in done:
if w.x != 0 or w.y != 0:
ret.append(idx)
break
done.add(idx)
if w.command == mavutil.mavlink.MAV_CMD_DO_JUMP:
idx = int(w.param1)
w = self.wp(idx)
if w.x != 0 or w.y != 0:
ret.append(idx)
continue
if (w.x != 0 or w.y != 0) and self.is_location_command(w.command):
ret.append(idx)
idx += 1
return ret | [
"def",
"view_indexes",
"(",
"self",
",",
"done",
"=",
"None",
")",
":",
"ret",
"=",
"[",
"]",
"if",
"done",
"is",
"None",
":",
"done",
"=",
"set",
"(",
")",
"idx",
"=",
"0",
"# find first point not done yet",
"while",
"idx",
"<",
"self",
".",
"count",
"(",
")",
":",
"if",
"not",
"idx",
"in",
"done",
":",
"break",
"idx",
"+=",
"1",
"while",
"idx",
"<",
"self",
".",
"count",
"(",
")",
":",
"w",
"=",
"self",
".",
"wp",
"(",
"idx",
")",
"if",
"idx",
"in",
"done",
":",
"if",
"w",
".",
"x",
"!=",
"0",
"or",
"w",
".",
"y",
"!=",
"0",
":",
"ret",
".",
"append",
"(",
"idx",
")",
"break",
"done",
".",
"add",
"(",
"idx",
")",
"if",
"w",
".",
"command",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_DO_JUMP",
":",
"idx",
"=",
"int",
"(",
"w",
".",
"param1",
")",
"w",
"=",
"self",
".",
"wp",
"(",
"idx",
")",
"if",
"w",
".",
"x",
"!=",
"0",
"or",
"w",
".",
"y",
"!=",
"0",
":",
"ret",
".",
"append",
"(",
"idx",
")",
"continue",
"if",
"(",
"w",
".",
"x",
"!=",
"0",
"or",
"w",
".",
"y",
"!=",
"0",
")",
"and",
"self",
".",
"is_location_command",
"(",
"w",
".",
"command",
")",
":",
"ret",
".",
"append",
"(",
"idx",
")",
"idx",
"+=",
"1",
"return",
"ret"
] | return a list waypoint indexes in view order | [
"return",
"a",
"list",
"waypoint",
"indexes",
"in",
"view",
"order"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L330-L359 |
249,267 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVWPLoader.polygon | def polygon(self, done=None):
'''return a polygon for the waypoints'''
indexes = self.view_indexes(done)
points = []
for idx in indexes:
w = self.wp(idx)
points.append((w.x, w.y))
return points | python | def polygon(self, done=None):
'''return a polygon for the waypoints'''
indexes = self.view_indexes(done)
points = []
for idx in indexes:
w = self.wp(idx)
points.append((w.x, w.y))
return points | [
"def",
"polygon",
"(",
"self",
",",
"done",
"=",
"None",
")",
":",
"indexes",
"=",
"self",
".",
"view_indexes",
"(",
"done",
")",
"points",
"=",
"[",
"]",
"for",
"idx",
"in",
"indexes",
":",
"w",
"=",
"self",
".",
"wp",
"(",
"idx",
")",
"points",
".",
"append",
"(",
"(",
"w",
".",
"x",
",",
"w",
".",
"y",
")",
")",
"return",
"points"
] | return a polygon for the waypoints | [
"return",
"a",
"polygon",
"for",
"the",
"waypoints"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L361-L368 |
249,268 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVWPLoader.polygon_list | def polygon_list(self):
'''return a list of polygons for the waypoints'''
done = set()
ret = []
while len(done) != self.count():
p = self.polygon(done)
if len(p) > 0:
ret.append(p)
return ret | python | def polygon_list(self):
'''return a list of polygons for the waypoints'''
done = set()
ret = []
while len(done) != self.count():
p = self.polygon(done)
if len(p) > 0:
ret.append(p)
return ret | [
"def",
"polygon_list",
"(",
"self",
")",
":",
"done",
"=",
"set",
"(",
")",
"ret",
"=",
"[",
"]",
"while",
"len",
"(",
"done",
")",
"!=",
"self",
".",
"count",
"(",
")",
":",
"p",
"=",
"self",
".",
"polygon",
"(",
"done",
")",
"if",
"len",
"(",
"p",
")",
">",
"0",
":",
"ret",
".",
"append",
"(",
"p",
")",
"return",
"ret"
] | return a list of polygons for the waypoints | [
"return",
"a",
"list",
"of",
"polygons",
"for",
"the",
"waypoints"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L370-L378 |
249,269 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVWPLoader.view_list | def view_list(self):
'''return a list of polygon indexes lists for the waypoints'''
done = set()
ret = []
while len(done) != self.count():
p = self.view_indexes(done)
if len(p) > 0:
ret.append(p)
return ret | python | def view_list(self):
'''return a list of polygon indexes lists for the waypoints'''
done = set()
ret = []
while len(done) != self.count():
p = self.view_indexes(done)
if len(p) > 0:
ret.append(p)
return ret | [
"def",
"view_list",
"(",
"self",
")",
":",
"done",
"=",
"set",
"(",
")",
"ret",
"=",
"[",
"]",
"while",
"len",
"(",
"done",
")",
"!=",
"self",
".",
"count",
"(",
")",
":",
"p",
"=",
"self",
".",
"view_indexes",
"(",
"done",
")",
"if",
"len",
"(",
"p",
")",
">",
"0",
":",
"ret",
".",
"append",
"(",
"p",
")",
"return",
"ret"
] | return a list of polygon indexes lists for the waypoints | [
"return",
"a",
"list",
"of",
"polygon",
"indexes",
"lists",
"for",
"the",
"waypoints"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L380-L388 |
249,270 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVRallyLoader.reindex | def reindex(self):
'''reset counters and indexes'''
for i in range(self.rally_count()):
self.rally_points[i].count = self.rally_count()
self.rally_points[i].idx = i
self.last_change = time.time() | python | def reindex(self):
'''reset counters and indexes'''
for i in range(self.rally_count()):
self.rally_points[i].count = self.rally_count()
self.rally_points[i].idx = i
self.last_change = time.time() | [
"def",
"reindex",
"(",
"self",
")",
":",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"rally_count",
"(",
")",
")",
":",
"self",
".",
"rally_points",
"[",
"i",
"]",
".",
"count",
"=",
"self",
".",
"rally_count",
"(",
")",
"self",
".",
"rally_points",
"[",
"i",
"]",
".",
"idx",
"=",
"i",
"self",
".",
"last_change",
"=",
"time",
".",
"time",
"(",
")"
] | reset counters and indexes | [
"reset",
"counters",
"and",
"indexes"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L412-L417 |
249,271 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVRallyLoader.append_rally_point | def append_rally_point(self, p):
'''add rallypoint to end of list'''
if (self.rally_count() > 9):
print("Can't have more than 10 rally points, not adding.")
return
self.rally_points.append(p)
self.reindex() | python | def append_rally_point(self, p):
'''add rallypoint to end of list'''
if (self.rally_count() > 9):
print("Can't have more than 10 rally points, not adding.")
return
self.rally_points.append(p)
self.reindex() | [
"def",
"append_rally_point",
"(",
"self",
",",
"p",
")",
":",
"if",
"(",
"self",
".",
"rally_count",
"(",
")",
">",
"9",
")",
":",
"print",
"(",
"\"Can't have more than 10 rally points, not adding.\"",
")",
"return",
"self",
".",
"rally_points",
".",
"append",
"(",
"p",
")",
"self",
".",
"reindex",
"(",
")"
] | add rallypoint to end of list | [
"add",
"rallypoint",
"to",
"end",
"of",
"list"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L419-L426 |
249,272 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVRallyLoader.load | def load(self, filename):
'''load rally and rally_land points from a file.
returns number of points loaded'''
f = open(filename, mode='r')
self.clear()
for line in f:
if line.startswith('#'):
continue
line = line.strip()
if not line:
continue
a = line.split()
if len(a) != 7:
raise MAVRallyError("invalid rally file line: %s" % line)
if (a[0].lower() == "rally"):
self.create_and_append_rally_point(float(a[1]) * 1e7, float(a[2]) * 1e7,
float(a[3]), float(a[4]), float(a[5]) * 100.0, int(a[6]))
f.close()
return len(self.rally_points) | python | def load(self, filename):
'''load rally and rally_land points from a file.
returns number of points loaded'''
f = open(filename, mode='r')
self.clear()
for line in f:
if line.startswith('#'):
continue
line = line.strip()
if not line:
continue
a = line.split()
if len(a) != 7:
raise MAVRallyError("invalid rally file line: %s" % line)
if (a[0].lower() == "rally"):
self.create_and_append_rally_point(float(a[1]) * 1e7, float(a[2]) * 1e7,
float(a[3]), float(a[4]), float(a[5]) * 100.0, int(a[6]))
f.close()
return len(self.rally_points) | [
"def",
"load",
"(",
"self",
",",
"filename",
")",
":",
"f",
"=",
"open",
"(",
"filename",
",",
"mode",
"=",
"'r'",
")",
"self",
".",
"clear",
"(",
")",
"for",
"line",
"in",
"f",
":",
"if",
"line",
".",
"startswith",
"(",
"'#'",
")",
":",
"continue",
"line",
"=",
"line",
".",
"strip",
"(",
")",
"if",
"not",
"line",
":",
"continue",
"a",
"=",
"line",
".",
"split",
"(",
")",
"if",
"len",
"(",
"a",
")",
"!=",
"7",
":",
"raise",
"MAVRallyError",
"(",
"\"invalid rally file line: %s\"",
"%",
"line",
")",
"if",
"(",
"a",
"[",
"0",
"]",
".",
"lower",
"(",
")",
"==",
"\"rally\"",
")",
":",
"self",
".",
"create_and_append_rally_point",
"(",
"float",
"(",
"a",
"[",
"1",
"]",
")",
"*",
"1e7",
",",
"float",
"(",
"a",
"[",
"2",
"]",
")",
"*",
"1e7",
",",
"float",
"(",
"a",
"[",
"3",
"]",
")",
",",
"float",
"(",
"a",
"[",
"4",
"]",
")",
",",
"float",
"(",
"a",
"[",
"5",
"]",
")",
"*",
"100.0",
",",
"int",
"(",
"a",
"[",
"6",
"]",
")",
")",
"f",
".",
"close",
"(",
")",
"return",
"len",
"(",
"self",
".",
"rally_points",
")"
] | load rally and rally_land points from a file.
returns number of points loaded | [
"load",
"rally",
"and",
"rally_land",
"points",
"from",
"a",
"file",
".",
"returns",
"number",
"of",
"points",
"loaded"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L466-L485 |
249,273 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVFenceLoader.load | def load(self, filename):
'''load points from a file.
returns number of points loaded'''
f = open(filename, mode='r')
self.clear()
for line in f:
if line.startswith('#'):
continue
line = line.strip()
if not line:
continue
a = line.split()
if len(a) != 2:
raise MAVFenceError("invalid fence point line: %s" % line)
self.add_latlon(float(a[0]), float(a[1]))
f.close()
return len(self.points) | python | def load(self, filename):
'''load points from a file.
returns number of points loaded'''
f = open(filename, mode='r')
self.clear()
for line in f:
if line.startswith('#'):
continue
line = line.strip()
if not line:
continue
a = line.split()
if len(a) != 2:
raise MAVFenceError("invalid fence point line: %s" % line)
self.add_latlon(float(a[0]), float(a[1]))
f.close()
return len(self.points) | [
"def",
"load",
"(",
"self",
",",
"filename",
")",
":",
"f",
"=",
"open",
"(",
"filename",
",",
"mode",
"=",
"'r'",
")",
"self",
".",
"clear",
"(",
")",
"for",
"line",
"in",
"f",
":",
"if",
"line",
".",
"startswith",
"(",
"'#'",
")",
":",
"continue",
"line",
"=",
"line",
".",
"strip",
"(",
")",
"if",
"not",
"line",
":",
"continue",
"a",
"=",
"line",
".",
"split",
"(",
")",
"if",
"len",
"(",
"a",
")",
"!=",
"2",
":",
"raise",
"MAVFenceError",
"(",
"\"invalid fence point line: %s\"",
"%",
"line",
")",
"self",
".",
"add_latlon",
"(",
"float",
"(",
"a",
"[",
"0",
"]",
")",
",",
"float",
"(",
"a",
"[",
"1",
"]",
")",
")",
"f",
".",
"close",
"(",
")",
"return",
"len",
"(",
"self",
".",
"points",
")"
] | load points from a file.
returns number of points loaded | [
"load",
"points",
"from",
"a",
"file",
".",
"returns",
"number",
"of",
"points",
"loaded"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L543-L559 |
249,274 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVFenceLoader.move | def move(self, i, lat, lng, change_time=True):
'''move a fence point'''
if i < 0 or i >= self.count():
print("Invalid fence point number %u" % i)
self.points[i].lat = lat
self.points[i].lng = lng
# ensure we close the polygon
if i == 1:
self.points[self.count()-1].lat = lat
self.points[self.count()-1].lng = lng
if i == self.count() - 1:
self.points[1].lat = lat
self.points[1].lng = lng
if change_time:
self.last_change = time.time() | python | def move(self, i, lat, lng, change_time=True):
'''move a fence point'''
if i < 0 or i >= self.count():
print("Invalid fence point number %u" % i)
self.points[i].lat = lat
self.points[i].lng = lng
# ensure we close the polygon
if i == 1:
self.points[self.count()-1].lat = lat
self.points[self.count()-1].lng = lng
if i == self.count() - 1:
self.points[1].lat = lat
self.points[1].lng = lng
if change_time:
self.last_change = time.time() | [
"def",
"move",
"(",
"self",
",",
"i",
",",
"lat",
",",
"lng",
",",
"change_time",
"=",
"True",
")",
":",
"if",
"i",
"<",
"0",
"or",
"i",
">=",
"self",
".",
"count",
"(",
")",
":",
"print",
"(",
"\"Invalid fence point number %u\"",
"%",
"i",
")",
"self",
".",
"points",
"[",
"i",
"]",
".",
"lat",
"=",
"lat",
"self",
".",
"points",
"[",
"i",
"]",
".",
"lng",
"=",
"lng",
"# ensure we close the polygon",
"if",
"i",
"==",
"1",
":",
"self",
".",
"points",
"[",
"self",
".",
"count",
"(",
")",
"-",
"1",
"]",
".",
"lat",
"=",
"lat",
"self",
".",
"points",
"[",
"self",
".",
"count",
"(",
")",
"-",
"1",
"]",
".",
"lng",
"=",
"lng",
"if",
"i",
"==",
"self",
".",
"count",
"(",
")",
"-",
"1",
":",
"self",
".",
"points",
"[",
"1",
"]",
".",
"lat",
"=",
"lat",
"self",
".",
"points",
"[",
"1",
"]",
".",
"lng",
"=",
"lng",
"if",
"change_time",
":",
"self",
".",
"last_change",
"=",
"time",
".",
"time",
"(",
")"
] | move a fence point | [
"move",
"a",
"fence",
"point"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L568-L582 |
249,275 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVFenceLoader.remove | def remove(self, i, change_time=True):
'''remove a fence point'''
if i < 0 or i >= self.count():
print("Invalid fence point number %u" % i)
self.points.pop(i)
# ensure we close the polygon
if i == 1:
self.points[self.count()-1].lat = self.points[1].lat
self.points[self.count()-1].lng = self.points[1].lng
if i == self.count():
self.points[1].lat = self.points[self.count()-1].lat
self.points[1].lng = self.points[self.count()-1].lng
if change_time:
self.last_change = time.time() | python | def remove(self, i, change_time=True):
'''remove a fence point'''
if i < 0 or i >= self.count():
print("Invalid fence point number %u" % i)
self.points.pop(i)
# ensure we close the polygon
if i == 1:
self.points[self.count()-1].lat = self.points[1].lat
self.points[self.count()-1].lng = self.points[1].lng
if i == self.count():
self.points[1].lat = self.points[self.count()-1].lat
self.points[1].lng = self.points[self.count()-1].lng
if change_time:
self.last_change = time.time() | [
"def",
"remove",
"(",
"self",
",",
"i",
",",
"change_time",
"=",
"True",
")",
":",
"if",
"i",
"<",
"0",
"or",
"i",
">=",
"self",
".",
"count",
"(",
")",
":",
"print",
"(",
"\"Invalid fence point number %u\"",
"%",
"i",
")",
"self",
".",
"points",
".",
"pop",
"(",
"i",
")",
"# ensure we close the polygon",
"if",
"i",
"==",
"1",
":",
"self",
".",
"points",
"[",
"self",
".",
"count",
"(",
")",
"-",
"1",
"]",
".",
"lat",
"=",
"self",
".",
"points",
"[",
"1",
"]",
".",
"lat",
"self",
".",
"points",
"[",
"self",
".",
"count",
"(",
")",
"-",
"1",
"]",
".",
"lng",
"=",
"self",
".",
"points",
"[",
"1",
"]",
".",
"lng",
"if",
"i",
"==",
"self",
".",
"count",
"(",
")",
":",
"self",
".",
"points",
"[",
"1",
"]",
".",
"lat",
"=",
"self",
".",
"points",
"[",
"self",
".",
"count",
"(",
")",
"-",
"1",
"]",
".",
"lat",
"self",
".",
"points",
"[",
"1",
"]",
".",
"lng",
"=",
"self",
".",
"points",
"[",
"self",
".",
"count",
"(",
")",
"-",
"1",
"]",
".",
"lng",
"if",
"change_time",
":",
"self",
".",
"last_change",
"=",
"time",
".",
"time",
"(",
")"
] | remove a fence point | [
"remove",
"a",
"fence",
"point"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L584-L597 |
249,276 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py | MAVFenceLoader.polygon | def polygon(self):
'''return a polygon for the fence'''
points = []
for fp in self.points[1:]:
points.append((fp.lat, fp.lng))
return points | python | def polygon(self):
'''return a polygon for the fence'''
points = []
for fp in self.points[1:]:
points.append((fp.lat, fp.lng))
return points | [
"def",
"polygon",
"(",
"self",
")",
":",
"points",
"=",
"[",
"]",
"for",
"fp",
"in",
"self",
".",
"points",
"[",
"1",
":",
"]",
":",
"points",
".",
"append",
"(",
"(",
"fp",
".",
"lat",
",",
"fp",
".",
"lng",
")",
")",
"return",
"points"
] | return a polygon for the fence | [
"return",
"a",
"polygon",
"for",
"the",
"fence"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/mavwp.py#L599-L604 |
249,277 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/mavproxy.py | add_input | def add_input(cmd, immediate=False):
'''add some command input to be processed'''
if immediate:
process_stdin(cmd)
else:
mpstate.input_queue.put(cmd) | python | def add_input(cmd, immediate=False):
'''add some command input to be processed'''
if immediate:
process_stdin(cmd)
else:
mpstate.input_queue.put(cmd) | [
"def",
"add_input",
"(",
"cmd",
",",
"immediate",
"=",
"False",
")",
":",
"if",
"immediate",
":",
"process_stdin",
"(",
"cmd",
")",
"else",
":",
"mpstate",
".",
"input_queue",
".",
"put",
"(",
"cmd",
")"
] | add some command input to be processed | [
"add",
"some",
"command",
"input",
"to",
"be",
"processed"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/mavproxy.py#L122-L127 |
249,278 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/mavproxy.py | param_set | def param_set(name, value, retries=3):
'''set a parameter'''
name = name.upper()
return mpstate.mav_param.mavset(mpstate.master(), name, value, retries=retries) | python | def param_set(name, value, retries=3):
'''set a parameter'''
name = name.upper()
return mpstate.mav_param.mavset(mpstate.master(), name, value, retries=retries) | [
"def",
"param_set",
"(",
"name",
",",
"value",
",",
"retries",
"=",
"3",
")",
":",
"name",
"=",
"name",
".",
"upper",
"(",
")",
"return",
"mpstate",
".",
"mav_param",
".",
"mavset",
"(",
"mpstate",
".",
"master",
"(",
")",
",",
"name",
",",
"value",
",",
"retries",
"=",
"retries",
")"
] | set a parameter | [
"set",
"a",
"parameter"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/mavproxy.py#L242-L245 |
249,279 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/mavproxy.py | unload_module | def unload_module(modname):
'''unload a module'''
for (m,pm) in mpstate.modules:
if m.name == modname:
if hasattr(m, 'unload'):
m.unload()
mpstate.modules.remove((m,pm))
print("Unloaded module %s" % modname)
return True
print("Unable to find module %s" % modname)
return False | python | def unload_module(modname):
'''unload a module'''
for (m,pm) in mpstate.modules:
if m.name == modname:
if hasattr(m, 'unload'):
m.unload()
mpstate.modules.remove((m,pm))
print("Unloaded module %s" % modname)
return True
print("Unable to find module %s" % modname)
return False | [
"def",
"unload_module",
"(",
"modname",
")",
":",
"for",
"(",
"m",
",",
"pm",
")",
"in",
"mpstate",
".",
"modules",
":",
"if",
"m",
".",
"name",
"==",
"modname",
":",
"if",
"hasattr",
"(",
"m",
",",
"'unload'",
")",
":",
"m",
".",
"unload",
"(",
")",
"mpstate",
".",
"modules",
".",
"remove",
"(",
"(",
"m",
",",
"pm",
")",
")",
"print",
"(",
"\"Unloaded module %s\"",
"%",
"modname",
")",
"return",
"True",
"print",
"(",
"\"Unable to find module %s\"",
"%",
"modname",
")",
"return",
"False"
] | unload a module | [
"unload",
"a",
"module"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/mavproxy.py#L313-L323 |
249,280 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/mavproxy.py | import_package | def import_package(name):
"""Given a package name like 'foo.bar.quux', imports the package
and returns the desired module."""
import zipimport
try:
mod = __import__(name)
except ImportError:
clear_zipimport_cache()
mod = __import__(name)
components = name.split('.')
for comp in components[1:]:
mod = getattr(mod, comp)
return mod | python | def import_package(name):
import zipimport
try:
mod = __import__(name)
except ImportError:
clear_zipimport_cache()
mod = __import__(name)
components = name.split('.')
for comp in components[1:]:
mod = getattr(mod, comp)
return mod | [
"def",
"import_package",
"(",
"name",
")",
":",
"import",
"zipimport",
"try",
":",
"mod",
"=",
"__import__",
"(",
"name",
")",
"except",
"ImportError",
":",
"clear_zipimport_cache",
"(",
")",
"mod",
"=",
"__import__",
"(",
"name",
")",
"components",
"=",
"name",
".",
"split",
"(",
"'.'",
")",
"for",
"comp",
"in",
"components",
"[",
"1",
":",
"]",
":",
"mod",
"=",
"getattr",
"(",
"mod",
",",
"comp",
")",
"return",
"mod"
] | Given a package name like 'foo.bar.quux', imports the package
and returns the desired module. | [
"Given",
"a",
"package",
"name",
"like",
"foo",
".",
"bar",
".",
"quux",
"imports",
"the",
"package",
"and",
"returns",
"the",
"desired",
"module",
"."
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/mavproxy.py#L416-L429 |
249,281 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/mavproxy.py | process_master | def process_master(m):
'''process packets from the MAVLink master'''
try:
s = m.recv(16*1024)
except Exception:
time.sleep(0.1)
return
# prevent a dead serial port from causing the CPU to spin. The user hitting enter will
# cause it to try and reconnect
if len(s) == 0:
time.sleep(0.1)
return
if (mpstate.settings.compdebug & 1) != 0:
return
if mpstate.logqueue_raw:
mpstate.logqueue_raw.put(str(s))
if mpstate.status.setup_mode:
if mpstate.system == 'Windows':
# strip nsh ansi codes
s = s.replace("\033[K","")
sys.stdout.write(str(s))
sys.stdout.flush()
return
if m.first_byte and opts.auto_protocol:
m.auto_mavlink_version(s)
msgs = m.mav.parse_buffer(s)
if msgs:
for msg in msgs:
sysid = msg.get_srcSystem()
if sysid in mpstate.sysid_outputs:
# the message has been handled by a specialised handler for this system
continue
if getattr(m, '_timestamp', None) is None:
m.post_message(msg)
if msg.get_type() == "BAD_DATA":
if opts.show_errors:
mpstate.console.writeln("MAV error: %s" % msg)
mpstate.status.mav_error += 1 | python | def process_master(m):
'''process packets from the MAVLink master'''
try:
s = m.recv(16*1024)
except Exception:
time.sleep(0.1)
return
# prevent a dead serial port from causing the CPU to spin. The user hitting enter will
# cause it to try and reconnect
if len(s) == 0:
time.sleep(0.1)
return
if (mpstate.settings.compdebug & 1) != 0:
return
if mpstate.logqueue_raw:
mpstate.logqueue_raw.put(str(s))
if mpstate.status.setup_mode:
if mpstate.system == 'Windows':
# strip nsh ansi codes
s = s.replace("\033[K","")
sys.stdout.write(str(s))
sys.stdout.flush()
return
if m.first_byte and opts.auto_protocol:
m.auto_mavlink_version(s)
msgs = m.mav.parse_buffer(s)
if msgs:
for msg in msgs:
sysid = msg.get_srcSystem()
if sysid in mpstate.sysid_outputs:
# the message has been handled by a specialised handler for this system
continue
if getattr(m, '_timestamp', None) is None:
m.post_message(msg)
if msg.get_type() == "BAD_DATA":
if opts.show_errors:
mpstate.console.writeln("MAV error: %s" % msg)
mpstate.status.mav_error += 1 | [
"def",
"process_master",
"(",
"m",
")",
":",
"try",
":",
"s",
"=",
"m",
".",
"recv",
"(",
"16",
"*",
"1024",
")",
"except",
"Exception",
":",
"time",
".",
"sleep",
"(",
"0.1",
")",
"return",
"# prevent a dead serial port from causing the CPU to spin. The user hitting enter will",
"# cause it to try and reconnect",
"if",
"len",
"(",
"s",
")",
"==",
"0",
":",
"time",
".",
"sleep",
"(",
"0.1",
")",
"return",
"if",
"(",
"mpstate",
".",
"settings",
".",
"compdebug",
"&",
"1",
")",
"!=",
"0",
":",
"return",
"if",
"mpstate",
".",
"logqueue_raw",
":",
"mpstate",
".",
"logqueue_raw",
".",
"put",
"(",
"str",
"(",
"s",
")",
")",
"if",
"mpstate",
".",
"status",
".",
"setup_mode",
":",
"if",
"mpstate",
".",
"system",
"==",
"'Windows'",
":",
"# strip nsh ansi codes",
"s",
"=",
"s",
".",
"replace",
"(",
"\"\\033[K\"",
",",
"\"\"",
")",
"sys",
".",
"stdout",
".",
"write",
"(",
"str",
"(",
"s",
")",
")",
"sys",
".",
"stdout",
".",
"flush",
"(",
")",
"return",
"if",
"m",
".",
"first_byte",
"and",
"opts",
".",
"auto_protocol",
":",
"m",
".",
"auto_mavlink_version",
"(",
"s",
")",
"msgs",
"=",
"m",
".",
"mav",
".",
"parse_buffer",
"(",
"s",
")",
"if",
"msgs",
":",
"for",
"msg",
"in",
"msgs",
":",
"sysid",
"=",
"msg",
".",
"get_srcSystem",
"(",
")",
"if",
"sysid",
"in",
"mpstate",
".",
"sysid_outputs",
":",
"# the message has been handled by a specialised handler for this system",
"continue",
"if",
"getattr",
"(",
"m",
",",
"'_timestamp'",
",",
"None",
")",
"is",
"None",
":",
"m",
".",
"post_message",
"(",
"msg",
")",
"if",
"msg",
".",
"get_type",
"(",
")",
"==",
"\"BAD_DATA\"",
":",
"if",
"opts",
".",
"show_errors",
":",
"mpstate",
".",
"console",
".",
"writeln",
"(",
"\"MAV error: %s\"",
"%",
"msg",
")",
"mpstate",
".",
"status",
".",
"mav_error",
"+=",
"1"
] | process packets from the MAVLink master | [
"process",
"packets",
"from",
"the",
"MAVLink",
"master"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/mavproxy.py#L518-L559 |
249,282 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/mavproxy.py | set_stream_rates | def set_stream_rates():
'''set mavlink stream rates'''
if (not msg_period.trigger() and
mpstate.status.last_streamrate1 == mpstate.settings.streamrate and
mpstate.status.last_streamrate2 == mpstate.settings.streamrate2):
return
mpstate.status.last_streamrate1 = mpstate.settings.streamrate
mpstate.status.last_streamrate2 = mpstate.settings.streamrate2
for master in mpstate.mav_master:
if master.linknum == 0:
rate = mpstate.settings.streamrate
else:
rate = mpstate.settings.streamrate2
if rate != -1:
master.mav.request_data_stream_send(mpstate.settings.target_system, mpstate.settings.target_component,
mavutil.mavlink.MAV_DATA_STREAM_ALL,
rate, 1) | python | def set_stream_rates():
'''set mavlink stream rates'''
if (not msg_period.trigger() and
mpstate.status.last_streamrate1 == mpstate.settings.streamrate and
mpstate.status.last_streamrate2 == mpstate.settings.streamrate2):
return
mpstate.status.last_streamrate1 = mpstate.settings.streamrate
mpstate.status.last_streamrate2 = mpstate.settings.streamrate2
for master in mpstate.mav_master:
if master.linknum == 0:
rate = mpstate.settings.streamrate
else:
rate = mpstate.settings.streamrate2
if rate != -1:
master.mav.request_data_stream_send(mpstate.settings.target_system, mpstate.settings.target_component,
mavutil.mavlink.MAV_DATA_STREAM_ALL,
rate, 1) | [
"def",
"set_stream_rates",
"(",
")",
":",
"if",
"(",
"not",
"msg_period",
".",
"trigger",
"(",
")",
"and",
"mpstate",
".",
"status",
".",
"last_streamrate1",
"==",
"mpstate",
".",
"settings",
".",
"streamrate",
"and",
"mpstate",
".",
"status",
".",
"last_streamrate2",
"==",
"mpstate",
".",
"settings",
".",
"streamrate2",
")",
":",
"return",
"mpstate",
".",
"status",
".",
"last_streamrate1",
"=",
"mpstate",
".",
"settings",
".",
"streamrate",
"mpstate",
".",
"status",
".",
"last_streamrate2",
"=",
"mpstate",
".",
"settings",
".",
"streamrate2",
"for",
"master",
"in",
"mpstate",
".",
"mav_master",
":",
"if",
"master",
".",
"linknum",
"==",
"0",
":",
"rate",
"=",
"mpstate",
".",
"settings",
".",
"streamrate",
"else",
":",
"rate",
"=",
"mpstate",
".",
"settings",
".",
"streamrate2",
"if",
"rate",
"!=",
"-",
"1",
":",
"master",
".",
"mav",
".",
"request_data_stream_send",
"(",
"mpstate",
".",
"settings",
".",
"target_system",
",",
"mpstate",
".",
"settings",
".",
"target_component",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_DATA_STREAM_ALL",
",",
"rate",
",",
"1",
")"
] | set mavlink stream rates | [
"set",
"mavlink",
"stream",
"rates"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/mavproxy.py#L669-L685 |
249,283 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/mavproxy.py | periodic_tasks | def periodic_tasks():
'''run periodic checks'''
if mpstate.status.setup_mode:
return
if (mpstate.settings.compdebug & 2) != 0:
return
if mpstate.settings.heartbeat != 0:
heartbeat_period.frequency = mpstate.settings.heartbeat
if heartbeat_period.trigger() and mpstate.settings.heartbeat != 0:
mpstate.status.counters['MasterOut'] += 1
for master in mpstate.mav_master:
send_heartbeat(master)
if heartbeat_check_period.trigger():
check_link_status()
set_stream_rates()
# call optional module idle tasks. These are called at several hundred Hz
for (m,pm) in mpstate.modules:
if hasattr(m, 'idle_task'):
try:
m.idle_task()
except Exception as msg:
if mpstate.settings.moddebug == 1:
print(msg)
elif mpstate.settings.moddebug > 1:
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback,
limit=2, file=sys.stdout)
# also see if the module should be unloaded:
if m.needs_unloading:
unload_module(m.name) | python | def periodic_tasks():
'''run periodic checks'''
if mpstate.status.setup_mode:
return
if (mpstate.settings.compdebug & 2) != 0:
return
if mpstate.settings.heartbeat != 0:
heartbeat_period.frequency = mpstate.settings.heartbeat
if heartbeat_period.trigger() and mpstate.settings.heartbeat != 0:
mpstate.status.counters['MasterOut'] += 1
for master in mpstate.mav_master:
send_heartbeat(master)
if heartbeat_check_period.trigger():
check_link_status()
set_stream_rates()
# call optional module idle tasks. These are called at several hundred Hz
for (m,pm) in mpstate.modules:
if hasattr(m, 'idle_task'):
try:
m.idle_task()
except Exception as msg:
if mpstate.settings.moddebug == 1:
print(msg)
elif mpstate.settings.moddebug > 1:
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback,
limit=2, file=sys.stdout)
# also see if the module should be unloaded:
if m.needs_unloading:
unload_module(m.name) | [
"def",
"periodic_tasks",
"(",
")",
":",
"if",
"mpstate",
".",
"status",
".",
"setup_mode",
":",
"return",
"if",
"(",
"mpstate",
".",
"settings",
".",
"compdebug",
"&",
"2",
")",
"!=",
"0",
":",
"return",
"if",
"mpstate",
".",
"settings",
".",
"heartbeat",
"!=",
"0",
":",
"heartbeat_period",
".",
"frequency",
"=",
"mpstate",
".",
"settings",
".",
"heartbeat",
"if",
"heartbeat_period",
".",
"trigger",
"(",
")",
"and",
"mpstate",
".",
"settings",
".",
"heartbeat",
"!=",
"0",
":",
"mpstate",
".",
"status",
".",
"counters",
"[",
"'MasterOut'",
"]",
"+=",
"1",
"for",
"master",
"in",
"mpstate",
".",
"mav_master",
":",
"send_heartbeat",
"(",
"master",
")",
"if",
"heartbeat_check_period",
".",
"trigger",
"(",
")",
":",
"check_link_status",
"(",
")",
"set_stream_rates",
"(",
")",
"# call optional module idle tasks. These are called at several hundred Hz",
"for",
"(",
"m",
",",
"pm",
")",
"in",
"mpstate",
".",
"modules",
":",
"if",
"hasattr",
"(",
"m",
",",
"'idle_task'",
")",
":",
"try",
":",
"m",
".",
"idle_task",
"(",
")",
"except",
"Exception",
"as",
"msg",
":",
"if",
"mpstate",
".",
"settings",
".",
"moddebug",
"==",
"1",
":",
"print",
"(",
"msg",
")",
"elif",
"mpstate",
".",
"settings",
".",
"moddebug",
">",
"1",
":",
"exc_type",
",",
"exc_value",
",",
"exc_traceback",
"=",
"sys",
".",
"exc_info",
"(",
")",
"traceback",
".",
"print_exception",
"(",
"exc_type",
",",
"exc_value",
",",
"exc_traceback",
",",
"limit",
"=",
"2",
",",
"file",
"=",
"sys",
".",
"stdout",
")",
"# also see if the module should be unloaded:",
"if",
"m",
".",
"needs_unloading",
":",
"unload_module",
"(",
"m",
".",
"name",
")"
] | run periodic checks | [
"run",
"periodic",
"checks"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/mavproxy.py#L707-L743 |
249,284 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/mavproxy.py | MPState.master | def master(self):
'''return the currently chosen mavlink master object'''
if len(self.mav_master) == 0:
return None
if self.settings.link > len(self.mav_master):
self.settings.link = 1
# try to use one with no link error
if not self.mav_master[self.settings.link-1].linkerror:
return self.mav_master[self.settings.link-1]
for m in self.mav_master:
if not m.linkerror:
return m
return self.mav_master[self.settings.link-1] | python | def master(self):
'''return the currently chosen mavlink master object'''
if len(self.mav_master) == 0:
return None
if self.settings.link > len(self.mav_master):
self.settings.link = 1
# try to use one with no link error
if not self.mav_master[self.settings.link-1].linkerror:
return self.mav_master[self.settings.link-1]
for m in self.mav_master:
if not m.linkerror:
return m
return self.mav_master[self.settings.link-1] | [
"def",
"master",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"mav_master",
")",
"==",
"0",
":",
"return",
"None",
"if",
"self",
".",
"settings",
".",
"link",
">",
"len",
"(",
"self",
".",
"mav_master",
")",
":",
"self",
".",
"settings",
".",
"link",
"=",
"1",
"# try to use one with no link error",
"if",
"not",
"self",
".",
"mav_master",
"[",
"self",
".",
"settings",
".",
"link",
"-",
"1",
"]",
".",
"linkerror",
":",
"return",
"self",
".",
"mav_master",
"[",
"self",
".",
"settings",
".",
"link",
"-",
"1",
"]",
"for",
"m",
"in",
"self",
".",
"mav_master",
":",
"if",
"not",
"m",
".",
"linkerror",
":",
"return",
"m",
"return",
"self",
".",
"mav_master",
"[",
"self",
".",
"settings",
".",
"link",
"-",
"1",
"]"
] | return the currently chosen mavlink master object | [
"return",
"the",
"currently",
"chosen",
"mavlink",
"master",
"object"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/mavproxy.py#L223-L235 |
249,285 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_cs.py | generate | def generate(basename, xml):
'''generate complete MAVLink CSharp implemenation'''
structsfilename = basename + '.generated.cs'
msgs = []
enums = []
filelist = []
for x in xml:
msgs.extend(x.message)
enums.extend(x.enum)
filelist.append(os.path.basename(x.filename))
for m in msgs:
m.order_map = [ 0 ] * len(m.fieldnames)
for i in range(0, len(m.fieldnames)):
m.order_map[i] = m.ordered_fieldnames.index(m.fieldnames[i])
m.fields_in_order = []
for i in range(0, len(m.fieldnames)):
m.order_map[i] = m.ordered_fieldnames.index(m.fieldnames[i])
print("Generating messages file: %s" % structsfilename)
dir = os.path.dirname(structsfilename)
if not os.path.exists(dir):
os.makedirs(dir)
outf = open(structsfilename, "w")
generate_preamble(outf, msgs, filelist, xml[0])
outf.write("""
using System.Reflection;
[assembly: AssemblyTitle("Mavlink Classes")]
[assembly: AssemblyDescription("Generated Message Classes for Mavlink. See http://qgroundcontrol.org/mavlink/start")]
[assembly: AssemblyProduct("Mavlink")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
""")
generate_enums(outf, enums)
generate_classes(outf, msgs)
outf.close()
print("Generating the (De)Serializer classes")
serfilename = basename + '_codec.generated.cs'
outf = open(serfilename, "w")
generate_CodecIndex(outf, msgs, xml)
generate_Deserialization(outf, msgs)
generate_Serialization(outf, msgs)
outf.write("\t}\n\n")
outf.write("}\n\n")
outf.close()
# Some build commands depend on the platform - eg MS .NET Windows Vs Mono on Linux
if platform.system() == "Windows":
winpath=os.environ['WinDir']
cscCommand = winpath + "\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe"
if (os.path.exists(cscCommand)==False):
print("\nError: CS compiler not found. .Net Assembly generation skipped")
return
else:
print("Error:.Net Assembly generation not yet supported on non Windows platforms")
return
cscCommand = "csc"
print("Compiling Assembly for .Net Framework 4.0")
generatedCsFiles = [ serfilename, structsfilename]
includedCsFiles = [ 'CS/common/ByteArrayUtil.cs', 'CS/common/FrameworkBitConverter.cs', 'CS/common/Mavlink.cs' ]
outputLibraryPath = os.path.normpath(dir + "/mavlink.dll")
compileCommand = "%s %s" % (cscCommand, "/target:library /debug /out:" + outputLibraryPath)
compileCommand = compileCommand + " /doc:" + os.path.normpath(dir + "/mavlink.xml")
for csFile in generatedCsFiles + includedCsFiles:
compileCommand = compileCommand + " " + os.path.normpath(csFile)
#print("Cmd:" + compileCommand)
res = os.system (compileCommand)
if res == '0':
print("Generated %s OK" % filename)
else:
print("Error") | python | def generate(basename, xml):
'''generate complete MAVLink CSharp implemenation'''
structsfilename = basename + '.generated.cs'
msgs = []
enums = []
filelist = []
for x in xml:
msgs.extend(x.message)
enums.extend(x.enum)
filelist.append(os.path.basename(x.filename))
for m in msgs:
m.order_map = [ 0 ] * len(m.fieldnames)
for i in range(0, len(m.fieldnames)):
m.order_map[i] = m.ordered_fieldnames.index(m.fieldnames[i])
m.fields_in_order = []
for i in range(0, len(m.fieldnames)):
m.order_map[i] = m.ordered_fieldnames.index(m.fieldnames[i])
print("Generating messages file: %s" % structsfilename)
dir = os.path.dirname(structsfilename)
if not os.path.exists(dir):
os.makedirs(dir)
outf = open(structsfilename, "w")
generate_preamble(outf, msgs, filelist, xml[0])
outf.write("""
using System.Reflection;
[assembly: AssemblyTitle("Mavlink Classes")]
[assembly: AssemblyDescription("Generated Message Classes for Mavlink. See http://qgroundcontrol.org/mavlink/start")]
[assembly: AssemblyProduct("Mavlink")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
""")
generate_enums(outf, enums)
generate_classes(outf, msgs)
outf.close()
print("Generating the (De)Serializer classes")
serfilename = basename + '_codec.generated.cs'
outf = open(serfilename, "w")
generate_CodecIndex(outf, msgs, xml)
generate_Deserialization(outf, msgs)
generate_Serialization(outf, msgs)
outf.write("\t}\n\n")
outf.write("}\n\n")
outf.close()
# Some build commands depend on the platform - eg MS .NET Windows Vs Mono on Linux
if platform.system() == "Windows":
winpath=os.environ['WinDir']
cscCommand = winpath + "\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe"
if (os.path.exists(cscCommand)==False):
print("\nError: CS compiler not found. .Net Assembly generation skipped")
return
else:
print("Error:.Net Assembly generation not yet supported on non Windows platforms")
return
cscCommand = "csc"
print("Compiling Assembly for .Net Framework 4.0")
generatedCsFiles = [ serfilename, structsfilename]
includedCsFiles = [ 'CS/common/ByteArrayUtil.cs', 'CS/common/FrameworkBitConverter.cs', 'CS/common/Mavlink.cs' ]
outputLibraryPath = os.path.normpath(dir + "/mavlink.dll")
compileCommand = "%s %s" % (cscCommand, "/target:library /debug /out:" + outputLibraryPath)
compileCommand = compileCommand + " /doc:" + os.path.normpath(dir + "/mavlink.xml")
for csFile in generatedCsFiles + includedCsFiles:
compileCommand = compileCommand + " " + os.path.normpath(csFile)
#print("Cmd:" + compileCommand)
res = os.system (compileCommand)
if res == '0':
print("Generated %s OK" % filename)
else:
print("Error") | [
"def",
"generate",
"(",
"basename",
",",
"xml",
")",
":",
"structsfilename",
"=",
"basename",
"+",
"'.generated.cs'",
"msgs",
"=",
"[",
"]",
"enums",
"=",
"[",
"]",
"filelist",
"=",
"[",
"]",
"for",
"x",
"in",
"xml",
":",
"msgs",
".",
"extend",
"(",
"x",
".",
"message",
")",
"enums",
".",
"extend",
"(",
"x",
".",
"enum",
")",
"filelist",
".",
"append",
"(",
"os",
".",
"path",
".",
"basename",
"(",
"x",
".",
"filename",
")",
")",
"for",
"m",
"in",
"msgs",
":",
"m",
".",
"order_map",
"=",
"[",
"0",
"]",
"*",
"len",
"(",
"m",
".",
"fieldnames",
")",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"m",
".",
"fieldnames",
")",
")",
":",
"m",
".",
"order_map",
"[",
"i",
"]",
"=",
"m",
".",
"ordered_fieldnames",
".",
"index",
"(",
"m",
".",
"fieldnames",
"[",
"i",
"]",
")",
"m",
".",
"fields_in_order",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"m",
".",
"fieldnames",
")",
")",
":",
"m",
".",
"order_map",
"[",
"i",
"]",
"=",
"m",
".",
"ordered_fieldnames",
".",
"index",
"(",
"m",
".",
"fieldnames",
"[",
"i",
"]",
")",
"print",
"(",
"\"Generating messages file: %s\"",
"%",
"structsfilename",
")",
"dir",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"structsfilename",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"dir",
")",
":",
"os",
".",
"makedirs",
"(",
"dir",
")",
"outf",
"=",
"open",
"(",
"structsfilename",
",",
"\"w\"",
")",
"generate_preamble",
"(",
"outf",
",",
"msgs",
",",
"filelist",
",",
"xml",
"[",
"0",
"]",
")",
"outf",
".",
"write",
"(",
"\"\"\"\n \nusing System.Reflection; \n \n[assembly: AssemblyTitle(\"Mavlink Classes\")]\n[assembly: AssemblyDescription(\"Generated Message Classes for Mavlink. See http://qgroundcontrol.org/mavlink/start\")]\n[assembly: AssemblyProduct(\"Mavlink\")]\n[assembly: AssemblyVersion(\"1.0.0.0\")]\n[assembly: AssemblyFileVersion(\"1.0.0.0\")]\n\n \"\"\"",
")",
"generate_enums",
"(",
"outf",
",",
"enums",
")",
"generate_classes",
"(",
"outf",
",",
"msgs",
")",
"outf",
".",
"close",
"(",
")",
"print",
"(",
"\"Generating the (De)Serializer classes\"",
")",
"serfilename",
"=",
"basename",
"+",
"'_codec.generated.cs'",
"outf",
"=",
"open",
"(",
"serfilename",
",",
"\"w\"",
")",
"generate_CodecIndex",
"(",
"outf",
",",
"msgs",
",",
"xml",
")",
"generate_Deserialization",
"(",
"outf",
",",
"msgs",
")",
"generate_Serialization",
"(",
"outf",
",",
"msgs",
")",
"outf",
".",
"write",
"(",
"\"\\t}\\n\\n\"",
")",
"outf",
".",
"write",
"(",
"\"}\\n\\n\"",
")",
"outf",
".",
"close",
"(",
")",
"# Some build commands depend on the platform - eg MS .NET Windows Vs Mono on Linux",
"if",
"platform",
".",
"system",
"(",
")",
"==",
"\"Windows\"",
":",
"winpath",
"=",
"os",
".",
"environ",
"[",
"'WinDir'",
"]",
"cscCommand",
"=",
"winpath",
"+",
"\"\\\\Microsoft.NET\\\\Framework\\\\v4.0.30319\\\\csc.exe\"",
"if",
"(",
"os",
".",
"path",
".",
"exists",
"(",
"cscCommand",
")",
"==",
"False",
")",
":",
"print",
"(",
"\"\\nError: CS compiler not found. .Net Assembly generation skipped\"",
")",
"return",
"else",
":",
"print",
"(",
"\"Error:.Net Assembly generation not yet supported on non Windows platforms\"",
")",
"return",
"cscCommand",
"=",
"\"csc\"",
"print",
"(",
"\"Compiling Assembly for .Net Framework 4.0\"",
")",
"generatedCsFiles",
"=",
"[",
"serfilename",
",",
"structsfilename",
"]",
"includedCsFiles",
"=",
"[",
"'CS/common/ByteArrayUtil.cs'",
",",
"'CS/common/FrameworkBitConverter.cs'",
",",
"'CS/common/Mavlink.cs'",
"]",
"outputLibraryPath",
"=",
"os",
".",
"path",
".",
"normpath",
"(",
"dir",
"+",
"\"/mavlink.dll\"",
")",
"compileCommand",
"=",
"\"%s %s\"",
"%",
"(",
"cscCommand",
",",
"\"/target:library /debug /out:\"",
"+",
"outputLibraryPath",
")",
"compileCommand",
"=",
"compileCommand",
"+",
"\" /doc:\"",
"+",
"os",
".",
"path",
".",
"normpath",
"(",
"dir",
"+",
"\"/mavlink.xml\"",
")",
"for",
"csFile",
"in",
"generatedCsFiles",
"+",
"includedCsFiles",
":",
"compileCommand",
"=",
"compileCommand",
"+",
"\" \"",
"+",
"os",
".",
"path",
".",
"normpath",
"(",
"csFile",
")",
"#print(\"Cmd:\" + compileCommand)",
"res",
"=",
"os",
".",
"system",
"(",
"compileCommand",
")",
"if",
"res",
"==",
"'0'",
":",
"print",
"(",
"\"Generated %s OK\"",
"%",
"filename",
")",
"else",
":",
"print",
"(",
"\"Error\"",
")"
] | generate complete MAVLink CSharp implemenation | [
"generate",
"complete",
"MAVLink",
"CSharp",
"implemenation"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/pymavlink/generator/mavgen_cs.py#L254-L343 |
249,286 | JdeRobot/base | src/tools/colorTuner_py/QDarkStyleSheet/qdarkstyle/__init__.py | load_stylesheet | def load_stylesheet(pyside=True):
"""
Loads the stylesheet. Takes care of importing the rc module.
:param pyside: True to load the pyside rc file, False to load the PyQt rc file
:return the stylesheet string
"""
# Smart import of the rc file
if pyside:
import qdarkstyle.pyside_style_rc
else:
import qdarkstyle.pyqt_style_rc
# Load the stylesheet content from resources
if not pyside:
from PyQt4.QtCore import QFile, QTextStream
else:
from PySide.QtCore import QFile, QTextStream
f = QFile(":qdarkstyle/style.qss")
if not f.exists():
_logger().error("Unable to load stylesheet, file not found in "
"resources")
return ""
else:
f.open(QFile.ReadOnly | QFile.Text)
ts = QTextStream(f)
stylesheet = ts.readAll()
if platform.system().lower() == 'darwin': # see issue #12 on github
mac_fix = '''
QDockWidget::title
{
background-color: #31363b;
text-align: center;
height: 12px;
}
'''
stylesheet += mac_fix
return stylesheet | python | def load_stylesheet(pyside=True):
# Smart import of the rc file
if pyside:
import qdarkstyle.pyside_style_rc
else:
import qdarkstyle.pyqt_style_rc
# Load the stylesheet content from resources
if not pyside:
from PyQt4.QtCore import QFile, QTextStream
else:
from PySide.QtCore import QFile, QTextStream
f = QFile(":qdarkstyle/style.qss")
if not f.exists():
_logger().error("Unable to load stylesheet, file not found in "
"resources")
return ""
else:
f.open(QFile.ReadOnly | QFile.Text)
ts = QTextStream(f)
stylesheet = ts.readAll()
if platform.system().lower() == 'darwin': # see issue #12 on github
mac_fix = '''
QDockWidget::title
{
background-color: #31363b;
text-align: center;
height: 12px;
}
'''
stylesheet += mac_fix
return stylesheet | [
"def",
"load_stylesheet",
"(",
"pyside",
"=",
"True",
")",
":",
"# Smart import of the rc file",
"if",
"pyside",
":",
"import",
"qdarkstyle",
".",
"pyside_style_rc",
"else",
":",
"import",
"qdarkstyle",
".",
"pyqt_style_rc",
"# Load the stylesheet content from resources",
"if",
"not",
"pyside",
":",
"from",
"PyQt4",
".",
"QtCore",
"import",
"QFile",
",",
"QTextStream",
"else",
":",
"from",
"PySide",
".",
"QtCore",
"import",
"QFile",
",",
"QTextStream",
"f",
"=",
"QFile",
"(",
"\":qdarkstyle/style.qss\"",
")",
"if",
"not",
"f",
".",
"exists",
"(",
")",
":",
"_logger",
"(",
")",
".",
"error",
"(",
"\"Unable to load stylesheet, file not found in \"",
"\"resources\"",
")",
"return",
"\"\"",
"else",
":",
"f",
".",
"open",
"(",
"QFile",
".",
"ReadOnly",
"|",
"QFile",
".",
"Text",
")",
"ts",
"=",
"QTextStream",
"(",
"f",
")",
"stylesheet",
"=",
"ts",
".",
"readAll",
"(",
")",
"if",
"platform",
".",
"system",
"(",
")",
".",
"lower",
"(",
")",
"==",
"'darwin'",
":",
"# see issue #12 on github",
"mac_fix",
"=",
"'''\n QDockWidget::title\n {\n background-color: #31363b;\n text-align: center;\n height: 12px;\n }\n '''",
"stylesheet",
"+=",
"mac_fix",
"return",
"stylesheet"
] | Loads the stylesheet. Takes care of importing the rc module.
:param pyside: True to load the pyside rc file, False to load the PyQt rc file
:return the stylesheet string | [
"Loads",
"the",
"stylesheet",
".",
"Takes",
"care",
"of",
"importing",
"the",
"rc",
"module",
"."
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/tools/colorTuner_py/QDarkStyleSheet/qdarkstyle/__init__.py#L42-L81 |
249,287 | JdeRobot/base | src/tools/colorTuner_py/QDarkStyleSheet/qdarkstyle/__init__.py | load_stylesheet_pyqt5 | def load_stylesheet_pyqt5():
"""
Loads the stylesheet for use in a pyqt5 application.
:param pyside: True to load the pyside rc file, False to load the PyQt rc file
:return the stylesheet string
"""
# Smart import of the rc file
import qdarkstyle.pyqt5_style_rc
# Load the stylesheet content from resources
from PyQt5.QtCore import QFile, QTextStream
f = QFile(":qdarkstyle/style.qss")
if not f.exists():
_logger().error("Unable to load stylesheet, file not found in "
"resources")
return ""
else:
f.open(QFile.ReadOnly | QFile.Text)
ts = QTextStream(f)
stylesheet = ts.readAll()
if platform.system().lower() == 'darwin': # see issue #12 on github
mac_fix = '''
QDockWidget::title
{
background-color: #31363b;
text-align: center;
height: 12px;
}
'''
stylesheet += mac_fix
return stylesheet | python | def load_stylesheet_pyqt5():
# Smart import of the rc file
import qdarkstyle.pyqt5_style_rc
# Load the stylesheet content from resources
from PyQt5.QtCore import QFile, QTextStream
f = QFile(":qdarkstyle/style.qss")
if not f.exists():
_logger().error("Unable to load stylesheet, file not found in "
"resources")
return ""
else:
f.open(QFile.ReadOnly | QFile.Text)
ts = QTextStream(f)
stylesheet = ts.readAll()
if platform.system().lower() == 'darwin': # see issue #12 on github
mac_fix = '''
QDockWidget::title
{
background-color: #31363b;
text-align: center;
height: 12px;
}
'''
stylesheet += mac_fix
return stylesheet | [
"def",
"load_stylesheet_pyqt5",
"(",
")",
":",
"# Smart import of the rc file",
"import",
"qdarkstyle",
".",
"pyqt5_style_rc",
"# Load the stylesheet content from resources",
"from",
"PyQt5",
".",
"QtCore",
"import",
"QFile",
",",
"QTextStream",
"f",
"=",
"QFile",
"(",
"\":qdarkstyle/style.qss\"",
")",
"if",
"not",
"f",
".",
"exists",
"(",
")",
":",
"_logger",
"(",
")",
".",
"error",
"(",
"\"Unable to load stylesheet, file not found in \"",
"\"resources\"",
")",
"return",
"\"\"",
"else",
":",
"f",
".",
"open",
"(",
"QFile",
".",
"ReadOnly",
"|",
"QFile",
".",
"Text",
")",
"ts",
"=",
"QTextStream",
"(",
"f",
")",
"stylesheet",
"=",
"ts",
".",
"readAll",
"(",
")",
"if",
"platform",
".",
"system",
"(",
")",
".",
"lower",
"(",
")",
"==",
"'darwin'",
":",
"# see issue #12 on github",
"mac_fix",
"=",
"'''\n QDockWidget::title\n {\n background-color: #31363b;\n text-align: center;\n height: 12px;\n }\n '''",
"stylesheet",
"+=",
"mac_fix",
"return",
"stylesheet"
] | Loads the stylesheet for use in a pyqt5 application.
:param pyside: True to load the pyside rc file, False to load the PyQt rc file
:return the stylesheet string | [
"Loads",
"the",
"stylesheet",
"for",
"use",
"in",
"a",
"pyqt5",
"application",
"."
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/tools/colorTuner_py/QDarkStyleSheet/qdarkstyle/__init__.py#L84-L117 |
249,288 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_menu.py | MPMenuItem.call_handler | def call_handler(self):
'''optionally call a handler function'''
if self.handler is None:
return
call = getattr(self.handler, 'call', None)
if call is not None:
self.handler_result = call() | python | def call_handler(self):
'''optionally call a handler function'''
if self.handler is None:
return
call = getattr(self.handler, 'call', None)
if call is not None:
self.handler_result = call() | [
"def",
"call_handler",
"(",
"self",
")",
":",
"if",
"self",
".",
"handler",
"is",
"None",
":",
"return",
"call",
"=",
"getattr",
"(",
"self",
".",
"handler",
",",
"'call'",
",",
"None",
")",
"if",
"call",
"is",
"not",
"None",
":",
"self",
".",
"handler_result",
"=",
"call",
"(",
")"
] | optionally call a handler function | [
"optionally",
"call",
"a",
"handler",
"function"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_menu.py#L58-L64 |
249,289 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_menu.py | MPMenuTop.add | def add(self, items):
'''add a submenu'''
if not isinstance(items, list):
items = [items]
for m in items:
updated = False
for i in range(len(self.items)):
if self.items[i].name == m.name:
self.items[i] = m
updated = True
if not updated:
self.items.append(m) | python | def add(self, items):
'''add a submenu'''
if not isinstance(items, list):
items = [items]
for m in items:
updated = False
for i in range(len(self.items)):
if self.items[i].name == m.name:
self.items[i] = m
updated = True
if not updated:
self.items.append(m) | [
"def",
"add",
"(",
"self",
",",
"items",
")",
":",
"if",
"not",
"isinstance",
"(",
"items",
",",
"list",
")",
":",
"items",
"=",
"[",
"items",
"]",
"for",
"m",
"in",
"items",
":",
"updated",
"=",
"False",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"items",
")",
")",
":",
"if",
"self",
".",
"items",
"[",
"i",
"]",
".",
"name",
"==",
"m",
".",
"name",
":",
"self",
".",
"items",
"[",
"i",
"]",
"=",
"m",
"updated",
"=",
"True",
"if",
"not",
"updated",
":",
"self",
".",
"items",
".",
"append",
"(",
"m",
")"
] | add a submenu | [
"add",
"a",
"submenu"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_menu.py#L216-L227 |
249,290 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_menu.py | MPMenuChildMessageDialog.call | def call(self):
'''show the dialog as a child process'''
mp_util.child_close_fds()
import wx_processguard
from wx_loader import wx
from wx.lib.agw.genericmessagedialog import GenericMessageDialog
app = wx.App(False)
# note! font size change is not working. I don't know why yet
font = wx.Font(self.font_size, wx.MODERN, wx.NORMAL, wx.NORMAL)
dlg = GenericMessageDialog(None, self.message, self.title, wx.ICON_INFORMATION|wx.OK)
dlg.SetFont(font)
dlg.ShowModal()
app.MainLoop() | python | def call(self):
'''show the dialog as a child process'''
mp_util.child_close_fds()
import wx_processguard
from wx_loader import wx
from wx.lib.agw.genericmessagedialog import GenericMessageDialog
app = wx.App(False)
# note! font size change is not working. I don't know why yet
font = wx.Font(self.font_size, wx.MODERN, wx.NORMAL, wx.NORMAL)
dlg = GenericMessageDialog(None, self.message, self.title, wx.ICON_INFORMATION|wx.OK)
dlg.SetFont(font)
dlg.ShowModal()
app.MainLoop() | [
"def",
"call",
"(",
"self",
")",
":",
"mp_util",
".",
"child_close_fds",
"(",
")",
"import",
"wx_processguard",
"from",
"wx_loader",
"import",
"wx",
"from",
"wx",
".",
"lib",
".",
"agw",
".",
"genericmessagedialog",
"import",
"GenericMessageDialog",
"app",
"=",
"wx",
".",
"App",
"(",
"False",
")",
"# note! font size change is not working. I don't know why yet",
"font",
"=",
"wx",
".",
"Font",
"(",
"self",
".",
"font_size",
",",
"wx",
".",
"MODERN",
",",
"wx",
".",
"NORMAL",
",",
"wx",
".",
"NORMAL",
")",
"dlg",
"=",
"GenericMessageDialog",
"(",
"None",
",",
"self",
".",
"message",
",",
"self",
".",
"title",
",",
"wx",
".",
"ICON_INFORMATION",
"|",
"wx",
".",
"OK",
")",
"dlg",
".",
"SetFont",
"(",
"font",
")",
"dlg",
".",
"ShowModal",
"(",
")",
"app",
".",
"MainLoop",
"(",
")"
] | show the dialog as a child process | [
"show",
"the",
"dialog",
"as",
"a",
"child",
"process"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_menu.py#L299-L311 |
249,291 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/GAreader.py | ERMap.read_ermapper | def read_ermapper(self, ifile):
'''Read in a DEM file and associated .ers file'''
ers_index = ifile.find('.ers')
if ers_index > 0:
data_file = ifile[0:ers_index]
header_file = ifile
else:
data_file = ifile
header_file = ifile + '.ers'
self.header = self.read_ermapper_header(header_file)
nroflines = int(self.header['nroflines'])
nrofcellsperlines = int(self.header['nrofcellsperline'])
self.data = self.read_ermapper_data(data_file, offset=int(self.header['headeroffset']))
self.data = numpy.reshape(self.data,(nroflines,nrofcellsperlines))
longy = numpy.fromstring(self.getHeaderParam('longitude'), sep=':')
latty = numpy.fromstring(self.getHeaderParam('latitude'), sep=':')
self.deltalatitude = float(self.header['ydimension'])
self.deltalongitude = float(self.header['xdimension'])
if longy[0] < 0:
self.startlongitude = longy[0]+-((longy[1]/60)+(longy[2]/3600))
self.endlongitude = self.startlongitude - int(self.header['nrofcellsperline'])*self.deltalongitude
else:
self.startlongitude = longy[0]+(longy[1]/60)+(longy[2]/3600)
self.endlongitude = self.startlongitude + int(self.header['nrofcellsperline'])*self.deltalongitude
if latty[0] < 0:
self.startlatitude = latty[0]-((latty[1]/60)+(latty[2]/3600))
self.endlatitude = self.startlatitude - int(self.header['nroflines'])*self.deltalatitude
else:
self.startlatitude = latty[0]+(latty[1]/60)+(latty[2]/3600)
self.endlatitude = self.startlatitude + int(self.header['nroflines'])*self.deltalatitude | python | def read_ermapper(self, ifile):
'''Read in a DEM file and associated .ers file'''
ers_index = ifile.find('.ers')
if ers_index > 0:
data_file = ifile[0:ers_index]
header_file = ifile
else:
data_file = ifile
header_file = ifile + '.ers'
self.header = self.read_ermapper_header(header_file)
nroflines = int(self.header['nroflines'])
nrofcellsperlines = int(self.header['nrofcellsperline'])
self.data = self.read_ermapper_data(data_file, offset=int(self.header['headeroffset']))
self.data = numpy.reshape(self.data,(nroflines,nrofcellsperlines))
longy = numpy.fromstring(self.getHeaderParam('longitude'), sep=':')
latty = numpy.fromstring(self.getHeaderParam('latitude'), sep=':')
self.deltalatitude = float(self.header['ydimension'])
self.deltalongitude = float(self.header['xdimension'])
if longy[0] < 0:
self.startlongitude = longy[0]+-((longy[1]/60)+(longy[2]/3600))
self.endlongitude = self.startlongitude - int(self.header['nrofcellsperline'])*self.deltalongitude
else:
self.startlongitude = longy[0]+(longy[1]/60)+(longy[2]/3600)
self.endlongitude = self.startlongitude + int(self.header['nrofcellsperline'])*self.deltalongitude
if latty[0] < 0:
self.startlatitude = latty[0]-((latty[1]/60)+(latty[2]/3600))
self.endlatitude = self.startlatitude - int(self.header['nroflines'])*self.deltalatitude
else:
self.startlatitude = latty[0]+(latty[1]/60)+(latty[2]/3600)
self.endlatitude = self.startlatitude + int(self.header['nroflines'])*self.deltalatitude | [
"def",
"read_ermapper",
"(",
"self",
",",
"ifile",
")",
":",
"ers_index",
"=",
"ifile",
".",
"find",
"(",
"'.ers'",
")",
"if",
"ers_index",
">",
"0",
":",
"data_file",
"=",
"ifile",
"[",
"0",
":",
"ers_index",
"]",
"header_file",
"=",
"ifile",
"else",
":",
"data_file",
"=",
"ifile",
"header_file",
"=",
"ifile",
"+",
"'.ers'",
"self",
".",
"header",
"=",
"self",
".",
"read_ermapper_header",
"(",
"header_file",
")",
"nroflines",
"=",
"int",
"(",
"self",
".",
"header",
"[",
"'nroflines'",
"]",
")",
"nrofcellsperlines",
"=",
"int",
"(",
"self",
".",
"header",
"[",
"'nrofcellsperline'",
"]",
")",
"self",
".",
"data",
"=",
"self",
".",
"read_ermapper_data",
"(",
"data_file",
",",
"offset",
"=",
"int",
"(",
"self",
".",
"header",
"[",
"'headeroffset'",
"]",
")",
")",
"self",
".",
"data",
"=",
"numpy",
".",
"reshape",
"(",
"self",
".",
"data",
",",
"(",
"nroflines",
",",
"nrofcellsperlines",
")",
")",
"longy",
"=",
"numpy",
".",
"fromstring",
"(",
"self",
".",
"getHeaderParam",
"(",
"'longitude'",
")",
",",
"sep",
"=",
"':'",
")",
"latty",
"=",
"numpy",
".",
"fromstring",
"(",
"self",
".",
"getHeaderParam",
"(",
"'latitude'",
")",
",",
"sep",
"=",
"':'",
")",
"self",
".",
"deltalatitude",
"=",
"float",
"(",
"self",
".",
"header",
"[",
"'ydimension'",
"]",
")",
"self",
".",
"deltalongitude",
"=",
"float",
"(",
"self",
".",
"header",
"[",
"'xdimension'",
"]",
")",
"if",
"longy",
"[",
"0",
"]",
"<",
"0",
":",
"self",
".",
"startlongitude",
"=",
"longy",
"[",
"0",
"]",
"+",
"-",
"(",
"(",
"longy",
"[",
"1",
"]",
"/",
"60",
")",
"+",
"(",
"longy",
"[",
"2",
"]",
"/",
"3600",
")",
")",
"self",
".",
"endlongitude",
"=",
"self",
".",
"startlongitude",
"-",
"int",
"(",
"self",
".",
"header",
"[",
"'nrofcellsperline'",
"]",
")",
"*",
"self",
".",
"deltalongitude",
"else",
":",
"self",
".",
"startlongitude",
"=",
"longy",
"[",
"0",
"]",
"+",
"(",
"longy",
"[",
"1",
"]",
"/",
"60",
")",
"+",
"(",
"longy",
"[",
"2",
"]",
"/",
"3600",
")",
"self",
".",
"endlongitude",
"=",
"self",
".",
"startlongitude",
"+",
"int",
"(",
"self",
".",
"header",
"[",
"'nrofcellsperline'",
"]",
")",
"*",
"self",
".",
"deltalongitude",
"if",
"latty",
"[",
"0",
"]",
"<",
"0",
":",
"self",
".",
"startlatitude",
"=",
"latty",
"[",
"0",
"]",
"-",
"(",
"(",
"latty",
"[",
"1",
"]",
"/",
"60",
")",
"+",
"(",
"latty",
"[",
"2",
"]",
"/",
"3600",
")",
")",
"self",
".",
"endlatitude",
"=",
"self",
".",
"startlatitude",
"-",
"int",
"(",
"self",
".",
"header",
"[",
"'nroflines'",
"]",
")",
"*",
"self",
".",
"deltalatitude",
"else",
":",
"self",
".",
"startlatitude",
"=",
"latty",
"[",
"0",
"]",
"+",
"(",
"latty",
"[",
"1",
"]",
"/",
"60",
")",
"+",
"(",
"latty",
"[",
"2",
"]",
"/",
"3600",
")",
"self",
".",
"endlatitude",
"=",
"self",
".",
"startlatitude",
"+",
"int",
"(",
"self",
".",
"header",
"[",
"'nroflines'",
"]",
")",
"*",
"self",
".",
"deltalatitude"
] | Read in a DEM file and associated .ers file | [
"Read",
"in",
"a",
"DEM",
"file",
"and",
"associated",
".",
"ers",
"file"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/GAreader.py#L25-L59 |
249,292 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/GAreader.py | ERMap.printBoundingBox | def printBoundingBox(self):
'''Print the bounding box that this DEM covers'''
print ("Bounding Latitude: ")
print (self.startlatitude)
print (self.endlatitude)
print ("Bounding Longitude: ")
print (self.startlongitude)
print (self.endlongitude) | python | def printBoundingBox(self):
'''Print the bounding box that this DEM covers'''
print ("Bounding Latitude: ")
print (self.startlatitude)
print (self.endlatitude)
print ("Bounding Longitude: ")
print (self.startlongitude)
print (self.endlongitude) | [
"def",
"printBoundingBox",
"(",
"self",
")",
":",
"print",
"(",
"\"Bounding Latitude: \"",
")",
"print",
"(",
"self",
".",
"startlatitude",
")",
"print",
"(",
"self",
".",
"endlatitude",
")",
"print",
"(",
"\"Bounding Longitude: \"",
")",
"print",
"(",
"self",
".",
"startlongitude",
")",
"print",
"(",
"self",
".",
"endlongitude",
")"
] | Print the bounding box that this DEM covers | [
"Print",
"the",
"bounding",
"box",
"that",
"this",
"DEM",
"covers"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/GAreader.py#L92-L100 |
249,293 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/GAreader.py | ERMap.getPercentBlank | def getPercentBlank(self):
'''Print how many null cells are in the DEM - Quality measure'''
blank = 0
nonblank = 0
for x in self.data.flat:
if x == -99999.0:
blank = blank + 1
else:
nonblank = nonblank + 1
print ("Blank tiles = ", blank, "out of ", (nonblank+blank)) | python | def getPercentBlank(self):
'''Print how many null cells are in the DEM - Quality measure'''
blank = 0
nonblank = 0
for x in self.data.flat:
if x == -99999.0:
blank = blank + 1
else:
nonblank = nonblank + 1
print ("Blank tiles = ", blank, "out of ", (nonblank+blank)) | [
"def",
"getPercentBlank",
"(",
"self",
")",
":",
"blank",
"=",
"0",
"nonblank",
"=",
"0",
"for",
"x",
"in",
"self",
".",
"data",
".",
"flat",
":",
"if",
"x",
"==",
"-",
"99999.0",
":",
"blank",
"=",
"blank",
"+",
"1",
"else",
":",
"nonblank",
"=",
"nonblank",
"+",
"1",
"print",
"(",
"\"Blank tiles = \"",
",",
"blank",
",",
"\"out of \"",
",",
"(",
"nonblank",
"+",
"blank",
")",
")"
] | Print how many null cells are in the DEM - Quality measure | [
"Print",
"how",
"many",
"null",
"cells",
"are",
"in",
"the",
"DEM",
"-",
"Quality",
"measure"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_map/GAreader.py#L102-L112 |
249,294 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_rc.py | RCModule.send_rc_override | def send_rc_override(self):
'''send RC override packet'''
if self.sitl_output:
buf = struct.pack('<HHHHHHHH',
*self.override)
self.sitl_output.write(buf)
else:
self.master.mav.rc_channels_override_send(self.target_system,
self.target_component,
*self.override) | python | def send_rc_override(self):
'''send RC override packet'''
if self.sitl_output:
buf = struct.pack('<HHHHHHHH',
*self.override)
self.sitl_output.write(buf)
else:
self.master.mav.rc_channels_override_send(self.target_system,
self.target_component,
*self.override) | [
"def",
"send_rc_override",
"(",
"self",
")",
":",
"if",
"self",
".",
"sitl_output",
":",
"buf",
"=",
"struct",
".",
"pack",
"(",
"'<HHHHHHHH'",
",",
"*",
"self",
".",
"override",
")",
"self",
".",
"sitl_output",
".",
"write",
"(",
"buf",
")",
"else",
":",
"self",
".",
"master",
".",
"mav",
".",
"rc_channels_override_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"*",
"self",
".",
"override",
")"
] | send RC override packet | [
"send",
"RC",
"override",
"packet"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_rc.py#L31-L40 |
249,295 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_rc.py | RCModule.cmd_switch | def cmd_switch(self, args):
'''handle RC switch changes'''
mapping = [ 0, 1165, 1295, 1425, 1555, 1685, 1815 ]
if len(args) != 1:
print("Usage: switch <pwmvalue>")
return
value = int(args[0])
if value < 0 or value > 6:
print("Invalid switch value. Use 1-6 for flight modes, '0' to disable")
return
if self.vehicle_type == 'copter':
default_channel = 5
else:
default_channel = 8
if self.vehicle_type == 'rover':
flite_mode_ch_parm = int(self.get_mav_param("MODE_CH", default_channel))
else:
flite_mode_ch_parm = int(self.get_mav_param("FLTMODE_CH", default_channel))
self.override[flite_mode_ch_parm - 1] = mapping[value]
self.override_counter = 10
self.send_rc_override()
if value == 0:
print("Disabled RC switch override")
else:
print("Set RC switch override to %u (PWM=%u channel=%u)" % (
value, mapping[value], flite_mode_ch_parm)) | python | def cmd_switch(self, args):
'''handle RC switch changes'''
mapping = [ 0, 1165, 1295, 1425, 1555, 1685, 1815 ]
if len(args) != 1:
print("Usage: switch <pwmvalue>")
return
value = int(args[0])
if value < 0 or value > 6:
print("Invalid switch value. Use 1-6 for flight modes, '0' to disable")
return
if self.vehicle_type == 'copter':
default_channel = 5
else:
default_channel = 8
if self.vehicle_type == 'rover':
flite_mode_ch_parm = int(self.get_mav_param("MODE_CH", default_channel))
else:
flite_mode_ch_parm = int(self.get_mav_param("FLTMODE_CH", default_channel))
self.override[flite_mode_ch_parm - 1] = mapping[value]
self.override_counter = 10
self.send_rc_override()
if value == 0:
print("Disabled RC switch override")
else:
print("Set RC switch override to %u (PWM=%u channel=%u)" % (
value, mapping[value], flite_mode_ch_parm)) | [
"def",
"cmd_switch",
"(",
"self",
",",
"args",
")",
":",
"mapping",
"=",
"[",
"0",
",",
"1165",
",",
"1295",
",",
"1425",
",",
"1555",
",",
"1685",
",",
"1815",
"]",
"if",
"len",
"(",
"args",
")",
"!=",
"1",
":",
"print",
"(",
"\"Usage: switch <pwmvalue>\"",
")",
"return",
"value",
"=",
"int",
"(",
"args",
"[",
"0",
"]",
")",
"if",
"value",
"<",
"0",
"or",
"value",
">",
"6",
":",
"print",
"(",
"\"Invalid switch value. Use 1-6 for flight modes, '0' to disable\"",
")",
"return",
"if",
"self",
".",
"vehicle_type",
"==",
"'copter'",
":",
"default_channel",
"=",
"5",
"else",
":",
"default_channel",
"=",
"8",
"if",
"self",
".",
"vehicle_type",
"==",
"'rover'",
":",
"flite_mode_ch_parm",
"=",
"int",
"(",
"self",
".",
"get_mav_param",
"(",
"\"MODE_CH\"",
",",
"default_channel",
")",
")",
"else",
":",
"flite_mode_ch_parm",
"=",
"int",
"(",
"self",
".",
"get_mav_param",
"(",
"\"FLTMODE_CH\"",
",",
"default_channel",
")",
")",
"self",
".",
"override",
"[",
"flite_mode_ch_parm",
"-",
"1",
"]",
"=",
"mapping",
"[",
"value",
"]",
"self",
".",
"override_counter",
"=",
"10",
"self",
".",
"send_rc_override",
"(",
")",
"if",
"value",
"==",
"0",
":",
"print",
"(",
"\"Disabled RC switch override\"",
")",
"else",
":",
"print",
"(",
"\"Set RC switch override to %u (PWM=%u channel=%u)\"",
"%",
"(",
"value",
",",
"mapping",
"[",
"value",
"]",
",",
"flite_mode_ch_parm",
")",
")"
] | handle RC switch changes | [
"handle",
"RC",
"switch",
"changes"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/mavproxy_rc.py#L42-L67 |
249,296 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/ANUGA/geo_reference.py | write_NetCDF_georeference | def write_NetCDF_georeference(origin, outfile):
"""Write georeference info to a netcdf file, usually sww.
The origin can be a georef instance or parameters for a geo_ref instance
outfile is the name of the file to be written to.
"""
geo_ref = ensure_geo_reference(origin)
geo_ref.write_NetCDF(outfile)
return geo_ref | python | def write_NetCDF_georeference(origin, outfile):
geo_ref = ensure_geo_reference(origin)
geo_ref.write_NetCDF(outfile)
return geo_ref | [
"def",
"write_NetCDF_georeference",
"(",
"origin",
",",
"outfile",
")",
":",
"geo_ref",
"=",
"ensure_geo_reference",
"(",
"origin",
")",
"geo_ref",
".",
"write_NetCDF",
"(",
"outfile",
")",
"return",
"geo_ref"
] | Write georeference info to a netcdf file, usually sww.
The origin can be a georef instance or parameters for a geo_ref instance
outfile is the name of the file to be written to. | [
"Write",
"georeference",
"info",
"to",
"a",
"netcdf",
"file",
"usually",
"sww",
"."
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/ANUGA/geo_reference.py#L430-L440 |
249,297 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/ANUGA/geo_reference.py | Geo_reference.is_absolute | def is_absolute(self):
"""Return True if xllcorner==yllcorner==0 indicating that points
in question are absolute.
"""
# FIXME(Ole): It is unfortunate that decision about whether points
# are absolute or not lies with the georeference object. Ross pointed this out.
# Moreover, this little function is responsible for a large fraction of the time
# using in data fitting (something in like 40 - 50%.
# This was due to the repeated calls to allclose.
# With the flag method fitting is much faster (18 Mar 2009).
# FIXME(Ole): HACK to be able to reuse data already cached (18 Mar 2009).
# Remove at some point
if not hasattr(self, 'absolute'):
self.absolute = num.allclose([self.xllcorner, self.yllcorner], 0)
# Return absolute flag
return self.absolute | python | def is_absolute(self):
# FIXME(Ole): It is unfortunate that decision about whether points
# are absolute or not lies with the georeference object. Ross pointed this out.
# Moreover, this little function is responsible for a large fraction of the time
# using in data fitting (something in like 40 - 50%.
# This was due to the repeated calls to allclose.
# With the flag method fitting is much faster (18 Mar 2009).
# FIXME(Ole): HACK to be able to reuse data already cached (18 Mar 2009).
# Remove at some point
if not hasattr(self, 'absolute'):
self.absolute = num.allclose([self.xllcorner, self.yllcorner], 0)
# Return absolute flag
return self.absolute | [
"def",
"is_absolute",
"(",
"self",
")",
":",
"# FIXME(Ole): It is unfortunate that decision about whether points",
"# are absolute or not lies with the georeference object. Ross pointed this out.",
"# Moreover, this little function is responsible for a large fraction of the time",
"# using in data fitting (something in like 40 - 50%.",
"# This was due to the repeated calls to allclose.",
"# With the flag method fitting is much faster (18 Mar 2009).",
"# FIXME(Ole): HACK to be able to reuse data already cached (18 Mar 2009).",
"# Remove at some point",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'absolute'",
")",
":",
"self",
".",
"absolute",
"=",
"num",
".",
"allclose",
"(",
"[",
"self",
".",
"xllcorner",
",",
"self",
".",
"yllcorner",
"]",
",",
"0",
")",
"# Return absolute flag",
"return",
"self",
".",
"absolute"
] | Return True if xllcorner==yllcorner==0 indicating that points
in question are absolute. | [
"Return",
"True",
"if",
"xllcorner",
"==",
"yllcorner",
"==",
"0",
"indicating",
"that",
"points",
"in",
"question",
"are",
"absolute",
"."
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/ANUGA/geo_reference.py#L275-L293 |
249,298 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_util.py | mkdir_p | def mkdir_p(dir):
'''like mkdir -p'''
if not dir:
return
if dir.endswith("/") or dir.endswith("\\"):
mkdir_p(dir[:-1])
return
if os.path.isdir(dir):
return
mkdir_p(os.path.dirname(dir))
try:
os.mkdir(dir)
except Exception:
pass | python | def mkdir_p(dir):
'''like mkdir -p'''
if not dir:
return
if dir.endswith("/") or dir.endswith("\\"):
mkdir_p(dir[:-1])
return
if os.path.isdir(dir):
return
mkdir_p(os.path.dirname(dir))
try:
os.mkdir(dir)
except Exception:
pass | [
"def",
"mkdir_p",
"(",
"dir",
")",
":",
"if",
"not",
"dir",
":",
"return",
"if",
"dir",
".",
"endswith",
"(",
"\"/\"",
")",
"or",
"dir",
".",
"endswith",
"(",
"\"\\\\\"",
")",
":",
"mkdir_p",
"(",
"dir",
"[",
":",
"-",
"1",
"]",
")",
"return",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"dir",
")",
":",
"return",
"mkdir_p",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"dir",
")",
")",
"try",
":",
"os",
".",
"mkdir",
"(",
"dir",
")",
"except",
"Exception",
":",
"pass"
] | like mkdir -p | [
"like",
"mkdir",
"-",
"p"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_util.py#L88-L101 |
249,299 | JdeRobot/base | src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_util.py | polygon_load | def polygon_load(filename):
'''load a polygon from a file'''
ret = []
f = open(filename)
for line in f:
if line.startswith('#'):
continue
line = line.strip()
if not line:
continue
a = line.split()
if len(a) != 2:
raise RuntimeError("invalid polygon line: %s" % line)
ret.append((float(a[0]), float(a[1])))
f.close()
return ret | python | def polygon_load(filename):
'''load a polygon from a file'''
ret = []
f = open(filename)
for line in f:
if line.startswith('#'):
continue
line = line.strip()
if not line:
continue
a = line.split()
if len(a) != 2:
raise RuntimeError("invalid polygon line: %s" % line)
ret.append((float(a[0]), float(a[1])))
f.close()
return ret | [
"def",
"polygon_load",
"(",
"filename",
")",
":",
"ret",
"=",
"[",
"]",
"f",
"=",
"open",
"(",
"filename",
")",
"for",
"line",
"in",
"f",
":",
"if",
"line",
".",
"startswith",
"(",
"'#'",
")",
":",
"continue",
"line",
"=",
"line",
".",
"strip",
"(",
")",
"if",
"not",
"line",
":",
"continue",
"a",
"=",
"line",
".",
"split",
"(",
")",
"if",
"len",
"(",
"a",
")",
"!=",
"2",
":",
"raise",
"RuntimeError",
"(",
"\"invalid polygon line: %s\"",
"%",
"line",
")",
"ret",
".",
"append",
"(",
"(",
"float",
"(",
"a",
"[",
"0",
"]",
")",
",",
"float",
"(",
"a",
"[",
"1",
"]",
")",
")",
")",
"f",
".",
"close",
"(",
")",
"return",
"ret"
] | load a polygon from a file | [
"load",
"a",
"polygon",
"from",
"a",
"file"
] | 303b18992785b2fe802212f2d758a60873007f1f | https://github.com/JdeRobot/base/blob/303b18992785b2fe802212f2d758a60873007f1f/src/drivers/MAVLinkServer/MAVProxy/modules/lib/mp_util.py#L103-L118 |
Subsets and Splits