@@ -9,7 +9,7 @@ AUTO mode is used run pre-defined waypoint missions on Copter, Plane and Rover.
99DroneKit-Python provides basic methods to download and clear the current mission commands
1010from the vehicle, to add and upload new mission commands, to count the number of waypoints,
1111and to read and set the currently executed mission command.
12- Using these primitive methods you can create any other needed mission planning functionality.
12+ You can build upon these basic primitives to create high-level mission planning functionality.
1313
1414This section shows how to use the basic methods and provides a few useful helper functions.
1515Most of the code can be observed running in :ref: `example_mission_basic ` and :ref: `example_mission_import_export `.
@@ -18,9 +18,9 @@ Most of the code can be observed running in :ref:`example_mission_basic` and :re
1818
1919 We recommend that you :ref: `use GUIDED mode <guided_mode_copter >` instead of AUTO mode where possible, because it offers finer
2020 and more responsive control over movement, and can emulate most mission planning activities.
21-
22- AUTO mode can be helpful if a command you need is not supported in GUIDED mode on a particular vehicle.
23-
21+
22+ AUTO mode can be helpful if a command you need is not supported in GUIDED mode on a particular vehicle type .
23+
2424
2525.. _auto_mode_supported_commands :
2626
@@ -32,8 +32,6 @@ The mission commands (e.g. ``MAV_CMD_NAV_TAKEOFF``, ``MAV_CMD_NAV_WAYPOINT`` ) s
3232`Plane <http://plane.ardupilot.com/wiki/common-mavlink-mission-command-messages-mav_cmd/#commands_supported_by_plane >`_,
3333`Rover <http://rover.ardupilot.com/wiki/common-mavlink-mission-command-messages-mav_cmd/#commands_supported_by_rover >`_.
3434
35- .. tip :: If the autopilot receives a command that it cannot handle, then the command will be (silently) dropped.
36-
3735There are three types of commands:
3836
3937* *NAVigation commands * (``MAV_CMD_NAV_* ``) are used to control vehicle movement,
@@ -44,14 +42,19 @@ There are three types of commands:
4442 For example ``MAV_CMD_CONDITION_DISTANCE `` will prevent DO commands executing until the vehicle
4543 reaches the specified distance from the waypoint.
4644
47- During a mission at most one *NAV * command and one *DO * or *CONDITION * command can be running **at one time **.
48- *CONDITION * and *DO * commands are associated with the preceding *NAV * command: if the UAV reaches the waypoint before these
45+ During a mission at most one *NAV * command and one *DO * or *CONDITION * command can be running **at the same time **.
46+ *CONDITION * and *DO * commands are associated with the last *NAV * command that was sent : if the UAV reaches the waypoint before these
4947commands are executed, the next *NAV * command is loaded and they will be skipped.
5048
5149The `MAVLink Mission Command Messages (MAV_CMD) <http://planner.ardupilot.com/wiki/common-mavlink-mission-command-messages-mav_cmd >`_
5250wiki topic provides a more detailed overview of commands.
5351
54- .. todo :: Add how we can determine dynamically what commands are supported. Probably requires capability API which is not present yet.
52+ .. note ::
53+
54+ * If the autopilot receives a command that it cannot handle, then the command will be (silently) dropped.
55+ * You cannot yet determine dynamically what commands are supported. We hope to deliver this functionality in
56+ the forthcoming `capability API <https://github.com/dronekit/dronekit-python/issues/250 >`_.
57+
5558
5659.. _auto_mode_download_mission :
5760
@@ -105,27 +108,27 @@ To clear a mission you call :py:func:`clear() <droneapi.lib.CommandSequence.clea
105108 # Clear Vehicle.commands and flush.
106109 cmds.clear()
107110 vehicle.flush()
108-
111+
109112 # Reset the Vehicle.commands from the vehicle.
110113 cmds.download()
111114 cmds.wait_valid()
112-
115+
113116 .. warning ::
114117
115118 You must re-download the mission from the vehicle after clearing (as shown above) or the first command you add
116119 will be lost when you upload the new mission.
117-
120+
118121 This happens because :py:attr: `Vehicle.commands <droneapi.lib.Vehicle.commands> ` removes the :ref: `home location <vehicle_state_home_location >`
119122 (see `#132 <https://github.com/dronekit/dronekit-python/issues/132 >`_). Downloading adds it back again.
120123
121124If the current command completes before you add a new mission, then the vehicle mode will change to RTL (return to launch).
122125
123-
126+
124127.. _auto_mode_adding_command :
125128
126129Creating/adding mission commands
127130================================
128-
131+
129132After :ref: `downloading <auto_mode_download_mission >` or :ref: `clearing <auto_mode_clear_mission >` a mission new commands
130133can be added and uploaded to the vehicle. Commands are added to the mission using :py:func: `add() <droneapi.lib.CommandSequence.add> `
131134and are sent to the vehicle (either individually or in batches) using :py:func: `flush() <droneapi.lib.Vehicle.flush> `.
@@ -142,7 +145,7 @@ The supported commands for each vehicle are :ref:`linked above <auto_mode_suppor
142145 # Connect to API provider and get vehicle
143146 api = local_connect()
144147 vehicle = api.get_vehicles()[0 ]
145-
148+
146149 # Get the set of commands from the vehicle
147150 cmds = vehicle.commands
148151 cmds.download()
@@ -162,7 +165,7 @@ The supported commands for each vehicle are :ref:`linked above <auto_mode_suppor
162165
163166Modifying missions
164167==================
165-
168+
166169While you can :ref: `add new commands <auto_mode_adding_command >` after :ref: `downloading a mission <auto_mode_download_mission >`
167170it is not possible to directly modify and upload existing commands in ``Vehicle.commands `` (you can modify the commands but
168171changes do not propagate to the vehicle).
@@ -179,25 +182,25 @@ modify them as needed, then clear ``Vehicle.commands`` and upload the list as a
179182 cmds = vehicle.commands
180183 cmds.download()
181184 cmds.wait_valid()
182-
185+
183186 # Save the vehicle commands to a list
184187 missionlist= []
185188 for cmd in cmds[1 :]: # skip first item as it is home waypoint.
186189 missionlist.append(cmd)
187-
190+
188191 # Modify the mission as needed. For example, here we change the
189192 # first waypoint into a MAV_CMD_NAV_TAKEOFF command.
190193 missionlist[0 ].command= mavutil.mavlink.MAV_CMD_NAV_TAKEOFF
191-
194+
192195 # Clear the current mission
193196 cmds.clear()
194197 vehicle.flush()
195198 cmds.download()
196199 cmds.wait_valid()
197-
200+
198201 # Write the modified mission and flush to the vehicle
199202 for cmd in missionlist:
200- cmds.add(cmd)
203+ cmds.add(cmd)
201204 vehicle.flush()
202205
203206
@@ -226,7 +229,7 @@ To start a mission change the mode to AUTO:
226229
227230 If the vehicle is in the air, then changing the mode to AUTO is all that is required to start the
228231 mission.
229-
232+
230233 **Copter 3.3 release and later: ** If the vehicle is on the ground (only), you will additionally need to send the
231234 `MAV_CMD_MISSION_START <http://copter.ardupilot.com/wiki/common-mavlink-mission-command-messages-mav_cmd/#mav_cmd_mission_start >`_
232235 command.
@@ -247,15 +250,15 @@ to get the current command number. You can also change the current command by se
247250 print " Current Waypoint: %s " % vehicle.commands.next
248251
249252 There is no need to ``flush() `` changes to ``next `` to the vehicle (and as with other attributes, if you fetch a value, it is updated
250- from the vehicle).
253+ from the vehicle).
251254
252255
253256.. _auto_mode_handle_mission_end :
254257
255258Handling the end of a mission
256259===============================
257260
258- At the end of the mission the vehicle will typically "loiter" (hover in place for Copter,
261+ At the end of the mission the vehicle will enter LOITER mode (hover in place for Copter,
259262circle for Plane, stop for Rover). You can add new commands to the mission, but you will need to toggle from/back to
260263AUTO mode to start it running again.
261264
@@ -265,7 +268,7 @@ to perform some other operation) then you can either:
265268* Add a dummy mission command and poll :py:func: `Vehicle.commands.next <droneapi.lib.CommandSequence.next> ` for the
266269 transition to the final command, or
267270* Compare the current position to the position in the last command.
268-
271+
269272
270273
271274
@@ -289,7 +292,7 @@ clears the existing mission and uploads the new version.
289292Adding mission commands is discussed :ref: `here in the guide <auto_mode_adding_command >`.
290293
291294.. code :: python
292-
295+
293296 def upload_mission (aFileName ):
294297 """
295298 Upload a mission from a file.
@@ -308,9 +311,9 @@ Adding mission commands is discussed :ref:`here in the guide <auto_mode_adding_c
308311 cmds.wait_valid()
309312 for command in missionlist:
310313 cmds.add(command)
311- vehicle.flush()
314+ vehicle.flush()
315+
312316
313-
314317 ``readmission() `` reads a mission from the specified file and returns a list of :py:class: `Command <droneapi.lib.Command> ` objects.
315318
316319Each line is split up. The first line is used to test whether the file has the correct (stated) format.
@@ -323,8 +326,8 @@ The commands are added to a list which is returned by the function.
323326 def readmission (aFileName ):
324327 """
325328 Load a mission from a file into a list.
326-
327- This function is used by upload_mission().
329+
330+ This function is used by upload_mission().
328331 """
329332 print " Reading mission from file: %s \n " % aFileName
330333 cmds = vehicle.commands
@@ -381,7 +384,7 @@ It uses ``download_mission()`` (below) to get them mission, and then writes the
381384adds them to a list. Downloading mission is discussed :ref: `in the guide <auto_mode_download_mission >`.
382385
383386.. code :: python
384-
387+
385388 def download_mission ():
386389 """
387390 Downloads the current mission and returns it in a list.
@@ -394,7 +397,7 @@ adds them to a list. Downloading mission is discussed :ref:`in the guide <auto_m
394397 for cmd in cmds[1 :]: # skip first item as it is home waypoint.
395398 missionlist.append(cmd)
396399 return missionlist
397-
400+
398401
399402
400403
@@ -407,16 +410,16 @@ Get distance to waypoint
407410``distance_to_current_waypoint() `` returns the distance (in metres) to the next waypoint:
408411
409412.. code :: python
410-
413+
411414 def distance_to_current_waypoint ():
412415 """
413416 Gets distance in metres to the current waypoint.
414- It returns None for the first waypoint (Home location).
417+ It returns None for the first waypoint (Home location).
415418 """
416- nextcommand = vehicle.commands.next
417- if nextcommand == 1 :
419+ nextwaypoint = vehicle.commands.next
420+ if nextwaypoint == 1 :
418421 return None
419- missionitem= vehicle.commands[nextcommand ]
422+ missionitem= vehicle.commands[nextwaypoint ]
420423 lat= missionitem.x
421424 lon= missionitem.y
422425 alt= missionitem.z
@@ -435,8 +438,8 @@ The implementation ignores the first waypoint (which will be the "home location"
435438
436439 This implementation is very basic. It assumes that the next command number is for a valid NAV command (it might not be)
437440 and that the lat/lon/alt values are non-zero. It is however a useful indicator for test code.
438-
439-
441+
442+
440443
441444.. _auto_mode_mission_useful_links :
442445
0 commit comments