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,500 | ArduPilot/MAVProxy | MAVProxy/modules/lib/wxhorizon_ui.py | HorizonFrame.on_idle | def on_idle(self, event):
'''To adjust text and positions on rescaling the window when resized.'''
# Check for resize
self.checkReszie()
if self.resized:
# Fix Window Scales
self.rescaleX()
self.calcFontScaling()
# Recalculate Horizon Polygons
self.calcHorizonPoints()
# Update Roll, Pitch, Yaw Text Locations
self.updateRPYLocations()
# Update Airpseed, Altitude, Climb Rate Locations
self.updateAARLocations()
# Update Pitch Markers
self.adjustPitchmarkers()
# Update Heading and North Pointer
self.adjustHeadingPointer()
self.adjustNorthPointer()
# Update Battery Bar
self.updateBatteryBar()
# Update Mode and State
self.updateStateText()
# Update Waypoint Text
self.updateWPText()
# Adjust Waypoint Pointer
self.adjustWPPointer()
# Update History Plot
self.updateAltHistory()
# Update Matplotlib Plot
self.canvas.draw()
self.canvas.Refresh()
self.resized = False
time.sleep(0.05) | python | def on_idle(self, event):
'''To adjust text and positions on rescaling the window when resized.'''
# Check for resize
self.checkReszie()
if self.resized:
# Fix Window Scales
self.rescaleX()
self.calcFontScaling()
# Recalculate Horizon Polygons
self.calcHorizonPoints()
# Update Roll, Pitch, Yaw Text Locations
self.updateRPYLocations()
# Update Airpseed, Altitude, Climb Rate Locations
self.updateAARLocations()
# Update Pitch Markers
self.adjustPitchmarkers()
# Update Heading and North Pointer
self.adjustHeadingPointer()
self.adjustNorthPointer()
# Update Battery Bar
self.updateBatteryBar()
# Update Mode and State
self.updateStateText()
# Update Waypoint Text
self.updateWPText()
# Adjust Waypoint Pointer
self.adjustWPPointer()
# Update History Plot
self.updateAltHistory()
# Update Matplotlib Plot
self.canvas.draw()
self.canvas.Refresh()
self.resized = False
time.sleep(0.05) | [
"def",
"on_idle",
"(",
"self",
",",
"event",
")",
":",
"# Check for resize",
"self",
".",
"checkReszie",
"(",
")",
"if",
"self",
".",
"resized",
":",
"# Fix Window Scales ",
"self",
".",
"rescaleX",
"(",
")",
"self",
".",
"calcFontScaling",
"(",
")",
"# Recalculate Horizon Polygons",
"self",
".",
"calcHorizonPoints",
"(",
")",
"# Update Roll, Pitch, Yaw Text Locations",
"self",
".",
"updateRPYLocations",
"(",
")",
"# Update Airpseed, Altitude, Climb Rate Locations",
"self",
".",
"updateAARLocations",
"(",
")",
"# Update Pitch Markers",
"self",
".",
"adjustPitchmarkers",
"(",
")",
"# Update Heading and North Pointer",
"self",
".",
"adjustHeadingPointer",
"(",
")",
"self",
".",
"adjustNorthPointer",
"(",
")",
"# Update Battery Bar",
"self",
".",
"updateBatteryBar",
"(",
")",
"# Update Mode and State",
"self",
".",
"updateStateText",
"(",
")",
"# Update Waypoint Text",
"self",
".",
"updateWPText",
"(",
")",
"# Adjust Waypoint Pointer",
"self",
".",
"adjustWPPointer",
"(",
")",
"# Update History Plot",
"self",
".",
"updateAltHistory",
"(",
")",
"# Update Matplotlib Plot",
"self",
".",
"canvas",
".",
"draw",
"(",
")",
"self",
".",
"canvas",
".",
"Refresh",
"(",
")",
"self",
".",
"resized",
"=",
"False",
"time",
".",
"sleep",
"(",
"0.05",
")"
] | To adjust text and positions on rescaling the window when resized. | [
"To",
"adjust",
"text",
"and",
"positions",
"on",
"rescaling",
"the",
"window",
"when",
"resized",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/wxhorizon_ui.py#L520-L567 |
249,501 | ArduPilot/MAVProxy | MAVProxy/modules/lib/wxhorizon_ui.py | HorizonFrame.on_timer | def on_timer(self, event):
'''Main Loop.'''
state = self.state
self.loopStartTime = time.time()
if state.close_event.wait(0.001):
self.timer.Stop()
self.Destroy()
return
# Check for resizing
self.checkReszie()
if self.resized:
self.on_idle(0)
# Get attitude information
while state.child_pipe_recv.poll():
objList = state.child_pipe_recv.recv()
for obj in objList:
self.calcFontScaling()
if isinstance(obj,Attitude):
self.oldRoll = self.roll
self.pitch = obj.pitch*180/math.pi
self.roll = obj.roll*180/math.pi
self.yaw = obj.yaw*180/math.pi
# Update Roll, Pitch, Yaw Text Text
self.updateRPYText()
# Recalculate Horizon Polygons
self.calcHorizonPoints()
# Update Pitch Markers
self.adjustPitchmarkers()
elif isinstance(obj,VFR_HUD):
self.heading = obj.heading
self.airspeed = obj.airspeed
self.climbRate = obj.climbRate
# Update Airpseed, Altitude, Climb Rate Locations
self.updateAARText()
# Update Heading North Pointer
self.adjustHeadingPointer()
self.adjustNorthPointer()
elif isinstance(obj,Global_Position_INT):
self.relAlt = obj.relAlt
self.relAltTime = obj.curTime
# Update Airpseed, Altitude, Climb Rate Locations
self.updateAARText()
# Update Altitude History
self.updateAltHistory()
elif isinstance(obj,BatteryInfo):
self.voltage = obj.voltage
self.current = obj.current
self.batRemain = obj.batRemain
# Update Battery Bar
self.updateBatteryBar()
elif isinstance(obj,FlightState):
self.mode = obj.mode
self.armed = obj.armState
# Update Mode and Arm State Text
self.updateStateText()
elif isinstance(obj,WaypointInfo):
self.currentWP = obj.current
self.finalWP = obj.final
self.wpDist = obj.currentDist
self.nextWPTime = obj.nextWPTime
if obj.wpBearing < 0.0:
self.wpBearing = obj.wpBearing + 360
else:
self.wpBearing = obj.wpBearing
# Update waypoint text
self.updateWPText()
# Adjust Waypoint Pointer
self.adjustWPPointer()
elif isinstance(obj, FPS):
# Update fps target
self.fps = obj.fps
# Quit Drawing if too early
if (time.time() > self.nextTime):
# Update Matplotlib Plot
self.canvas.draw()
self.canvas.Refresh()
self.Refresh()
self.Update()
# Calculate next frame time
if (self.fps > 0):
fpsTime = 1/self.fps
self.nextTime = fpsTime + self.loopStartTime
else:
self.nextTime = time.time() | python | def on_timer(self, event):
'''Main Loop.'''
state = self.state
self.loopStartTime = time.time()
if state.close_event.wait(0.001):
self.timer.Stop()
self.Destroy()
return
# Check for resizing
self.checkReszie()
if self.resized:
self.on_idle(0)
# Get attitude information
while state.child_pipe_recv.poll():
objList = state.child_pipe_recv.recv()
for obj in objList:
self.calcFontScaling()
if isinstance(obj,Attitude):
self.oldRoll = self.roll
self.pitch = obj.pitch*180/math.pi
self.roll = obj.roll*180/math.pi
self.yaw = obj.yaw*180/math.pi
# Update Roll, Pitch, Yaw Text Text
self.updateRPYText()
# Recalculate Horizon Polygons
self.calcHorizonPoints()
# Update Pitch Markers
self.adjustPitchmarkers()
elif isinstance(obj,VFR_HUD):
self.heading = obj.heading
self.airspeed = obj.airspeed
self.climbRate = obj.climbRate
# Update Airpseed, Altitude, Climb Rate Locations
self.updateAARText()
# Update Heading North Pointer
self.adjustHeadingPointer()
self.adjustNorthPointer()
elif isinstance(obj,Global_Position_INT):
self.relAlt = obj.relAlt
self.relAltTime = obj.curTime
# Update Airpseed, Altitude, Climb Rate Locations
self.updateAARText()
# Update Altitude History
self.updateAltHistory()
elif isinstance(obj,BatteryInfo):
self.voltage = obj.voltage
self.current = obj.current
self.batRemain = obj.batRemain
# Update Battery Bar
self.updateBatteryBar()
elif isinstance(obj,FlightState):
self.mode = obj.mode
self.armed = obj.armState
# Update Mode and Arm State Text
self.updateStateText()
elif isinstance(obj,WaypointInfo):
self.currentWP = obj.current
self.finalWP = obj.final
self.wpDist = obj.currentDist
self.nextWPTime = obj.nextWPTime
if obj.wpBearing < 0.0:
self.wpBearing = obj.wpBearing + 360
else:
self.wpBearing = obj.wpBearing
# Update waypoint text
self.updateWPText()
# Adjust Waypoint Pointer
self.adjustWPPointer()
elif isinstance(obj, FPS):
# Update fps target
self.fps = obj.fps
# Quit Drawing if too early
if (time.time() > self.nextTime):
# Update Matplotlib Plot
self.canvas.draw()
self.canvas.Refresh()
self.Refresh()
self.Update()
# Calculate next frame time
if (self.fps > 0):
fpsTime = 1/self.fps
self.nextTime = fpsTime + self.loopStartTime
else:
self.nextTime = time.time() | [
"def",
"on_timer",
"(",
"self",
",",
"event",
")",
":",
"state",
"=",
"self",
".",
"state",
"self",
".",
"loopStartTime",
"=",
"time",
".",
"time",
"(",
")",
"if",
"state",
".",
"close_event",
".",
"wait",
"(",
"0.001",
")",
":",
"self",
".",
"timer",
".",
"Stop",
"(",
")",
"self",
".",
"Destroy",
"(",
")",
"return",
"# Check for resizing",
"self",
".",
"checkReszie",
"(",
")",
"if",
"self",
".",
"resized",
":",
"self",
".",
"on_idle",
"(",
"0",
")",
"# Get attitude information",
"while",
"state",
".",
"child_pipe_recv",
".",
"poll",
"(",
")",
":",
"objList",
"=",
"state",
".",
"child_pipe_recv",
".",
"recv",
"(",
")",
"for",
"obj",
"in",
"objList",
":",
"self",
".",
"calcFontScaling",
"(",
")",
"if",
"isinstance",
"(",
"obj",
",",
"Attitude",
")",
":",
"self",
".",
"oldRoll",
"=",
"self",
".",
"roll",
"self",
".",
"pitch",
"=",
"obj",
".",
"pitch",
"*",
"180",
"/",
"math",
".",
"pi",
"self",
".",
"roll",
"=",
"obj",
".",
"roll",
"*",
"180",
"/",
"math",
".",
"pi",
"self",
".",
"yaw",
"=",
"obj",
".",
"yaw",
"*",
"180",
"/",
"math",
".",
"pi",
"# Update Roll, Pitch, Yaw Text Text",
"self",
".",
"updateRPYText",
"(",
")",
"# Recalculate Horizon Polygons",
"self",
".",
"calcHorizonPoints",
"(",
")",
"# Update Pitch Markers",
"self",
".",
"adjustPitchmarkers",
"(",
")",
"elif",
"isinstance",
"(",
"obj",
",",
"VFR_HUD",
")",
":",
"self",
".",
"heading",
"=",
"obj",
".",
"heading",
"self",
".",
"airspeed",
"=",
"obj",
".",
"airspeed",
"self",
".",
"climbRate",
"=",
"obj",
".",
"climbRate",
"# Update Airpseed, Altitude, Climb Rate Locations",
"self",
".",
"updateAARText",
"(",
")",
"# Update Heading North Pointer",
"self",
".",
"adjustHeadingPointer",
"(",
")",
"self",
".",
"adjustNorthPointer",
"(",
")",
"elif",
"isinstance",
"(",
"obj",
",",
"Global_Position_INT",
")",
":",
"self",
".",
"relAlt",
"=",
"obj",
".",
"relAlt",
"self",
".",
"relAltTime",
"=",
"obj",
".",
"curTime",
"# Update Airpseed, Altitude, Climb Rate Locations",
"self",
".",
"updateAARText",
"(",
")",
"# Update Altitude History",
"self",
".",
"updateAltHistory",
"(",
")",
"elif",
"isinstance",
"(",
"obj",
",",
"BatteryInfo",
")",
":",
"self",
".",
"voltage",
"=",
"obj",
".",
"voltage",
"self",
".",
"current",
"=",
"obj",
".",
"current",
"self",
".",
"batRemain",
"=",
"obj",
".",
"batRemain",
"# Update Battery Bar",
"self",
".",
"updateBatteryBar",
"(",
")",
"elif",
"isinstance",
"(",
"obj",
",",
"FlightState",
")",
":",
"self",
".",
"mode",
"=",
"obj",
".",
"mode",
"self",
".",
"armed",
"=",
"obj",
".",
"armState",
"# Update Mode and Arm State Text",
"self",
".",
"updateStateText",
"(",
")",
"elif",
"isinstance",
"(",
"obj",
",",
"WaypointInfo",
")",
":",
"self",
".",
"currentWP",
"=",
"obj",
".",
"current",
"self",
".",
"finalWP",
"=",
"obj",
".",
"final",
"self",
".",
"wpDist",
"=",
"obj",
".",
"currentDist",
"self",
".",
"nextWPTime",
"=",
"obj",
".",
"nextWPTime",
"if",
"obj",
".",
"wpBearing",
"<",
"0.0",
":",
"self",
".",
"wpBearing",
"=",
"obj",
".",
"wpBearing",
"+",
"360",
"else",
":",
"self",
".",
"wpBearing",
"=",
"obj",
".",
"wpBearing",
"# Update waypoint text",
"self",
".",
"updateWPText",
"(",
")",
"# Adjust Waypoint Pointer",
"self",
".",
"adjustWPPointer",
"(",
")",
"elif",
"isinstance",
"(",
"obj",
",",
"FPS",
")",
":",
"# Update fps target",
"self",
".",
"fps",
"=",
"obj",
".",
"fps",
"# Quit Drawing if too early",
"if",
"(",
"time",
".",
"time",
"(",
")",
">",
"self",
".",
"nextTime",
")",
":",
"# Update Matplotlib Plot",
"self",
".",
"canvas",
".",
"draw",
"(",
")",
"self",
".",
"canvas",
".",
"Refresh",
"(",
")",
"self",
".",
"Refresh",
"(",
")",
"self",
".",
"Update",
"(",
")",
"# Calculate next frame time",
"if",
"(",
"self",
".",
"fps",
">",
"0",
")",
":",
"fpsTime",
"=",
"1",
"/",
"self",
".",
"fps",
"self",
".",
"nextTime",
"=",
"fpsTime",
"+",
"self",
".",
"loopStartTime",
"else",
":",
"self",
".",
"nextTime",
"=",
"time",
".",
"time",
"(",
")"
] | Main Loop. | [
"Main",
"Loop",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/wxhorizon_ui.py#L569-L675 |
249,502 | ArduPilot/MAVProxy | MAVProxy/modules/lib/wxhorizon_ui.py | HorizonFrame.on_KeyPress | def on_KeyPress(self,event):
'''To adjust the distance between pitch markers.'''
if event.GetKeyCode() == wx.WXK_UP:
self.dist10deg += 0.1
print('Dist per 10 deg: %.1f' % self.dist10deg)
elif event.GetKeyCode() == wx.WXK_DOWN:
self.dist10deg -= 0.1
if self.dist10deg <= 0:
self.dist10deg = 0.1
print('Dist per 10 deg: %.1f' % self.dist10deg)
# Toggle Widgets
elif event.GetKeyCode() == 49: # 1
widgets = [self.modeText,self.wpText]
self.toggleWidgets(widgets)
elif event.GetKeyCode() == 50: # 2
widgets = [self.batOutRec,self.batInRec,self.voltsText,self.ampsText,self.batPerText]
self.toggleWidgets(widgets)
elif event.GetKeyCode() == 51: # 3
widgets = [self.rollText,self.pitchText,self.yawText]
self.toggleWidgets(widgets)
elif event.GetKeyCode() == 52: # 4
widgets = [self.airspeedText,self.altitudeText,self.climbRateText]
self.toggleWidgets(widgets)
elif event.GetKeyCode() == 53: # 5
widgets = [self.altHistRect,self.altPlot,self.altMarker,self.altText2]
self.toggleWidgets(widgets)
elif event.GetKeyCode() == 54: # 6
widgets = [self.headingTri,self.headingText,self.headingNorthTri,self.headingNorthText,self.headingWPTri,self.headingWPText]
self.toggleWidgets(widgets)
# Update Matplotlib Plot
self.canvas.draw()
self.canvas.Refresh()
self.Refresh()
self.Update() | python | def on_KeyPress(self,event):
'''To adjust the distance between pitch markers.'''
if event.GetKeyCode() == wx.WXK_UP:
self.dist10deg += 0.1
print('Dist per 10 deg: %.1f' % self.dist10deg)
elif event.GetKeyCode() == wx.WXK_DOWN:
self.dist10deg -= 0.1
if self.dist10deg <= 0:
self.dist10deg = 0.1
print('Dist per 10 deg: %.1f' % self.dist10deg)
# Toggle Widgets
elif event.GetKeyCode() == 49: # 1
widgets = [self.modeText,self.wpText]
self.toggleWidgets(widgets)
elif event.GetKeyCode() == 50: # 2
widgets = [self.batOutRec,self.batInRec,self.voltsText,self.ampsText,self.batPerText]
self.toggleWidgets(widgets)
elif event.GetKeyCode() == 51: # 3
widgets = [self.rollText,self.pitchText,self.yawText]
self.toggleWidgets(widgets)
elif event.GetKeyCode() == 52: # 4
widgets = [self.airspeedText,self.altitudeText,self.climbRateText]
self.toggleWidgets(widgets)
elif event.GetKeyCode() == 53: # 5
widgets = [self.altHistRect,self.altPlot,self.altMarker,self.altText2]
self.toggleWidgets(widgets)
elif event.GetKeyCode() == 54: # 6
widgets = [self.headingTri,self.headingText,self.headingNorthTri,self.headingNorthText,self.headingWPTri,self.headingWPText]
self.toggleWidgets(widgets)
# Update Matplotlib Plot
self.canvas.draw()
self.canvas.Refresh()
self.Refresh()
self.Update() | [
"def",
"on_KeyPress",
"(",
"self",
",",
"event",
")",
":",
"if",
"event",
".",
"GetKeyCode",
"(",
")",
"==",
"wx",
".",
"WXK_UP",
":",
"self",
".",
"dist10deg",
"+=",
"0.1",
"print",
"(",
"'Dist per 10 deg: %.1f'",
"%",
"self",
".",
"dist10deg",
")",
"elif",
"event",
".",
"GetKeyCode",
"(",
")",
"==",
"wx",
".",
"WXK_DOWN",
":",
"self",
".",
"dist10deg",
"-=",
"0.1",
"if",
"self",
".",
"dist10deg",
"<=",
"0",
":",
"self",
".",
"dist10deg",
"=",
"0.1",
"print",
"(",
"'Dist per 10 deg: %.1f'",
"%",
"self",
".",
"dist10deg",
")",
"# Toggle Widgets",
"elif",
"event",
".",
"GetKeyCode",
"(",
")",
"==",
"49",
":",
"# 1",
"widgets",
"=",
"[",
"self",
".",
"modeText",
",",
"self",
".",
"wpText",
"]",
"self",
".",
"toggleWidgets",
"(",
"widgets",
")",
"elif",
"event",
".",
"GetKeyCode",
"(",
")",
"==",
"50",
":",
"# 2",
"widgets",
"=",
"[",
"self",
".",
"batOutRec",
",",
"self",
".",
"batInRec",
",",
"self",
".",
"voltsText",
",",
"self",
".",
"ampsText",
",",
"self",
".",
"batPerText",
"]",
"self",
".",
"toggleWidgets",
"(",
"widgets",
")",
"elif",
"event",
".",
"GetKeyCode",
"(",
")",
"==",
"51",
":",
"# 3",
"widgets",
"=",
"[",
"self",
".",
"rollText",
",",
"self",
".",
"pitchText",
",",
"self",
".",
"yawText",
"]",
"self",
".",
"toggleWidgets",
"(",
"widgets",
")",
"elif",
"event",
".",
"GetKeyCode",
"(",
")",
"==",
"52",
":",
"# 4",
"widgets",
"=",
"[",
"self",
".",
"airspeedText",
",",
"self",
".",
"altitudeText",
",",
"self",
".",
"climbRateText",
"]",
"self",
".",
"toggleWidgets",
"(",
"widgets",
")",
"elif",
"event",
".",
"GetKeyCode",
"(",
")",
"==",
"53",
":",
"# 5",
"widgets",
"=",
"[",
"self",
".",
"altHistRect",
",",
"self",
".",
"altPlot",
",",
"self",
".",
"altMarker",
",",
"self",
".",
"altText2",
"]",
"self",
".",
"toggleWidgets",
"(",
"widgets",
")",
"elif",
"event",
".",
"GetKeyCode",
"(",
")",
"==",
"54",
":",
"# 6",
"widgets",
"=",
"[",
"self",
".",
"headingTri",
",",
"self",
".",
"headingText",
",",
"self",
".",
"headingNorthTri",
",",
"self",
".",
"headingNorthText",
",",
"self",
".",
"headingWPTri",
",",
"self",
".",
"headingWPText",
"]",
"self",
".",
"toggleWidgets",
"(",
"widgets",
")",
"# Update Matplotlib Plot",
"self",
".",
"canvas",
".",
"draw",
"(",
")",
"self",
".",
"canvas",
".",
"Refresh",
"(",
")",
"self",
".",
"Refresh",
"(",
")",
"self",
".",
"Update",
"(",
")"
] | To adjust the distance between pitch markers. | [
"To",
"adjust",
"the",
"distance",
"between",
"pitch",
"markers",
"."
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/wxhorizon_ui.py#L677-L712 |
249,503 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_fence.py | FenceModule.fenceloader | def fenceloader(self):
'''fence loader by sysid'''
if not self.target_system in self.fenceloader_by_sysid:
self.fenceloader_by_sysid[self.target_system] = mavwp.MAVFenceLoader()
return self.fenceloader_by_sysid[self.target_system] | python | def fenceloader(self):
'''fence loader by sysid'''
if not self.target_system in self.fenceloader_by_sysid:
self.fenceloader_by_sysid[self.target_system] = mavwp.MAVFenceLoader()
return self.fenceloader_by_sysid[self.target_system] | [
"def",
"fenceloader",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"target_system",
"in",
"self",
".",
"fenceloader_by_sysid",
":",
"self",
".",
"fenceloader_by_sysid",
"[",
"self",
".",
"target_system",
"]",
"=",
"mavwp",
".",
"MAVFenceLoader",
"(",
")",
"return",
"self",
".",
"fenceloader_by_sysid",
"[",
"self",
".",
"target_system",
"]"
] | fence loader by sysid | [
"fence",
"loader",
"by",
"sysid"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_fence.py#L51-L55 |
249,504 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_fence.py | FenceModule.mavlink_packet | def mavlink_packet(self, m):
'''handle and incoming mavlink packet'''
if m.get_type() == "FENCE_STATUS":
self.last_fence_breach = m.breach_time
self.last_fence_status = m.breach_status
elif m.get_type() in ['SYS_STATUS']:
bits = mavutil.mavlink.MAV_SYS_STATUS_GEOFENCE
present = ((m.onboard_control_sensors_present & bits) == bits)
if self.present == False and present == True:
self.say("fence present")
elif self.present == True and present == False:
self.say("fence removed")
self.present = present
enabled = ((m.onboard_control_sensors_enabled & bits) == bits)
if self.enabled == False and enabled == True:
self.say("fence enabled")
elif self.enabled == True and enabled == False:
self.say("fence disabled")
self.enabled = enabled
healthy = ((m.onboard_control_sensors_health & bits) == bits)
if self.healthy == False and healthy == True:
self.say("fence OK")
elif self.healthy == True and healthy == False:
self.say("fence breach")
self.healthy = healthy
#console output for fence:
if not self.present:
self.console.set_status('Fence', 'FEN', row=0, fg='black')
elif self.enabled == False:
self.console.set_status('Fence', 'FEN', row=0, fg='grey')
elif self.enabled == True and self.healthy == True:
self.console.set_status('Fence', 'FEN', row=0, fg='green')
elif self.enabled == True and self.healthy == False:
self.console.set_status('Fence', 'FEN', row=0, fg='red') | python | def mavlink_packet(self, m):
'''handle and incoming mavlink packet'''
if m.get_type() == "FENCE_STATUS":
self.last_fence_breach = m.breach_time
self.last_fence_status = m.breach_status
elif m.get_type() in ['SYS_STATUS']:
bits = mavutil.mavlink.MAV_SYS_STATUS_GEOFENCE
present = ((m.onboard_control_sensors_present & bits) == bits)
if self.present == False and present == True:
self.say("fence present")
elif self.present == True and present == False:
self.say("fence removed")
self.present = present
enabled = ((m.onboard_control_sensors_enabled & bits) == bits)
if self.enabled == False and enabled == True:
self.say("fence enabled")
elif self.enabled == True and enabled == False:
self.say("fence disabled")
self.enabled = enabled
healthy = ((m.onboard_control_sensors_health & bits) == bits)
if self.healthy == False and healthy == True:
self.say("fence OK")
elif self.healthy == True and healthy == False:
self.say("fence breach")
self.healthy = healthy
#console output for fence:
if not self.present:
self.console.set_status('Fence', 'FEN', row=0, fg='black')
elif self.enabled == False:
self.console.set_status('Fence', 'FEN', row=0, fg='grey')
elif self.enabled == True and self.healthy == True:
self.console.set_status('Fence', 'FEN', row=0, fg='green')
elif self.enabled == True and self.healthy == False:
self.console.set_status('Fence', 'FEN', row=0, fg='red') | [
"def",
"mavlink_packet",
"(",
"self",
",",
"m",
")",
":",
"if",
"m",
".",
"get_type",
"(",
")",
"==",
"\"FENCE_STATUS\"",
":",
"self",
".",
"last_fence_breach",
"=",
"m",
".",
"breach_time",
"self",
".",
"last_fence_status",
"=",
"m",
".",
"breach_status",
"elif",
"m",
".",
"get_type",
"(",
")",
"in",
"[",
"'SYS_STATUS'",
"]",
":",
"bits",
"=",
"mavutil",
".",
"mavlink",
".",
"MAV_SYS_STATUS_GEOFENCE",
"present",
"=",
"(",
"(",
"m",
".",
"onboard_control_sensors_present",
"&",
"bits",
")",
"==",
"bits",
")",
"if",
"self",
".",
"present",
"==",
"False",
"and",
"present",
"==",
"True",
":",
"self",
".",
"say",
"(",
"\"fence present\"",
")",
"elif",
"self",
".",
"present",
"==",
"True",
"and",
"present",
"==",
"False",
":",
"self",
".",
"say",
"(",
"\"fence removed\"",
")",
"self",
".",
"present",
"=",
"present",
"enabled",
"=",
"(",
"(",
"m",
".",
"onboard_control_sensors_enabled",
"&",
"bits",
")",
"==",
"bits",
")",
"if",
"self",
".",
"enabled",
"==",
"False",
"and",
"enabled",
"==",
"True",
":",
"self",
".",
"say",
"(",
"\"fence enabled\"",
")",
"elif",
"self",
".",
"enabled",
"==",
"True",
"and",
"enabled",
"==",
"False",
":",
"self",
".",
"say",
"(",
"\"fence disabled\"",
")",
"self",
".",
"enabled",
"=",
"enabled",
"healthy",
"=",
"(",
"(",
"m",
".",
"onboard_control_sensors_health",
"&",
"bits",
")",
"==",
"bits",
")",
"if",
"self",
".",
"healthy",
"==",
"False",
"and",
"healthy",
"==",
"True",
":",
"self",
".",
"say",
"(",
"\"fence OK\"",
")",
"elif",
"self",
".",
"healthy",
"==",
"True",
"and",
"healthy",
"==",
"False",
":",
"self",
".",
"say",
"(",
"\"fence breach\"",
")",
"self",
".",
"healthy",
"=",
"healthy",
"#console output for fence:",
"if",
"not",
"self",
".",
"present",
":",
"self",
".",
"console",
".",
"set_status",
"(",
"'Fence'",
",",
"'FEN'",
",",
"row",
"=",
"0",
",",
"fg",
"=",
"'black'",
")",
"elif",
"self",
".",
"enabled",
"==",
"False",
":",
"self",
".",
"console",
".",
"set_status",
"(",
"'Fence'",
",",
"'FEN'",
",",
"row",
"=",
"0",
",",
"fg",
"=",
"'grey'",
")",
"elif",
"self",
".",
"enabled",
"==",
"True",
"and",
"self",
".",
"healthy",
"==",
"True",
":",
"self",
".",
"console",
".",
"set_status",
"(",
"'Fence'",
",",
"'FEN'",
",",
"row",
"=",
"0",
",",
"fg",
"=",
"'green'",
")",
"elif",
"self",
".",
"enabled",
"==",
"True",
"and",
"self",
".",
"healthy",
"==",
"False",
":",
"self",
".",
"console",
".",
"set_status",
"(",
"'Fence'",
",",
"'FEN'",
",",
"row",
"=",
"0",
",",
"fg",
"=",
"'red'",
")"
] | handle and incoming mavlink packet | [
"handle",
"and",
"incoming",
"mavlink",
"packet"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_fence.py#L66-L103 |
249,505 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_fence.py | FenceModule.load_fence | def load_fence(self, filename):
'''load fence points from a file'''
try:
self.fenceloader.target_system = self.target_system
self.fenceloader.target_component = self.target_component
self.fenceloader.load(filename.strip('"'))
except Exception as msg:
print("Unable to load %s - %s" % (filename, msg))
return
print("Loaded %u geo-fence points from %s" % (self.fenceloader.count(), filename))
self.send_fence() | python | def load_fence(self, filename):
'''load fence points from a file'''
try:
self.fenceloader.target_system = self.target_system
self.fenceloader.target_component = self.target_component
self.fenceloader.load(filename.strip('"'))
except Exception as msg:
print("Unable to load %s - %s" % (filename, msg))
return
print("Loaded %u geo-fence points from %s" % (self.fenceloader.count(), filename))
self.send_fence() | [
"def",
"load_fence",
"(",
"self",
",",
"filename",
")",
":",
"try",
":",
"self",
".",
"fenceloader",
".",
"target_system",
"=",
"self",
".",
"target_system",
"self",
".",
"fenceloader",
".",
"target_component",
"=",
"self",
".",
"target_component",
"self",
".",
"fenceloader",
".",
"load",
"(",
"filename",
".",
"strip",
"(",
"'\"'",
")",
")",
"except",
"Exception",
"as",
"msg",
":",
"print",
"(",
"\"Unable to load %s - %s\"",
"%",
"(",
"filename",
",",
"msg",
")",
")",
"return",
"print",
"(",
"\"Loaded %u geo-fence points from %s\"",
"%",
"(",
"self",
".",
"fenceloader",
".",
"count",
"(",
")",
",",
"filename",
")",
")",
"self",
".",
"send_fence",
"(",
")"
] | load fence points from a file | [
"load",
"fence",
"points",
"from",
"a",
"file"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_fence.py#L205-L215 |
249,506 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_fence.py | FenceModule.list_fence | def list_fence(self, filename):
'''list fence points, optionally saving to a file'''
self.fenceloader.clear()
count = self.get_mav_param('FENCE_TOTAL', 0)
if count == 0:
print("No geo-fence points")
return
for i in range(int(count)):
p = self.fetch_fence_point(i)
if p is None:
return
self.fenceloader.add(p)
if filename is not None:
try:
self.fenceloader.save(filename.strip('"'))
except Exception as msg:
print("Unable to save %s - %s" % (filename, msg))
return
print("Saved %u geo-fence points to %s" % (self.fenceloader.count(), filename))
else:
for i in range(self.fenceloader.count()):
p = self.fenceloader.point(i)
self.console.writeln("lat=%f lng=%f" % (p.lat, p.lng))
if self.status.logdir is not None:
fname = 'fence.txt'
if self.target_system > 1:
fname = 'fence_%u.txt' % self.target_system
fencetxt = os.path.join(self.status.logdir, fname)
self.fenceloader.save(fencetxt.strip('"'))
print("Saved fence to %s" % fencetxt)
self.have_list = True | python | def list_fence(self, filename):
'''list fence points, optionally saving to a file'''
self.fenceloader.clear()
count = self.get_mav_param('FENCE_TOTAL', 0)
if count == 0:
print("No geo-fence points")
return
for i in range(int(count)):
p = self.fetch_fence_point(i)
if p is None:
return
self.fenceloader.add(p)
if filename is not None:
try:
self.fenceloader.save(filename.strip('"'))
except Exception as msg:
print("Unable to save %s - %s" % (filename, msg))
return
print("Saved %u geo-fence points to %s" % (self.fenceloader.count(), filename))
else:
for i in range(self.fenceloader.count()):
p = self.fenceloader.point(i)
self.console.writeln("lat=%f lng=%f" % (p.lat, p.lng))
if self.status.logdir is not None:
fname = 'fence.txt'
if self.target_system > 1:
fname = 'fence_%u.txt' % self.target_system
fencetxt = os.path.join(self.status.logdir, fname)
self.fenceloader.save(fencetxt.strip('"'))
print("Saved fence to %s" % fencetxt)
self.have_list = True | [
"def",
"list_fence",
"(",
"self",
",",
"filename",
")",
":",
"self",
".",
"fenceloader",
".",
"clear",
"(",
")",
"count",
"=",
"self",
".",
"get_mav_param",
"(",
"'FENCE_TOTAL'",
",",
"0",
")",
"if",
"count",
"==",
"0",
":",
"print",
"(",
"\"No geo-fence points\"",
")",
"return",
"for",
"i",
"in",
"range",
"(",
"int",
"(",
"count",
")",
")",
":",
"p",
"=",
"self",
".",
"fetch_fence_point",
"(",
"i",
")",
"if",
"p",
"is",
"None",
":",
"return",
"self",
".",
"fenceloader",
".",
"add",
"(",
"p",
")",
"if",
"filename",
"is",
"not",
"None",
":",
"try",
":",
"self",
".",
"fenceloader",
".",
"save",
"(",
"filename",
".",
"strip",
"(",
"'\"'",
")",
")",
"except",
"Exception",
"as",
"msg",
":",
"print",
"(",
"\"Unable to save %s - %s\"",
"%",
"(",
"filename",
",",
"msg",
")",
")",
"return",
"print",
"(",
"\"Saved %u geo-fence points to %s\"",
"%",
"(",
"self",
".",
"fenceloader",
".",
"count",
"(",
")",
",",
"filename",
")",
")",
"else",
":",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"fenceloader",
".",
"count",
"(",
")",
")",
":",
"p",
"=",
"self",
".",
"fenceloader",
".",
"point",
"(",
"i",
")",
"self",
".",
"console",
".",
"writeln",
"(",
"\"lat=%f lng=%f\"",
"%",
"(",
"p",
".",
"lat",
",",
"p",
".",
"lng",
")",
")",
"if",
"self",
".",
"status",
".",
"logdir",
"is",
"not",
"None",
":",
"fname",
"=",
"'fence.txt'",
"if",
"self",
".",
"target_system",
">",
"1",
":",
"fname",
"=",
"'fence_%u.txt'",
"%",
"self",
".",
"target_system",
"fencetxt",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"status",
".",
"logdir",
",",
"fname",
")",
"self",
".",
"fenceloader",
".",
"save",
"(",
"fencetxt",
".",
"strip",
"(",
"'\"'",
")",
")",
"print",
"(",
"\"Saved fence to %s\"",
"%",
"fencetxt",
")",
"self",
".",
"have_list",
"=",
"True"
] | list fence points, optionally saving to a file | [
"list",
"fence",
"points",
"optionally",
"saving",
"to",
"a",
"file"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_fence.py#L277-L308 |
249,507 | ArduPilot/MAVProxy | MAVProxy/modules/lib/mp_image.py | MPImage.poll | def poll(self):
'''check for events, returning one event'''
if self.out_queue.qsize() <= 0:
return None
evt = self.out_queue.get()
while isinstance(evt, win_layout.WinLayout):
win_layout.set_layout(evt, self.set_layout)
if self.out_queue.qsize() == 0:
return None
evt = self.out_queue.get()
return evt | python | def poll(self):
'''check for events, returning one event'''
if self.out_queue.qsize() <= 0:
return None
evt = self.out_queue.get()
while isinstance(evt, win_layout.WinLayout):
win_layout.set_layout(evt, self.set_layout)
if self.out_queue.qsize() == 0:
return None
evt = self.out_queue.get()
return evt | [
"def",
"poll",
"(",
"self",
")",
":",
"if",
"self",
".",
"out_queue",
".",
"qsize",
"(",
")",
"<=",
"0",
":",
"return",
"None",
"evt",
"=",
"self",
".",
"out_queue",
".",
"get",
"(",
")",
"while",
"isinstance",
"(",
"evt",
",",
"win_layout",
".",
"WinLayout",
")",
":",
"win_layout",
".",
"set_layout",
"(",
"evt",
",",
"self",
".",
"set_layout",
")",
"if",
"self",
".",
"out_queue",
".",
"qsize",
"(",
")",
"==",
"0",
":",
"return",
"None",
"evt",
"=",
"self",
".",
"out_queue",
".",
"get",
"(",
")",
"return",
"evt"
] | check for events, returning one event | [
"check",
"for",
"events",
"returning",
"one",
"event"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_image.py#L172-L182 |
249,508 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/mp_slipmap_ui.py | MPSlipMapFrame.find_object | def find_object(self, key, layers):
'''find an object to be modified'''
state = self.state
if layers is None or layers == '':
layers = state.layers.keys()
for layer in layers:
if key in state.layers[layer]:
return state.layers[layer][key]
return None | python | def find_object(self, key, layers):
'''find an object to be modified'''
state = self.state
if layers is None or layers == '':
layers = state.layers.keys()
for layer in layers:
if key in state.layers[layer]:
return state.layers[layer][key]
return None | [
"def",
"find_object",
"(",
"self",
",",
"key",
",",
"layers",
")",
":",
"state",
"=",
"self",
".",
"state",
"if",
"layers",
"is",
"None",
"or",
"layers",
"==",
"''",
":",
"layers",
"=",
"state",
".",
"layers",
".",
"keys",
"(",
")",
"for",
"layer",
"in",
"layers",
":",
"if",
"key",
"in",
"state",
".",
"layers",
"[",
"layer",
"]",
":",
"return",
"state",
".",
"layers",
"[",
"layer",
"]",
"[",
"key",
"]",
"return",
"None"
] | find an object to be modified | [
"find",
"an",
"object",
"to",
"be",
"modified"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/mp_slipmap_ui.py#L140-L149 |
249,509 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/mp_slipmap_ui.py | MPSlipMapFrame.add_object | def add_object(self, obj):
'''add an object to a layer'''
state = self.state
if not obj.layer in state.layers:
# its a new layer
state.layers[obj.layer] = {}
state.layers[obj.layer][obj.key] = obj
state.need_redraw = True
if (not self.legend_checkbox_menuitem_added and
isinstance(obj, SlipFlightModeLegend)):
self.add_legend_checkbox_menuitem()
self.legend_checkbox_menuitem_added = True
self.SetMenuBar(self.menu.wx_menu()) | python | def add_object(self, obj):
'''add an object to a layer'''
state = self.state
if not obj.layer in state.layers:
# its a new layer
state.layers[obj.layer] = {}
state.layers[obj.layer][obj.key] = obj
state.need_redraw = True
if (not self.legend_checkbox_menuitem_added and
isinstance(obj, SlipFlightModeLegend)):
self.add_legend_checkbox_menuitem()
self.legend_checkbox_menuitem_added = True
self.SetMenuBar(self.menu.wx_menu()) | [
"def",
"add_object",
"(",
"self",
",",
"obj",
")",
":",
"state",
"=",
"self",
".",
"state",
"if",
"not",
"obj",
".",
"layer",
"in",
"state",
".",
"layers",
":",
"# its a new layer",
"state",
".",
"layers",
"[",
"obj",
".",
"layer",
"]",
"=",
"{",
"}",
"state",
".",
"layers",
"[",
"obj",
".",
"layer",
"]",
"[",
"obj",
".",
"key",
"]",
"=",
"obj",
"state",
".",
"need_redraw",
"=",
"True",
"if",
"(",
"not",
"self",
".",
"legend_checkbox_menuitem_added",
"and",
"isinstance",
"(",
"obj",
",",
"SlipFlightModeLegend",
")",
")",
":",
"self",
".",
"add_legend_checkbox_menuitem",
"(",
")",
"self",
".",
"legend_checkbox_menuitem_added",
"=",
"True",
"self",
".",
"SetMenuBar",
"(",
"self",
".",
"menu",
".",
"wx_menu",
"(",
")",
")"
] | add an object to a layer | [
"add",
"an",
"object",
"to",
"a",
"layer"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/mp_slipmap_ui.py#L177-L189 |
249,510 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/mp_slipmap_ui.py | MPSlipMapPanel.set_ground_width | def set_ground_width(self, ground_width):
'''set ground width of view'''
state = self.state
state.ground_width = ground_width
state.panel.re_center(state.width/2, state.height/2, state.lat, state.lon) | python | def set_ground_width(self, ground_width):
'''set ground width of view'''
state = self.state
state.ground_width = ground_width
state.panel.re_center(state.width/2, state.height/2, state.lat, state.lon) | [
"def",
"set_ground_width",
"(",
"self",
",",
"ground_width",
")",
":",
"state",
"=",
"self",
".",
"state",
"state",
".",
"ground_width",
"=",
"ground_width",
"state",
".",
"panel",
".",
"re_center",
"(",
"state",
".",
"width",
"/",
"2",
",",
"state",
".",
"height",
"/",
"2",
",",
"state",
".",
"lat",
",",
"state",
".",
"lon",
")"
] | set ground width of view | [
"set",
"ground",
"width",
"of",
"view"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/mp_slipmap_ui.py#L387-L391 |
249,511 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/mp_slipmap_ui.py | MPSlipMapPanel.show_popup | def show_popup(self, selected, pos):
'''show popup menu for an object'''
state = self.state
if selected.popup_menu is not None:
import copy
popup_menu = selected.popup_menu
if state.default_popup is not None and state.default_popup.combine:
popup_menu = copy.deepcopy(popup_menu)
popup_menu.add(MPMenuSeparator())
popup_menu.combine(state.default_popup.popup)
wx_menu = popup_menu.wx_menu()
state.frame.PopupMenu(wx_menu, pos) | python | def show_popup(self, selected, pos):
'''show popup menu for an object'''
state = self.state
if selected.popup_menu is not None:
import copy
popup_menu = selected.popup_menu
if state.default_popup is not None and state.default_popup.combine:
popup_menu = copy.deepcopy(popup_menu)
popup_menu.add(MPMenuSeparator())
popup_menu.combine(state.default_popup.popup)
wx_menu = popup_menu.wx_menu()
state.frame.PopupMenu(wx_menu, pos) | [
"def",
"show_popup",
"(",
"self",
",",
"selected",
",",
"pos",
")",
":",
"state",
"=",
"self",
".",
"state",
"if",
"selected",
".",
"popup_menu",
"is",
"not",
"None",
":",
"import",
"copy",
"popup_menu",
"=",
"selected",
".",
"popup_menu",
"if",
"state",
".",
"default_popup",
"is",
"not",
"None",
"and",
"state",
".",
"default_popup",
".",
"combine",
":",
"popup_menu",
"=",
"copy",
".",
"deepcopy",
"(",
"popup_menu",
")",
"popup_menu",
".",
"add",
"(",
"MPMenuSeparator",
"(",
")",
")",
"popup_menu",
".",
"combine",
"(",
"state",
".",
"default_popup",
".",
"popup",
")",
"wx_menu",
"=",
"popup_menu",
".",
"wx_menu",
"(",
")",
"state",
".",
"frame",
".",
"PopupMenu",
"(",
"wx_menu",
",",
"pos",
")"
] | show popup menu for an object | [
"show",
"popup",
"menu",
"for",
"an",
"object"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/mp_slipmap_ui.py#L568-L579 |
249,512 | ArduPilot/MAVProxy | MAVProxy/mavproxy.py | cmd_watch | def cmd_watch(args):
'''watch a mavlink packet pattern'''
if len(args) == 0:
mpstate.status.watch = None
return
mpstate.status.watch = args
print("Watching %s" % mpstate.status.watch) | python | def cmd_watch(args):
'''watch a mavlink packet pattern'''
if len(args) == 0:
mpstate.status.watch = None
return
mpstate.status.watch = args
print("Watching %s" % mpstate.status.watch) | [
"def",
"cmd_watch",
"(",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"mpstate",
".",
"status",
".",
"watch",
"=",
"None",
"return",
"mpstate",
".",
"status",
".",
"watch",
"=",
"args",
"print",
"(",
"\"Watching %s\"",
"%",
"mpstate",
".",
"status",
".",
"watch",
")"
] | watch a mavlink packet pattern | [
"watch",
"a",
"mavlink",
"packet",
"pattern"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/mavproxy.py#L315-L321 |
249,513 | ArduPilot/MAVProxy | MAVProxy/mavproxy.py | load_module | def load_module(modname, quiet=False, **kwargs):
'''load a module'''
modpaths = ['MAVProxy.modules.mavproxy_%s' % modname, modname]
for (m,pm) in mpstate.modules:
if m.name == modname and not modname in mpstate.multi_instance:
if not quiet:
print("module %s already loaded" % modname)
# don't report an error
return True
ex = None
for modpath in modpaths:
try:
m = import_package(modpath)
reload(m)
module = m.init(mpstate, **kwargs)
if isinstance(module, mp_module.MPModule):
mpstate.modules.append((module, m))
if not quiet:
if kwargs:
print("Loaded module %s with kwargs = %s" % (modname, kwargs))
else:
print("Loaded module %s" % (modname,))
return True
else:
ex = "%s.init did not return a MPModule instance" % modname
break
except ImportError as msg:
ex = msg
if mpstate.settings.moddebug > 1:
import traceback
print(traceback.format_exc())
help_traceback = ""
if mpstate.settings.moddebug < 3:
help_traceback = " Use 'set moddebug 3' in the MAVProxy console to enable traceback"
print("Failed to load module: %s.%s" % (ex, help_traceback))
return False | python | def load_module(modname, quiet=False, **kwargs):
'''load a module'''
modpaths = ['MAVProxy.modules.mavproxy_%s' % modname, modname]
for (m,pm) in mpstate.modules:
if m.name == modname and not modname in mpstate.multi_instance:
if not quiet:
print("module %s already loaded" % modname)
# don't report an error
return True
ex = None
for modpath in modpaths:
try:
m = import_package(modpath)
reload(m)
module = m.init(mpstate, **kwargs)
if isinstance(module, mp_module.MPModule):
mpstate.modules.append((module, m))
if not quiet:
if kwargs:
print("Loaded module %s with kwargs = %s" % (modname, kwargs))
else:
print("Loaded module %s" % (modname,))
return True
else:
ex = "%s.init did not return a MPModule instance" % modname
break
except ImportError as msg:
ex = msg
if mpstate.settings.moddebug > 1:
import traceback
print(traceback.format_exc())
help_traceback = ""
if mpstate.settings.moddebug < 3:
help_traceback = " Use 'set moddebug 3' in the MAVProxy console to enable traceback"
print("Failed to load module: %s.%s" % (ex, help_traceback))
return False | [
"def",
"load_module",
"(",
"modname",
",",
"quiet",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"modpaths",
"=",
"[",
"'MAVProxy.modules.mavproxy_%s'",
"%",
"modname",
",",
"modname",
"]",
"for",
"(",
"m",
",",
"pm",
")",
"in",
"mpstate",
".",
"modules",
":",
"if",
"m",
".",
"name",
"==",
"modname",
"and",
"not",
"modname",
"in",
"mpstate",
".",
"multi_instance",
":",
"if",
"not",
"quiet",
":",
"print",
"(",
"\"module %s already loaded\"",
"%",
"modname",
")",
"# don't report an error",
"return",
"True",
"ex",
"=",
"None",
"for",
"modpath",
"in",
"modpaths",
":",
"try",
":",
"m",
"=",
"import_package",
"(",
"modpath",
")",
"reload",
"(",
"m",
")",
"module",
"=",
"m",
".",
"init",
"(",
"mpstate",
",",
"*",
"*",
"kwargs",
")",
"if",
"isinstance",
"(",
"module",
",",
"mp_module",
".",
"MPModule",
")",
":",
"mpstate",
".",
"modules",
".",
"append",
"(",
"(",
"module",
",",
"m",
")",
")",
"if",
"not",
"quiet",
":",
"if",
"kwargs",
":",
"print",
"(",
"\"Loaded module %s with kwargs = %s\"",
"%",
"(",
"modname",
",",
"kwargs",
")",
")",
"else",
":",
"print",
"(",
"\"Loaded module %s\"",
"%",
"(",
"modname",
",",
")",
")",
"return",
"True",
"else",
":",
"ex",
"=",
"\"%s.init did not return a MPModule instance\"",
"%",
"modname",
"break",
"except",
"ImportError",
"as",
"msg",
":",
"ex",
"=",
"msg",
"if",
"mpstate",
".",
"settings",
".",
"moddebug",
">",
"1",
":",
"import",
"traceback",
"print",
"(",
"traceback",
".",
"format_exc",
"(",
")",
")",
"help_traceback",
"=",
"\"\"",
"if",
"mpstate",
".",
"settings",
".",
"moddebug",
"<",
"3",
":",
"help_traceback",
"=",
"\" Use 'set moddebug 3' in the MAVProxy console to enable traceback\"",
"print",
"(",
"\"Failed to load module: %s.%s\"",
"%",
"(",
"ex",
",",
"help_traceback",
")",
")",
"return",
"False"
] | load a module | [
"load",
"a",
"module"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/mavproxy.py#L337-L372 |
249,514 | ArduPilot/MAVProxy | MAVProxy/mavproxy.py | process_mavlink | def process_mavlink(slave):
'''process packets from MAVLink slaves, forwarding to the master'''
try:
buf = slave.recv()
except socket.error:
return
try:
global mavversion
if slave.first_byte and mavversion is None:
slave.auto_mavlink_version(buf)
msgs = slave.mav.parse_buffer(buf)
except mavutil.mavlink.MAVError as e:
mpstate.console.error("Bad MAVLink slave message from %s: %s" % (slave.address, e.message))
return
if msgs is None:
return
if mpstate.settings.mavfwd and not mpstate.status.setup_mode:
for m in msgs:
mpstate.master().write(m.get_msgbuf())
if mpstate.status.watch:
for msg_type in mpstate.status.watch:
if fnmatch.fnmatch(m.get_type().upper(), msg_type.upper()):
mpstate.console.writeln('> '+ str(m))
break
mpstate.status.counters['Slave'] += 1 | python | def process_mavlink(slave):
'''process packets from MAVLink slaves, forwarding to the master'''
try:
buf = slave.recv()
except socket.error:
return
try:
global mavversion
if slave.first_byte and mavversion is None:
slave.auto_mavlink_version(buf)
msgs = slave.mav.parse_buffer(buf)
except mavutil.mavlink.MAVError as e:
mpstate.console.error("Bad MAVLink slave message from %s: %s" % (slave.address, e.message))
return
if msgs is None:
return
if mpstate.settings.mavfwd and not mpstate.status.setup_mode:
for m in msgs:
mpstate.master().write(m.get_msgbuf())
if mpstate.status.watch:
for msg_type in mpstate.status.watch:
if fnmatch.fnmatch(m.get_type().upper(), msg_type.upper()):
mpstate.console.writeln('> '+ str(m))
break
mpstate.status.counters['Slave'] += 1 | [
"def",
"process_mavlink",
"(",
"slave",
")",
":",
"try",
":",
"buf",
"=",
"slave",
".",
"recv",
"(",
")",
"except",
"socket",
".",
"error",
":",
"return",
"try",
":",
"global",
"mavversion",
"if",
"slave",
".",
"first_byte",
"and",
"mavversion",
"is",
"None",
":",
"slave",
".",
"auto_mavlink_version",
"(",
"buf",
")",
"msgs",
"=",
"slave",
".",
"mav",
".",
"parse_buffer",
"(",
"buf",
")",
"except",
"mavutil",
".",
"mavlink",
".",
"MAVError",
"as",
"e",
":",
"mpstate",
".",
"console",
".",
"error",
"(",
"\"Bad MAVLink slave message from %s: %s\"",
"%",
"(",
"slave",
".",
"address",
",",
"e",
".",
"message",
")",
")",
"return",
"if",
"msgs",
"is",
"None",
":",
"return",
"if",
"mpstate",
".",
"settings",
".",
"mavfwd",
"and",
"not",
"mpstate",
".",
"status",
".",
"setup_mode",
":",
"for",
"m",
"in",
"msgs",
":",
"mpstate",
".",
"master",
"(",
")",
".",
"write",
"(",
"m",
".",
"get_msgbuf",
"(",
")",
")",
"if",
"mpstate",
".",
"status",
".",
"watch",
":",
"for",
"msg_type",
"in",
"mpstate",
".",
"status",
".",
"watch",
":",
"if",
"fnmatch",
".",
"fnmatch",
"(",
"m",
".",
"get_type",
"(",
")",
".",
"upper",
"(",
")",
",",
"msg_type",
".",
"upper",
"(",
")",
")",
":",
"mpstate",
".",
"console",
".",
"writeln",
"(",
"'> '",
"+",
"str",
"(",
"m",
")",
")",
"break",
"mpstate",
".",
"status",
".",
"counters",
"[",
"'Slave'",
"]",
"+=",
"1"
] | process packets from MAVLink slaves, forwarding to the master | [
"process",
"packets",
"from",
"MAVLink",
"slaves",
"forwarding",
"to",
"the",
"master"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/mavproxy.py#L638-L662 |
249,515 | ArduPilot/MAVProxy | MAVProxy/mavproxy.py | log_writer | def log_writer():
'''log writing thread'''
while True:
mpstate.logfile_raw.write(bytearray(mpstate.logqueue_raw.get()))
timeout = time.time() + 10
while not mpstate.logqueue_raw.empty() and time.time() < timeout:
mpstate.logfile_raw.write(mpstate.logqueue_raw.get())
while not mpstate.logqueue.empty() and time.time() < timeout:
mpstate.logfile.write(mpstate.logqueue.get())
if mpstate.settings.flushlogs or time.time() >= timeout:
mpstate.logfile.flush()
mpstate.logfile_raw.flush() | python | def log_writer():
'''log writing thread'''
while True:
mpstate.logfile_raw.write(bytearray(mpstate.logqueue_raw.get()))
timeout = time.time() + 10
while not mpstate.logqueue_raw.empty() and time.time() < timeout:
mpstate.logfile_raw.write(mpstate.logqueue_raw.get())
while not mpstate.logqueue.empty() and time.time() < timeout:
mpstate.logfile.write(mpstate.logqueue.get())
if mpstate.settings.flushlogs or time.time() >= timeout:
mpstate.logfile.flush()
mpstate.logfile_raw.flush() | [
"def",
"log_writer",
"(",
")",
":",
"while",
"True",
":",
"mpstate",
".",
"logfile_raw",
".",
"write",
"(",
"bytearray",
"(",
"mpstate",
".",
"logqueue_raw",
".",
"get",
"(",
")",
")",
")",
"timeout",
"=",
"time",
".",
"time",
"(",
")",
"+",
"10",
"while",
"not",
"mpstate",
".",
"logqueue_raw",
".",
"empty",
"(",
")",
"and",
"time",
".",
"time",
"(",
")",
"<",
"timeout",
":",
"mpstate",
".",
"logfile_raw",
".",
"write",
"(",
"mpstate",
".",
"logqueue_raw",
".",
"get",
"(",
")",
")",
"while",
"not",
"mpstate",
".",
"logqueue",
".",
"empty",
"(",
")",
"and",
"time",
".",
"time",
"(",
")",
"<",
"timeout",
":",
"mpstate",
".",
"logfile",
".",
"write",
"(",
"mpstate",
".",
"logqueue",
".",
"get",
"(",
")",
")",
"if",
"mpstate",
".",
"settings",
".",
"flushlogs",
"or",
"time",
".",
"time",
"(",
")",
">=",
"timeout",
":",
"mpstate",
".",
"logfile",
".",
"flush",
"(",
")",
"mpstate",
".",
"logfile_raw",
".",
"flush",
"(",
")"
] | log writing thread | [
"log",
"writing",
"thread"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/mavproxy.py#L677-L688 |
249,516 | ArduPilot/MAVProxy | MAVProxy/mavproxy.py | main_loop | def main_loop():
'''main processing loop'''
global screensaver_cookie
if not mpstate.status.setup_mode and not opts.nowait:
for master in mpstate.mav_master:
if master.linknum != 0:
break
print("Waiting for heartbeat from %s" % master.address)
send_heartbeat(master)
master.wait_heartbeat(timeout=0.1)
set_stream_rates()
while True:
if mpstate is None or mpstate.status.exit:
return
# enable or disable screensaver:
if (mpstate.settings.inhibit_screensaver_when_armed and
screensaver_interface is not None):
if mpstate.status.armed and screensaver_cookie is None:
# now we can inhibit the screensaver
screensaver_cookie = screensaver_interface.Inhibit("MAVProxy",
"Vehicle is armed")
elif not mpstate.status.armed and screensaver_cookie is not None:
# we can also restore it
screensaver_interface.UnInhibit(screensaver_cookie)
screensaver_cookie = None
while not mpstate.input_queue.empty():
line = mpstate.input_queue.get()
mpstate.input_count += 1
cmds = line.split(';')
if len(cmds) == 1 and cmds[0] == "":
mpstate.empty_input_count += 1
for c in cmds:
process_stdin(c)
for master in mpstate.mav_master:
if master.fd is None:
if master.port.inWaiting() > 0:
process_master(master)
periodic_tasks()
rin = []
for master in mpstate.mav_master:
if master.fd is not None and not master.portdead:
rin.append(master.fd)
for m in mpstate.mav_outputs:
rin.append(m.fd)
for sysid in mpstate.sysid_outputs:
m = mpstate.sysid_outputs[sysid]
rin.append(m.fd)
if rin == []:
time.sleep(0.0001)
continue
for fd in mpstate.select_extra:
rin.append(fd)
try:
(rin, win, xin) = select.select(rin, [], [], mpstate.settings.select_timeout)
except select.error:
continue
if mpstate is None:
return
for fd in rin:
if mpstate is None:
return
for master in mpstate.mav_master:
if fd == master.fd:
process_master(master)
if mpstate is None:
return
continue
for m in mpstate.mav_outputs:
if fd == m.fd:
process_mavlink(m)
if mpstate is None:
return
continue
for sysid in mpstate.sysid_outputs:
m = mpstate.sysid_outputs[sysid]
if fd == m.fd:
process_mavlink(m)
if mpstate is None:
return
continue
# this allow modules to register their own file descriptors
# for the main select loop
if fd in mpstate.select_extra:
try:
# call the registered read function
(fn, args) = mpstate.select_extra[fd]
fn(args)
except Exception as msg:
if mpstate.settings.moddebug == 1:
print(msg)
# on an exception, remove it from the select list
mpstate.select_extra.pop(fd) | python | def main_loop():
'''main processing loop'''
global screensaver_cookie
if not mpstate.status.setup_mode and not opts.nowait:
for master in mpstate.mav_master:
if master.linknum != 0:
break
print("Waiting for heartbeat from %s" % master.address)
send_heartbeat(master)
master.wait_heartbeat(timeout=0.1)
set_stream_rates()
while True:
if mpstate is None or mpstate.status.exit:
return
# enable or disable screensaver:
if (mpstate.settings.inhibit_screensaver_when_armed and
screensaver_interface is not None):
if mpstate.status.armed and screensaver_cookie is None:
# now we can inhibit the screensaver
screensaver_cookie = screensaver_interface.Inhibit("MAVProxy",
"Vehicle is armed")
elif not mpstate.status.armed and screensaver_cookie is not None:
# we can also restore it
screensaver_interface.UnInhibit(screensaver_cookie)
screensaver_cookie = None
while not mpstate.input_queue.empty():
line = mpstate.input_queue.get()
mpstate.input_count += 1
cmds = line.split(';')
if len(cmds) == 1 and cmds[0] == "":
mpstate.empty_input_count += 1
for c in cmds:
process_stdin(c)
for master in mpstate.mav_master:
if master.fd is None:
if master.port.inWaiting() > 0:
process_master(master)
periodic_tasks()
rin = []
for master in mpstate.mav_master:
if master.fd is not None and not master.portdead:
rin.append(master.fd)
for m in mpstate.mav_outputs:
rin.append(m.fd)
for sysid in mpstate.sysid_outputs:
m = mpstate.sysid_outputs[sysid]
rin.append(m.fd)
if rin == []:
time.sleep(0.0001)
continue
for fd in mpstate.select_extra:
rin.append(fd)
try:
(rin, win, xin) = select.select(rin, [], [], mpstate.settings.select_timeout)
except select.error:
continue
if mpstate is None:
return
for fd in rin:
if mpstate is None:
return
for master in mpstate.mav_master:
if fd == master.fd:
process_master(master)
if mpstate is None:
return
continue
for m in mpstate.mav_outputs:
if fd == m.fd:
process_mavlink(m)
if mpstate is None:
return
continue
for sysid in mpstate.sysid_outputs:
m = mpstate.sysid_outputs[sysid]
if fd == m.fd:
process_mavlink(m)
if mpstate is None:
return
continue
# this allow modules to register their own file descriptors
# for the main select loop
if fd in mpstate.select_extra:
try:
# call the registered read function
(fn, args) = mpstate.select_extra[fd]
fn(args)
except Exception as msg:
if mpstate.settings.moddebug == 1:
print(msg)
# on an exception, remove it from the select list
mpstate.select_extra.pop(fd) | [
"def",
"main_loop",
"(",
")",
":",
"global",
"screensaver_cookie",
"if",
"not",
"mpstate",
".",
"status",
".",
"setup_mode",
"and",
"not",
"opts",
".",
"nowait",
":",
"for",
"master",
"in",
"mpstate",
".",
"mav_master",
":",
"if",
"master",
".",
"linknum",
"!=",
"0",
":",
"break",
"print",
"(",
"\"Waiting for heartbeat from %s\"",
"%",
"master",
".",
"address",
")",
"send_heartbeat",
"(",
"master",
")",
"master",
".",
"wait_heartbeat",
"(",
"timeout",
"=",
"0.1",
")",
"set_stream_rates",
"(",
")",
"while",
"True",
":",
"if",
"mpstate",
"is",
"None",
"or",
"mpstate",
".",
"status",
".",
"exit",
":",
"return",
"# enable or disable screensaver:",
"if",
"(",
"mpstate",
".",
"settings",
".",
"inhibit_screensaver_when_armed",
"and",
"screensaver_interface",
"is",
"not",
"None",
")",
":",
"if",
"mpstate",
".",
"status",
".",
"armed",
"and",
"screensaver_cookie",
"is",
"None",
":",
"# now we can inhibit the screensaver",
"screensaver_cookie",
"=",
"screensaver_interface",
".",
"Inhibit",
"(",
"\"MAVProxy\"",
",",
"\"Vehicle is armed\"",
")",
"elif",
"not",
"mpstate",
".",
"status",
".",
"armed",
"and",
"screensaver_cookie",
"is",
"not",
"None",
":",
"# we can also restore it",
"screensaver_interface",
".",
"UnInhibit",
"(",
"screensaver_cookie",
")",
"screensaver_cookie",
"=",
"None",
"while",
"not",
"mpstate",
".",
"input_queue",
".",
"empty",
"(",
")",
":",
"line",
"=",
"mpstate",
".",
"input_queue",
".",
"get",
"(",
")",
"mpstate",
".",
"input_count",
"+=",
"1",
"cmds",
"=",
"line",
".",
"split",
"(",
"';'",
")",
"if",
"len",
"(",
"cmds",
")",
"==",
"1",
"and",
"cmds",
"[",
"0",
"]",
"==",
"\"\"",
":",
"mpstate",
".",
"empty_input_count",
"+=",
"1",
"for",
"c",
"in",
"cmds",
":",
"process_stdin",
"(",
"c",
")",
"for",
"master",
"in",
"mpstate",
".",
"mav_master",
":",
"if",
"master",
".",
"fd",
"is",
"None",
":",
"if",
"master",
".",
"port",
".",
"inWaiting",
"(",
")",
">",
"0",
":",
"process_master",
"(",
"master",
")",
"periodic_tasks",
"(",
")",
"rin",
"=",
"[",
"]",
"for",
"master",
"in",
"mpstate",
".",
"mav_master",
":",
"if",
"master",
".",
"fd",
"is",
"not",
"None",
"and",
"not",
"master",
".",
"portdead",
":",
"rin",
".",
"append",
"(",
"master",
".",
"fd",
")",
"for",
"m",
"in",
"mpstate",
".",
"mav_outputs",
":",
"rin",
".",
"append",
"(",
"m",
".",
"fd",
")",
"for",
"sysid",
"in",
"mpstate",
".",
"sysid_outputs",
":",
"m",
"=",
"mpstate",
".",
"sysid_outputs",
"[",
"sysid",
"]",
"rin",
".",
"append",
"(",
"m",
".",
"fd",
")",
"if",
"rin",
"==",
"[",
"]",
":",
"time",
".",
"sleep",
"(",
"0.0001",
")",
"continue",
"for",
"fd",
"in",
"mpstate",
".",
"select_extra",
":",
"rin",
".",
"append",
"(",
"fd",
")",
"try",
":",
"(",
"rin",
",",
"win",
",",
"xin",
")",
"=",
"select",
".",
"select",
"(",
"rin",
",",
"[",
"]",
",",
"[",
"]",
",",
"mpstate",
".",
"settings",
".",
"select_timeout",
")",
"except",
"select",
".",
"error",
":",
"continue",
"if",
"mpstate",
"is",
"None",
":",
"return",
"for",
"fd",
"in",
"rin",
":",
"if",
"mpstate",
"is",
"None",
":",
"return",
"for",
"master",
"in",
"mpstate",
".",
"mav_master",
":",
"if",
"fd",
"==",
"master",
".",
"fd",
":",
"process_master",
"(",
"master",
")",
"if",
"mpstate",
"is",
"None",
":",
"return",
"continue",
"for",
"m",
"in",
"mpstate",
".",
"mav_outputs",
":",
"if",
"fd",
"==",
"m",
".",
"fd",
":",
"process_mavlink",
"(",
"m",
")",
"if",
"mpstate",
"is",
"None",
":",
"return",
"continue",
"for",
"sysid",
"in",
"mpstate",
".",
"sysid_outputs",
":",
"m",
"=",
"mpstate",
".",
"sysid_outputs",
"[",
"sysid",
"]",
"if",
"fd",
"==",
"m",
".",
"fd",
":",
"process_mavlink",
"(",
"m",
")",
"if",
"mpstate",
"is",
"None",
":",
"return",
"continue",
"# this allow modules to register their own file descriptors",
"# for the main select loop",
"if",
"fd",
"in",
"mpstate",
".",
"select_extra",
":",
"try",
":",
"# call the registered read function",
"(",
"fn",
",",
"args",
")",
"=",
"mpstate",
".",
"select_extra",
"[",
"fd",
"]",
"fn",
"(",
"args",
")",
"except",
"Exception",
"as",
"msg",
":",
"if",
"mpstate",
".",
"settings",
".",
"moddebug",
"==",
"1",
":",
"print",
"(",
"msg",
")",
"# on an exception, remove it from the select list",
"mpstate",
".",
"select_extra",
".",
"pop",
"(",
"fd",
")"
] | main processing loop | [
"main",
"processing",
"loop"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/mavproxy.py#L842-L946 |
249,517 | ArduPilot/MAVProxy | MAVProxy/mavproxy.py | set_mav_version | def set_mav_version(mav10, mav20, autoProtocol, mavversionArg):
'''Set the Mavlink version based on commandline options'''
# if(mav10 == True or mav20 == True or autoProtocol == True):
# print("Warning: Using deprecated --mav10, --mav20 or --auto-protocol options. Use --mavversion instead")
#sanity check the options
if (mav10 == True or mav20 == True) and autoProtocol == True:
print("Error: Can't have [--mav10, --mav20] and --auto-protocol both True")
sys.exit(1)
if mav10 == True and mav20 == True:
print("Error: Can't have --mav10 and --mav20 both True")
sys.exit(1)
if mavversionArg is not None and (mav10 == True or mav20 == True or autoProtocol == True):
print("Error: Can't use --mavversion with legacy (--mav10, --mav20 or --auto-protocol) options")
sys.exit(1)
#and set the specific mavlink version (False = autodetect)
global mavversion
if mavversionArg == "1.0" or mav10 == True:
os.environ['MAVLINK09'] = '1'
mavversion = "1"
else:
os.environ['MAVLINK20'] = '1'
mavversion = "2" | python | def set_mav_version(mav10, mav20, autoProtocol, mavversionArg):
'''Set the Mavlink version based on commandline options'''
# if(mav10 == True or mav20 == True or autoProtocol == True):
# print("Warning: Using deprecated --mav10, --mav20 or --auto-protocol options. Use --mavversion instead")
#sanity check the options
if (mav10 == True or mav20 == True) and autoProtocol == True:
print("Error: Can't have [--mav10, --mav20] and --auto-protocol both True")
sys.exit(1)
if mav10 == True and mav20 == True:
print("Error: Can't have --mav10 and --mav20 both True")
sys.exit(1)
if mavversionArg is not None and (mav10 == True or mav20 == True or autoProtocol == True):
print("Error: Can't use --mavversion with legacy (--mav10, --mav20 or --auto-protocol) options")
sys.exit(1)
#and set the specific mavlink version (False = autodetect)
global mavversion
if mavversionArg == "1.0" or mav10 == True:
os.environ['MAVLINK09'] = '1'
mavversion = "1"
else:
os.environ['MAVLINK20'] = '1'
mavversion = "2" | [
"def",
"set_mav_version",
"(",
"mav10",
",",
"mav20",
",",
"autoProtocol",
",",
"mavversionArg",
")",
":",
"# if(mav10 == True or mav20 == True or autoProtocol == True):",
"# print(\"Warning: Using deprecated --mav10, --mav20 or --auto-protocol options. Use --mavversion instead\")",
"#sanity check the options",
"if",
"(",
"mav10",
"==",
"True",
"or",
"mav20",
"==",
"True",
")",
"and",
"autoProtocol",
"==",
"True",
":",
"print",
"(",
"\"Error: Can't have [--mav10, --mav20] and --auto-protocol both True\"",
")",
"sys",
".",
"exit",
"(",
"1",
")",
"if",
"mav10",
"==",
"True",
"and",
"mav20",
"==",
"True",
":",
"print",
"(",
"\"Error: Can't have --mav10 and --mav20 both True\"",
")",
"sys",
".",
"exit",
"(",
"1",
")",
"if",
"mavversionArg",
"is",
"not",
"None",
"and",
"(",
"mav10",
"==",
"True",
"or",
"mav20",
"==",
"True",
"or",
"autoProtocol",
"==",
"True",
")",
":",
"print",
"(",
"\"Error: Can't use --mavversion with legacy (--mav10, --mav20 or --auto-protocol) options\"",
")",
"sys",
".",
"exit",
"(",
"1",
")",
"#and set the specific mavlink version (False = autodetect)",
"global",
"mavversion",
"if",
"mavversionArg",
"==",
"\"1.0\"",
"or",
"mav10",
"==",
"True",
":",
"os",
".",
"environ",
"[",
"'MAVLINK09'",
"]",
"=",
"'1'",
"mavversion",
"=",
"\"1\"",
"else",
":",
"os",
".",
"environ",
"[",
"'MAVLINK20'",
"]",
"=",
"'1'",
"mavversion",
"=",
"\"2\""
] | Set the Mavlink version based on commandline options | [
"Set",
"the",
"Mavlink",
"version",
"based",
"on",
"commandline",
"options"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/mavproxy.py#L988-L1011 |
249,518 | ArduPilot/MAVProxy | MAVProxy/mavproxy.py | MPState.mav_param | def mav_param(self):
'''map mav_param onto the current target system parameters'''
compid = self.settings.target_component
if compid == 0:
compid = 1
sysid = (self.settings.target_system, compid)
if not sysid in self.mav_param_by_sysid:
self.mav_param_by_sysid[sysid] = mavparm.MAVParmDict()
return self.mav_param_by_sysid[sysid] | python | def mav_param(self):
'''map mav_param onto the current target system parameters'''
compid = self.settings.target_component
if compid == 0:
compid = 1
sysid = (self.settings.target_system, compid)
if not sysid in self.mav_param_by_sysid:
self.mav_param_by_sysid[sysid] = mavparm.MAVParmDict()
return self.mav_param_by_sysid[sysid] | [
"def",
"mav_param",
"(",
"self",
")",
":",
"compid",
"=",
"self",
".",
"settings",
".",
"target_component",
"if",
"compid",
"==",
"0",
":",
"compid",
"=",
"1",
"sysid",
"=",
"(",
"self",
".",
"settings",
".",
"target_system",
",",
"compid",
")",
"if",
"not",
"sysid",
"in",
"self",
".",
"mav_param_by_sysid",
":",
"self",
".",
"mav_param_by_sysid",
"[",
"sysid",
"]",
"=",
"mavparm",
".",
"MAVParmDict",
"(",
")",
"return",
"self",
".",
"mav_param_by_sysid",
"[",
"sysid",
"]"
] | map mav_param onto the current target system parameters | [
"map",
"mav_param",
"onto",
"the",
"current",
"target",
"system",
"parameters"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/mavproxy.py#L245-L253 |
249,519 | ArduPilot/MAVProxy | MAVProxy/modules/lib/win_layout.py | get_wx_window_layout | def get_wx_window_layout(wx_window):
'''get a WinLayout for a wx window'''
dsize = wx.DisplaySize()
pos = wx_window.GetPosition()
size = wx_window.GetSize()
name = wx_window.GetTitle()
return WinLayout(name, pos, size, dsize) | python | def get_wx_window_layout(wx_window):
'''get a WinLayout for a wx window'''
dsize = wx.DisplaySize()
pos = wx_window.GetPosition()
size = wx_window.GetSize()
name = wx_window.GetTitle()
return WinLayout(name, pos, size, dsize) | [
"def",
"get_wx_window_layout",
"(",
"wx_window",
")",
":",
"dsize",
"=",
"wx",
".",
"DisplaySize",
"(",
")",
"pos",
"=",
"wx_window",
".",
"GetPosition",
"(",
")",
"size",
"=",
"wx_window",
".",
"GetSize",
"(",
")",
"name",
"=",
"wx_window",
".",
"GetTitle",
"(",
")",
"return",
"WinLayout",
"(",
"name",
",",
"pos",
",",
"size",
",",
"dsize",
")"
] | get a WinLayout for a wx window | [
"get",
"a",
"WinLayout",
"for",
"a",
"wx",
"window"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/win_layout.py#L35-L41 |
249,520 | ArduPilot/MAVProxy | MAVProxy/modules/lib/win_layout.py | set_wx_window_layout | def set_wx_window_layout(wx_window, layout):
'''set a WinLayout for a wx window'''
try:
wx_window.SetSize(layout.size)
wx_window.SetPosition(layout.pos)
except Exception as ex:
print(ex) | python | def set_wx_window_layout(wx_window, layout):
'''set a WinLayout for a wx window'''
try:
wx_window.SetSize(layout.size)
wx_window.SetPosition(layout.pos)
except Exception as ex:
print(ex) | [
"def",
"set_wx_window_layout",
"(",
"wx_window",
",",
"layout",
")",
":",
"try",
":",
"wx_window",
".",
"SetSize",
"(",
"layout",
".",
"size",
")",
"wx_window",
".",
"SetPosition",
"(",
"layout",
".",
"pos",
")",
"except",
"Exception",
"as",
"ex",
":",
"print",
"(",
"ex",
")"
] | set a WinLayout for a wx window | [
"set",
"a",
"WinLayout",
"for",
"a",
"wx",
"window"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/win_layout.py#L43-L49 |
249,521 | ArduPilot/MAVProxy | MAVProxy/modules/lib/win_layout.py | set_layout | def set_layout(wlayout, callback):
'''set window layout'''
global display_size
global window_list
global loaded_layout
global pending_load
global vehiclename
#if not wlayout.name in window_list:
# print("layout %s" % wlayout)
if not wlayout.name in window_list and loaded_layout is not None and wlayout.name in loaded_layout:
callback(loaded_layout[wlayout.name])
window_list[wlayout.name] = ManagedWindow(wlayout, callback)
display_size = wlayout.dsize
if pending_load:
pending_load = False
load_layout(vehiclename) | python | def set_layout(wlayout, callback):
'''set window layout'''
global display_size
global window_list
global loaded_layout
global pending_load
global vehiclename
#if not wlayout.name in window_list:
# print("layout %s" % wlayout)
if not wlayout.name in window_list and loaded_layout is not None and wlayout.name in loaded_layout:
callback(loaded_layout[wlayout.name])
window_list[wlayout.name] = ManagedWindow(wlayout, callback)
display_size = wlayout.dsize
if pending_load:
pending_load = False
load_layout(vehiclename) | [
"def",
"set_layout",
"(",
"wlayout",
",",
"callback",
")",
":",
"global",
"display_size",
"global",
"window_list",
"global",
"loaded_layout",
"global",
"pending_load",
"global",
"vehiclename",
"#if not wlayout.name in window_list:",
"# print(\"layout %s\" % wlayout)",
"if",
"not",
"wlayout",
".",
"name",
"in",
"window_list",
"and",
"loaded_layout",
"is",
"not",
"None",
"and",
"wlayout",
".",
"name",
"in",
"loaded_layout",
":",
"callback",
"(",
"loaded_layout",
"[",
"wlayout",
".",
"name",
"]",
")",
"window_list",
"[",
"wlayout",
".",
"name",
"]",
"=",
"ManagedWindow",
"(",
"wlayout",
",",
"callback",
")",
"display_size",
"=",
"wlayout",
".",
"dsize",
"if",
"pending_load",
":",
"pending_load",
"=",
"False",
"load_layout",
"(",
"vehiclename",
")"
] | set window layout | [
"set",
"window",
"layout"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/win_layout.py#L51-L66 |
249,522 | ArduPilot/MAVProxy | MAVProxy/modules/lib/win_layout.py | layout_filename | def layout_filename(fallback):
'''get location of layout file'''
global display_size
global vehiclename
(dw,dh) = display_size
if 'HOME' in os.environ:
dirname = os.path.join(os.environ['HOME'], ".mavproxy")
if not os.path.exists(dirname):
try:
os.mkdir(dirname)
except Exception:
pass
elif 'LOCALAPPDATA' in os.environ:
dirname = os.path.join(os.environ['LOCALAPPDATA'], "MAVProxy")
else:
return None
if vehiclename:
fname = os.path.join(dirname, "layout-%s-%ux%u" % (vehiclename,dw,dh))
if not fallback or os.path.exists(fname):
return fname
return os.path.join(dirname, "layout-%ux%u" % (dw,dh)) | python | def layout_filename(fallback):
'''get location of layout file'''
global display_size
global vehiclename
(dw,dh) = display_size
if 'HOME' in os.environ:
dirname = os.path.join(os.environ['HOME'], ".mavproxy")
if not os.path.exists(dirname):
try:
os.mkdir(dirname)
except Exception:
pass
elif 'LOCALAPPDATA' in os.environ:
dirname = os.path.join(os.environ['LOCALAPPDATA'], "MAVProxy")
else:
return None
if vehiclename:
fname = os.path.join(dirname, "layout-%s-%ux%u" % (vehiclename,dw,dh))
if not fallback or os.path.exists(fname):
return fname
return os.path.join(dirname, "layout-%ux%u" % (dw,dh)) | [
"def",
"layout_filename",
"(",
"fallback",
")",
":",
"global",
"display_size",
"global",
"vehiclename",
"(",
"dw",
",",
"dh",
")",
"=",
"display_size",
"if",
"'HOME'",
"in",
"os",
".",
"environ",
":",
"dirname",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"environ",
"[",
"'HOME'",
"]",
",",
"\".mavproxy\"",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"dirname",
")",
":",
"try",
":",
"os",
".",
"mkdir",
"(",
"dirname",
")",
"except",
"Exception",
":",
"pass",
"elif",
"'LOCALAPPDATA'",
"in",
"os",
".",
"environ",
":",
"dirname",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"environ",
"[",
"'LOCALAPPDATA'",
"]",
",",
"\"MAVProxy\"",
")",
"else",
":",
"return",
"None",
"if",
"vehiclename",
":",
"fname",
"=",
"os",
".",
"path",
".",
"join",
"(",
"dirname",
",",
"\"layout-%s-%ux%u\"",
"%",
"(",
"vehiclename",
",",
"dw",
",",
"dh",
")",
")",
"if",
"not",
"fallback",
"or",
"os",
".",
"path",
".",
"exists",
"(",
"fname",
")",
":",
"return",
"fname",
"return",
"os",
".",
"path",
".",
"join",
"(",
"dirname",
",",
"\"layout-%ux%u\"",
"%",
"(",
"dw",
",",
"dh",
")",
")"
] | get location of layout file | [
"get",
"location",
"of",
"layout",
"file"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/win_layout.py#L68-L88 |
249,523 | ArduPilot/MAVProxy | MAVProxy/modules/lib/win_layout.py | save_layout | def save_layout(vehname):
'''save window layout'''
global display_size
global window_list
global vehiclename
if display_size is None:
print("No layouts to save")
return
vehiclename = vehname
fname = layout_filename(False)
if fname is None:
print("No file to save layout to")
return
layout = {}
try:
# include previous layout, so we retain layouts for widows not
# currently displayed
layout = pickle.load(open(fname,"rb"))
except Exception:
pass
count = 0
for name in window_list:
layout[name] = window_list[name].layout
count += 1
pickle.dump(layout, open(fname,"wb"))
print("Saved layout for %u windows" % count) | python | def save_layout(vehname):
'''save window layout'''
global display_size
global window_list
global vehiclename
if display_size is None:
print("No layouts to save")
return
vehiclename = vehname
fname = layout_filename(False)
if fname is None:
print("No file to save layout to")
return
layout = {}
try:
# include previous layout, so we retain layouts for widows not
# currently displayed
layout = pickle.load(open(fname,"rb"))
except Exception:
pass
count = 0
for name in window_list:
layout[name] = window_list[name].layout
count += 1
pickle.dump(layout, open(fname,"wb"))
print("Saved layout for %u windows" % count) | [
"def",
"save_layout",
"(",
"vehname",
")",
":",
"global",
"display_size",
"global",
"window_list",
"global",
"vehiclename",
"if",
"display_size",
"is",
"None",
":",
"print",
"(",
"\"No layouts to save\"",
")",
"return",
"vehiclename",
"=",
"vehname",
"fname",
"=",
"layout_filename",
"(",
"False",
")",
"if",
"fname",
"is",
"None",
":",
"print",
"(",
"\"No file to save layout to\"",
")",
"return",
"layout",
"=",
"{",
"}",
"try",
":",
"# include previous layout, so we retain layouts for widows not",
"# currently displayed",
"layout",
"=",
"pickle",
".",
"load",
"(",
"open",
"(",
"fname",
",",
"\"rb\"",
")",
")",
"except",
"Exception",
":",
"pass",
"count",
"=",
"0",
"for",
"name",
"in",
"window_list",
":",
"layout",
"[",
"name",
"]",
"=",
"window_list",
"[",
"name",
"]",
".",
"layout",
"count",
"+=",
"1",
"pickle",
".",
"dump",
"(",
"layout",
",",
"open",
"(",
"fname",
",",
"\"wb\"",
")",
")",
"print",
"(",
"\"Saved layout for %u windows\"",
"%",
"count",
")"
] | save window layout | [
"save",
"window",
"layout"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/win_layout.py#L90-L115 |
249,524 | ArduPilot/MAVProxy | MAVProxy/modules/lib/win_layout.py | load_layout | def load_layout(vehname):
'''load window layout'''
global display_size
global window_list
global loaded_layout
global pending_load
global vehiclename
if display_size is None:
pending_load = True
return
vehiclename = vehname
fname = layout_filename(True)
if fname is None:
print("No file to load layout from")
return
try:
layout = pickle.load(open(fname,"rb"))
except Exception:
layout = {}
print("Unable to load %s" % fname)
loaded_layout = layout
return
count = 0
for name in window_list:
if name in layout:
try:
window_list[name].callback(layout[name])
count += 1
except Exception as ex:
print(ex)
loaded_layout = layout
print("Loaded layout for %u windows" % count) | python | def load_layout(vehname):
'''load window layout'''
global display_size
global window_list
global loaded_layout
global pending_load
global vehiclename
if display_size is None:
pending_load = True
return
vehiclename = vehname
fname = layout_filename(True)
if fname is None:
print("No file to load layout from")
return
try:
layout = pickle.load(open(fname,"rb"))
except Exception:
layout = {}
print("Unable to load %s" % fname)
loaded_layout = layout
return
count = 0
for name in window_list:
if name in layout:
try:
window_list[name].callback(layout[name])
count += 1
except Exception as ex:
print(ex)
loaded_layout = layout
print("Loaded layout for %u windows" % count) | [
"def",
"load_layout",
"(",
"vehname",
")",
":",
"global",
"display_size",
"global",
"window_list",
"global",
"loaded_layout",
"global",
"pending_load",
"global",
"vehiclename",
"if",
"display_size",
"is",
"None",
":",
"pending_load",
"=",
"True",
"return",
"vehiclename",
"=",
"vehname",
"fname",
"=",
"layout_filename",
"(",
"True",
")",
"if",
"fname",
"is",
"None",
":",
"print",
"(",
"\"No file to load layout from\"",
")",
"return",
"try",
":",
"layout",
"=",
"pickle",
".",
"load",
"(",
"open",
"(",
"fname",
",",
"\"rb\"",
")",
")",
"except",
"Exception",
":",
"layout",
"=",
"{",
"}",
"print",
"(",
"\"Unable to load %s\"",
"%",
"fname",
")",
"loaded_layout",
"=",
"layout",
"return",
"count",
"=",
"0",
"for",
"name",
"in",
"window_list",
":",
"if",
"name",
"in",
"layout",
":",
"try",
":",
"window_list",
"[",
"name",
"]",
".",
"callback",
"(",
"layout",
"[",
"name",
"]",
")",
"count",
"+=",
"1",
"except",
"Exception",
"as",
"ex",
":",
"print",
"(",
"ex",
")",
"loaded_layout",
"=",
"layout",
"print",
"(",
"\"Loaded layout for %u windows\"",
"%",
"count",
")"
] | load window layout | [
"load",
"window",
"layout"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/win_layout.py#L117-L148 |
249,525 | ArduPilot/MAVProxy | MAVProxy/modules/lib/wxsettings_ui.py | TabbedDialog.on_apply | def on_apply(self, event):
'''called on apply'''
for label in self.setting_map.keys():
setting = self.setting_map[label]
ctrl = self.controls[label]
value = ctrl.GetValue()
if str(value) != str(setting.value):
oldvalue = setting.value
if not setting.set(value):
print("Invalid value %s for %s" % (value, setting.name))
continue
if str(oldvalue) != str(setting.value):
self.parent_pipe.send(setting) | python | def on_apply(self, event):
'''called on apply'''
for label in self.setting_map.keys():
setting = self.setting_map[label]
ctrl = self.controls[label]
value = ctrl.GetValue()
if str(value) != str(setting.value):
oldvalue = setting.value
if not setting.set(value):
print("Invalid value %s for %s" % (value, setting.name))
continue
if str(oldvalue) != str(setting.value):
self.parent_pipe.send(setting) | [
"def",
"on_apply",
"(",
"self",
",",
"event",
")",
":",
"for",
"label",
"in",
"self",
".",
"setting_map",
".",
"keys",
"(",
")",
":",
"setting",
"=",
"self",
".",
"setting_map",
"[",
"label",
"]",
"ctrl",
"=",
"self",
".",
"controls",
"[",
"label",
"]",
"value",
"=",
"ctrl",
".",
"GetValue",
"(",
")",
"if",
"str",
"(",
"value",
")",
"!=",
"str",
"(",
"setting",
".",
"value",
")",
":",
"oldvalue",
"=",
"setting",
".",
"value",
"if",
"not",
"setting",
".",
"set",
"(",
"value",
")",
":",
"print",
"(",
"\"Invalid value %s for %s\"",
"%",
"(",
"value",
",",
"setting",
".",
"name",
")",
")",
"continue",
"if",
"str",
"(",
"oldvalue",
")",
"!=",
"str",
"(",
"setting",
".",
"value",
")",
":",
"self",
".",
"parent_pipe",
".",
"send",
"(",
"setting",
")"
] | called on apply | [
"called",
"on",
"apply"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/wxsettings_ui.py#L42-L54 |
249,526 | ArduPilot/MAVProxy | MAVProxy/modules/lib/wxsettings_ui.py | TabbedDialog.on_save | def on_save(self, event):
'''called on save button'''
dlg = wx.FileDialog(None, self.settings.get_title(), '', "", '*.*',
wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
if dlg.ShowModal() == wx.ID_OK:
self.settings.save(dlg.GetPath()) | python | def on_save(self, event):
'''called on save button'''
dlg = wx.FileDialog(None, self.settings.get_title(), '', "", '*.*',
wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
if dlg.ShowModal() == wx.ID_OK:
self.settings.save(dlg.GetPath()) | [
"def",
"on_save",
"(",
"self",
",",
"event",
")",
":",
"dlg",
"=",
"wx",
".",
"FileDialog",
"(",
"None",
",",
"self",
".",
"settings",
".",
"get_title",
"(",
")",
",",
"''",
",",
"\"\"",
",",
"'*.*'",
",",
"wx",
".",
"FD_SAVE",
"|",
"wx",
".",
"FD_OVERWRITE_PROMPT",
")",
"if",
"dlg",
".",
"ShowModal",
"(",
")",
"==",
"wx",
".",
"ID_OK",
":",
"self",
".",
"settings",
".",
"save",
"(",
"dlg",
".",
"GetPath",
"(",
")",
")"
] | called on save button | [
"called",
"on",
"save",
"button"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/wxsettings_ui.py#L56-L61 |
249,527 | ArduPilot/MAVProxy | MAVProxy/modules/lib/wxsettings_ui.py | TabbedDialog.on_load | def on_load(self, event):
'''called on load button'''
dlg = wx.FileDialog(None, self.settings.get_title(), '', "", '*.*', wx.FD_OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.settings.load(dlg.GetPath())
# update the controls with new values
for label in self.setting_map.keys():
setting = self.setting_map[label]
ctrl = self.controls[label]
value = ctrl.GetValue()
if isinstance(value, str) or isinstance(value, unicode):
ctrl.SetValue(str(setting.value))
else:
ctrl.SetValue(setting.value) | python | def on_load(self, event):
'''called on load button'''
dlg = wx.FileDialog(None, self.settings.get_title(), '', "", '*.*', wx.FD_OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.settings.load(dlg.GetPath())
# update the controls with new values
for label in self.setting_map.keys():
setting = self.setting_map[label]
ctrl = self.controls[label]
value = ctrl.GetValue()
if isinstance(value, str) or isinstance(value, unicode):
ctrl.SetValue(str(setting.value))
else:
ctrl.SetValue(setting.value) | [
"def",
"on_load",
"(",
"self",
",",
"event",
")",
":",
"dlg",
"=",
"wx",
".",
"FileDialog",
"(",
"None",
",",
"self",
".",
"settings",
".",
"get_title",
"(",
")",
",",
"''",
",",
"\"\"",
",",
"'*.*'",
",",
"wx",
".",
"FD_OPEN",
")",
"if",
"dlg",
".",
"ShowModal",
"(",
")",
"==",
"wx",
".",
"ID_OK",
":",
"self",
".",
"settings",
".",
"load",
"(",
"dlg",
".",
"GetPath",
"(",
")",
")",
"# update the controls with new values",
"for",
"label",
"in",
"self",
".",
"setting_map",
".",
"keys",
"(",
")",
":",
"setting",
"=",
"self",
".",
"setting_map",
"[",
"label",
"]",
"ctrl",
"=",
"self",
".",
"controls",
"[",
"label",
"]",
"value",
"=",
"ctrl",
".",
"GetValue",
"(",
")",
"if",
"isinstance",
"(",
"value",
",",
"str",
")",
"or",
"isinstance",
"(",
"value",
",",
"unicode",
")",
":",
"ctrl",
".",
"SetValue",
"(",
"str",
"(",
"setting",
".",
"value",
")",
")",
"else",
":",
"ctrl",
".",
"SetValue",
"(",
"setting",
".",
"value",
")"
] | called on load button | [
"called",
"on",
"load",
"button"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/wxsettings_ui.py#L63-L76 |
249,528 | ArduPilot/MAVProxy | MAVProxy/modules/lib/wxsettings_ui.py | TabbedDialog.add_text | def add_text(self, setting, width=300, height=100, multiline=False):
'''add a text input line'''
tab = self.panel(setting.tab)
if multiline:
ctrl = wx.TextCtrl(tab, -1, "", size=(width,height), style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER)
else:
ctrl = wx.TextCtrl(tab, -1, "", size=(width,-1) )
self._add_input(setting, ctrl) | python | def add_text(self, setting, width=300, height=100, multiline=False):
'''add a text input line'''
tab = self.panel(setting.tab)
if multiline:
ctrl = wx.TextCtrl(tab, -1, "", size=(width,height), style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER)
else:
ctrl = wx.TextCtrl(tab, -1, "", size=(width,-1) )
self._add_input(setting, ctrl) | [
"def",
"add_text",
"(",
"self",
",",
"setting",
",",
"width",
"=",
"300",
",",
"height",
"=",
"100",
",",
"multiline",
"=",
"False",
")",
":",
"tab",
"=",
"self",
".",
"panel",
"(",
"setting",
".",
"tab",
")",
"if",
"multiline",
":",
"ctrl",
"=",
"wx",
".",
"TextCtrl",
"(",
"tab",
",",
"-",
"1",
",",
"\"\"",
",",
"size",
"=",
"(",
"width",
",",
"height",
")",
",",
"style",
"=",
"wx",
".",
"TE_MULTILINE",
"|",
"wx",
".",
"TE_PROCESS_ENTER",
")",
"else",
":",
"ctrl",
"=",
"wx",
".",
"TextCtrl",
"(",
"tab",
",",
"-",
"1",
",",
"\"\"",
",",
"size",
"=",
"(",
"width",
",",
"-",
"1",
")",
")",
"self",
".",
"_add_input",
"(",
"setting",
",",
"ctrl",
")"
] | add a text input line | [
"add",
"a",
"text",
"input",
"line"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/wxsettings_ui.py#L109-L116 |
249,529 | ArduPilot/MAVProxy | MAVProxy/modules/lib/wxsettings_ui.py | TabbedDialog.add_choice | def add_choice(self, setting, choices):
'''add a choice input line'''
tab = self.panel(setting.tab)
default = setting.value
if default is None:
default = choices[0]
ctrl = wx.ComboBox(tab, -1, choices=choices,
value = str(default),
style = wx.CB_DROPDOWN | wx.CB_READONLY | wx.CB_SORT )
self._add_input(setting, ctrl) | python | def add_choice(self, setting, choices):
'''add a choice input line'''
tab = self.panel(setting.tab)
default = setting.value
if default is None:
default = choices[0]
ctrl = wx.ComboBox(tab, -1, choices=choices,
value = str(default),
style = wx.CB_DROPDOWN | wx.CB_READONLY | wx.CB_SORT )
self._add_input(setting, ctrl) | [
"def",
"add_choice",
"(",
"self",
",",
"setting",
",",
"choices",
")",
":",
"tab",
"=",
"self",
".",
"panel",
"(",
"setting",
".",
"tab",
")",
"default",
"=",
"setting",
".",
"value",
"if",
"default",
"is",
"None",
":",
"default",
"=",
"choices",
"[",
"0",
"]",
"ctrl",
"=",
"wx",
".",
"ComboBox",
"(",
"tab",
",",
"-",
"1",
",",
"choices",
"=",
"choices",
",",
"value",
"=",
"str",
"(",
"default",
")",
",",
"style",
"=",
"wx",
".",
"CB_DROPDOWN",
"|",
"wx",
".",
"CB_READONLY",
"|",
"wx",
".",
"CB_SORT",
")",
"self",
".",
"_add_input",
"(",
"setting",
",",
"ctrl",
")"
] | add a choice input line | [
"add",
"a",
"choice",
"input",
"line"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/wxsettings_ui.py#L118-L127 |
249,530 | ArduPilot/MAVProxy | MAVProxy/modules/lib/wxsettings_ui.py | TabbedDialog.add_intspin | def add_intspin(self, setting):
'''add a spin control'''
tab = self.panel(setting.tab)
default = setting.value
(minv, maxv) = setting.range
ctrl = wx.SpinCtrl(tab, -1,
initial = default,
min = minv,
max = maxv)
self._add_input(setting, ctrl, value=default) | python | def add_intspin(self, setting):
'''add a spin control'''
tab = self.panel(setting.tab)
default = setting.value
(minv, maxv) = setting.range
ctrl = wx.SpinCtrl(tab, -1,
initial = default,
min = minv,
max = maxv)
self._add_input(setting, ctrl, value=default) | [
"def",
"add_intspin",
"(",
"self",
",",
"setting",
")",
":",
"tab",
"=",
"self",
".",
"panel",
"(",
"setting",
".",
"tab",
")",
"default",
"=",
"setting",
".",
"value",
"(",
"minv",
",",
"maxv",
")",
"=",
"setting",
".",
"range",
"ctrl",
"=",
"wx",
".",
"SpinCtrl",
"(",
"tab",
",",
"-",
"1",
",",
"initial",
"=",
"default",
",",
"min",
"=",
"minv",
",",
"max",
"=",
"maxv",
")",
"self",
".",
"_add_input",
"(",
"setting",
",",
"ctrl",
",",
"value",
"=",
"default",
")"
] | add a spin control | [
"add",
"a",
"spin",
"control"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/wxsettings_ui.py#L129-L138 |
249,531 | ArduPilot/MAVProxy | MAVProxy/modules/lib/wxsettings_ui.py | TabbedDialog.add_floatspin | def add_floatspin(self, setting):
'''add a floating point spin control'''
from wx.lib.agw.floatspin import FloatSpin
tab = self.panel(setting.tab)
default = setting.value
(minv, maxv) = setting.range
ctrl = FloatSpin(tab, -1,
value = default,
min_val = minv,
max_val = maxv,
increment = setting.increment)
if setting.format is not None:
ctrl.SetFormat(setting.format)
if setting.digits is not None:
ctrl.SetDigits(setting.digits)
self._add_input(setting, ctrl, value=default) | python | def add_floatspin(self, setting):
'''add a floating point spin control'''
from wx.lib.agw.floatspin import FloatSpin
tab = self.panel(setting.tab)
default = setting.value
(minv, maxv) = setting.range
ctrl = FloatSpin(tab, -1,
value = default,
min_val = minv,
max_val = maxv,
increment = setting.increment)
if setting.format is not None:
ctrl.SetFormat(setting.format)
if setting.digits is not None:
ctrl.SetDigits(setting.digits)
self._add_input(setting, ctrl, value=default) | [
"def",
"add_floatspin",
"(",
"self",
",",
"setting",
")",
":",
"from",
"wx",
".",
"lib",
".",
"agw",
".",
"floatspin",
"import",
"FloatSpin",
"tab",
"=",
"self",
".",
"panel",
"(",
"setting",
".",
"tab",
")",
"default",
"=",
"setting",
".",
"value",
"(",
"minv",
",",
"maxv",
")",
"=",
"setting",
".",
"range",
"ctrl",
"=",
"FloatSpin",
"(",
"tab",
",",
"-",
"1",
",",
"value",
"=",
"default",
",",
"min_val",
"=",
"minv",
",",
"max_val",
"=",
"maxv",
",",
"increment",
"=",
"setting",
".",
"increment",
")",
"if",
"setting",
".",
"format",
"is",
"not",
"None",
":",
"ctrl",
".",
"SetFormat",
"(",
"setting",
".",
"format",
")",
"if",
"setting",
".",
"digits",
"is",
"not",
"None",
":",
"ctrl",
".",
"SetDigits",
"(",
"setting",
".",
"digits",
")",
"self",
".",
"_add_input",
"(",
"setting",
",",
"ctrl",
",",
"value",
"=",
"default",
")"
] | add a floating point spin control | [
"add",
"a",
"floating",
"point",
"spin",
"control"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/wxsettings_ui.py#L140-L156 |
249,532 | ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_agg.py | RendererAgg.draw_path | def draw_path(self, gc, path, transform, rgbFace=None):
"""
Draw the path
"""
nmax = rcParams['agg.path.chunksize'] # here at least for testing
npts = path.vertices.shape[0]
if (nmax > 100 and npts > nmax and path.should_simplify and
rgbFace is None and gc.get_hatch() is None):
nch = np.ceil(npts/float(nmax))
chsize = int(np.ceil(npts/nch))
i0 = np.arange(0, npts, chsize)
i1 = np.zeros_like(i0)
i1[:-1] = i0[1:] - 1
i1[-1] = npts
for ii0, ii1 in zip(i0, i1):
v = path.vertices[ii0:ii1,:]
c = path.codes
if c is not None:
c = c[ii0:ii1]
c[0] = Path.MOVETO # move to end of last chunk
p = Path(v, c)
self._renderer.draw_path(gc, p, transform, rgbFace)
else:
self._renderer.draw_path(gc, path, transform, rgbFace) | python | def draw_path(self, gc, path, transform, rgbFace=None):
nmax = rcParams['agg.path.chunksize'] # here at least for testing
npts = path.vertices.shape[0]
if (nmax > 100 and npts > nmax and path.should_simplify and
rgbFace is None and gc.get_hatch() is None):
nch = np.ceil(npts/float(nmax))
chsize = int(np.ceil(npts/nch))
i0 = np.arange(0, npts, chsize)
i1 = np.zeros_like(i0)
i1[:-1] = i0[1:] - 1
i1[-1] = npts
for ii0, ii1 in zip(i0, i1):
v = path.vertices[ii0:ii1,:]
c = path.codes
if c is not None:
c = c[ii0:ii1]
c[0] = Path.MOVETO # move to end of last chunk
p = Path(v, c)
self._renderer.draw_path(gc, p, transform, rgbFace)
else:
self._renderer.draw_path(gc, path, transform, rgbFace) | [
"def",
"draw_path",
"(",
"self",
",",
"gc",
",",
"path",
",",
"transform",
",",
"rgbFace",
"=",
"None",
")",
":",
"nmax",
"=",
"rcParams",
"[",
"'agg.path.chunksize'",
"]",
"# here at least for testing",
"npts",
"=",
"path",
".",
"vertices",
".",
"shape",
"[",
"0",
"]",
"if",
"(",
"nmax",
">",
"100",
"and",
"npts",
">",
"nmax",
"and",
"path",
".",
"should_simplify",
"and",
"rgbFace",
"is",
"None",
"and",
"gc",
".",
"get_hatch",
"(",
")",
"is",
"None",
")",
":",
"nch",
"=",
"np",
".",
"ceil",
"(",
"npts",
"/",
"float",
"(",
"nmax",
")",
")",
"chsize",
"=",
"int",
"(",
"np",
".",
"ceil",
"(",
"npts",
"/",
"nch",
")",
")",
"i0",
"=",
"np",
".",
"arange",
"(",
"0",
",",
"npts",
",",
"chsize",
")",
"i1",
"=",
"np",
".",
"zeros_like",
"(",
"i0",
")",
"i1",
"[",
":",
"-",
"1",
"]",
"=",
"i0",
"[",
"1",
":",
"]",
"-",
"1",
"i1",
"[",
"-",
"1",
"]",
"=",
"npts",
"for",
"ii0",
",",
"ii1",
"in",
"zip",
"(",
"i0",
",",
"i1",
")",
":",
"v",
"=",
"path",
".",
"vertices",
"[",
"ii0",
":",
"ii1",
",",
":",
"]",
"c",
"=",
"path",
".",
"codes",
"if",
"c",
"is",
"not",
"None",
":",
"c",
"=",
"c",
"[",
"ii0",
":",
"ii1",
"]",
"c",
"[",
"0",
"]",
"=",
"Path",
".",
"MOVETO",
"# move to end of last chunk",
"p",
"=",
"Path",
"(",
"v",
",",
"c",
")",
"self",
".",
"_renderer",
".",
"draw_path",
"(",
"gc",
",",
"p",
",",
"transform",
",",
"rgbFace",
")",
"else",
":",
"self",
".",
"_renderer",
".",
"draw_path",
"(",
"gc",
",",
"path",
",",
"transform",
",",
"rgbFace",
")"
] | Draw the path | [
"Draw",
"the",
"path"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_agg.py#L128-L151 |
249,533 | ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_agg.py | RendererAgg.draw_mathtext | def draw_mathtext(self, gc, x, y, s, prop, angle):
"""
Draw the math text using matplotlib.mathtext
"""
if __debug__: verbose.report('RendererAgg.draw_mathtext',
'debug-annoying')
ox, oy, width, height, descent, font_image, used_characters = \
self.mathtext_parser.parse(s, self.dpi, prop)
xd = descent * np.sin(np.deg2rad(angle))
yd = descent * np.cos(np.deg2rad(angle))
x = np.round(x + ox + xd)
y = np.round(y - oy + yd)
self._renderer.draw_text_image(font_image, x, y + 1, angle, gc) | python | def draw_mathtext(self, gc, x, y, s, prop, angle):
if __debug__: verbose.report('RendererAgg.draw_mathtext',
'debug-annoying')
ox, oy, width, height, descent, font_image, used_characters = \
self.mathtext_parser.parse(s, self.dpi, prop)
xd = descent * np.sin(np.deg2rad(angle))
yd = descent * np.cos(np.deg2rad(angle))
x = np.round(x + ox + xd)
y = np.round(y - oy + yd)
self._renderer.draw_text_image(font_image, x, y + 1, angle, gc) | [
"def",
"draw_mathtext",
"(",
"self",
",",
"gc",
",",
"x",
",",
"y",
",",
"s",
",",
"prop",
",",
"angle",
")",
":",
"if",
"__debug__",
":",
"verbose",
".",
"report",
"(",
"'RendererAgg.draw_mathtext'",
",",
"'debug-annoying'",
")",
"ox",
",",
"oy",
",",
"width",
",",
"height",
",",
"descent",
",",
"font_image",
",",
"used_characters",
"=",
"self",
".",
"mathtext_parser",
".",
"parse",
"(",
"s",
",",
"self",
".",
"dpi",
",",
"prop",
")",
"xd",
"=",
"descent",
"*",
"np",
".",
"sin",
"(",
"np",
".",
"deg2rad",
"(",
"angle",
")",
")",
"yd",
"=",
"descent",
"*",
"np",
".",
"cos",
"(",
"np",
".",
"deg2rad",
"(",
"angle",
")",
")",
"x",
"=",
"np",
".",
"round",
"(",
"x",
"+",
"ox",
"+",
"xd",
")",
"y",
"=",
"np",
".",
"round",
"(",
"y",
"-",
"oy",
"+",
"yd",
")",
"self",
".",
"_renderer",
".",
"draw_text_image",
"(",
"font_image",
",",
"x",
",",
"y",
"+",
"1",
",",
"angle",
",",
"gc",
")"
] | Draw the math text using matplotlib.mathtext | [
"Draw",
"the",
"math",
"text",
"using",
"matplotlib",
".",
"mathtext"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_agg.py#L153-L166 |
249,534 | ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_agg.py | RendererAgg.draw_text | def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
"""
Render the text
"""
if __debug__: verbose.report('RendererAgg.draw_text', 'debug-annoying')
if ismath:
return self.draw_mathtext(gc, x, y, s, prop, angle)
flags = get_hinting_flag()
font = self._get_agg_font(prop)
if font is None: return None
if len(s) == 1 and ord(s) > 127:
font.load_char(ord(s), flags=flags)
else:
# We pass '0' for angle here, since it will be rotated (in raster
# space) in the following call to draw_text_image).
font.set_text(s, 0, flags=flags)
font.draw_glyphs_to_bitmap(antialiased=rcParams['text.antialiased'])
d = font.get_descent() / 64.0
# The descent needs to be adjusted for the angle
xd = -d * np.sin(np.deg2rad(angle))
yd = d * np.cos(np.deg2rad(angle))
#print x, y, int(x), int(y), s
self._renderer.draw_text_image(
font.get_image(), np.round(x - xd), np.round(y + yd) + 1, angle, gc) | python | def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
if __debug__: verbose.report('RendererAgg.draw_text', 'debug-annoying')
if ismath:
return self.draw_mathtext(gc, x, y, s, prop, angle)
flags = get_hinting_flag()
font = self._get_agg_font(prop)
if font is None: return None
if len(s) == 1 and ord(s) > 127:
font.load_char(ord(s), flags=flags)
else:
# We pass '0' for angle here, since it will be rotated (in raster
# space) in the following call to draw_text_image).
font.set_text(s, 0, flags=flags)
font.draw_glyphs_to_bitmap(antialiased=rcParams['text.antialiased'])
d = font.get_descent() / 64.0
# The descent needs to be adjusted for the angle
xd = -d * np.sin(np.deg2rad(angle))
yd = d * np.cos(np.deg2rad(angle))
#print x, y, int(x), int(y), s
self._renderer.draw_text_image(
font.get_image(), np.round(x - xd), np.round(y + yd) + 1, angle, gc) | [
"def",
"draw_text",
"(",
"self",
",",
"gc",
",",
"x",
",",
"y",
",",
"s",
",",
"prop",
",",
"angle",
",",
"ismath",
"=",
"False",
",",
"mtext",
"=",
"None",
")",
":",
"if",
"__debug__",
":",
"verbose",
".",
"report",
"(",
"'RendererAgg.draw_text'",
",",
"'debug-annoying'",
")",
"if",
"ismath",
":",
"return",
"self",
".",
"draw_mathtext",
"(",
"gc",
",",
"x",
",",
"y",
",",
"s",
",",
"prop",
",",
"angle",
")",
"flags",
"=",
"get_hinting_flag",
"(",
")",
"font",
"=",
"self",
".",
"_get_agg_font",
"(",
"prop",
")",
"if",
"font",
"is",
"None",
":",
"return",
"None",
"if",
"len",
"(",
"s",
")",
"==",
"1",
"and",
"ord",
"(",
"s",
")",
">",
"127",
":",
"font",
".",
"load_char",
"(",
"ord",
"(",
"s",
")",
",",
"flags",
"=",
"flags",
")",
"else",
":",
"# We pass '0' for angle here, since it will be rotated (in raster",
"# space) in the following call to draw_text_image).",
"font",
".",
"set_text",
"(",
"s",
",",
"0",
",",
"flags",
"=",
"flags",
")",
"font",
".",
"draw_glyphs_to_bitmap",
"(",
"antialiased",
"=",
"rcParams",
"[",
"'text.antialiased'",
"]",
")",
"d",
"=",
"font",
".",
"get_descent",
"(",
")",
"/",
"64.0",
"# The descent needs to be adjusted for the angle",
"xd",
"=",
"-",
"d",
"*",
"np",
".",
"sin",
"(",
"np",
".",
"deg2rad",
"(",
"angle",
")",
")",
"yd",
"=",
"d",
"*",
"np",
".",
"cos",
"(",
"np",
".",
"deg2rad",
"(",
"angle",
")",
")",
"#print x, y, int(x), int(y), s",
"self",
".",
"_renderer",
".",
"draw_text_image",
"(",
"font",
".",
"get_image",
"(",
")",
",",
"np",
".",
"round",
"(",
"x",
"-",
"xd",
")",
",",
"np",
".",
"round",
"(",
"y",
"+",
"yd",
")",
"+",
"1",
",",
"angle",
",",
"gc",
")"
] | Render the text | [
"Render",
"the",
"text"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_agg.py#L168-L194 |
249,535 | ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_agg.py | RendererAgg._get_agg_font | def _get_agg_font(self, prop):
"""
Get the font for text instance t, cacheing for efficiency
"""
if __debug__: verbose.report('RendererAgg._get_agg_font',
'debug-annoying')
key = hash(prop)
font = RendererAgg._fontd.get(key)
if font is None:
fname = findfont(prop)
font = RendererAgg._fontd.get(fname)
if font is None:
font = FT2Font(
str(fname),
hinting_factor=rcParams['text.hinting_factor'])
RendererAgg._fontd[fname] = font
RendererAgg._fontd[key] = font
font.clear()
size = prop.get_size_in_points()
font.set_size(size, self.dpi)
return font | python | def _get_agg_font(self, prop):
if __debug__: verbose.report('RendererAgg._get_agg_font',
'debug-annoying')
key = hash(prop)
font = RendererAgg._fontd.get(key)
if font is None:
fname = findfont(prop)
font = RendererAgg._fontd.get(fname)
if font is None:
font = FT2Font(
str(fname),
hinting_factor=rcParams['text.hinting_factor'])
RendererAgg._fontd[fname] = font
RendererAgg._fontd[key] = font
font.clear()
size = prop.get_size_in_points()
font.set_size(size, self.dpi)
return font | [
"def",
"_get_agg_font",
"(",
"self",
",",
"prop",
")",
":",
"if",
"__debug__",
":",
"verbose",
".",
"report",
"(",
"'RendererAgg._get_agg_font'",
",",
"'debug-annoying'",
")",
"key",
"=",
"hash",
"(",
"prop",
")",
"font",
"=",
"RendererAgg",
".",
"_fontd",
".",
"get",
"(",
"key",
")",
"if",
"font",
"is",
"None",
":",
"fname",
"=",
"findfont",
"(",
"prop",
")",
"font",
"=",
"RendererAgg",
".",
"_fontd",
".",
"get",
"(",
"fname",
")",
"if",
"font",
"is",
"None",
":",
"font",
"=",
"FT2Font",
"(",
"str",
"(",
"fname",
")",
",",
"hinting_factor",
"=",
"rcParams",
"[",
"'text.hinting_factor'",
"]",
")",
"RendererAgg",
".",
"_fontd",
"[",
"fname",
"]",
"=",
"font",
"RendererAgg",
".",
"_fontd",
"[",
"key",
"]",
"=",
"font",
"font",
".",
"clear",
"(",
")",
"size",
"=",
"prop",
".",
"get_size_in_points",
"(",
")",
"font",
".",
"set_size",
"(",
"size",
",",
"self",
".",
"dpi",
")",
"return",
"font"
] | Get the font for text instance t, cacheing for efficiency | [
"Get",
"the",
"font",
"for",
"text",
"instance",
"t",
"cacheing",
"for",
"efficiency"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_agg.py#L253-L277 |
249,536 | ArduPilot/MAVProxy | MAVProxy/modules/lib/MacOS/backend_agg.py | FigureCanvasAgg.draw | def draw(self):
"""
Draw the figure using the renderer
"""
if __debug__: verbose.report('FigureCanvasAgg.draw', 'debug-annoying')
self.renderer = self.get_renderer(cleared=True)
# acquire a lock on the shared font cache
RendererAgg.lock.acquire()
try:
self.figure.draw(self.renderer)
finally:
RendererAgg.lock.release() | python | def draw(self):
if __debug__: verbose.report('FigureCanvasAgg.draw', 'debug-annoying')
self.renderer = self.get_renderer(cleared=True)
# acquire a lock on the shared font cache
RendererAgg.lock.acquire()
try:
self.figure.draw(self.renderer)
finally:
RendererAgg.lock.release() | [
"def",
"draw",
"(",
"self",
")",
":",
"if",
"__debug__",
":",
"verbose",
".",
"report",
"(",
"'FigureCanvasAgg.draw'",
",",
"'debug-annoying'",
")",
"self",
".",
"renderer",
"=",
"self",
".",
"get_renderer",
"(",
"cleared",
"=",
"True",
")",
"# acquire a lock on the shared font cache",
"RendererAgg",
".",
"lock",
".",
"acquire",
"(",
")",
"try",
":",
"self",
".",
"figure",
".",
"draw",
"(",
"self",
".",
"renderer",
")",
"finally",
":",
"RendererAgg",
".",
"lock",
".",
"release",
"(",
")"
] | Draw the figure using the renderer | [
"Draw",
"the",
"figure",
"using",
"the",
"renderer"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/MacOS/backend_agg.py#L446-L459 |
249,537 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_console.py | ConsoleModule.vehicle_type_string | def vehicle_type_string(self, hb):
'''return vehicle type string from a heartbeat'''
if hb.type == mavutil.mavlink.MAV_TYPE_FIXED_WING:
return 'Plane'
if hb.type == mavutil.mavlink.MAV_TYPE_GROUND_ROVER:
return 'Rover'
if hb.type == mavutil.mavlink.MAV_TYPE_SURFACE_BOAT:
return 'Boat'
if hb.type == mavutil.mavlink.MAV_TYPE_SUBMARINE:
return 'Sub'
if hb.type in [mavutil.mavlink.MAV_TYPE_QUADROTOR,
mavutil.mavlink.MAV_TYPE_COAXIAL,
mavutil.mavlink.MAV_TYPE_HEXAROTOR,
mavutil.mavlink.MAV_TYPE_OCTOROTOR,
mavutil.mavlink.MAV_TYPE_TRICOPTER,
mavutil.mavlink.MAV_TYPE_DODECAROTOR]:
return "Copter"
if hb.type == mavutil.mavlink.MAV_TYPE_HELICOPTER:
return "Heli"
if hb.type == mavutil.mavlink.MAV_TYPE_ANTENNA_TRACKER:
return "Tracker"
return "UNKNOWN(%u)" % hb.type | python | def vehicle_type_string(self, hb):
'''return vehicle type string from a heartbeat'''
if hb.type == mavutil.mavlink.MAV_TYPE_FIXED_WING:
return 'Plane'
if hb.type == mavutil.mavlink.MAV_TYPE_GROUND_ROVER:
return 'Rover'
if hb.type == mavutil.mavlink.MAV_TYPE_SURFACE_BOAT:
return 'Boat'
if hb.type == mavutil.mavlink.MAV_TYPE_SUBMARINE:
return 'Sub'
if hb.type in [mavutil.mavlink.MAV_TYPE_QUADROTOR,
mavutil.mavlink.MAV_TYPE_COAXIAL,
mavutil.mavlink.MAV_TYPE_HEXAROTOR,
mavutil.mavlink.MAV_TYPE_OCTOROTOR,
mavutil.mavlink.MAV_TYPE_TRICOPTER,
mavutil.mavlink.MAV_TYPE_DODECAROTOR]:
return "Copter"
if hb.type == mavutil.mavlink.MAV_TYPE_HELICOPTER:
return "Heli"
if hb.type == mavutil.mavlink.MAV_TYPE_ANTENNA_TRACKER:
return "Tracker"
return "UNKNOWN(%u)" % hb.type | [
"def",
"vehicle_type_string",
"(",
"self",
",",
"hb",
")",
":",
"if",
"hb",
".",
"type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_FIXED_WING",
":",
"return",
"'Plane'",
"if",
"hb",
".",
"type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_GROUND_ROVER",
":",
"return",
"'Rover'",
"if",
"hb",
".",
"type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_SURFACE_BOAT",
":",
"return",
"'Boat'",
"if",
"hb",
".",
"type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_SUBMARINE",
":",
"return",
"'Sub'",
"if",
"hb",
".",
"type",
"in",
"[",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_QUADROTOR",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_COAXIAL",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_HEXAROTOR",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_OCTOROTOR",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_TRICOPTER",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_DODECAROTOR",
"]",
":",
"return",
"\"Copter\"",
"if",
"hb",
".",
"type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_HELICOPTER",
":",
"return",
"\"Heli\"",
"if",
"hb",
".",
"type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_ANTENNA_TRACKER",
":",
"return",
"\"Tracker\"",
"return",
"\"UNKNOWN(%u)\"",
"%",
"hb",
".",
"type"
] | return vehicle type string from a heartbeat | [
"return",
"vehicle",
"type",
"string",
"from",
"a",
"heartbeat"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_console.py#L130-L151 |
249,538 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_console.py | ConsoleModule.update_vehicle_menu | def update_vehicle_menu(self):
'''update menu for new vehicles'''
self.vehicle_menu.items = []
for s in sorted(self.vehicle_list):
clist = self.module('param').get_component_id_list(s)
if len(clist) == 1:
name = 'SysID %u: %s' % (s, self.vehicle_name_by_sysid[s])
self.vehicle_menu.items.append(MPMenuItem(name, name, '# vehicle %u' % s))
else:
for c in sorted(clist):
try:
name = 'SysID %u[%u]: %s' % (s, c, self.component_name[s][c])
except KeyError as e:
name = 'SysID %u[%u]: ?' % (s,c)
self.vehicle_menu.items.append(MPMenuItem(name, name, '# vehicle %u:%u' % (s,c)))
self.mpstate.console.set_menu(self.menu, self.menu_callback) | python | def update_vehicle_menu(self):
'''update menu for new vehicles'''
self.vehicle_menu.items = []
for s in sorted(self.vehicle_list):
clist = self.module('param').get_component_id_list(s)
if len(clist) == 1:
name = 'SysID %u: %s' % (s, self.vehicle_name_by_sysid[s])
self.vehicle_menu.items.append(MPMenuItem(name, name, '# vehicle %u' % s))
else:
for c in sorted(clist):
try:
name = 'SysID %u[%u]: %s' % (s, c, self.component_name[s][c])
except KeyError as e:
name = 'SysID %u[%u]: ?' % (s,c)
self.vehicle_menu.items.append(MPMenuItem(name, name, '# vehicle %u:%u' % (s,c)))
self.mpstate.console.set_menu(self.menu, self.menu_callback) | [
"def",
"update_vehicle_menu",
"(",
"self",
")",
":",
"self",
".",
"vehicle_menu",
".",
"items",
"=",
"[",
"]",
"for",
"s",
"in",
"sorted",
"(",
"self",
".",
"vehicle_list",
")",
":",
"clist",
"=",
"self",
".",
"module",
"(",
"'param'",
")",
".",
"get_component_id_list",
"(",
"s",
")",
"if",
"len",
"(",
"clist",
")",
"==",
"1",
":",
"name",
"=",
"'SysID %u: %s'",
"%",
"(",
"s",
",",
"self",
".",
"vehicle_name_by_sysid",
"[",
"s",
"]",
")",
"self",
".",
"vehicle_menu",
".",
"items",
".",
"append",
"(",
"MPMenuItem",
"(",
"name",
",",
"name",
",",
"'# vehicle %u'",
"%",
"s",
")",
")",
"else",
":",
"for",
"c",
"in",
"sorted",
"(",
"clist",
")",
":",
"try",
":",
"name",
"=",
"'SysID %u[%u]: %s'",
"%",
"(",
"s",
",",
"c",
",",
"self",
".",
"component_name",
"[",
"s",
"]",
"[",
"c",
"]",
")",
"except",
"KeyError",
"as",
"e",
":",
"name",
"=",
"'SysID %u[%u]: ?'",
"%",
"(",
"s",
",",
"c",
")",
"self",
".",
"vehicle_menu",
".",
"items",
".",
"append",
"(",
"MPMenuItem",
"(",
"name",
",",
"name",
",",
"'# vehicle %u:%u'",
"%",
"(",
"s",
",",
"c",
")",
")",
")",
"self",
".",
"mpstate",
".",
"console",
".",
"set_menu",
"(",
"self",
".",
"menu",
",",
"self",
".",
"menu_callback",
")"
] | update menu for new vehicles | [
"update",
"menu",
"for",
"new",
"vehicles"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_console.py#L165-L180 |
249,539 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_console.py | ConsoleModule.add_new_vehicle | def add_new_vehicle(self, hb):
'''add a new vehicle'''
if hb.type == mavutil.mavlink.MAV_TYPE_GCS:
return
sysid = hb.get_srcSystem()
self.vehicle_list.append(sysid)
self.vehicle_name_by_sysid[sysid] = self.vehicle_type_string(hb)
self.update_vehicle_menu() | python | def add_new_vehicle(self, hb):
'''add a new vehicle'''
if hb.type == mavutil.mavlink.MAV_TYPE_GCS:
return
sysid = hb.get_srcSystem()
self.vehicle_list.append(sysid)
self.vehicle_name_by_sysid[sysid] = self.vehicle_type_string(hb)
self.update_vehicle_menu() | [
"def",
"add_new_vehicle",
"(",
"self",
",",
"hb",
")",
":",
"if",
"hb",
".",
"type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_GCS",
":",
"return",
"sysid",
"=",
"hb",
".",
"get_srcSystem",
"(",
")",
"self",
".",
"vehicle_list",
".",
"append",
"(",
"sysid",
")",
"self",
".",
"vehicle_name_by_sysid",
"[",
"sysid",
"]",
"=",
"self",
".",
"vehicle_type_string",
"(",
"hb",
")",
"self",
".",
"update_vehicle_menu",
"(",
")"
] | add a new vehicle | [
"add",
"a",
"new",
"vehicle"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_console.py#L182-L189 |
249,540 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_speech.py | SpeechModule.say_espeak | def say_espeak(self, text, priority='important'):
'''speak some text using espeak'''
from espeak import espeak
if self.settings.speech_voice:
espeak.set_voice(self.settings.speech_voice)
espeak.synth(text) | python | def say_espeak(self, text, priority='important'):
'''speak some text using espeak'''
from espeak import espeak
if self.settings.speech_voice:
espeak.set_voice(self.settings.speech_voice)
espeak.synth(text) | [
"def",
"say_espeak",
"(",
"self",
",",
"text",
",",
"priority",
"=",
"'important'",
")",
":",
"from",
"espeak",
"import",
"espeak",
"if",
"self",
".",
"settings",
".",
"speech_voice",
":",
"espeak",
".",
"set_voice",
"(",
"self",
".",
"settings",
".",
"speech_voice",
")",
"espeak",
".",
"synth",
"(",
"text",
")"
] | speak some text using espeak | [
"speak",
"some",
"text",
"using",
"espeak"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_speech.py#L71-L76 |
249,541 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_cmdlong.py | CmdlongModule.cmd_long | def cmd_long(self, args):
'''execute supplied command long'''
if len(args) < 1:
print("Usage: long <command> [arg1] [arg2]...")
return
command = None
if args[0].isdigit():
command = int(args[0])
else:
try:
command = eval("mavutil.mavlink." + args[0])
except AttributeError as e:
try:
command = eval("mavutil.mavlink.MAV_CMD_" + args[0])
except AttributeError as e:
pass
if command is None:
print("Unknown command long ({0})".format(args[0]))
return
floating_args = [ float(x) for x in args[1:] ]
while len(floating_args) < 7:
floating_args.append(float(0))
self.master.mav.command_long_send(self.settings.target_system,
self.settings.target_component,
command,
0,
*floating_args) | python | def cmd_long(self, args):
'''execute supplied command long'''
if len(args) < 1:
print("Usage: long <command> [arg1] [arg2]...")
return
command = None
if args[0].isdigit():
command = int(args[0])
else:
try:
command = eval("mavutil.mavlink." + args[0])
except AttributeError as e:
try:
command = eval("mavutil.mavlink.MAV_CMD_" + args[0])
except AttributeError as e:
pass
if command is None:
print("Unknown command long ({0})".format(args[0]))
return
floating_args = [ float(x) for x in args[1:] ]
while len(floating_args) < 7:
floating_args.append(float(0))
self.master.mav.command_long_send(self.settings.target_system,
self.settings.target_component,
command,
0,
*floating_args) | [
"def",
"cmd_long",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"<",
"1",
":",
"print",
"(",
"\"Usage: long <command> [arg1] [arg2]...\"",
")",
"return",
"command",
"=",
"None",
"if",
"args",
"[",
"0",
"]",
".",
"isdigit",
"(",
")",
":",
"command",
"=",
"int",
"(",
"args",
"[",
"0",
"]",
")",
"else",
":",
"try",
":",
"command",
"=",
"eval",
"(",
"\"mavutil.mavlink.\"",
"+",
"args",
"[",
"0",
"]",
")",
"except",
"AttributeError",
"as",
"e",
":",
"try",
":",
"command",
"=",
"eval",
"(",
"\"mavutil.mavlink.MAV_CMD_\"",
"+",
"args",
"[",
"0",
"]",
")",
"except",
"AttributeError",
"as",
"e",
":",
"pass",
"if",
"command",
"is",
"None",
":",
"print",
"(",
"\"Unknown command long ({0})\"",
".",
"format",
"(",
"args",
"[",
"0",
"]",
")",
")",
"return",
"floating_args",
"=",
"[",
"float",
"(",
"x",
")",
"for",
"x",
"in",
"args",
"[",
"1",
":",
"]",
"]",
"while",
"len",
"(",
"floating_args",
")",
"<",
"7",
":",
"floating_args",
".",
"append",
"(",
"float",
"(",
"0",
")",
")",
"self",
".",
"master",
".",
"mav",
".",
"command_long_send",
"(",
"self",
".",
"settings",
".",
"target_system",
",",
"self",
".",
"settings",
".",
"target_component",
",",
"command",
",",
"0",
",",
"*",
"floating_args",
")"
] | execute supplied command long | [
"execute",
"supplied",
"command",
"long"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_cmdlong.py#L316-L344 |
249,542 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_cmdlong.py | CmdlongModule.cmd_command_int | def cmd_command_int(self, args):
'''execute supplied command_int'''
if len(args) != 11:
print("num args{0}".format(len(args)))
print("Usage: command_int frame command current autocontinue param1 param2 param3 param4 x y z")
print("e.g. command_int GLOBAL_RELATIVE_ALT DO_SET_HOME 0 0 0 0 0 0 -353632120 1491659330 0")
print("e.g. command_int GLOBAL MAV_CMD_DO_SET_ROI 0 0 0 0 0 0 5000000 5000000 500")
return
if args[0].isdigit():
frame = int(args[0])
else:
try:
# attempt to allow MAV_FRAME_GLOBAL for frame
frame = eval("mavutil.mavlink." + args[0])
except AttributeError as e:
try:
# attempt to allow GLOBAL for frame
frame = eval("mavutil.mavlink.MAV_FRAME_" + args[0])
except AttributeError as e:
pass
if frame is None:
print("Unknown frame ({0})".format(args[0]))
return
command = None
if args[1].isdigit():
command = int(args[1])
else:
# let "command_int ... MAV_CMD_DO_SET_HOME ..." work
try:
command = eval("mavutil.mavlink." + args[1])
except AttributeError as e:
try:
# let "command_int ... DO_SET_HOME" work
command = eval("mavutil.mavlink.MAV_CMD_" + args[1])
except AttributeError as e:
pass
current = int(args[2])
autocontinue = int(args[3])
param1 = float(args[4])
param2 = float(args[5])
param3 = float(args[6])
param4 = float(args[7])
x = int(args[8])
y = int(args[9])
z = float(args[10])
self.master.mav.command_int_send(self.settings.target_system,
self.settings.target_component,
frame,
command,
0,
0,
param1,
param2,
param3,
param4,
x,
y,
z) | python | def cmd_command_int(self, args):
'''execute supplied command_int'''
if len(args) != 11:
print("num args{0}".format(len(args)))
print("Usage: command_int frame command current autocontinue param1 param2 param3 param4 x y z")
print("e.g. command_int GLOBAL_RELATIVE_ALT DO_SET_HOME 0 0 0 0 0 0 -353632120 1491659330 0")
print("e.g. command_int GLOBAL MAV_CMD_DO_SET_ROI 0 0 0 0 0 0 5000000 5000000 500")
return
if args[0].isdigit():
frame = int(args[0])
else:
try:
# attempt to allow MAV_FRAME_GLOBAL for frame
frame = eval("mavutil.mavlink." + args[0])
except AttributeError as e:
try:
# attempt to allow GLOBAL for frame
frame = eval("mavutil.mavlink.MAV_FRAME_" + args[0])
except AttributeError as e:
pass
if frame is None:
print("Unknown frame ({0})".format(args[0]))
return
command = None
if args[1].isdigit():
command = int(args[1])
else:
# let "command_int ... MAV_CMD_DO_SET_HOME ..." work
try:
command = eval("mavutil.mavlink." + args[1])
except AttributeError as e:
try:
# let "command_int ... DO_SET_HOME" work
command = eval("mavutil.mavlink.MAV_CMD_" + args[1])
except AttributeError as e:
pass
current = int(args[2])
autocontinue = int(args[3])
param1 = float(args[4])
param2 = float(args[5])
param3 = float(args[6])
param4 = float(args[7])
x = int(args[8])
y = int(args[9])
z = float(args[10])
self.master.mav.command_int_send(self.settings.target_system,
self.settings.target_component,
frame,
command,
0,
0,
param1,
param2,
param3,
param4,
x,
y,
z) | [
"def",
"cmd_command_int",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"!=",
"11",
":",
"print",
"(",
"\"num args{0}\"",
".",
"format",
"(",
"len",
"(",
"args",
")",
")",
")",
"print",
"(",
"\"Usage: command_int frame command current autocontinue param1 param2 param3 param4 x y z\"",
")",
"print",
"(",
"\"e.g. command_int GLOBAL_RELATIVE_ALT DO_SET_HOME 0 0 0 0 0 0 -353632120 1491659330 0\"",
")",
"print",
"(",
"\"e.g. command_int GLOBAL MAV_CMD_DO_SET_ROI 0 0 0 0 0 0 5000000 5000000 500\"",
")",
"return",
"if",
"args",
"[",
"0",
"]",
".",
"isdigit",
"(",
")",
":",
"frame",
"=",
"int",
"(",
"args",
"[",
"0",
"]",
")",
"else",
":",
"try",
":",
"# attempt to allow MAV_FRAME_GLOBAL for frame",
"frame",
"=",
"eval",
"(",
"\"mavutil.mavlink.\"",
"+",
"args",
"[",
"0",
"]",
")",
"except",
"AttributeError",
"as",
"e",
":",
"try",
":",
"# attempt to allow GLOBAL for frame",
"frame",
"=",
"eval",
"(",
"\"mavutil.mavlink.MAV_FRAME_\"",
"+",
"args",
"[",
"0",
"]",
")",
"except",
"AttributeError",
"as",
"e",
":",
"pass",
"if",
"frame",
"is",
"None",
":",
"print",
"(",
"\"Unknown frame ({0})\"",
".",
"format",
"(",
"args",
"[",
"0",
"]",
")",
")",
"return",
"command",
"=",
"None",
"if",
"args",
"[",
"1",
"]",
".",
"isdigit",
"(",
")",
":",
"command",
"=",
"int",
"(",
"args",
"[",
"1",
"]",
")",
"else",
":",
"# let \"command_int ... MAV_CMD_DO_SET_HOME ...\" work",
"try",
":",
"command",
"=",
"eval",
"(",
"\"mavutil.mavlink.\"",
"+",
"args",
"[",
"1",
"]",
")",
"except",
"AttributeError",
"as",
"e",
":",
"try",
":",
"# let \"command_int ... DO_SET_HOME\" work",
"command",
"=",
"eval",
"(",
"\"mavutil.mavlink.MAV_CMD_\"",
"+",
"args",
"[",
"1",
"]",
")",
"except",
"AttributeError",
"as",
"e",
":",
"pass",
"current",
"=",
"int",
"(",
"args",
"[",
"2",
"]",
")",
"autocontinue",
"=",
"int",
"(",
"args",
"[",
"3",
"]",
")",
"param1",
"=",
"float",
"(",
"args",
"[",
"4",
"]",
")",
"param2",
"=",
"float",
"(",
"args",
"[",
"5",
"]",
")",
"param3",
"=",
"float",
"(",
"args",
"[",
"6",
"]",
")",
"param4",
"=",
"float",
"(",
"args",
"[",
"7",
"]",
")",
"x",
"=",
"int",
"(",
"args",
"[",
"8",
"]",
")",
"y",
"=",
"int",
"(",
"args",
"[",
"9",
"]",
")",
"z",
"=",
"float",
"(",
"args",
"[",
"10",
"]",
")",
"self",
".",
"master",
".",
"mav",
".",
"command_int_send",
"(",
"self",
".",
"settings",
".",
"target_system",
",",
"self",
".",
"settings",
".",
"target_component",
",",
"frame",
",",
"command",
",",
"0",
",",
"0",
",",
"param1",
",",
"param2",
",",
"param3",
",",
"param4",
",",
"x",
",",
"y",
",",
"z",
")"
] | execute supplied command_int | [
"execute",
"supplied",
"command_int"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_cmdlong.py#L346-L407 |
249,543 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_sensors.py | SensorsModule.cmd_sensors | def cmd_sensors(self, args):
'''show key sensors'''
gps_heading = self.status.msgs['GPS_RAW_INT'].cog * 0.01
self.console.writeln("heading: %u/%u alt: %u/%u r/p: %u/%u speed: %u/%u thr: %u" % (
self.status.msgs['VFR_HUD'].heading,
gps_heading,
self.status.altitude,
self.gps_alt,
math.degrees(self.status.msgs['ATTITUDE'].roll),
math.degrees(self.status.msgs['ATTITUDE'].pitch),
self.status.msgs['VFR_HUD'].airspeed,
self.status.msgs['VFR_HUD'].groundspeed,
self.status.msgs['VFR_HUD'].throttle)) | python | def cmd_sensors(self, args):
'''show key sensors'''
gps_heading = self.status.msgs['GPS_RAW_INT'].cog * 0.01
self.console.writeln("heading: %u/%u alt: %u/%u r/p: %u/%u speed: %u/%u thr: %u" % (
self.status.msgs['VFR_HUD'].heading,
gps_heading,
self.status.altitude,
self.gps_alt,
math.degrees(self.status.msgs['ATTITUDE'].roll),
math.degrees(self.status.msgs['ATTITUDE'].pitch),
self.status.msgs['VFR_HUD'].airspeed,
self.status.msgs['VFR_HUD'].groundspeed,
self.status.msgs['VFR_HUD'].throttle)) | [
"def",
"cmd_sensors",
"(",
"self",
",",
"args",
")",
":",
"gps_heading",
"=",
"self",
".",
"status",
".",
"msgs",
"[",
"'GPS_RAW_INT'",
"]",
".",
"cog",
"*",
"0.01",
"self",
".",
"console",
".",
"writeln",
"(",
"\"heading: %u/%u alt: %u/%u r/p: %u/%u speed: %u/%u thr: %u\"",
"%",
"(",
"self",
".",
"status",
".",
"msgs",
"[",
"'VFR_HUD'",
"]",
".",
"heading",
",",
"gps_heading",
",",
"self",
".",
"status",
".",
"altitude",
",",
"self",
".",
"gps_alt",
",",
"math",
".",
"degrees",
"(",
"self",
".",
"status",
".",
"msgs",
"[",
"'ATTITUDE'",
"]",
".",
"roll",
")",
",",
"math",
".",
"degrees",
"(",
"self",
".",
"status",
".",
"msgs",
"[",
"'ATTITUDE'",
"]",
".",
"pitch",
")",
",",
"self",
".",
"status",
".",
"msgs",
"[",
"'VFR_HUD'",
"]",
".",
"airspeed",
",",
"self",
".",
"status",
".",
"msgs",
"[",
"'VFR_HUD'",
"]",
".",
"groundspeed",
",",
"self",
".",
"status",
".",
"msgs",
"[",
"'VFR_HUD'",
"]",
".",
"throttle",
")",
")"
] | show key sensors | [
"show",
"key",
"sensors"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_sensors.py#L50-L63 |
249,544 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_misseditor/me_defines.py | cmd_reverse_lookup | def cmd_reverse_lookup(command_name):
'''returns 0 if key not found'''
for key, value in miss_cmds.items():
if (value.upper() == command_name.upper()):
return key
return 0 | python | def cmd_reverse_lookup(command_name):
'''returns 0 if key not found'''
for key, value in miss_cmds.items():
if (value.upper() == command_name.upper()):
return key
return 0 | [
"def",
"cmd_reverse_lookup",
"(",
"command_name",
")",
":",
"for",
"key",
",",
"value",
"in",
"miss_cmds",
".",
"items",
"(",
")",
":",
"if",
"(",
"value",
".",
"upper",
"(",
")",
"==",
"command_name",
".",
"upper",
"(",
")",
")",
":",
"return",
"key",
"return",
"0"
] | returns 0 if key not found | [
"returns",
"0",
"if",
"key",
"not",
"found"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_misseditor/me_defines.py#L17-L22 |
249,545 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_misseditor/me_defines.py | make_column_label | def make_column_label(command_name, description, default):
'''try to work out a reasonable column name from parameter description'''
for (pattern, label) in description_map:
if fnmatch.fnmatch(description, pattern):
return label
return default | python | def make_column_label(command_name, description, default):
'''try to work out a reasonable column name from parameter description'''
for (pattern, label) in description_map:
if fnmatch.fnmatch(description, pattern):
return label
return default | [
"def",
"make_column_label",
"(",
"command_name",
",",
"description",
",",
"default",
")",
":",
"for",
"(",
"pattern",
",",
"label",
")",
"in",
"description_map",
":",
"if",
"fnmatch",
".",
"fnmatch",
"(",
"description",
",",
"pattern",
")",
":",
"return",
"label",
"return",
"default"
] | try to work out a reasonable column name from parameter description | [
"try",
"to",
"work",
"out",
"a",
"reasonable",
"column",
"name",
"from",
"parameter",
"description"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_misseditor/me_defines.py#L51-L56 |
249,546 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_misseditor/me_defines.py | get_column_labels | def get_column_labels(command_name):
'''return dictionary of column labels if available'''
cmd = cmd_reverse_lookup(command_name)
if cmd == 0:
return {}
labels = {}
enum = mavutil.mavlink.enums['MAV_CMD'][cmd]
for col in enum.param.keys():
labels[col] = make_column_label(command_name, enum.param[col], "P%u" % col)
return labels | python | def get_column_labels(command_name):
'''return dictionary of column labels if available'''
cmd = cmd_reverse_lookup(command_name)
if cmd == 0:
return {}
labels = {}
enum = mavutil.mavlink.enums['MAV_CMD'][cmd]
for col in enum.param.keys():
labels[col] = make_column_label(command_name, enum.param[col], "P%u" % col)
return labels | [
"def",
"get_column_labels",
"(",
"command_name",
")",
":",
"cmd",
"=",
"cmd_reverse_lookup",
"(",
"command_name",
")",
"if",
"cmd",
"==",
"0",
":",
"return",
"{",
"}",
"labels",
"=",
"{",
"}",
"enum",
"=",
"mavutil",
".",
"mavlink",
".",
"enums",
"[",
"'MAV_CMD'",
"]",
"[",
"cmd",
"]",
"for",
"col",
"in",
"enum",
".",
"param",
".",
"keys",
"(",
")",
":",
"labels",
"[",
"col",
"]",
"=",
"make_column_label",
"(",
"command_name",
",",
"enum",
".",
"param",
"[",
"col",
"]",
",",
"\"P%u\"",
"%",
"col",
")",
"return",
"labels"
] | return dictionary of column labels if available | [
"return",
"dictionary",
"of",
"column",
"labels",
"if",
"available"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_misseditor/me_defines.py#L59-L68 |
249,547 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_tracker.py | TrackerModule.find_connection | def find_connection(self):
'''find an antenna tracker connection if possible'''
if self.connection is not None:
return self.connection
for m in self.mpstate.mav_master:
if 'HEARTBEAT' in m.messages:
if m.messages['HEARTBEAT'].type == mavutil.mavlink.MAV_TYPE_ANTENNA_TRACKER:
return m
return None | python | def find_connection(self):
'''find an antenna tracker connection if possible'''
if self.connection is not None:
return self.connection
for m in self.mpstate.mav_master:
if 'HEARTBEAT' in m.messages:
if m.messages['HEARTBEAT'].type == mavutil.mavlink.MAV_TYPE_ANTENNA_TRACKER:
return m
return None | [
"def",
"find_connection",
"(",
"self",
")",
":",
"if",
"self",
".",
"connection",
"is",
"not",
"None",
":",
"return",
"self",
".",
"connection",
"for",
"m",
"in",
"self",
".",
"mpstate",
".",
"mav_master",
":",
"if",
"'HEARTBEAT'",
"in",
"m",
".",
"messages",
":",
"if",
"m",
".",
"messages",
"[",
"'HEARTBEAT'",
"]",
".",
"type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_TYPE_ANTENNA_TRACKER",
":",
"return",
"m",
"return",
"None"
] | find an antenna tracker connection if possible | [
"find",
"an",
"antenna",
"tracker",
"connection",
"if",
"possible"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_tracker.py#L52-L60 |
249,548 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_tracker.py | TrackerModule.cmd_tracker | def cmd_tracker(self, args):
'''tracker command parser'''
usage = "usage: tracker <start|set|arm|disarm|level|param|mode|position> [options]"
if len(args) == 0:
print(usage)
return
if args[0] == "start":
self.cmd_tracker_start()
elif args[0] == "set":
self.tracker_settings.command(args[1:])
elif args[0] == 'arm':
self.cmd_tracker_arm()
elif args[0] == 'disarm':
self.cmd_tracker_disarm()
elif args[0] == 'level':
self.cmd_tracker_level()
elif args[0] == 'param':
self.cmd_tracker_param(args[1:])
elif args[0] == 'mode':
self.cmd_tracker_mode(args[1:])
elif args[0] == 'position':
self.cmd_tracker_position(args[1:])
elif args[0] == 'calpress':
self.cmd_tracker_calpress(args[1:])
else:
print(usage) | python | def cmd_tracker(self, args):
'''tracker command parser'''
usage = "usage: tracker <start|set|arm|disarm|level|param|mode|position> [options]"
if len(args) == 0:
print(usage)
return
if args[0] == "start":
self.cmd_tracker_start()
elif args[0] == "set":
self.tracker_settings.command(args[1:])
elif args[0] == 'arm':
self.cmd_tracker_arm()
elif args[0] == 'disarm':
self.cmd_tracker_disarm()
elif args[0] == 'level':
self.cmd_tracker_level()
elif args[0] == 'param':
self.cmd_tracker_param(args[1:])
elif args[0] == 'mode':
self.cmd_tracker_mode(args[1:])
elif args[0] == 'position':
self.cmd_tracker_position(args[1:])
elif args[0] == 'calpress':
self.cmd_tracker_calpress(args[1:])
else:
print(usage) | [
"def",
"cmd_tracker",
"(",
"self",
",",
"args",
")",
":",
"usage",
"=",
"\"usage: tracker <start|set|arm|disarm|level|param|mode|position> [options]\"",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"print",
"(",
"usage",
")",
"return",
"if",
"args",
"[",
"0",
"]",
"==",
"\"start\"",
":",
"self",
".",
"cmd_tracker_start",
"(",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"\"set\"",
":",
"self",
".",
"tracker_settings",
".",
"command",
"(",
"args",
"[",
"1",
":",
"]",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"'arm'",
":",
"self",
".",
"cmd_tracker_arm",
"(",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"'disarm'",
":",
"self",
".",
"cmd_tracker_disarm",
"(",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"'level'",
":",
"self",
".",
"cmd_tracker_level",
"(",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"'param'",
":",
"self",
".",
"cmd_tracker_param",
"(",
"args",
"[",
"1",
":",
"]",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"'mode'",
":",
"self",
".",
"cmd_tracker_mode",
"(",
"args",
"[",
"1",
":",
"]",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"'position'",
":",
"self",
".",
"cmd_tracker_position",
"(",
"args",
"[",
"1",
":",
"]",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"'calpress'",
":",
"self",
".",
"cmd_tracker_calpress",
"(",
"args",
"[",
"1",
":",
"]",
")",
"else",
":",
"print",
"(",
"usage",
")"
] | tracker command parser | [
"tracker",
"command",
"parser"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_tracker.py#L62-L87 |
249,549 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_tracker.py | TrackerModule.cmd_tracker_position | def cmd_tracker_position(self, args):
'''tracker manual positioning commands'''
connection = self.find_connection()
if not connection:
print("No antenna tracker found")
return
positions = [0, 0, 0, 0, 0] # x, y, z, r, buttons. only position[0] (yaw) and position[1] (pitch) are currently used
for i in range(0, 4):
if len(args) > i:
positions[i] = int(args[i]) # default values are 0
connection.mav.manual_control_send(connection.target_system,
positions[0], positions[1],
positions[2], positions[3],
positions[4]) | python | def cmd_tracker_position(self, args):
'''tracker manual positioning commands'''
connection = self.find_connection()
if not connection:
print("No antenna tracker found")
return
positions = [0, 0, 0, 0, 0] # x, y, z, r, buttons. only position[0] (yaw) and position[1] (pitch) are currently used
for i in range(0, 4):
if len(args) > i:
positions[i] = int(args[i]) # default values are 0
connection.mav.manual_control_send(connection.target_system,
positions[0], positions[1],
positions[2], positions[3],
positions[4]) | [
"def",
"cmd_tracker_position",
"(",
"self",
",",
"args",
")",
":",
"connection",
"=",
"self",
".",
"find_connection",
"(",
")",
"if",
"not",
"connection",
":",
"print",
"(",
"\"No antenna tracker found\"",
")",
"return",
"positions",
"=",
"[",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
"]",
"# x, y, z, r, buttons. only position[0] (yaw) and position[1] (pitch) are currently used",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"4",
")",
":",
"if",
"len",
"(",
"args",
")",
">",
"i",
":",
"positions",
"[",
"i",
"]",
"=",
"int",
"(",
"args",
"[",
"i",
"]",
")",
"# default values are 0",
"connection",
".",
"mav",
".",
"manual_control_send",
"(",
"connection",
".",
"target_system",
",",
"positions",
"[",
"0",
"]",
",",
"positions",
"[",
"1",
"]",
",",
"positions",
"[",
"2",
"]",
",",
"positions",
"[",
"3",
"]",
",",
"positions",
"[",
"4",
"]",
")"
] | tracker manual positioning commands | [
"tracker",
"manual",
"positioning",
"commands"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_tracker.py#L89-L102 |
249,550 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_tracker.py | TrackerModule.cmd_tracker_calpress | def cmd_tracker_calpress(self, args):
'''calibrate barometer on tracker'''
connection = self.find_connection()
if not connection:
print("No antenna tracker found")
return
connection.calibrate_pressure() | python | def cmd_tracker_calpress(self, args):
'''calibrate barometer on tracker'''
connection = self.find_connection()
if not connection:
print("No antenna tracker found")
return
connection.calibrate_pressure() | [
"def",
"cmd_tracker_calpress",
"(",
"self",
",",
"args",
")",
":",
"connection",
"=",
"self",
".",
"find_connection",
"(",
")",
"if",
"not",
"connection",
":",
"print",
"(",
"\"No antenna tracker found\"",
")",
"return",
"connection",
".",
"calibrate_pressure",
"(",
")"
] | calibrate barometer on tracker | [
"calibrate",
"barometer",
"on",
"tracker"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_tracker.py#L104-L110 |
249,551 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_tracker.py | TrackerModule.mavlink_packet | def mavlink_packet(self, m):
'''handle an incoming mavlink packet from the master vehicle. Relay it to the tracker
if it is a GLOBAL_POSITION_INT'''
if m.get_type() in ['GLOBAL_POSITION_INT', 'SCALED_PRESSURE']:
connection = self.find_connection()
if not connection:
return
if m.get_srcSystem() != connection.target_system:
connection.mav.send(m) | python | def mavlink_packet(self, m):
'''handle an incoming mavlink packet from the master vehicle. Relay it to the tracker
if it is a GLOBAL_POSITION_INT'''
if m.get_type() in ['GLOBAL_POSITION_INT', 'SCALED_PRESSURE']:
connection = self.find_connection()
if not connection:
return
if m.get_srcSystem() != connection.target_system:
connection.mav.send(m) | [
"def",
"mavlink_packet",
"(",
"self",
",",
"m",
")",
":",
"if",
"m",
".",
"get_type",
"(",
")",
"in",
"[",
"'GLOBAL_POSITION_INT'",
",",
"'SCALED_PRESSURE'",
"]",
":",
"connection",
"=",
"self",
".",
"find_connection",
"(",
")",
"if",
"not",
"connection",
":",
"return",
"if",
"m",
".",
"get_srcSystem",
"(",
")",
"!=",
"connection",
".",
"target_system",
":",
"connection",
".",
"mav",
".",
"send",
"(",
"m",
")"
] | handle an incoming mavlink packet from the master vehicle. Relay it to the tracker
if it is a GLOBAL_POSITION_INT | [
"handle",
"an",
"incoming",
"mavlink",
"packet",
"from",
"the",
"master",
"vehicle",
".",
"Relay",
"it",
"to",
"the",
"tracker",
"if",
"it",
"is",
"a",
"GLOBAL_POSITION_INT"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_tracker.py#L131-L139 |
249,552 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_graph.py | GraphModule.cmd_legend | def cmd_legend(self, args):
'''setup legend for graphs'''
if len(args) == 0:
for leg in self.legend.keys():
print("%s -> %s" % (leg, self.legend[leg]))
elif len(args) == 1:
leg = args[0]
if leg in self.legend:
print("Removing legend %s" % leg)
self.legend.pop(leg)
elif len(args) >= 2:
leg = args[0]
leg2 = args[1]
print("Adding legend %s -> %s" % (leg, leg2))
self.legend[leg] = leg2 | python | def cmd_legend(self, args):
'''setup legend for graphs'''
if len(args) == 0:
for leg in self.legend.keys():
print("%s -> %s" % (leg, self.legend[leg]))
elif len(args) == 1:
leg = args[0]
if leg in self.legend:
print("Removing legend %s" % leg)
self.legend.pop(leg)
elif len(args) >= 2:
leg = args[0]
leg2 = args[1]
print("Adding legend %s -> %s" % (leg, leg2))
self.legend[leg] = leg2 | [
"def",
"cmd_legend",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"for",
"leg",
"in",
"self",
".",
"legend",
".",
"keys",
"(",
")",
":",
"print",
"(",
"\"%s -> %s\"",
"%",
"(",
"leg",
",",
"self",
".",
"legend",
"[",
"leg",
"]",
")",
")",
"elif",
"len",
"(",
"args",
")",
"==",
"1",
":",
"leg",
"=",
"args",
"[",
"0",
"]",
"if",
"leg",
"in",
"self",
".",
"legend",
":",
"print",
"(",
"\"Removing legend %s\"",
"%",
"leg",
")",
"self",
".",
"legend",
".",
"pop",
"(",
"leg",
")",
"elif",
"len",
"(",
"args",
")",
">=",
"2",
":",
"leg",
"=",
"args",
"[",
"0",
"]",
"leg2",
"=",
"args",
"[",
"1",
"]",
"print",
"(",
"\"Adding legend %s -> %s\"",
"%",
"(",
"leg",
",",
"leg2",
")",
")",
"self",
".",
"legend",
"[",
"leg",
"]",
"=",
"leg2"
] | setup legend for graphs | [
"setup",
"legend",
"for",
"graphs"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_graph.py#L55-L69 |
249,553 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_gimbal.py | GimbalModule.cmd_gimbal_mode | def cmd_gimbal_mode(self, args):
'''control gimbal mode'''
if len(args) != 1:
print("usage: gimbal mode <GPS|MAVLink>")
return
if args[0].upper() == 'GPS':
mode = mavutil.mavlink.MAV_MOUNT_MODE_GPS_POINT
elif args[0].upper() == 'MAVLINK':
mode = mavutil.mavlink.MAV_MOUNT_MODE_MAVLINK_TARGETING
elif args[0].upper() == 'RC':
mode = mavutil.mavlink.MAV_MOUNT_MODE_RC_TARGETING
else:
print("Unsupported mode %s" % args[0])
self.master.mav.mount_configure_send(self.target_system,
self.target_component,
mode,
1, 1, 1) | python | def cmd_gimbal_mode(self, args):
'''control gimbal mode'''
if len(args) != 1:
print("usage: gimbal mode <GPS|MAVLink>")
return
if args[0].upper() == 'GPS':
mode = mavutil.mavlink.MAV_MOUNT_MODE_GPS_POINT
elif args[0].upper() == 'MAVLINK':
mode = mavutil.mavlink.MAV_MOUNT_MODE_MAVLINK_TARGETING
elif args[0].upper() == 'RC':
mode = mavutil.mavlink.MAV_MOUNT_MODE_RC_TARGETING
else:
print("Unsupported mode %s" % args[0])
self.master.mav.mount_configure_send(self.target_system,
self.target_component,
mode,
1, 1, 1) | [
"def",
"cmd_gimbal_mode",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"!=",
"1",
":",
"print",
"(",
"\"usage: gimbal mode <GPS|MAVLink>\"",
")",
"return",
"if",
"args",
"[",
"0",
"]",
".",
"upper",
"(",
")",
"==",
"'GPS'",
":",
"mode",
"=",
"mavutil",
".",
"mavlink",
".",
"MAV_MOUNT_MODE_GPS_POINT",
"elif",
"args",
"[",
"0",
"]",
".",
"upper",
"(",
")",
"==",
"'MAVLINK'",
":",
"mode",
"=",
"mavutil",
".",
"mavlink",
".",
"MAV_MOUNT_MODE_MAVLINK_TARGETING",
"elif",
"args",
"[",
"0",
"]",
".",
"upper",
"(",
")",
"==",
"'RC'",
":",
"mode",
"=",
"mavutil",
".",
"mavlink",
".",
"MAV_MOUNT_MODE_RC_TARGETING",
"else",
":",
"print",
"(",
"\"Unsupported mode %s\"",
"%",
"args",
"[",
"0",
"]",
")",
"self",
".",
"master",
".",
"mav",
".",
"mount_configure_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"mode",
",",
"1",
",",
"1",
",",
"1",
")"
] | control gimbal mode | [
"control",
"gimbal",
"mode"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_gimbal.py#L58-L74 |
249,554 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_gimbal.py | GimbalModule.cmd_gimbal_roi | def cmd_gimbal_roi(self, args):
'''control roi position'''
latlon = None
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
if latlon is None:
print("No map click position available")
return
self.master.mav.mount_control_send(self.target_system,
self.target_component,
latlon[0]*1e7,
latlon[1]*1e7,
0, # altitude zero for now
0) | python | def cmd_gimbal_roi(self, args):
'''control roi position'''
latlon = None
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
if latlon is None:
print("No map click position available")
return
self.master.mav.mount_control_send(self.target_system,
self.target_component,
latlon[0]*1e7,
latlon[1]*1e7,
0, # altitude zero for now
0) | [
"def",
"cmd_gimbal_roi",
"(",
"self",
",",
"args",
")",
":",
"latlon",
"=",
"None",
"try",
":",
"latlon",
"=",
"self",
".",
"module",
"(",
"'map'",
")",
".",
"click_position",
"except",
"Exception",
":",
"print",
"(",
"\"No map available\"",
")",
"return",
"if",
"latlon",
"is",
"None",
":",
"print",
"(",
"\"No map click position available\"",
")",
"return",
"self",
".",
"master",
".",
"mav",
".",
"mount_control_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"latlon",
"[",
"0",
"]",
"*",
"1e7",
",",
"latlon",
"[",
"1",
"]",
"*",
"1e7",
",",
"0",
",",
"# altitude zero for now",
"0",
")"
] | control roi position | [
"control",
"roi",
"position"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_gimbal.py#L76-L92 |
249,555 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_gimbal.py | GimbalModule.cmd_gimbal_roi_vel | def cmd_gimbal_roi_vel(self, args):
'''control roi position and velocity'''
if len(args) != 0 and len(args) != 3 and len(args) != 6:
print("usage: gimbal roivel [VEL_NORTH VEL_EAST VEL_DOWN] [ACC_NORTH ACC_EASY ACC_DOWN]")
return
latlon = None
vel = [0,0,0]
acc = [0,0,0]
if (len(args) >= 3):
vel[0:3] = args[0:3]
if (len(args) == 6):
acc[0:3] = args[3:6]
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
if latlon is None:
print("No map click position available")
latlon = (0,0,0)
self.master.mav.set_roi_global_int_send(0, #time_boot_ms
1, #target_system
1, #target_component
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT_INT,
0, #type_mask
0, #roi_index
0, #timeout_ms
int(latlon[0]*1e7), #lat int
int(latlon[1]*1e7), #lng int
float(0), #alt
float(vel[0]), #vx
float(vel[1]), #vy
float(vel[2]), #vz
float(acc[0]), #ax
float(acc[1]), #ay
float(acc[2])) | python | def cmd_gimbal_roi_vel(self, args):
'''control roi position and velocity'''
if len(args) != 0 and len(args) != 3 and len(args) != 6:
print("usage: gimbal roivel [VEL_NORTH VEL_EAST VEL_DOWN] [ACC_NORTH ACC_EASY ACC_DOWN]")
return
latlon = None
vel = [0,0,0]
acc = [0,0,0]
if (len(args) >= 3):
vel[0:3] = args[0:3]
if (len(args) == 6):
acc[0:3] = args[3:6]
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
if latlon is None:
print("No map click position available")
latlon = (0,0,0)
self.master.mav.set_roi_global_int_send(0, #time_boot_ms
1, #target_system
1, #target_component
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT_INT,
0, #type_mask
0, #roi_index
0, #timeout_ms
int(latlon[0]*1e7), #lat int
int(latlon[1]*1e7), #lng int
float(0), #alt
float(vel[0]), #vx
float(vel[1]), #vy
float(vel[2]), #vz
float(acc[0]), #ax
float(acc[1]), #ay
float(acc[2])) | [
"def",
"cmd_gimbal_roi_vel",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"!=",
"0",
"and",
"len",
"(",
"args",
")",
"!=",
"3",
"and",
"len",
"(",
"args",
")",
"!=",
"6",
":",
"print",
"(",
"\"usage: gimbal roivel [VEL_NORTH VEL_EAST VEL_DOWN] [ACC_NORTH ACC_EASY ACC_DOWN]\"",
")",
"return",
"latlon",
"=",
"None",
"vel",
"=",
"[",
"0",
",",
"0",
",",
"0",
"]",
"acc",
"=",
"[",
"0",
",",
"0",
",",
"0",
"]",
"if",
"(",
"len",
"(",
"args",
")",
">=",
"3",
")",
":",
"vel",
"[",
"0",
":",
"3",
"]",
"=",
"args",
"[",
"0",
":",
"3",
"]",
"if",
"(",
"len",
"(",
"args",
")",
"==",
"6",
")",
":",
"acc",
"[",
"0",
":",
"3",
"]",
"=",
"args",
"[",
"3",
":",
"6",
"]",
"try",
":",
"latlon",
"=",
"self",
".",
"module",
"(",
"'map'",
")",
".",
"click_position",
"except",
"Exception",
":",
"print",
"(",
"\"No map available\"",
")",
"return",
"if",
"latlon",
"is",
"None",
":",
"print",
"(",
"\"No map click position available\"",
")",
"latlon",
"=",
"(",
"0",
",",
"0",
",",
"0",
")",
"self",
".",
"master",
".",
"mav",
".",
"set_roi_global_int_send",
"(",
"0",
",",
"#time_boot_ms",
"1",
",",
"#target_system",
"1",
",",
"#target_component",
"mavutil",
".",
"mavlink",
".",
"MAV_FRAME_GLOBAL_RELATIVE_ALT_INT",
",",
"0",
",",
"#type_mask",
"0",
",",
"#roi_index",
"0",
",",
"#timeout_ms",
"int",
"(",
"latlon",
"[",
"0",
"]",
"*",
"1e7",
")",
",",
"#lat int",
"int",
"(",
"latlon",
"[",
"1",
"]",
"*",
"1e7",
")",
",",
"#lng int",
"float",
"(",
"0",
")",
",",
"#alt",
"float",
"(",
"vel",
"[",
"0",
"]",
")",
",",
"#vx",
"float",
"(",
"vel",
"[",
"1",
"]",
")",
",",
"#vy",
"float",
"(",
"vel",
"[",
"2",
"]",
")",
",",
"#vz",
"float",
"(",
"acc",
"[",
"0",
"]",
")",
",",
"#ax",
"float",
"(",
"acc",
"[",
"1",
"]",
")",
",",
"#ay",
"float",
"(",
"acc",
"[",
"2",
"]",
")",
")"
] | control roi position and velocity | [
"control",
"roi",
"position",
"and",
"velocity"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_gimbal.py#L94-L129 |
249,556 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_gimbal.py | GimbalModule.cmd_gimbal_rate | def cmd_gimbal_rate(self, args):
'''control gimbal rate'''
if len(args) != 3:
print("usage: gimbal rate ROLL PITCH YAW")
return
(roll, pitch, yaw) = (float(args[0]), float(args[1]), float(args[2]))
self.master.mav.gimbal_control_send(self.target_system,
mavutil.mavlink.MAV_COMP_ID_GIMBAL,
radians(roll),
radians(pitch),
radians(yaw)) | python | def cmd_gimbal_rate(self, args):
'''control gimbal rate'''
if len(args) != 3:
print("usage: gimbal rate ROLL PITCH YAW")
return
(roll, pitch, yaw) = (float(args[0]), float(args[1]), float(args[2]))
self.master.mav.gimbal_control_send(self.target_system,
mavutil.mavlink.MAV_COMP_ID_GIMBAL,
radians(roll),
radians(pitch),
radians(yaw)) | [
"def",
"cmd_gimbal_rate",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"!=",
"3",
":",
"print",
"(",
"\"usage: gimbal rate ROLL PITCH YAW\"",
")",
"return",
"(",
"roll",
",",
"pitch",
",",
"yaw",
")",
"=",
"(",
"float",
"(",
"args",
"[",
"0",
"]",
")",
",",
"float",
"(",
"args",
"[",
"1",
"]",
")",
",",
"float",
"(",
"args",
"[",
"2",
"]",
")",
")",
"self",
".",
"master",
".",
"mav",
".",
"gimbal_control_send",
"(",
"self",
".",
"target_system",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_COMP_ID_GIMBAL",
",",
"radians",
"(",
"roll",
")",
",",
"radians",
"(",
"pitch",
")",
",",
"radians",
"(",
"yaw",
")",
")"
] | control gimbal rate | [
"control",
"gimbal",
"rate"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_gimbal.py#L131-L141 |
249,557 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_gimbal.py | GimbalModule.cmd_gimbal_point | def cmd_gimbal_point(self, args):
'''control gimbal pointing'''
if len(args) != 3:
print("usage: gimbal point ROLL PITCH YAW")
return
(roll, pitch, yaw) = (float(args[0]), float(args[1]), float(args[2]))
self.master.mav.mount_control_send(self.target_system,
self.target_component,
pitch*100,
roll*100,
yaw*100,
0) | python | def cmd_gimbal_point(self, args):
'''control gimbal pointing'''
if len(args) != 3:
print("usage: gimbal point ROLL PITCH YAW")
return
(roll, pitch, yaw) = (float(args[0]), float(args[1]), float(args[2]))
self.master.mav.mount_control_send(self.target_system,
self.target_component,
pitch*100,
roll*100,
yaw*100,
0) | [
"def",
"cmd_gimbal_point",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"!=",
"3",
":",
"print",
"(",
"\"usage: gimbal point ROLL PITCH YAW\"",
")",
"return",
"(",
"roll",
",",
"pitch",
",",
"yaw",
")",
"=",
"(",
"float",
"(",
"args",
"[",
"0",
"]",
")",
",",
"float",
"(",
"args",
"[",
"1",
"]",
")",
",",
"float",
"(",
"args",
"[",
"2",
"]",
")",
")",
"self",
".",
"master",
".",
"mav",
".",
"mount_control_send",
"(",
"self",
".",
"target_system",
",",
"self",
".",
"target_component",
",",
"pitch",
"*",
"100",
",",
"roll",
"*",
"100",
",",
"yaw",
"*",
"100",
",",
"0",
")"
] | control gimbal pointing | [
"control",
"gimbal",
"pointing"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_gimbal.py#L143-L154 |
249,558 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_gimbal.py | GimbalModule.cmd_gimbal_status | def cmd_gimbal_status(self, args):
'''show gimbal status'''
master = self.master
if 'GIMBAL_REPORT' in master.messages:
print(master.messages['GIMBAL_REPORT'])
else:
print("No GIMBAL_REPORT messages") | python | def cmd_gimbal_status(self, args):
'''show gimbal status'''
master = self.master
if 'GIMBAL_REPORT' in master.messages:
print(master.messages['GIMBAL_REPORT'])
else:
print("No GIMBAL_REPORT messages") | [
"def",
"cmd_gimbal_status",
"(",
"self",
",",
"args",
")",
":",
"master",
"=",
"self",
".",
"master",
"if",
"'GIMBAL_REPORT'",
"in",
"master",
".",
"messages",
":",
"print",
"(",
"master",
".",
"messages",
"[",
"'GIMBAL_REPORT'",
"]",
")",
"else",
":",
"print",
"(",
"\"No GIMBAL_REPORT messages\"",
")"
] | show gimbal status | [
"show",
"gimbal",
"status"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_gimbal.py#L156-L162 |
249,559 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/mp_slipmap_util.py | SlipFlightModeLegend.draw | def draw(self, img, pixmapper, bounds):
'''draw legend on the image'''
if self._img is None:
self._img = self.draw_legend()
w = self._img.shape[1]
h = self._img.shape[0]
px = 5
py = 5
img[py:py+h,px:px+w] = self._img | python | def draw(self, img, pixmapper, bounds):
'''draw legend on the image'''
if self._img is None:
self._img = self.draw_legend()
w = self._img.shape[1]
h = self._img.shape[0]
px = 5
py = 5
img[py:py+h,px:px+w] = self._img | [
"def",
"draw",
"(",
"self",
",",
"img",
",",
"pixmapper",
",",
"bounds",
")",
":",
"if",
"self",
".",
"_img",
"is",
"None",
":",
"self",
".",
"_img",
"=",
"self",
".",
"draw_legend",
"(",
")",
"w",
"=",
"self",
".",
"_img",
".",
"shape",
"[",
"1",
"]",
"h",
"=",
"self",
".",
"_img",
".",
"shape",
"[",
"0",
"]",
"px",
"=",
"5",
"py",
"=",
"5",
"img",
"[",
"py",
":",
"py",
"+",
"h",
",",
"px",
":",
"px",
"+",
"w",
"]",
"=",
"self",
".",
"_img"
] | draw legend on the image | [
"draw",
"legend",
"on",
"the",
"image"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/mp_slipmap_util.py#L349-L358 |
249,560 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_map/mp_slipmap_util.py | SlipThumbnail.draw | def draw(self, img, pixmapper, bounds):
'''draw the thumbnail on the image'''
if self.hidden:
return
thumb = self.img()
(px,py) = pixmapper(self.latlon)
# find top left
(w, h) = image_shape(thumb)
px -= w//2
py -= h//2
(px, py, sx, sy, w, h) = self.clip(px, py, w, h, img)
thumb_roi = thumb[sy:sy+h, sx:sx+w]
img[py:py+h, px:px+w] = thumb_roi
# remember where we placed it for clicked()
self.posx = px+w//2
self.posy = py+h//2 | python | def draw(self, img, pixmapper, bounds):
'''draw the thumbnail on the image'''
if self.hidden:
return
thumb = self.img()
(px,py) = pixmapper(self.latlon)
# find top left
(w, h) = image_shape(thumb)
px -= w//2
py -= h//2
(px, py, sx, sy, w, h) = self.clip(px, py, w, h, img)
thumb_roi = thumb[sy:sy+h, sx:sx+w]
img[py:py+h, px:px+w] = thumb_roi
# remember where we placed it for clicked()
self.posx = px+w//2
self.posy = py+h//2 | [
"def",
"draw",
"(",
"self",
",",
"img",
",",
"pixmapper",
",",
"bounds",
")",
":",
"if",
"self",
".",
"hidden",
":",
"return",
"thumb",
"=",
"self",
".",
"img",
"(",
")",
"(",
"px",
",",
"py",
")",
"=",
"pixmapper",
"(",
"self",
".",
"latlon",
")",
"# find top left",
"(",
"w",
",",
"h",
")",
"=",
"image_shape",
"(",
"thumb",
")",
"px",
"-=",
"w",
"//",
"2",
"py",
"-=",
"h",
"//",
"2",
"(",
"px",
",",
"py",
",",
"sx",
",",
"sy",
",",
"w",
",",
"h",
")",
"=",
"self",
".",
"clip",
"(",
"px",
",",
"py",
",",
"w",
",",
"h",
",",
"img",
")",
"thumb_roi",
"=",
"thumb",
"[",
"sy",
":",
"sy",
"+",
"h",
",",
"sx",
":",
"sx",
"+",
"w",
"]",
"img",
"[",
"py",
":",
"py",
"+",
"h",
",",
"px",
":",
"px",
"+",
"w",
"]",
"=",
"thumb_roi",
"# remember where we placed it for clicked()",
"self",
".",
"posx",
"=",
"px",
"+",
"w",
"//",
"2",
"self",
".",
"posy",
"=",
"py",
"+",
"h",
"//",
"2"
] | draw the thumbnail on the image | [
"draw",
"the",
"thumbnail",
"on",
"the",
"image"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_map/mp_slipmap_util.py#L393-L412 |
249,561 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_terrain.py | TerrainModule.cmd_terrain | def cmd_terrain(self, args):
'''terrain command parser'''
usage = "usage: terrain <set|status|check>"
if len(args) == 0:
print(usage)
return
if args[0] == "status":
print("blocks_sent: %u requests_received: %u" % (
self.blocks_sent,
self.requests_received))
elif args[0] == "set":
self.terrain_settings.command(args[1:])
elif args[0] == "check":
self.cmd_terrain_check(args[1:])
else:
print(usage) | python | def cmd_terrain(self, args):
'''terrain command parser'''
usage = "usage: terrain <set|status|check>"
if len(args) == 0:
print(usage)
return
if args[0] == "status":
print("blocks_sent: %u requests_received: %u" % (
self.blocks_sent,
self.requests_received))
elif args[0] == "set":
self.terrain_settings.command(args[1:])
elif args[0] == "check":
self.cmd_terrain_check(args[1:])
else:
print(usage) | [
"def",
"cmd_terrain",
"(",
"self",
",",
"args",
")",
":",
"usage",
"=",
"\"usage: terrain <set|status|check>\"",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"print",
"(",
"usage",
")",
"return",
"if",
"args",
"[",
"0",
"]",
"==",
"\"status\"",
":",
"print",
"(",
"\"blocks_sent: %u requests_received: %u\"",
"%",
"(",
"self",
".",
"blocks_sent",
",",
"self",
".",
"requests_received",
")",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"\"set\"",
":",
"self",
".",
"terrain_settings",
".",
"command",
"(",
"args",
"[",
"1",
":",
"]",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"\"check\"",
":",
"self",
".",
"cmd_terrain_check",
"(",
"args",
"[",
"1",
":",
"]",
")",
"else",
":",
"print",
"(",
"usage",
")"
] | terrain command parser | [
"terrain",
"command",
"parser"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_terrain.py#L32-L47 |
249,562 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_terrain.py | TerrainModule.cmd_terrain_check | def cmd_terrain_check(self, args):
'''check a piece of terrain data'''
if len(args) >= 2:
latlon = (float(args[0]), float(args[1]))
else:
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
if latlon is None:
print("No map click position available")
return
self.check_lat = int(latlon[0]*1e7)
self.check_lon = int(latlon[1]*1e7)
self.master.mav.terrain_check_send(self.check_lat, self.check_lon) | python | def cmd_terrain_check(self, args):
'''check a piece of terrain data'''
if len(args) >= 2:
latlon = (float(args[0]), float(args[1]))
else:
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
if latlon is None:
print("No map click position available")
return
self.check_lat = int(latlon[0]*1e7)
self.check_lon = int(latlon[1]*1e7)
self.master.mav.terrain_check_send(self.check_lat, self.check_lon) | [
"def",
"cmd_terrain_check",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
">=",
"2",
":",
"latlon",
"=",
"(",
"float",
"(",
"args",
"[",
"0",
"]",
")",
",",
"float",
"(",
"args",
"[",
"1",
"]",
")",
")",
"else",
":",
"try",
":",
"latlon",
"=",
"self",
".",
"module",
"(",
"'map'",
")",
".",
"click_position",
"except",
"Exception",
":",
"print",
"(",
"\"No map available\"",
")",
"return",
"if",
"latlon",
"is",
"None",
":",
"print",
"(",
"\"No map click position available\"",
")",
"return",
"self",
".",
"check_lat",
"=",
"int",
"(",
"latlon",
"[",
"0",
"]",
"*",
"1e7",
")",
"self",
".",
"check_lon",
"=",
"int",
"(",
"latlon",
"[",
"1",
"]",
"*",
"1e7",
")",
"self",
".",
"master",
".",
"mav",
".",
"terrain_check_send",
"(",
"self",
".",
"check_lat",
",",
"self",
".",
"check_lon",
")"
] | check a piece of terrain data | [
"check",
"a",
"piece",
"of",
"terrain",
"data"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_terrain.py#L49-L64 |
249,563 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_terrain.py | TerrainModule.idle_task | def idle_task(self):
'''called when idle'''
if self.current_request is None:
return
if time.time() - self.last_send_time < 0.2:
# limit to 5 per second
return
self.send_terrain_data() | python | def idle_task(self):
'''called when idle'''
if self.current_request is None:
return
if time.time() - self.last_send_time < 0.2:
# limit to 5 per second
return
self.send_terrain_data() | [
"def",
"idle_task",
"(",
"self",
")",
":",
"if",
"self",
".",
"current_request",
"is",
"None",
":",
"return",
"if",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"last_send_time",
"<",
"0.2",
":",
"# limit to 5 per second",
"return",
"self",
".",
"send_terrain_data",
"(",
")"
] | called when idle | [
"called",
"when",
"idle"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_terrain.py#L134-L141 |
249,564 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_mode.py | ModeModule.unknown_command | def unknown_command(self, args):
'''handle mode switch by mode name as command'''
mode_mapping = self.master.mode_mapping()
mode = args[0].upper()
if mode in mode_mapping:
self.master.set_mode(mode_mapping[mode])
return True
return False | python | def unknown_command(self, args):
'''handle mode switch by mode name as command'''
mode_mapping = self.master.mode_mapping()
mode = args[0].upper()
if mode in mode_mapping:
self.master.set_mode(mode_mapping[mode])
return True
return False | [
"def",
"unknown_command",
"(",
"self",
",",
"args",
")",
":",
"mode_mapping",
"=",
"self",
".",
"master",
".",
"mode_mapping",
"(",
")",
"mode",
"=",
"args",
"[",
"0",
"]",
".",
"upper",
"(",
")",
"if",
"mode",
"in",
"mode_mapping",
":",
"self",
".",
"master",
".",
"set_mode",
"(",
"mode_mapping",
"[",
"mode",
"]",
")",
"return",
"True",
"return",
"False"
] | handle mode switch by mode name as command | [
"handle",
"mode",
"switch",
"by",
"mode",
"name",
"as",
"command"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_mode.py#L41-L48 |
249,565 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_mode.py | ModeModule.cmd_guided | def cmd_guided(self, args):
'''set GUIDED target'''
if len(args) != 1 and len(args) != 3:
print("Usage: guided ALTITUDE | guided LAT LON ALTITUDE")
return
if len(args) == 3:
latitude = float(args[0])
longitude = float(args[1])
altitude = float(args[2])
latlon = (latitude, longitude)
else:
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
if latlon is None:
print("No map click position available")
return
altitude = float(args[0])
print("Guided %s %s" % (str(latlon), str(altitude)))
self.master.mav.mission_item_send (self.settings.target_system,
self.settings.target_component,
0,
self.module('wp').get_default_frame(),
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
2, 0, 0, 0, 0, 0,
latlon[0], latlon[1], altitude) | python | def cmd_guided(self, args):
'''set GUIDED target'''
if len(args) != 1 and len(args) != 3:
print("Usage: guided ALTITUDE | guided LAT LON ALTITUDE")
return
if len(args) == 3:
latitude = float(args[0])
longitude = float(args[1])
altitude = float(args[2])
latlon = (latitude, longitude)
else:
try:
latlon = self.module('map').click_position
except Exception:
print("No map available")
return
if latlon is None:
print("No map click position available")
return
altitude = float(args[0])
print("Guided %s %s" % (str(latlon), str(altitude)))
self.master.mav.mission_item_send (self.settings.target_system,
self.settings.target_component,
0,
self.module('wp').get_default_frame(),
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
2, 0, 0, 0, 0, 0,
latlon[0], latlon[1], altitude) | [
"def",
"cmd_guided",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"!=",
"1",
"and",
"len",
"(",
"args",
")",
"!=",
"3",
":",
"print",
"(",
"\"Usage: guided ALTITUDE | guided LAT LON ALTITUDE\"",
")",
"return",
"if",
"len",
"(",
"args",
")",
"==",
"3",
":",
"latitude",
"=",
"float",
"(",
"args",
"[",
"0",
"]",
")",
"longitude",
"=",
"float",
"(",
"args",
"[",
"1",
"]",
")",
"altitude",
"=",
"float",
"(",
"args",
"[",
"2",
"]",
")",
"latlon",
"=",
"(",
"latitude",
",",
"longitude",
")",
"else",
":",
"try",
":",
"latlon",
"=",
"self",
".",
"module",
"(",
"'map'",
")",
".",
"click_position",
"except",
"Exception",
":",
"print",
"(",
"\"No map available\"",
")",
"return",
"if",
"latlon",
"is",
"None",
":",
"print",
"(",
"\"No map click position available\"",
")",
"return",
"altitude",
"=",
"float",
"(",
"args",
"[",
"0",
"]",
")",
"print",
"(",
"\"Guided %s %s\"",
"%",
"(",
"str",
"(",
"latlon",
")",
",",
"str",
"(",
"altitude",
")",
")",
")",
"self",
".",
"master",
".",
"mav",
".",
"mission_item_send",
"(",
"self",
".",
"settings",
".",
"target_system",
",",
"self",
".",
"settings",
".",
"target_component",
",",
"0",
",",
"self",
".",
"module",
"(",
"'wp'",
")",
".",
"get_default_frame",
"(",
")",
",",
"mavutil",
".",
"mavlink",
".",
"MAV_CMD_NAV_WAYPOINT",
",",
"2",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"latlon",
"[",
"0",
"]",
",",
"latlon",
"[",
"1",
"]",
",",
"altitude",
")"
] | set GUIDED target | [
"set",
"GUIDED",
"target"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_mode.py#L50-L79 |
249,566 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_HIL.py | HILModule.check_sim_in | def check_sim_in(self):
'''check for FDM packets from runsim'''
try:
pkt = self.sim_in.recv(17*8 + 4)
except socket.error as e:
if not e.errno in [ errno.EAGAIN, errno.EWOULDBLOCK ]:
raise
return
if len(pkt) != 17*8 + 4:
# wrong size, discard it
print("wrong size %u" % len(pkt))
return
(latitude, longitude, altitude, heading, v_north, v_east, v_down,
ax, ay, az,
phidot, thetadot, psidot,
roll, pitch, yaw,
vcas, check) = struct.unpack('<17dI', pkt)
(p, q, r) = self.convert_body_frame(radians(roll), radians(pitch), radians(phidot), radians(thetadot), radians(psidot))
try:
self.hil_state_msg = self.master.mav.hil_state_encode(int(time.time()*1e6),
radians(roll),
radians(pitch),
radians(yaw),
p,
q,
r,
int(latitude*1.0e7),
int(longitude*1.0e7),
int(altitude*1.0e3),
int(v_north*100),
int(v_east*100),
0,
int(ax*1000/9.81),
int(ay*1000/9.81),
int(az*1000/9.81))
except Exception:
return | python | def check_sim_in(self):
'''check for FDM packets from runsim'''
try:
pkt = self.sim_in.recv(17*8 + 4)
except socket.error as e:
if not e.errno in [ errno.EAGAIN, errno.EWOULDBLOCK ]:
raise
return
if len(pkt) != 17*8 + 4:
# wrong size, discard it
print("wrong size %u" % len(pkt))
return
(latitude, longitude, altitude, heading, v_north, v_east, v_down,
ax, ay, az,
phidot, thetadot, psidot,
roll, pitch, yaw,
vcas, check) = struct.unpack('<17dI', pkt)
(p, q, r) = self.convert_body_frame(radians(roll), radians(pitch), radians(phidot), radians(thetadot), radians(psidot))
try:
self.hil_state_msg = self.master.mav.hil_state_encode(int(time.time()*1e6),
radians(roll),
radians(pitch),
radians(yaw),
p,
q,
r,
int(latitude*1.0e7),
int(longitude*1.0e7),
int(altitude*1.0e3),
int(v_north*100),
int(v_east*100),
0,
int(ax*1000/9.81),
int(ay*1000/9.81),
int(az*1000/9.81))
except Exception:
return | [
"def",
"check_sim_in",
"(",
"self",
")",
":",
"try",
":",
"pkt",
"=",
"self",
".",
"sim_in",
".",
"recv",
"(",
"17",
"*",
"8",
"+",
"4",
")",
"except",
"socket",
".",
"error",
"as",
"e",
":",
"if",
"not",
"e",
".",
"errno",
"in",
"[",
"errno",
".",
"EAGAIN",
",",
"errno",
".",
"EWOULDBLOCK",
"]",
":",
"raise",
"return",
"if",
"len",
"(",
"pkt",
")",
"!=",
"17",
"*",
"8",
"+",
"4",
":",
"# wrong size, discard it",
"print",
"(",
"\"wrong size %u\"",
"%",
"len",
"(",
"pkt",
")",
")",
"return",
"(",
"latitude",
",",
"longitude",
",",
"altitude",
",",
"heading",
",",
"v_north",
",",
"v_east",
",",
"v_down",
",",
"ax",
",",
"ay",
",",
"az",
",",
"phidot",
",",
"thetadot",
",",
"psidot",
",",
"roll",
",",
"pitch",
",",
"yaw",
",",
"vcas",
",",
"check",
")",
"=",
"struct",
".",
"unpack",
"(",
"'<17dI'",
",",
"pkt",
")",
"(",
"p",
",",
"q",
",",
"r",
")",
"=",
"self",
".",
"convert_body_frame",
"(",
"radians",
"(",
"roll",
")",
",",
"radians",
"(",
"pitch",
")",
",",
"radians",
"(",
"phidot",
")",
",",
"radians",
"(",
"thetadot",
")",
",",
"radians",
"(",
"psidot",
")",
")",
"try",
":",
"self",
".",
"hil_state_msg",
"=",
"self",
".",
"master",
".",
"mav",
".",
"hil_state_encode",
"(",
"int",
"(",
"time",
".",
"time",
"(",
")",
"*",
"1e6",
")",
",",
"radians",
"(",
"roll",
")",
",",
"radians",
"(",
"pitch",
")",
",",
"radians",
"(",
"yaw",
")",
",",
"p",
",",
"q",
",",
"r",
",",
"int",
"(",
"latitude",
"*",
"1.0e7",
")",
",",
"int",
"(",
"longitude",
"*",
"1.0e7",
")",
",",
"int",
"(",
"altitude",
"*",
"1.0e3",
")",
",",
"int",
"(",
"v_north",
"*",
"100",
")",
",",
"int",
"(",
"v_east",
"*",
"100",
")",
",",
"0",
",",
"int",
"(",
"ax",
"*",
"1000",
"/",
"9.81",
")",
",",
"int",
"(",
"ay",
"*",
"1000",
"/",
"9.81",
")",
",",
"int",
"(",
"az",
"*",
"1000",
"/",
"9.81",
")",
")",
"except",
"Exception",
":",
"return"
] | check for FDM packets from runsim | [
"check",
"for",
"FDM",
"packets",
"from",
"runsim"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_HIL.py#L53-L90 |
249,567 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_HIL.py | HILModule.check_sim_out | def check_sim_out(self):
'''check if we should send new servos to flightgear'''
now = time.time()
if now - self.last_sim_send_time < 0.02 or self.rc_channels_scaled is None:
return
self.last_sim_send_time = now
servos = []
for ch in range(1,9):
servos.append(self.scale_channel(ch, getattr(self.rc_channels_scaled, 'chan%u_scaled' % ch)))
servos.extend([0,0,0, 0,0,0])
buf = struct.pack('<14H', *servos)
try:
self.sim_out.send(buf)
except socket.error as e:
if not e.errno in [ errno.ECONNREFUSED ]:
raise
return | python | def check_sim_out(self):
'''check if we should send new servos to flightgear'''
now = time.time()
if now - self.last_sim_send_time < 0.02 or self.rc_channels_scaled is None:
return
self.last_sim_send_time = now
servos = []
for ch in range(1,9):
servos.append(self.scale_channel(ch, getattr(self.rc_channels_scaled, 'chan%u_scaled' % ch)))
servos.extend([0,0,0, 0,0,0])
buf = struct.pack('<14H', *servos)
try:
self.sim_out.send(buf)
except socket.error as e:
if not e.errno in [ errno.ECONNREFUSED ]:
raise
return | [
"def",
"check_sim_out",
"(",
"self",
")",
":",
"now",
"=",
"time",
".",
"time",
"(",
")",
"if",
"now",
"-",
"self",
".",
"last_sim_send_time",
"<",
"0.02",
"or",
"self",
".",
"rc_channels_scaled",
"is",
"None",
":",
"return",
"self",
".",
"last_sim_send_time",
"=",
"now",
"servos",
"=",
"[",
"]",
"for",
"ch",
"in",
"range",
"(",
"1",
",",
"9",
")",
":",
"servos",
".",
"append",
"(",
"self",
".",
"scale_channel",
"(",
"ch",
",",
"getattr",
"(",
"self",
".",
"rc_channels_scaled",
",",
"'chan%u_scaled'",
"%",
"ch",
")",
")",
")",
"servos",
".",
"extend",
"(",
"[",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
"]",
")",
"buf",
"=",
"struct",
".",
"pack",
"(",
"'<14H'",
",",
"*",
"servos",
")",
"try",
":",
"self",
".",
"sim_out",
".",
"send",
"(",
"buf",
")",
"except",
"socket",
".",
"error",
"as",
"e",
":",
"if",
"not",
"e",
".",
"errno",
"in",
"[",
"errno",
".",
"ECONNREFUSED",
"]",
":",
"raise",
"return"
] | check if we should send new servos to flightgear | [
"check",
"if",
"we",
"should",
"send",
"new",
"servos",
"to",
"flightgear"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_HIL.py#L95-L112 |
249,568 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_HIL.py | HILModule.check_apm_out | def check_apm_out(self):
'''check if we should send new data to the APM'''
now = time.time()
if now - self.last_apm_send_time < 0.02:
return
self.last_apm_send_time = now
if self.hil_state_msg is not None:
self.master.mav.send(self.hil_state_msg) | python | def check_apm_out(self):
'''check if we should send new data to the APM'''
now = time.time()
if now - self.last_apm_send_time < 0.02:
return
self.last_apm_send_time = now
if self.hil_state_msg is not None:
self.master.mav.send(self.hil_state_msg) | [
"def",
"check_apm_out",
"(",
"self",
")",
":",
"now",
"=",
"time",
".",
"time",
"(",
")",
"if",
"now",
"-",
"self",
".",
"last_apm_send_time",
"<",
"0.02",
":",
"return",
"self",
".",
"last_apm_send_time",
"=",
"now",
"if",
"self",
".",
"hil_state_msg",
"is",
"not",
"None",
":",
"self",
".",
"master",
".",
"mav",
".",
"send",
"(",
"self",
".",
"hil_state_msg",
")"
] | check if we should send new data to the APM | [
"check",
"if",
"we",
"should",
"send",
"new",
"data",
"to",
"the",
"APM"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_HIL.py#L115-L122 |
249,569 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_HIL.py | HILModule.convert_body_frame | def convert_body_frame(self, phi, theta, phiDot, thetaDot, psiDot):
'''convert a set of roll rates from earth frame to body frame'''
p = phiDot - psiDot*math.sin(theta)
q = math.cos(phi)*thetaDot + math.sin(phi)*psiDot*math.cos(theta)
r = math.cos(phi)*psiDot*math.cos(theta) - math.sin(phi)*thetaDot
return (p, q, r) | python | def convert_body_frame(self, phi, theta, phiDot, thetaDot, psiDot):
'''convert a set of roll rates from earth frame to body frame'''
p = phiDot - psiDot*math.sin(theta)
q = math.cos(phi)*thetaDot + math.sin(phi)*psiDot*math.cos(theta)
r = math.cos(phi)*psiDot*math.cos(theta) - math.sin(phi)*thetaDot
return (p, q, r) | [
"def",
"convert_body_frame",
"(",
"self",
",",
"phi",
",",
"theta",
",",
"phiDot",
",",
"thetaDot",
",",
"psiDot",
")",
":",
"p",
"=",
"phiDot",
"-",
"psiDot",
"*",
"math",
".",
"sin",
"(",
"theta",
")",
"q",
"=",
"math",
".",
"cos",
"(",
"phi",
")",
"*",
"thetaDot",
"+",
"math",
".",
"sin",
"(",
"phi",
")",
"*",
"psiDot",
"*",
"math",
".",
"cos",
"(",
"theta",
")",
"r",
"=",
"math",
".",
"cos",
"(",
"phi",
")",
"*",
"psiDot",
"*",
"math",
".",
"cos",
"(",
"theta",
")",
"-",
"math",
".",
"sin",
"(",
"phi",
")",
"*",
"thetaDot",
"return",
"(",
"p",
",",
"q",
",",
"r",
")"
] | convert a set of roll rates from earth frame to body frame | [
"convert",
"a",
"set",
"of",
"roll",
"rates",
"from",
"earth",
"frame",
"to",
"body",
"frame"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_HIL.py#L124-L129 |
249,570 | ArduPilot/MAVProxy | MAVProxy/modules/lib/mp_settings.py | MPSettings.append | def append(self, v):
'''add a new setting'''
if isinstance(v, MPSetting):
setting = v
else:
(name,type,default) = v
label = name
tab = None
if len(v) > 3:
label = v[3]
if len(v) > 4:
tab = v[4]
setting = MPSetting(name, type, default, label=label, tab=tab)
# when a tab name is set, cascade it to future settings
if setting.tab is None:
setting.tab = self._default_tab
else:
self._default_tab = setting.tab
self._vars[setting.name] = setting
self._keys.append(setting.name)
self._last_change = time.time() | python | def append(self, v):
'''add a new setting'''
if isinstance(v, MPSetting):
setting = v
else:
(name,type,default) = v
label = name
tab = None
if len(v) > 3:
label = v[3]
if len(v) > 4:
tab = v[4]
setting = MPSetting(name, type, default, label=label, tab=tab)
# when a tab name is set, cascade it to future settings
if setting.tab is None:
setting.tab = self._default_tab
else:
self._default_tab = setting.tab
self._vars[setting.name] = setting
self._keys.append(setting.name)
self._last_change = time.time() | [
"def",
"append",
"(",
"self",
",",
"v",
")",
":",
"if",
"isinstance",
"(",
"v",
",",
"MPSetting",
")",
":",
"setting",
"=",
"v",
"else",
":",
"(",
"name",
",",
"type",
",",
"default",
")",
"=",
"v",
"label",
"=",
"name",
"tab",
"=",
"None",
"if",
"len",
"(",
"v",
")",
">",
"3",
":",
"label",
"=",
"v",
"[",
"3",
"]",
"if",
"len",
"(",
"v",
")",
">",
"4",
":",
"tab",
"=",
"v",
"[",
"4",
"]",
"setting",
"=",
"MPSetting",
"(",
"name",
",",
"type",
",",
"default",
",",
"label",
"=",
"label",
",",
"tab",
"=",
"tab",
")",
"# when a tab name is set, cascade it to future settings",
"if",
"setting",
".",
"tab",
"is",
"None",
":",
"setting",
".",
"tab",
"=",
"self",
".",
"_default_tab",
"else",
":",
"self",
".",
"_default_tab",
"=",
"setting",
".",
"tab",
"self",
".",
"_vars",
"[",
"setting",
".",
"name",
"]",
"=",
"setting",
"self",
".",
"_keys",
".",
"append",
"(",
"setting",
".",
"name",
")",
"self",
".",
"_last_change",
"=",
"time",
".",
"time",
"(",
")"
] | add a new setting | [
"add",
"a",
"new",
"setting"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_settings.py#L80-L101 |
249,571 | ArduPilot/MAVProxy | MAVProxy/modules/lib/mp_settings.py | MPSettings.get | def get(self, name):
'''get a setting'''
if not name in self._vars:
raise AttributeError
setting = self._vars[name]
return setting.value | python | def get(self, name):
'''get a setting'''
if not name in self._vars:
raise AttributeError
setting = self._vars[name]
return setting.value | [
"def",
"get",
"(",
"self",
",",
"name",
")",
":",
"if",
"not",
"name",
"in",
"self",
".",
"_vars",
":",
"raise",
"AttributeError",
"setting",
"=",
"self",
".",
"_vars",
"[",
"name",
"]",
"return",
"setting",
".",
"value"
] | get a setting | [
"get",
"a",
"setting"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_settings.py#L134-L139 |
249,572 | ArduPilot/MAVProxy | MAVProxy/modules/lib/mp_settings.py | MPSettings.command | def command(self, args):
'''control options from cmdline'''
if len(args) == 0:
self.show_all()
return
if getattr(self, args[0], [None]) == [None]:
print("Unknown setting '%s'" % args[0])
return
if len(args) == 1:
self.show(args[0])
else:
self.set(args[0], args[1]) | python | def command(self, args):
'''control options from cmdline'''
if len(args) == 0:
self.show_all()
return
if getattr(self, args[0], [None]) == [None]:
print("Unknown setting '%s'" % args[0])
return
if len(args) == 1:
self.show(args[0])
else:
self.set(args[0], args[1]) | [
"def",
"command",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"self",
".",
"show_all",
"(",
")",
"return",
"if",
"getattr",
"(",
"self",
",",
"args",
"[",
"0",
"]",
",",
"[",
"None",
"]",
")",
"==",
"[",
"None",
"]",
":",
"print",
"(",
"\"Unknown setting '%s'\"",
"%",
"args",
"[",
"0",
"]",
")",
"return",
"if",
"len",
"(",
"args",
")",
"==",
"1",
":",
"self",
".",
"show",
"(",
"args",
"[",
"0",
"]",
")",
"else",
":",
"self",
".",
"set",
"(",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
"]",
")"
] | control options from cmdline | [
"control",
"options",
"from",
"cmdline"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/mp_settings.py#L158-L169 |
249,573 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_arm.py | ArmModule.all_checks_enabled | def all_checks_enabled(self):
''' returns true if the UAV is skipping any arming checks'''
arming_mask = int(self.get_mav_param("ARMING_CHECK",0))
if arming_mask == 1:
return True
for bit in arming_masks.values():
if not arming_mask & bit and bit != 1:
return False
return True | python | def all_checks_enabled(self):
''' returns true if the UAV is skipping any arming checks'''
arming_mask = int(self.get_mav_param("ARMING_CHECK",0))
if arming_mask == 1:
return True
for bit in arming_masks.values():
if not arming_mask & bit and bit != 1:
return False
return True | [
"def",
"all_checks_enabled",
"(",
"self",
")",
":",
"arming_mask",
"=",
"int",
"(",
"self",
".",
"get_mav_param",
"(",
"\"ARMING_CHECK\"",
",",
"0",
")",
")",
"if",
"arming_mask",
"==",
"1",
":",
"return",
"True",
"for",
"bit",
"in",
"arming_masks",
".",
"values",
"(",
")",
":",
"if",
"not",
"arming_mask",
"&",
"bit",
"and",
"bit",
"!=",
"1",
":",
"return",
"False",
"return",
"True"
] | returns true if the UAV is skipping any arming checks | [
"returns",
"true",
"if",
"the",
"UAV",
"is",
"skipping",
"any",
"arming",
"checks"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_arm.py#L144-L152 |
249,574 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_param.py | ParamState.handle_px4_param_value | def handle_px4_param_value(self, m):
'''special handling for the px4 style of PARAM_VALUE'''
if m.param_type == mavutil.mavlink.MAV_PARAM_TYPE_REAL32:
# already right type
return m.param_value
is_px4_params = False
if m.get_srcComponent() in [mavutil.mavlink.MAV_COMP_ID_UDP_BRIDGE]:
# ESP8266 uses PX4 style parameters
is_px4_params = True
sysid = m.get_srcSystem()
if self.autopilot_type_by_sysid.get(sysid,-1) in [mavutil.mavlink.MAV_AUTOPILOT_PX4]:
is_px4_params = True
if not is_px4_params:
return m.param_value
# try to extract px4 param value
value = m.param_value
try:
v = struct.pack(">f", value)
except Exception:
return value
if m.param_type == mavutil.mavlink.MAV_PARAM_TYPE_UINT8:
value, = struct.unpack(">B", v[3:])
elif m.param_type == mavutil.mavlink.MAV_PARAM_TYPE_INT8:
value, = struct.unpack(">b", v[3:])
elif m.param_type == mavutil.mavlink.MAV_PARAM_TYPE_UINT16:
value, = struct.unpack(">H", v[2:])
elif m.param_type == mavutil.mavlink.MAV_PARAM_TYPE_INT16:
value, = struct.unpack(">h", v[2:])
elif m.param_type == mavutil.mavlink.MAV_PARAM_TYPE_UINT32:
value, = struct.unpack(">I", v[0:])
elif m.param_type == mavutil.mavlink.MAV_PARAM_TYPE_INT32:
value, = struct.unpack(">i", v[0:])
# can't pack other types
# remember type for param set
self.param_types[m.param_id.upper()] = m.param_type
return value | python | def handle_px4_param_value(self, m):
'''special handling for the px4 style of PARAM_VALUE'''
if m.param_type == mavutil.mavlink.MAV_PARAM_TYPE_REAL32:
# already right type
return m.param_value
is_px4_params = False
if m.get_srcComponent() in [mavutil.mavlink.MAV_COMP_ID_UDP_BRIDGE]:
# ESP8266 uses PX4 style parameters
is_px4_params = True
sysid = m.get_srcSystem()
if self.autopilot_type_by_sysid.get(sysid,-1) in [mavutil.mavlink.MAV_AUTOPILOT_PX4]:
is_px4_params = True
if not is_px4_params:
return m.param_value
# try to extract px4 param value
value = m.param_value
try:
v = struct.pack(">f", value)
except Exception:
return value
if m.param_type == mavutil.mavlink.MAV_PARAM_TYPE_UINT8:
value, = struct.unpack(">B", v[3:])
elif m.param_type == mavutil.mavlink.MAV_PARAM_TYPE_INT8:
value, = struct.unpack(">b", v[3:])
elif m.param_type == mavutil.mavlink.MAV_PARAM_TYPE_UINT16:
value, = struct.unpack(">H", v[2:])
elif m.param_type == mavutil.mavlink.MAV_PARAM_TYPE_INT16:
value, = struct.unpack(">h", v[2:])
elif m.param_type == mavutil.mavlink.MAV_PARAM_TYPE_UINT32:
value, = struct.unpack(">I", v[0:])
elif m.param_type == mavutil.mavlink.MAV_PARAM_TYPE_INT32:
value, = struct.unpack(">i", v[0:])
# can't pack other types
# remember type for param set
self.param_types[m.param_id.upper()] = m.param_type
return value | [
"def",
"handle_px4_param_value",
"(",
"self",
",",
"m",
")",
":",
"if",
"m",
".",
"param_type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_PARAM_TYPE_REAL32",
":",
"# already right type",
"return",
"m",
".",
"param_value",
"is_px4_params",
"=",
"False",
"if",
"m",
".",
"get_srcComponent",
"(",
")",
"in",
"[",
"mavutil",
".",
"mavlink",
".",
"MAV_COMP_ID_UDP_BRIDGE",
"]",
":",
"# ESP8266 uses PX4 style parameters",
"is_px4_params",
"=",
"True",
"sysid",
"=",
"m",
".",
"get_srcSystem",
"(",
")",
"if",
"self",
".",
"autopilot_type_by_sysid",
".",
"get",
"(",
"sysid",
",",
"-",
"1",
")",
"in",
"[",
"mavutil",
".",
"mavlink",
".",
"MAV_AUTOPILOT_PX4",
"]",
":",
"is_px4_params",
"=",
"True",
"if",
"not",
"is_px4_params",
":",
"return",
"m",
".",
"param_value",
"# try to extract px4 param value",
"value",
"=",
"m",
".",
"param_value",
"try",
":",
"v",
"=",
"struct",
".",
"pack",
"(",
"\">f\"",
",",
"value",
")",
"except",
"Exception",
":",
"return",
"value",
"if",
"m",
".",
"param_type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_PARAM_TYPE_UINT8",
":",
"value",
",",
"=",
"struct",
".",
"unpack",
"(",
"\">B\"",
",",
"v",
"[",
"3",
":",
"]",
")",
"elif",
"m",
".",
"param_type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_PARAM_TYPE_INT8",
":",
"value",
",",
"=",
"struct",
".",
"unpack",
"(",
"\">b\"",
",",
"v",
"[",
"3",
":",
"]",
")",
"elif",
"m",
".",
"param_type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_PARAM_TYPE_UINT16",
":",
"value",
",",
"=",
"struct",
".",
"unpack",
"(",
"\">H\"",
",",
"v",
"[",
"2",
":",
"]",
")",
"elif",
"m",
".",
"param_type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_PARAM_TYPE_INT16",
":",
"value",
",",
"=",
"struct",
".",
"unpack",
"(",
"\">h\"",
",",
"v",
"[",
"2",
":",
"]",
")",
"elif",
"m",
".",
"param_type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_PARAM_TYPE_UINT32",
":",
"value",
",",
"=",
"struct",
".",
"unpack",
"(",
"\">I\"",
",",
"v",
"[",
"0",
":",
"]",
")",
"elif",
"m",
".",
"param_type",
"==",
"mavutil",
".",
"mavlink",
".",
"MAV_PARAM_TYPE_INT32",
":",
"value",
",",
"=",
"struct",
".",
"unpack",
"(",
"\">i\"",
",",
"v",
"[",
"0",
":",
"]",
")",
"# can't pack other types",
"# remember type for param set",
"self",
".",
"param_types",
"[",
"m",
".",
"param_id",
".",
"upper",
"(",
")",
"]",
"=",
"m",
".",
"param_type",
"return",
"value"
] | special handling for the px4 style of PARAM_VALUE | [
"special",
"handling",
"for",
"the",
"px4",
"style",
"of",
"PARAM_VALUE"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_param.py#L28-L64 |
249,575 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_param.py | ParamState.param_help_download | def param_help_download(self):
'''download XML files for parameters'''
files = []
for vehicle in ['APMrover2', 'ArduCopter', 'ArduPlane', 'ArduSub', 'AntennaTracker']:
url = 'http://autotest.ardupilot.org/Parameters/%s/apm.pdef.xml' % vehicle
path = mp_util.dot_mavproxy("%s.xml" % vehicle)
files.append((url, path))
url = 'http://autotest.ardupilot.org/%s-defaults.parm' % vehicle
if vehicle != 'AntennaTracker':
# defaults not generated for AntennaTracker ATM
path = mp_util.dot_mavproxy("%s-defaults.parm" % vehicle)
files.append((url, path))
try:
child = multiproc.Process(target=mp_util.download_files, args=(files,))
child.start()
except Exception as e:
print(e) | python | def param_help_download(self):
'''download XML files for parameters'''
files = []
for vehicle in ['APMrover2', 'ArduCopter', 'ArduPlane', 'ArduSub', 'AntennaTracker']:
url = 'http://autotest.ardupilot.org/Parameters/%s/apm.pdef.xml' % vehicle
path = mp_util.dot_mavproxy("%s.xml" % vehicle)
files.append((url, path))
url = 'http://autotest.ardupilot.org/%s-defaults.parm' % vehicle
if vehicle != 'AntennaTracker':
# defaults not generated for AntennaTracker ATM
path = mp_util.dot_mavproxy("%s-defaults.parm" % vehicle)
files.append((url, path))
try:
child = multiproc.Process(target=mp_util.download_files, args=(files,))
child.start()
except Exception as e:
print(e) | [
"def",
"param_help_download",
"(",
"self",
")",
":",
"files",
"=",
"[",
"]",
"for",
"vehicle",
"in",
"[",
"'APMrover2'",
",",
"'ArduCopter'",
",",
"'ArduPlane'",
",",
"'ArduSub'",
",",
"'AntennaTracker'",
"]",
":",
"url",
"=",
"'http://autotest.ardupilot.org/Parameters/%s/apm.pdef.xml'",
"%",
"vehicle",
"path",
"=",
"mp_util",
".",
"dot_mavproxy",
"(",
"\"%s.xml\"",
"%",
"vehicle",
")",
"files",
".",
"append",
"(",
"(",
"url",
",",
"path",
")",
")",
"url",
"=",
"'http://autotest.ardupilot.org/%s-defaults.parm'",
"%",
"vehicle",
"if",
"vehicle",
"!=",
"'AntennaTracker'",
":",
"# defaults not generated for AntennaTracker ATM",
"path",
"=",
"mp_util",
".",
"dot_mavproxy",
"(",
"\"%s-defaults.parm\"",
"%",
"vehicle",
")",
"files",
".",
"append",
"(",
"(",
"url",
",",
"path",
")",
")",
"try",
":",
"child",
"=",
"multiproc",
".",
"Process",
"(",
"target",
"=",
"mp_util",
".",
"download_files",
",",
"args",
"=",
"(",
"files",
",",
")",
")",
"child",
".",
"start",
"(",
")",
"except",
"Exception",
"as",
"e",
":",
"print",
"(",
"e",
")"
] | download XML files for parameters | [
"download",
"XML",
"files",
"for",
"parameters"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_param.py#L121-L137 |
249,576 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_param.py | ParamState.param_help_tree | def param_help_tree(self):
'''return a "help tree", a map between a parameter and its metadata. May return None if help is not available'''
if self.xml_filepath is not None:
print("param: using xml_filepath=%s" % self.xml_filepath)
path = self.xml_filepath
else:
if self.vehicle_name is None:
print("Unknown vehicle type")
return None
path = mp_util.dot_mavproxy("%s.xml" % self.vehicle_name)
if not os.path.exists(path):
print("Please run 'param download' first (vehicle_name=%s)" % self.vehicle_name)
return None
if not os.path.exists(path):
print("Param XML (%s) does not exist" % path)
return None
xml = open(path,'rb').read()
from lxml import objectify
objectify.enable_recursive_str()
tree = objectify.fromstring(xml)
htree = {}
for p in tree.vehicles.parameters.param:
n = p.get('name').split(':')[1]
htree[n] = p
for lib in tree.libraries.parameters:
for p in lib.param:
n = p.get('name')
htree[n] = p
return htree | python | def param_help_tree(self):
'''return a "help tree", a map between a parameter and its metadata. May return None if help is not available'''
if self.xml_filepath is not None:
print("param: using xml_filepath=%s" % self.xml_filepath)
path = self.xml_filepath
else:
if self.vehicle_name is None:
print("Unknown vehicle type")
return None
path = mp_util.dot_mavproxy("%s.xml" % self.vehicle_name)
if not os.path.exists(path):
print("Please run 'param download' first (vehicle_name=%s)" % self.vehicle_name)
return None
if not os.path.exists(path):
print("Param XML (%s) does not exist" % path)
return None
xml = open(path,'rb').read()
from lxml import objectify
objectify.enable_recursive_str()
tree = objectify.fromstring(xml)
htree = {}
for p in tree.vehicles.parameters.param:
n = p.get('name').split(':')[1]
htree[n] = p
for lib in tree.libraries.parameters:
for p in lib.param:
n = p.get('name')
htree[n] = p
return htree | [
"def",
"param_help_tree",
"(",
"self",
")",
":",
"if",
"self",
".",
"xml_filepath",
"is",
"not",
"None",
":",
"print",
"(",
"\"param: using xml_filepath=%s\"",
"%",
"self",
".",
"xml_filepath",
")",
"path",
"=",
"self",
".",
"xml_filepath",
"else",
":",
"if",
"self",
".",
"vehicle_name",
"is",
"None",
":",
"print",
"(",
"\"Unknown vehicle type\"",
")",
"return",
"None",
"path",
"=",
"mp_util",
".",
"dot_mavproxy",
"(",
"\"%s.xml\"",
"%",
"self",
".",
"vehicle_name",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"print",
"(",
"\"Please run 'param download' first (vehicle_name=%s)\"",
"%",
"self",
".",
"vehicle_name",
")",
"return",
"None",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"print",
"(",
"\"Param XML (%s) does not exist\"",
"%",
"path",
")",
"return",
"None",
"xml",
"=",
"open",
"(",
"path",
",",
"'rb'",
")",
".",
"read",
"(",
")",
"from",
"lxml",
"import",
"objectify",
"objectify",
".",
"enable_recursive_str",
"(",
")",
"tree",
"=",
"objectify",
".",
"fromstring",
"(",
"xml",
")",
"htree",
"=",
"{",
"}",
"for",
"p",
"in",
"tree",
".",
"vehicles",
".",
"parameters",
".",
"param",
":",
"n",
"=",
"p",
".",
"get",
"(",
"'name'",
")",
".",
"split",
"(",
"':'",
")",
"[",
"1",
"]",
"htree",
"[",
"n",
"]",
"=",
"p",
"for",
"lib",
"in",
"tree",
".",
"libraries",
".",
"parameters",
":",
"for",
"p",
"in",
"lib",
".",
"param",
":",
"n",
"=",
"p",
".",
"get",
"(",
"'name'",
")",
"htree",
"[",
"n",
"]",
"=",
"p",
"return",
"htree"
] | return a "help tree", a map between a parameter and its metadata. May return None if help is not available | [
"return",
"a",
"help",
"tree",
"a",
"map",
"between",
"a",
"parameter",
"and",
"its",
"metadata",
".",
"May",
"return",
"None",
"if",
"help",
"is",
"not",
"available"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_param.py#L142-L170 |
249,577 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_param.py | ParamState.param_apropos | def param_apropos(self, args):
'''search parameter help for a keyword, list those parameters'''
if len(args) == 0:
print("Usage: param apropos keyword")
return
htree = self.param_help_tree()
if htree is None:
return
contains = {}
for keyword in args:
for param in htree.keys():
if str(htree[param]).find(keyword) != -1:
contains[param] = True
for param in contains.keys():
print("%s" % (param,)) | python | def param_apropos(self, args):
'''search parameter help for a keyword, list those parameters'''
if len(args) == 0:
print("Usage: param apropos keyword")
return
htree = self.param_help_tree()
if htree is None:
return
contains = {}
for keyword in args:
for param in htree.keys():
if str(htree[param]).find(keyword) != -1:
contains[param] = True
for param in contains.keys():
print("%s" % (param,)) | [
"def",
"param_apropos",
"(",
"self",
",",
"args",
")",
":",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"print",
"(",
"\"Usage: param apropos keyword\"",
")",
"return",
"htree",
"=",
"self",
".",
"param_help_tree",
"(",
")",
"if",
"htree",
"is",
"None",
":",
"return",
"contains",
"=",
"{",
"}",
"for",
"keyword",
"in",
"args",
":",
"for",
"param",
"in",
"htree",
".",
"keys",
"(",
")",
":",
"if",
"str",
"(",
"htree",
"[",
"param",
"]",
")",
".",
"find",
"(",
"keyword",
")",
"!=",
"-",
"1",
":",
"contains",
"[",
"param",
"]",
"=",
"True",
"for",
"param",
"in",
"contains",
".",
"keys",
"(",
")",
":",
"print",
"(",
"\"%s\"",
"%",
"(",
"param",
",",
")",
")"
] | search parameter help for a keyword, list those parameters | [
"search",
"parameter",
"help",
"for",
"a",
"keyword",
"list",
"those",
"parameters"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_param.py#L175-L191 |
249,578 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_param.py | ParamModule.get_component_id_list | def get_component_id_list(self, system_id):
'''get list of component IDs with parameters for a given system ID'''
ret = []
for (s,c) in self.mpstate.mav_param_by_sysid.keys():
if s == system_id:
ret.append(c)
return ret | python | def get_component_id_list(self, system_id):
'''get list of component IDs with parameters for a given system ID'''
ret = []
for (s,c) in self.mpstate.mav_param_by_sysid.keys():
if s == system_id:
ret.append(c)
return ret | [
"def",
"get_component_id_list",
"(",
"self",
",",
"system_id",
")",
":",
"ret",
"=",
"[",
"]",
"for",
"(",
"s",
",",
"c",
")",
"in",
"self",
".",
"mpstate",
".",
"mav_param_by_sysid",
".",
"keys",
"(",
")",
":",
"if",
"s",
"==",
"system_id",
":",
"ret",
".",
"append",
"(",
"c",
")",
"return",
"ret"
] | get list of component IDs with parameters for a given system ID | [
"get",
"list",
"of",
"component",
"IDs",
"with",
"parameters",
"for",
"a",
"given",
"system",
"ID"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_param.py#L371-L377 |
249,579 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_param.py | ParamModule.get_sysid | def get_sysid(self):
'''get sysid tuple to use for parameters'''
component = self.target_component
if component == 0:
component = 1
return (self.target_system, component) | python | def get_sysid(self):
'''get sysid tuple to use for parameters'''
component = self.target_component
if component == 0:
component = 1
return (self.target_system, component) | [
"def",
"get_sysid",
"(",
"self",
")",
":",
"component",
"=",
"self",
".",
"target_component",
"if",
"component",
"==",
"0",
":",
"component",
"=",
"1",
"return",
"(",
"self",
".",
"target_system",
",",
"component",
")"
] | get sysid tuple to use for parameters | [
"get",
"sysid",
"tuple",
"to",
"use",
"for",
"parameters"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_param.py#L398-L403 |
249,580 | ArduPilot/MAVProxy | MAVProxy/modules/lib/optparse_gui/__init__.py | OptionParser.parse_args | def parse_args( self, args = None, values = None ):
'''
multiprocessing wrapper around _parse_args
'''
q = multiproc.Queue()
p = multiproc.Process(target=self._parse_args, args=(q, args, values))
p.start()
ret = q.get()
p.join()
return ret | python | def parse_args( self, args = None, values = None ):
'''
multiprocessing wrapper around _parse_args
'''
q = multiproc.Queue()
p = multiproc.Process(target=self._parse_args, args=(q, args, values))
p.start()
ret = q.get()
p.join()
return ret | [
"def",
"parse_args",
"(",
"self",
",",
"args",
"=",
"None",
",",
"values",
"=",
"None",
")",
":",
"q",
"=",
"multiproc",
".",
"Queue",
"(",
")",
"p",
"=",
"multiproc",
".",
"Process",
"(",
"target",
"=",
"self",
".",
"_parse_args",
",",
"args",
"=",
"(",
"q",
",",
"args",
",",
"values",
")",
")",
"p",
".",
"start",
"(",
")",
"ret",
"=",
"q",
".",
"get",
"(",
")",
"p",
".",
"join",
"(",
")",
"return",
"ret"
] | multiprocessing wrapper around _parse_args | [
"multiprocessing",
"wrapper",
"around",
"_parse_args"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/optparse_gui/__init__.py#L206-L215 |
249,581 | ArduPilot/MAVProxy | MAVProxy/modules/lib/optparse_gui/__init__.py | OptionParser._parse_args | def _parse_args( self, q, args, values):
'''
This is the heart of it all - overrides optparse.OptionParser.parse_args
@param arg is irrelevant and thus ignored,
it is here only for interface compatibility
'''
if wx.GetApp() is None:
self.app = wx.App( False )
# preprocess command line arguments and set to defaults
option_values, args = self.SUPER.parse_args(self, args, values)
for option in self.option_list:
if option.dest and hasattr(option_values, option.dest):
default = getattr(option_values, option.dest)
if default is not None:
option.default = default
dlg = OptparseDialog( option_parser = self, title=self.get_description() )
if args:
dlg.args_ctrl.Value = ' '.join(args)
dlg_result = dlg.ShowModal()
if wx.ID_OK != dlg_result:
raise UserCancelledError( 'User has canceled' )
if values is None:
values = self.get_default_values()
option_values, args = dlg.getOptionsAndArgs()
for option, value in option_values.iteritems():
if ( 'store_true' == option.action ) and ( value is False ):
setattr( values, option.dest, False )
continue
if ( 'store_false' == option.action ) and ( value is True ):
setattr( values, option.dest, False )
continue
if option.takes_value() is False:
value = None
option.process( option, value, values, self )
q.put((values, args)) | python | def _parse_args( self, q, args, values):
'''
This is the heart of it all - overrides optparse.OptionParser.parse_args
@param arg is irrelevant and thus ignored,
it is here only for interface compatibility
'''
if wx.GetApp() is None:
self.app = wx.App( False )
# preprocess command line arguments and set to defaults
option_values, args = self.SUPER.parse_args(self, args, values)
for option in self.option_list:
if option.dest and hasattr(option_values, option.dest):
default = getattr(option_values, option.dest)
if default is not None:
option.default = default
dlg = OptparseDialog( option_parser = self, title=self.get_description() )
if args:
dlg.args_ctrl.Value = ' '.join(args)
dlg_result = dlg.ShowModal()
if wx.ID_OK != dlg_result:
raise UserCancelledError( 'User has canceled' )
if values is None:
values = self.get_default_values()
option_values, args = dlg.getOptionsAndArgs()
for option, value in option_values.iteritems():
if ( 'store_true' == option.action ) and ( value is False ):
setattr( values, option.dest, False )
continue
if ( 'store_false' == option.action ) and ( value is True ):
setattr( values, option.dest, False )
continue
if option.takes_value() is False:
value = None
option.process( option, value, values, self )
q.put((values, args)) | [
"def",
"_parse_args",
"(",
"self",
",",
"q",
",",
"args",
",",
"values",
")",
":",
"if",
"wx",
".",
"GetApp",
"(",
")",
"is",
"None",
":",
"self",
".",
"app",
"=",
"wx",
".",
"App",
"(",
"False",
")",
"# preprocess command line arguments and set to defaults",
"option_values",
",",
"args",
"=",
"self",
".",
"SUPER",
".",
"parse_args",
"(",
"self",
",",
"args",
",",
"values",
")",
"for",
"option",
"in",
"self",
".",
"option_list",
":",
"if",
"option",
".",
"dest",
"and",
"hasattr",
"(",
"option_values",
",",
"option",
".",
"dest",
")",
":",
"default",
"=",
"getattr",
"(",
"option_values",
",",
"option",
".",
"dest",
")",
"if",
"default",
"is",
"not",
"None",
":",
"option",
".",
"default",
"=",
"default",
"dlg",
"=",
"OptparseDialog",
"(",
"option_parser",
"=",
"self",
",",
"title",
"=",
"self",
".",
"get_description",
"(",
")",
")",
"if",
"args",
":",
"dlg",
".",
"args_ctrl",
".",
"Value",
"=",
"' '",
".",
"join",
"(",
"args",
")",
"dlg_result",
"=",
"dlg",
".",
"ShowModal",
"(",
")",
"if",
"wx",
".",
"ID_OK",
"!=",
"dlg_result",
":",
"raise",
"UserCancelledError",
"(",
"'User has canceled'",
")",
"if",
"values",
"is",
"None",
":",
"values",
"=",
"self",
".",
"get_default_values",
"(",
")",
"option_values",
",",
"args",
"=",
"dlg",
".",
"getOptionsAndArgs",
"(",
")",
"for",
"option",
",",
"value",
"in",
"option_values",
".",
"iteritems",
"(",
")",
":",
"if",
"(",
"'store_true'",
"==",
"option",
".",
"action",
")",
"and",
"(",
"value",
"is",
"False",
")",
":",
"setattr",
"(",
"values",
",",
"option",
".",
"dest",
",",
"False",
")",
"continue",
"if",
"(",
"'store_false'",
"==",
"option",
".",
"action",
")",
"and",
"(",
"value",
"is",
"True",
")",
":",
"setattr",
"(",
"values",
",",
"option",
".",
"dest",
",",
"False",
")",
"continue",
"if",
"option",
".",
"takes_value",
"(",
")",
"is",
"False",
":",
"value",
"=",
"None",
"option",
".",
"process",
"(",
"option",
",",
"value",
",",
"values",
",",
"self",
")",
"q",
".",
"put",
"(",
"(",
"values",
",",
"args",
")",
")"
] | This is the heart of it all - overrides optparse.OptionParser.parse_args
@param arg is irrelevant and thus ignored,
it is here only for interface compatibility | [
"This",
"is",
"the",
"heart",
"of",
"it",
"all",
"-",
"overrides",
"optparse",
".",
"OptionParser",
".",
"parse_args"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/optparse_gui/__init__.py#L217-L261 |
249,582 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_genobstacles.py | DNFZ.distance_from | def distance_from(self, lat, lon):
'''get distance from a point'''
lat1 = self.pkt['I105']['Lat']['val']
lon1 = self.pkt['I105']['Lon']['val']
return mp_util.gps_distance(lat1, lon1, lat, lon) | python | def distance_from(self, lat, lon):
'''get distance from a point'''
lat1 = self.pkt['I105']['Lat']['val']
lon1 = self.pkt['I105']['Lon']['val']
return mp_util.gps_distance(lat1, lon1, lat, lon) | [
"def",
"distance_from",
"(",
"self",
",",
"lat",
",",
"lon",
")",
":",
"lat1",
"=",
"self",
".",
"pkt",
"[",
"'I105'",
"]",
"[",
"'Lat'",
"]",
"[",
"'val'",
"]",
"lon1",
"=",
"self",
".",
"pkt",
"[",
"'I105'",
"]",
"[",
"'Lon'",
"]",
"[",
"'val'",
"]",
"return",
"mp_util",
".",
"gps_distance",
"(",
"lat1",
",",
"lon1",
",",
"lat",
",",
"lon",
")"
] | get distance from a point | [
"get",
"distance",
"from",
"a",
"point"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_genobstacles.py#L65-L69 |
249,583 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_genobstacles.py | DNFZ.randpos | def randpos(self):
'''random initial position'''
self.setpos(gen_settings.home_lat, gen_settings.home_lon)
self.move(random.uniform(0, 360), random.uniform(0, gen_settings.region_width)) | python | def randpos(self):
'''random initial position'''
self.setpos(gen_settings.home_lat, gen_settings.home_lon)
self.move(random.uniform(0, 360), random.uniform(0, gen_settings.region_width)) | [
"def",
"randpos",
"(",
"self",
")",
":",
"self",
".",
"setpos",
"(",
"gen_settings",
".",
"home_lat",
",",
"gen_settings",
".",
"home_lon",
")",
"self",
".",
"move",
"(",
"random",
".",
"uniform",
"(",
"0",
",",
"360",
")",
",",
"random",
".",
"uniform",
"(",
"0",
",",
"gen_settings",
".",
"region_width",
")",
")"
] | random initial position | [
"random",
"initial",
"position"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_genobstacles.py#L75-L78 |
249,584 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_genobstacles.py | DNFZ.ground_height | def ground_height(self):
'''return height above ground in feet'''
lat = self.pkt['I105']['Lat']['val']
lon = self.pkt['I105']['Lon']['val']
global ElevationMap
ret = ElevationMap.GetElevation(lat, lon)
ret -= gen_settings.wgs84_to_AMSL
return ret * 3.2807 | python | def ground_height(self):
'''return height above ground in feet'''
lat = self.pkt['I105']['Lat']['val']
lon = self.pkt['I105']['Lon']['val']
global ElevationMap
ret = ElevationMap.GetElevation(lat, lon)
ret -= gen_settings.wgs84_to_AMSL
return ret * 3.2807 | [
"def",
"ground_height",
"(",
"self",
")",
":",
"lat",
"=",
"self",
".",
"pkt",
"[",
"'I105'",
"]",
"[",
"'Lat'",
"]",
"[",
"'val'",
"]",
"lon",
"=",
"self",
".",
"pkt",
"[",
"'I105'",
"]",
"[",
"'Lon'",
"]",
"[",
"'val'",
"]",
"global",
"ElevationMap",
"ret",
"=",
"ElevationMap",
".",
"GetElevation",
"(",
"lat",
",",
"lon",
")",
"ret",
"-=",
"gen_settings",
".",
"wgs84_to_AMSL",
"return",
"ret",
"*",
"3.2807"
] | return height above ground in feet | [
"return",
"height",
"above",
"ground",
"in",
"feet"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_genobstacles.py#L80-L87 |
249,585 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_genobstacles.py | DNFZ.move | def move(self, bearing, distance):
'''move position by bearing and distance'''
lat = self.pkt['I105']['Lat']['val']
lon = self.pkt['I105']['Lon']['val']
(lat, lon) = mp_util.gps_newpos(lat, lon, bearing, distance)
self.setpos(lat, lon) | python | def move(self, bearing, distance):
'''move position by bearing and distance'''
lat = self.pkt['I105']['Lat']['val']
lon = self.pkt['I105']['Lon']['val']
(lat, lon) = mp_util.gps_newpos(lat, lon, bearing, distance)
self.setpos(lat, lon) | [
"def",
"move",
"(",
"self",
",",
"bearing",
",",
"distance",
")",
":",
"lat",
"=",
"self",
".",
"pkt",
"[",
"'I105'",
"]",
"[",
"'Lat'",
"]",
"[",
"'val'",
"]",
"lon",
"=",
"self",
".",
"pkt",
"[",
"'I105'",
"]",
"[",
"'Lon'",
"]",
"[",
"'val'",
"]",
"(",
"lat",
",",
"lon",
")",
"=",
"mp_util",
".",
"gps_newpos",
"(",
"lat",
",",
"lon",
",",
"bearing",
",",
"distance",
")",
"self",
".",
"setpos",
"(",
"lat",
",",
"lon",
")"
] | move position by bearing and distance | [
"move",
"position",
"by",
"bearing",
"and",
"distance"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_genobstacles.py#L93-L98 |
249,586 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_genobstacles.py | Aircraft.update | def update(self, deltat=1.0):
'''fly a square circuit'''
DNFZ.update(self, deltat)
self.dist_flown += self.speed * deltat
if self.dist_flown > self.circuit_width:
self.desired_heading = self.heading + 90
self.dist_flown = 0
if self.getalt() < self.ground_height() or self.getalt() > self.ground_height() + 2000:
self.randpos()
self.randalt() | python | def update(self, deltat=1.0):
'''fly a square circuit'''
DNFZ.update(self, deltat)
self.dist_flown += self.speed * deltat
if self.dist_flown > self.circuit_width:
self.desired_heading = self.heading + 90
self.dist_flown = 0
if self.getalt() < self.ground_height() or self.getalt() > self.ground_height() + 2000:
self.randpos()
self.randalt() | [
"def",
"update",
"(",
"self",
",",
"deltat",
"=",
"1.0",
")",
":",
"DNFZ",
".",
"update",
"(",
"self",
",",
"deltat",
")",
"self",
".",
"dist_flown",
"+=",
"self",
".",
"speed",
"*",
"deltat",
"if",
"self",
".",
"dist_flown",
">",
"self",
".",
"circuit_width",
":",
"self",
".",
"desired_heading",
"=",
"self",
".",
"heading",
"+",
"90",
"self",
".",
"dist_flown",
"=",
"0",
"if",
"self",
".",
"getalt",
"(",
")",
"<",
"self",
".",
"ground_height",
"(",
")",
"or",
"self",
".",
"getalt",
"(",
")",
">",
"self",
".",
"ground_height",
"(",
")",
"+",
"2000",
":",
"self",
".",
"randpos",
"(",
")",
"self",
".",
"randalt",
"(",
")"
] | fly a square circuit | [
"fly",
"a",
"square",
"circuit"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_genobstacles.py#L180-L189 |
249,587 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_genobstacles.py | BirdOfPrey.update | def update(self, deltat=1.0):
'''fly circles, then dive'''
DNFZ.update(self, deltat)
self.time_circling += deltat
self.setheading(self.heading + self.turn_rate * deltat)
self.move(self.drift_heading, self.drift_speed)
if self.getalt() > self.max_alt or self.getalt() < self.ground_height():
if self.getalt() > self.ground_height():
self.setclimbrate(self.dive_rate)
else:
self.setclimbrate(self.climb_rate)
if self.getalt() < self.ground_height():
self.setalt(self.ground_height())
if self.distance_from_home() > gen_settings.region_width:
self.randpos()
self.randalt() | python | def update(self, deltat=1.0):
'''fly circles, then dive'''
DNFZ.update(self, deltat)
self.time_circling += deltat
self.setheading(self.heading + self.turn_rate * deltat)
self.move(self.drift_heading, self.drift_speed)
if self.getalt() > self.max_alt or self.getalt() < self.ground_height():
if self.getalt() > self.ground_height():
self.setclimbrate(self.dive_rate)
else:
self.setclimbrate(self.climb_rate)
if self.getalt() < self.ground_height():
self.setalt(self.ground_height())
if self.distance_from_home() > gen_settings.region_width:
self.randpos()
self.randalt() | [
"def",
"update",
"(",
"self",
",",
"deltat",
"=",
"1.0",
")",
":",
"DNFZ",
".",
"update",
"(",
"self",
",",
"deltat",
")",
"self",
".",
"time_circling",
"+=",
"deltat",
"self",
".",
"setheading",
"(",
"self",
".",
"heading",
"+",
"self",
".",
"turn_rate",
"*",
"deltat",
")",
"self",
".",
"move",
"(",
"self",
".",
"drift_heading",
",",
"self",
".",
"drift_speed",
")",
"if",
"self",
".",
"getalt",
"(",
")",
">",
"self",
".",
"max_alt",
"or",
"self",
".",
"getalt",
"(",
")",
"<",
"self",
".",
"ground_height",
"(",
")",
":",
"if",
"self",
".",
"getalt",
"(",
")",
">",
"self",
".",
"ground_height",
"(",
")",
":",
"self",
".",
"setclimbrate",
"(",
"self",
".",
"dive_rate",
")",
"else",
":",
"self",
".",
"setclimbrate",
"(",
"self",
".",
"climb_rate",
")",
"if",
"self",
".",
"getalt",
"(",
")",
"<",
"self",
".",
"ground_height",
"(",
")",
":",
"self",
".",
"setalt",
"(",
"self",
".",
"ground_height",
"(",
")",
")",
"if",
"self",
".",
"distance_from_home",
"(",
")",
">",
"gen_settings",
".",
"region_width",
":",
"self",
".",
"randpos",
"(",
")",
"self",
".",
"randalt",
"(",
")"
] | fly circles, then dive | [
"fly",
"circles",
"then",
"dive"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_genobstacles.py#L209-L224 |
249,588 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_genobstacles.py | BirdMigrating.update | def update(self, deltat=1.0):
'''fly in long curves'''
DNFZ.update(self, deltat)
if (self.distance_from_home() > gen_settings.region_width or
self.getalt() < self.ground_height() or
self.getalt() > self.ground_height() + 1000):
self.randpos()
self.randalt() | python | def update(self, deltat=1.0):
'''fly in long curves'''
DNFZ.update(self, deltat)
if (self.distance_from_home() > gen_settings.region_width or
self.getalt() < self.ground_height() or
self.getalt() > self.ground_height() + 1000):
self.randpos()
self.randalt() | [
"def",
"update",
"(",
"self",
",",
"deltat",
"=",
"1.0",
")",
":",
"DNFZ",
".",
"update",
"(",
"self",
",",
"deltat",
")",
"if",
"(",
"self",
".",
"distance_from_home",
"(",
")",
">",
"gen_settings",
".",
"region_width",
"or",
"self",
".",
"getalt",
"(",
")",
"<",
"self",
".",
"ground_height",
"(",
")",
"or",
"self",
".",
"getalt",
"(",
")",
">",
"self",
".",
"ground_height",
"(",
")",
"+",
"1000",
")",
":",
"self",
".",
"randpos",
"(",
")",
"self",
".",
"randalt",
"(",
")"
] | fly in long curves | [
"fly",
"in",
"long",
"curves"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_genobstacles.py#L234-L241 |
249,589 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_genobstacles.py | Weather.update | def update(self, deltat=1.0):
'''straight lines, with short life'''
DNFZ.update(self, deltat)
self.lifetime -= deltat
if self.lifetime <= 0:
self.randpos()
self.lifetime = random.uniform(300,600) | python | def update(self, deltat=1.0):
'''straight lines, with short life'''
DNFZ.update(self, deltat)
self.lifetime -= deltat
if self.lifetime <= 0:
self.randpos()
self.lifetime = random.uniform(300,600) | [
"def",
"update",
"(",
"self",
",",
"deltat",
"=",
"1.0",
")",
":",
"DNFZ",
".",
"update",
"(",
"self",
",",
"deltat",
")",
"self",
".",
"lifetime",
"-=",
"deltat",
"if",
"self",
".",
"lifetime",
"<=",
"0",
":",
"self",
".",
"randpos",
"(",
")",
"self",
".",
"lifetime",
"=",
"random",
".",
"uniform",
"(",
"300",
",",
"600",
")"
] | straight lines, with short life | [
"straight",
"lines",
"with",
"short",
"life"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_genobstacles.py#L252-L258 |
249,590 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_genobstacles.py | GenobstaclesModule.cmd_dropobject | def cmd_dropobject(self, obj):
'''drop an object on the map'''
latlon = self.module('map').click_position
if self.last_click is not None and self.last_click == latlon:
return
self.last_click = latlon
if latlon is not None:
obj.setpos(latlon[0], latlon[1])
self.aircraft.append(obj) | python | def cmd_dropobject(self, obj):
'''drop an object on the map'''
latlon = self.module('map').click_position
if self.last_click is not None and self.last_click == latlon:
return
self.last_click = latlon
if latlon is not None:
obj.setpos(latlon[0], latlon[1])
self.aircraft.append(obj) | [
"def",
"cmd_dropobject",
"(",
"self",
",",
"obj",
")",
":",
"latlon",
"=",
"self",
".",
"module",
"(",
"'map'",
")",
".",
"click_position",
"if",
"self",
".",
"last_click",
"is",
"not",
"None",
"and",
"self",
".",
"last_click",
"==",
"latlon",
":",
"return",
"self",
".",
"last_click",
"=",
"latlon",
"if",
"latlon",
"is",
"not",
"None",
":",
"obj",
".",
"setpos",
"(",
"latlon",
"[",
"0",
"]",
",",
"latlon",
"[",
"1",
"]",
")",
"self",
".",
"aircraft",
".",
"append",
"(",
"obj",
")"
] | drop an object on the map | [
"drop",
"an",
"object",
"on",
"the",
"map"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_genobstacles.py#L291-L299 |
249,591 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_genobstacles.py | GenobstaclesModule.cmd_genobstacles | def cmd_genobstacles(self, args):
'''genobstacles command parser'''
usage = "usage: genobstacles <start|stop|restart|clearall|status|set>"
if len(args) == 0:
print(usage)
return
if args[0] == "set":
gen_settings.command(args[1:])
elif args[0] == "start":
if self.have_home:
self.start()
else:
self.pending_start = True
elif args[0] == "stop":
self.stop()
self.pending_start = False
elif args[0] == "restart":
self.stop()
self.start()
elif args[0] == "status":
print(self.status())
elif args[0] == "remove":
latlon = self.module('map').click_position
if self.last_click is not None and self.last_click == latlon:
return
self.last_click = latlon
if latlon is not None:
closest = None
closest_distance = 1000
for a in self.aircraft:
dist = a.distance_from(latlon[0], latlon[1])
if dist < closest_distance:
closest_distance = dist
closest = a
if closest is not None:
self.aircraft.remove(closest)
else:
print("No obstacle found at click point")
elif args[0] == "dropcloud":
self.cmd_dropobject(Weather())
elif args[0] == "dropeagle":
self.cmd_dropobject(BirdOfPrey())
elif args[0] == "dropbird":
self.cmd_dropobject(BirdMigrating())
elif args[0] == "dropplane":
self.cmd_dropobject(Aircraft())
elif args[0] == "clearall":
self.clearall()
else:
print(usage) | python | def cmd_genobstacles(self, args):
'''genobstacles command parser'''
usage = "usage: genobstacles <start|stop|restart|clearall|status|set>"
if len(args) == 0:
print(usage)
return
if args[0] == "set":
gen_settings.command(args[1:])
elif args[0] == "start":
if self.have_home:
self.start()
else:
self.pending_start = True
elif args[0] == "stop":
self.stop()
self.pending_start = False
elif args[0] == "restart":
self.stop()
self.start()
elif args[0] == "status":
print(self.status())
elif args[0] == "remove":
latlon = self.module('map').click_position
if self.last_click is not None and self.last_click == latlon:
return
self.last_click = latlon
if latlon is not None:
closest = None
closest_distance = 1000
for a in self.aircraft:
dist = a.distance_from(latlon[0], latlon[1])
if dist < closest_distance:
closest_distance = dist
closest = a
if closest is not None:
self.aircraft.remove(closest)
else:
print("No obstacle found at click point")
elif args[0] == "dropcloud":
self.cmd_dropobject(Weather())
elif args[0] == "dropeagle":
self.cmd_dropobject(BirdOfPrey())
elif args[0] == "dropbird":
self.cmd_dropobject(BirdMigrating())
elif args[0] == "dropplane":
self.cmd_dropobject(Aircraft())
elif args[0] == "clearall":
self.clearall()
else:
print(usage) | [
"def",
"cmd_genobstacles",
"(",
"self",
",",
"args",
")",
":",
"usage",
"=",
"\"usage: genobstacles <start|stop|restart|clearall|status|set>\"",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"print",
"(",
"usage",
")",
"return",
"if",
"args",
"[",
"0",
"]",
"==",
"\"set\"",
":",
"gen_settings",
".",
"command",
"(",
"args",
"[",
"1",
":",
"]",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"\"start\"",
":",
"if",
"self",
".",
"have_home",
":",
"self",
".",
"start",
"(",
")",
"else",
":",
"self",
".",
"pending_start",
"=",
"True",
"elif",
"args",
"[",
"0",
"]",
"==",
"\"stop\"",
":",
"self",
".",
"stop",
"(",
")",
"self",
".",
"pending_start",
"=",
"False",
"elif",
"args",
"[",
"0",
"]",
"==",
"\"restart\"",
":",
"self",
".",
"stop",
"(",
")",
"self",
".",
"start",
"(",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"\"status\"",
":",
"print",
"(",
"self",
".",
"status",
"(",
")",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"\"remove\"",
":",
"latlon",
"=",
"self",
".",
"module",
"(",
"'map'",
")",
".",
"click_position",
"if",
"self",
".",
"last_click",
"is",
"not",
"None",
"and",
"self",
".",
"last_click",
"==",
"latlon",
":",
"return",
"self",
".",
"last_click",
"=",
"latlon",
"if",
"latlon",
"is",
"not",
"None",
":",
"closest",
"=",
"None",
"closest_distance",
"=",
"1000",
"for",
"a",
"in",
"self",
".",
"aircraft",
":",
"dist",
"=",
"a",
".",
"distance_from",
"(",
"latlon",
"[",
"0",
"]",
",",
"latlon",
"[",
"1",
"]",
")",
"if",
"dist",
"<",
"closest_distance",
":",
"closest_distance",
"=",
"dist",
"closest",
"=",
"a",
"if",
"closest",
"is",
"not",
"None",
":",
"self",
".",
"aircraft",
".",
"remove",
"(",
"closest",
")",
"else",
":",
"print",
"(",
"\"No obstacle found at click point\"",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"\"dropcloud\"",
":",
"self",
".",
"cmd_dropobject",
"(",
"Weather",
"(",
")",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"\"dropeagle\"",
":",
"self",
".",
"cmd_dropobject",
"(",
"BirdOfPrey",
"(",
")",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"\"dropbird\"",
":",
"self",
".",
"cmd_dropobject",
"(",
"BirdMigrating",
"(",
")",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"\"dropplane\"",
":",
"self",
".",
"cmd_dropobject",
"(",
"Aircraft",
"(",
")",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"\"clearall\"",
":",
"self",
".",
"clearall",
"(",
")",
"else",
":",
"print",
"(",
"usage",
")"
] | genobstacles command parser | [
"genobstacles",
"command",
"parser"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_genobstacles.py#L309-L359 |
249,592 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_genobstacles.py | GenobstaclesModule.start | def start(self):
'''start sending packets'''
if self.sock is not None:
self.sock.close()
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.connect(('', gen_settings.port))
global track_count
self.aircraft = []
track_count = 0
self.last_t = 0
# some fixed wing aircraft
for i in range(gen_settings.num_aircraft):
self.aircraft.append(Aircraft(random.uniform(10, 100), 2000.0))
# some birds of prey
for i in range(gen_settings.num_bird_prey):
self.aircraft.append(BirdOfPrey())
# some migrating birds
for i in range(gen_settings.num_bird_migratory):
self.aircraft.append(BirdMigrating())
# some weather systems
for i in range(gen_settings.num_weather):
self.aircraft.append(Weather())
print("Started on port %u" % gen_settings.port) | python | def start(self):
'''start sending packets'''
if self.sock is not None:
self.sock.close()
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.connect(('', gen_settings.port))
global track_count
self.aircraft = []
track_count = 0
self.last_t = 0
# some fixed wing aircraft
for i in range(gen_settings.num_aircraft):
self.aircraft.append(Aircraft(random.uniform(10, 100), 2000.0))
# some birds of prey
for i in range(gen_settings.num_bird_prey):
self.aircraft.append(BirdOfPrey())
# some migrating birds
for i in range(gen_settings.num_bird_migratory):
self.aircraft.append(BirdMigrating())
# some weather systems
for i in range(gen_settings.num_weather):
self.aircraft.append(Weather())
print("Started on port %u" % gen_settings.port) | [
"def",
"start",
"(",
"self",
")",
":",
"if",
"self",
".",
"sock",
"is",
"not",
"None",
":",
"self",
".",
"sock",
".",
"close",
"(",
")",
"self",
".",
"sock",
"=",
"socket",
".",
"socket",
"(",
"socket",
".",
"AF_INET",
",",
"socket",
".",
"SOCK_DGRAM",
",",
"socket",
".",
"IPPROTO_UDP",
")",
"self",
".",
"sock",
".",
"setsockopt",
"(",
"socket",
".",
"SOL_SOCKET",
",",
"socket",
".",
"SO_REUSEADDR",
",",
"1",
")",
"self",
".",
"sock",
".",
"connect",
"(",
"(",
"''",
",",
"gen_settings",
".",
"port",
")",
")",
"global",
"track_count",
"self",
".",
"aircraft",
"=",
"[",
"]",
"track_count",
"=",
"0",
"self",
".",
"last_t",
"=",
"0",
"# some fixed wing aircraft",
"for",
"i",
"in",
"range",
"(",
"gen_settings",
".",
"num_aircraft",
")",
":",
"self",
".",
"aircraft",
".",
"append",
"(",
"Aircraft",
"(",
"random",
".",
"uniform",
"(",
"10",
",",
"100",
")",
",",
"2000.0",
")",
")",
"# some birds of prey",
"for",
"i",
"in",
"range",
"(",
"gen_settings",
".",
"num_bird_prey",
")",
":",
"self",
".",
"aircraft",
".",
"append",
"(",
"BirdOfPrey",
"(",
")",
")",
"# some migrating birds",
"for",
"i",
"in",
"range",
"(",
"gen_settings",
".",
"num_bird_migratory",
")",
":",
"self",
".",
"aircraft",
".",
"append",
"(",
"BirdMigrating",
"(",
")",
")",
"# some weather systems",
"for",
"i",
"in",
"range",
"(",
"gen_settings",
".",
"num_weather",
")",
":",
"self",
".",
"aircraft",
".",
"append",
"(",
"Weather",
"(",
")",
")",
"print",
"(",
"\"Started on port %u\"",
"%",
"gen_settings",
".",
"port",
")"
] | start sending packets | [
"start",
"sending",
"packets"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_genobstacles.py#L361-L389 |
249,593 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_genobstacles.py | GenobstaclesModule.mavlink_packet | def mavlink_packet(self, m):
'''trigger sends from ATTITUDE packets'''
if not self.have_home and m.get_type() == 'GPS_RAW_INT' and m.fix_type >= 3:
gen_settings.home_lat = m.lat * 1.0e-7
gen_settings.home_lon = m.lon * 1.0e-7
self.have_home = True
if self.pending_start:
self.start()
if m.get_type() != 'ATTITUDE':
return
t = self.get_time()
dt = t - self.last_t
if dt < 0 or dt > 10:
self.last_t = t
return
if dt > 10 or dt < 0.9:
return
self.last_t = t
for a in self.aircraft:
if not gen_settings.stop:
a.update(1.0)
self.pkt_queue.append(a.pickled())
while len(self.pkt_queue) > len(self.aircraft)*2:
self.pkt_queue.pop(0)
if self.module('map') is not None and not self.menu_added_map:
self.menu_added_map = True
self.module('map').add_menu(self.menu) | python | def mavlink_packet(self, m):
'''trigger sends from ATTITUDE packets'''
if not self.have_home and m.get_type() == 'GPS_RAW_INT' and m.fix_type >= 3:
gen_settings.home_lat = m.lat * 1.0e-7
gen_settings.home_lon = m.lon * 1.0e-7
self.have_home = True
if self.pending_start:
self.start()
if m.get_type() != 'ATTITUDE':
return
t = self.get_time()
dt = t - self.last_t
if dt < 0 or dt > 10:
self.last_t = t
return
if dt > 10 or dt < 0.9:
return
self.last_t = t
for a in self.aircraft:
if not gen_settings.stop:
a.update(1.0)
self.pkt_queue.append(a.pickled())
while len(self.pkt_queue) > len(self.aircraft)*2:
self.pkt_queue.pop(0)
if self.module('map') is not None and not self.menu_added_map:
self.menu_added_map = True
self.module('map').add_menu(self.menu) | [
"def",
"mavlink_packet",
"(",
"self",
",",
"m",
")",
":",
"if",
"not",
"self",
".",
"have_home",
"and",
"m",
".",
"get_type",
"(",
")",
"==",
"'GPS_RAW_INT'",
"and",
"m",
".",
"fix_type",
">=",
"3",
":",
"gen_settings",
".",
"home_lat",
"=",
"m",
".",
"lat",
"*",
"1.0e-7",
"gen_settings",
".",
"home_lon",
"=",
"m",
".",
"lon",
"*",
"1.0e-7",
"self",
".",
"have_home",
"=",
"True",
"if",
"self",
".",
"pending_start",
":",
"self",
".",
"start",
"(",
")",
"if",
"m",
".",
"get_type",
"(",
")",
"!=",
"'ATTITUDE'",
":",
"return",
"t",
"=",
"self",
".",
"get_time",
"(",
")",
"dt",
"=",
"t",
"-",
"self",
".",
"last_t",
"if",
"dt",
"<",
"0",
"or",
"dt",
">",
"10",
":",
"self",
".",
"last_t",
"=",
"t",
"return",
"if",
"dt",
">",
"10",
"or",
"dt",
"<",
"0.9",
":",
"return",
"self",
".",
"last_t",
"=",
"t",
"for",
"a",
"in",
"self",
".",
"aircraft",
":",
"if",
"not",
"gen_settings",
".",
"stop",
":",
"a",
".",
"update",
"(",
"1.0",
")",
"self",
".",
"pkt_queue",
".",
"append",
"(",
"a",
".",
"pickled",
"(",
")",
")",
"while",
"len",
"(",
"self",
".",
"pkt_queue",
")",
">",
"len",
"(",
"self",
".",
"aircraft",
")",
"*",
"2",
":",
"self",
".",
"pkt_queue",
".",
"pop",
"(",
"0",
")",
"if",
"self",
".",
"module",
"(",
"'map'",
")",
"is",
"not",
"None",
"and",
"not",
"self",
".",
"menu_added_map",
":",
"self",
".",
"menu_added_map",
"=",
"True",
"self",
".",
"module",
"(",
"'map'",
")",
".",
"add_menu",
"(",
"self",
".",
"menu",
")"
] | trigger sends from ATTITUDE packets | [
"trigger",
"sends",
"from",
"ATTITUDE",
"packets"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_genobstacles.py#L409-L436 |
249,594 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_adsb.py | ADSBVehicle.update | def update(self, state, tnow):
'''update the threat state'''
self.state = state
self.update_time = tnow | python | def update(self, state, tnow):
'''update the threat state'''
self.state = state
self.update_time = tnow | [
"def",
"update",
"(",
"self",
",",
"state",
",",
"tnow",
")",
":",
"self",
".",
"state",
"=",
"state",
"self",
".",
"update_time",
"=",
"tnow"
] | update the threat state | [
"update",
"the",
"threat",
"state"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_adsb.py#L50-L53 |
249,595 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_adsb.py | ADSBModule.cmd_ADSB | def cmd_ADSB(self, args):
'''adsb command parser'''
usage = "usage: adsb <set>"
if len(args) == 0:
print(usage)
return
if args[0] == "status":
print("total threat count: %u active threat count: %u" %
(len(self.threat_vehicles), len(self.active_threat_ids)))
for id in self.threat_vehicles.keys():
print("id: %s distance: %.2f m callsign: %s alt: %.2f" % (id,
self.threat_vehicles[id].distance,
self.threat_vehicles[id].state['callsign'],
self.threat_vehicles[id].state['altitude']))
elif args[0] == "set":
self.ADSB_settings.command(args[1:])
else:
print(usage) | python | def cmd_ADSB(self, args):
'''adsb command parser'''
usage = "usage: adsb <set>"
if len(args) == 0:
print(usage)
return
if args[0] == "status":
print("total threat count: %u active threat count: %u" %
(len(self.threat_vehicles), len(self.active_threat_ids)))
for id in self.threat_vehicles.keys():
print("id: %s distance: %.2f m callsign: %s alt: %.2f" % (id,
self.threat_vehicles[id].distance,
self.threat_vehicles[id].state['callsign'],
self.threat_vehicles[id].state['altitude']))
elif args[0] == "set":
self.ADSB_settings.command(args[1:])
else:
print(usage) | [
"def",
"cmd_ADSB",
"(",
"self",
",",
"args",
")",
":",
"usage",
"=",
"\"usage: adsb <set>\"",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"print",
"(",
"usage",
")",
"return",
"if",
"args",
"[",
"0",
"]",
"==",
"\"status\"",
":",
"print",
"(",
"\"total threat count: %u active threat count: %u\"",
"%",
"(",
"len",
"(",
"self",
".",
"threat_vehicles",
")",
",",
"len",
"(",
"self",
".",
"active_threat_ids",
")",
")",
")",
"for",
"id",
"in",
"self",
".",
"threat_vehicles",
".",
"keys",
"(",
")",
":",
"print",
"(",
"\"id: %s distance: %.2f m callsign: %s alt: %.2f\"",
"%",
"(",
"id",
",",
"self",
".",
"threat_vehicles",
"[",
"id",
"]",
".",
"distance",
",",
"self",
".",
"threat_vehicles",
"[",
"id",
"]",
".",
"state",
"[",
"'callsign'",
"]",
",",
"self",
".",
"threat_vehicles",
"[",
"id",
"]",
".",
"state",
"[",
"'altitude'",
"]",
")",
")",
"elif",
"args",
"[",
"0",
"]",
"==",
"\"set\"",
":",
"self",
".",
"ADSB_settings",
".",
"command",
"(",
"args",
"[",
"1",
":",
"]",
")",
"else",
":",
"print",
"(",
"usage",
")"
] | adsb command parser | [
"adsb",
"command",
"parser"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_adsb.py#L79-L97 |
249,596 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_adsb.py | ADSBModule.update_threat_distances | def update_threat_distances(self, latlonalt):
'''update the distance between threats and vehicle'''
for id in self.threat_vehicles.keys():
threat_latlonalt = (self.threat_vehicles[id].state['lat'] * 1e-7,
self.threat_vehicles[id].state['lon'] * 1e-7,
self.threat_vehicles[id].state['altitude'])
self.threat_vehicles[id].h_distance = self.get_h_distance(latlonalt, threat_latlonalt)
self.threat_vehicles[id].v_distance = self.get_v_distance(latlonalt, threat_latlonalt)
# calculate and set the total distance between threat and vehicle
self.threat_vehicles[id].distance = sqrt(
self.threat_vehicles[id].h_distance**2 + (self.threat_vehicles[id].v_distance)**2) | python | def update_threat_distances(self, latlonalt):
'''update the distance between threats and vehicle'''
for id in self.threat_vehicles.keys():
threat_latlonalt = (self.threat_vehicles[id].state['lat'] * 1e-7,
self.threat_vehicles[id].state['lon'] * 1e-7,
self.threat_vehicles[id].state['altitude'])
self.threat_vehicles[id].h_distance = self.get_h_distance(latlonalt, threat_latlonalt)
self.threat_vehicles[id].v_distance = self.get_v_distance(latlonalt, threat_latlonalt)
# calculate and set the total distance between threat and vehicle
self.threat_vehicles[id].distance = sqrt(
self.threat_vehicles[id].h_distance**2 + (self.threat_vehicles[id].v_distance)**2) | [
"def",
"update_threat_distances",
"(",
"self",
",",
"latlonalt",
")",
":",
"for",
"id",
"in",
"self",
".",
"threat_vehicles",
".",
"keys",
"(",
")",
":",
"threat_latlonalt",
"=",
"(",
"self",
".",
"threat_vehicles",
"[",
"id",
"]",
".",
"state",
"[",
"'lat'",
"]",
"*",
"1e-7",
",",
"self",
".",
"threat_vehicles",
"[",
"id",
"]",
".",
"state",
"[",
"'lon'",
"]",
"*",
"1e-7",
",",
"self",
".",
"threat_vehicles",
"[",
"id",
"]",
".",
"state",
"[",
"'altitude'",
"]",
")",
"self",
".",
"threat_vehicles",
"[",
"id",
"]",
".",
"h_distance",
"=",
"self",
".",
"get_h_distance",
"(",
"latlonalt",
",",
"threat_latlonalt",
")",
"self",
".",
"threat_vehicles",
"[",
"id",
"]",
".",
"v_distance",
"=",
"self",
".",
"get_v_distance",
"(",
"latlonalt",
",",
"threat_latlonalt",
")",
"# calculate and set the total distance between threat and vehicle",
"self",
".",
"threat_vehicles",
"[",
"id",
"]",
".",
"distance",
"=",
"sqrt",
"(",
"self",
".",
"threat_vehicles",
"[",
"id",
"]",
".",
"h_distance",
"**",
"2",
"+",
"(",
"self",
".",
"threat_vehicles",
"[",
"id",
"]",
".",
"v_distance",
")",
"**",
"2",
")"
] | update the distance between threats and vehicle | [
"update",
"the",
"distance",
"between",
"threats",
"and",
"vehicle"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_adsb.py#L122-L134 |
249,597 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_adsb.py | ADSBModule.check_threat_timeout | def check_threat_timeout(self):
'''check and handle threat time out'''
for id in self.threat_vehicles.keys():
if self.threat_vehicles[id].update_time == 0:
self.threat_vehicles[id].update_time = self.get_time()
dt = self.get_time() - self.threat_vehicles[id].update_time
if dt > self.ADSB_settings.timeout:
# if the threat has timed out...
del self.threat_vehicles[id] # remove the threat from the dict
for mp in self.module_matching('map*'):
# remove the threat from the map
mp.map.remove_object(id)
mp.map.remove_object(id+":circle")
# we've modified the dict we're iterating over, so
# we'll get any more timed-out threats next time we're
# called:
return | python | def check_threat_timeout(self):
'''check and handle threat time out'''
for id in self.threat_vehicles.keys():
if self.threat_vehicles[id].update_time == 0:
self.threat_vehicles[id].update_time = self.get_time()
dt = self.get_time() - self.threat_vehicles[id].update_time
if dt > self.ADSB_settings.timeout:
# if the threat has timed out...
del self.threat_vehicles[id] # remove the threat from the dict
for mp in self.module_matching('map*'):
# remove the threat from the map
mp.map.remove_object(id)
mp.map.remove_object(id+":circle")
# we've modified the dict we're iterating over, so
# we'll get any more timed-out threats next time we're
# called:
return | [
"def",
"check_threat_timeout",
"(",
"self",
")",
":",
"for",
"id",
"in",
"self",
".",
"threat_vehicles",
".",
"keys",
"(",
")",
":",
"if",
"self",
".",
"threat_vehicles",
"[",
"id",
"]",
".",
"update_time",
"==",
"0",
":",
"self",
".",
"threat_vehicles",
"[",
"id",
"]",
".",
"update_time",
"=",
"self",
".",
"get_time",
"(",
")",
"dt",
"=",
"self",
".",
"get_time",
"(",
")",
"-",
"self",
".",
"threat_vehicles",
"[",
"id",
"]",
".",
"update_time",
"if",
"dt",
">",
"self",
".",
"ADSB_settings",
".",
"timeout",
":",
"# if the threat has timed out...",
"del",
"self",
".",
"threat_vehicles",
"[",
"id",
"]",
"# remove the threat from the dict",
"for",
"mp",
"in",
"self",
".",
"module_matching",
"(",
"'map*'",
")",
":",
"# remove the threat from the map",
"mp",
".",
"map",
".",
"remove_object",
"(",
"id",
")",
"mp",
".",
"map",
".",
"remove_object",
"(",
"id",
"+",
"\":circle\"",
")",
"# we've modified the dict we're iterating over, so",
"# we'll get any more timed-out threats next time we're",
"# called:",
"return"
] | check and handle threat time out | [
"check",
"and",
"handle",
"threat",
"time",
"out"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_adsb.py#L160-L176 |
249,598 | ArduPilot/MAVProxy | MAVProxy/modules/mavproxy_gopro.py | GoProModule.cmd_gopro_status | def cmd_gopro_status(self, args):
'''show gopro status'''
master = self.master
if 'GOPRO_HEARTBEAT' in master.messages:
print(master.messages['GOPRO_HEARTBEAT'])
else:
print("No GOPRO_HEARTBEAT messages") | python | def cmd_gopro_status(self, args):
'''show gopro status'''
master = self.master
if 'GOPRO_HEARTBEAT' in master.messages:
print(master.messages['GOPRO_HEARTBEAT'])
else:
print("No GOPRO_HEARTBEAT messages") | [
"def",
"cmd_gopro_status",
"(",
"self",
",",
"args",
")",
":",
"master",
"=",
"self",
".",
"master",
"if",
"'GOPRO_HEARTBEAT'",
"in",
"master",
".",
"messages",
":",
"print",
"(",
"master",
".",
"messages",
"[",
"'GOPRO_HEARTBEAT'",
"]",
")",
"else",
":",
"print",
"(",
"\"No GOPRO_HEARTBEAT messages\"",
")"
] | show gopro status | [
"show",
"gopro",
"status"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/mavproxy_gopro.py#L76-L82 |
249,599 | ArduPilot/MAVProxy | MAVProxy/modules/lib/wxconsole_ui.py | ConsoleFrame.on_text_url | def on_text_url(self, event):
'''handle double clicks on URL text'''
try:
import webbrowser
except ImportError:
return
mouse_event = event.GetMouseEvent()
if mouse_event.LeftDClick():
url_start = event.GetURLStart()
url_end = event.GetURLEnd()
url = self.control.GetRange(url_start, url_end)
try:
# attempt to use google-chrome
browser_controller = webbrowser.get('google-chrome')
browser_controller.open_new_tab(url)
except webbrowser.Error:
# use the system configured default browser
webbrowser.open_new_tab(url) | python | def on_text_url(self, event):
'''handle double clicks on URL text'''
try:
import webbrowser
except ImportError:
return
mouse_event = event.GetMouseEvent()
if mouse_event.LeftDClick():
url_start = event.GetURLStart()
url_end = event.GetURLEnd()
url = self.control.GetRange(url_start, url_end)
try:
# attempt to use google-chrome
browser_controller = webbrowser.get('google-chrome')
browser_controller.open_new_tab(url)
except webbrowser.Error:
# use the system configured default browser
webbrowser.open_new_tab(url) | [
"def",
"on_text_url",
"(",
"self",
",",
"event",
")",
":",
"try",
":",
"import",
"webbrowser",
"except",
"ImportError",
":",
"return",
"mouse_event",
"=",
"event",
".",
"GetMouseEvent",
"(",
")",
"if",
"mouse_event",
".",
"LeftDClick",
"(",
")",
":",
"url_start",
"=",
"event",
".",
"GetURLStart",
"(",
")",
"url_end",
"=",
"event",
".",
"GetURLEnd",
"(",
")",
"url",
"=",
"self",
".",
"control",
".",
"GetRange",
"(",
"url_start",
",",
"url_end",
")",
"try",
":",
"# attempt to use google-chrome",
"browser_controller",
"=",
"webbrowser",
".",
"get",
"(",
"'google-chrome'",
")",
"browser_controller",
".",
"open_new_tab",
"(",
"url",
")",
"except",
"webbrowser",
".",
"Error",
":",
"# use the system configured default browser",
"webbrowser",
".",
"open_new_tab",
"(",
"url",
")"
] | handle double clicks on URL text | [
"handle",
"double",
"clicks",
"on",
"URL",
"text"
] | f50bdeff33064876f7dc8dc4683d278ff47f75d5 | https://github.com/ArduPilot/MAVProxy/blob/f50bdeff33064876f7dc8dc4683d278ff47f75d5/MAVProxy/modules/lib/wxconsole_ui.py#L55-L72 |
Subsets and Splits