MCPcopy Index your code
hub / github.com/dronekit/dronekit-python / adds_square_mission

Function adds_square_mission

examples/mission_basic/mission_basic.py:104–137  ·  view source on GitHub ↗

Adds a takeoff command and four waypoint commands to the current mission. The waypoints are positioned to form a square of side length 2*aSize around the specified LocationGlobal (aLocation). The function assumes vehicle.commands matches the vehicle mission state (you must h

(aLocation, aSize)

Source from the content-addressed store, hash-verified

102
103
104def adds_square_mission(aLocation, aSize):
105 """
106 Adds a takeoff command and four waypoint commands to the current mission.
107 The waypoints are positioned to form a square of side length 2*aSize around the specified LocationGlobal (aLocation).
108
109 The function assumes vehicle.commands matches the vehicle mission state
110 (you must have called download at least once in the session and after clearing the mission)
111 """
112
113 cmds = vehicle.commands
114
115 print " Clear any existing commands"
116 cmds.clear()
117
118 print " Define/add new commands."
119 # Add new commands. The meaning/order of the parameters is documented in the Command class.
120
121 #Add MAV_CMD_NAV_TAKEOFF command. This is ignored if the vehicle is already in the air.
122 cmds.add(Command( 0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_TAKEOFF, 0, 0, 0, 0, 0, 0, 0, 0, 10))
123
124 #Define the four MAV_CMD_NAV_WAYPOINT locations and add the commands
125 point1 = get_location_metres(aLocation, aSize, -aSize)
126 point2 = get_location_metres(aLocation, aSize, aSize)
127 point3 = get_location_metres(aLocation, -aSize, aSize)
128 point4 = get_location_metres(aLocation, -aSize, -aSize)
129 cmds.add(Command( 0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0, point1.lat, point1.lon, 11))
130 cmds.add(Command( 0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0, point2.lat, point2.lon, 12))
131 cmds.add(Command( 0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0, point3.lat, point3.lon, 13))
132 cmds.add(Command( 0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0, point4.lat, point4.lon, 14))
133 #add dummy waypoint "5" at point 4 (lets us know when have reached destination)
134 cmds.add(Command( 0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0, point4.lat, point4.lon, 14))
135
136 print " Upload new commands to vehicle"
137 cmds.upload()
138
139
140def arm_and_takeoff(aTargetAltitude):

Callers 1

mission_basic.pyFile · 0.85

Calls 5

CommandClass · 0.90
clearMethod · 0.80
addMethod · 0.80
uploadMethod · 0.80
get_location_metresFunction · 0.70

Tested by

no test coverage detected