Last updated
Last updated
Flight Tasks are used within to provide specific movement behaviours: e.g. follow me, or flight smoothing.
A flight task is a class in the flight task framework derived from the base class . Its goal is to generate setpoints for the controller from arbitrary input data, where each task implements the desired vehicle behavior for a specific mode. Programmers typically override the activate()
and update()
virtual methods by calling the base task's minimal implementation and extending with the implementation of the desired behavior. The activate()
method is called when switching to the task and allows to initialize its state and take over gently from the passed over setpoints the previous task was just applying.
update()
is called on every loop iteration during the execution and contains the core behavior implementation producing setpoints.
By convention tasks are contained in a subfolder of named after the task, and the source files are named with the prefix "FlightTask".
:::note Video overviews from PX4 developer summits are . :::
The instructions below might be used to create a task named MyTask:
Create a directory for the new flight task in . By convention the directory is named after the task, so we will call it /MyTask.
Create empty source code and cmake files for the new flight task in the MyTask directory using the prefix "FlightTask":
CMakeLists.txt
FlightTaskMyTask.hpp
FlightTaskMyTask.cpp
Update CMakeLists.txt for the new task
Copy the contents of the CMakeLists.txt for another task - e.g.
Update the copyright to the current year
Modify the code to reflect the new task - e.g. replace FlightTaskOrbit
with FlightTaskMyTask
. The code will look something like this:
Update the header file (in this case FlightTaskMyTask.hpp): Most tasks reimplement the virtual methods activate()
and update()
, and in this example we also have a private variable.
Update the cpp file as appropriate. This example provides as simple implementation of FlightTaskMyTask.cpp that simply indicates that the task methods are called.
Add the new task to the list of tasks to be built in :
Update a flight mode to ensure that the task is called. Usually a parameter is used to select when a particular flight task should be used.
For example, to enable our new MyTask
in multicopter Position mode:
Update MPC_POS_MODE
() to add an option for selecting "MyTask" if the parameter has a previously unused value like 5:
Add a case for your new option in the switch for the parameter to enable the task when _param_mpc_pos_mode
has the right value.
case 4: .... ...
:::note The task defined above should only be tested on the simulator. The code doesn't actually create setpoints so the vehicle will not fly. :::
The following videos provide an overview of flight tasks in PX4. The first covers the state of the flight task framework in PX4 v1.9. The second is an update, which covers the changes in PX4 v1.11.
A description of how flight modes work in PX4 v1.9 (Dennis Mannhart, Matthias Grob).
To test the flight task you need to run the vehicle with the task enabled. For the example above, this means setting the parameter MPC_POS_MODE
to 5, taking off, and switching the vehicle to .
@
@
The relevant section of this video is an update of flight tasks in PX4 v11.1 at (9min 20sec). The - Slides 9 and 12 are relevant.