mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 01:23:34 +08:00
docs: auto-sync metadata [skip ci]
Co-Authored-By: PX4 BuildBot <bot@px4.io>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Module Template for Full Applications
|
||||
|
||||
An application can be written to run as either a *task* (a module with its own stack and process priority) or as a *work queue task* (a module that runs on a work queue thread, sharing the stack and thread priority with other tasks on the work queue).
|
||||
An application can be written to run as either a _task_ (a module with its own stack and process priority) or as a _work queue task_ (a module that runs on a work queue thread, sharing the stack and thread priority with other tasks on the work queue).
|
||||
In most cases a work queue task can be used, as this minimizes resource usage.
|
||||
|
||||
::: info
|
||||
@@ -13,26 +13,28 @@ All the things learned in the [First Application Tutorial](../modules/hello_sky.
|
||||
|
||||
## Work Queue Task
|
||||
|
||||
PX4-Autopilot contains a template for writing a new application (module) that runs as a *work queue task*:
|
||||
PX4-Autopilot contains a template for writing a new application (module) that runs as a _work queue task_:
|
||||
[src/examples/work_item](https://github.com/PX4/PX4-Autopilot/tree/main/src/examples/work_item).
|
||||
|
||||
A work queue task application is just the same as an ordinary (task) application, except that it needs to specify that it is a work queue task, and schedule itself to run during initialisation.
|
||||
|
||||
The example shows how.
|
||||
In summary:
|
||||
|
||||
1. Specify the dependency on the work queue library in the cmake definition file ([CMakeLists.txt](https://github.com/PX4/PX4-Autopilot/blob/main/src/examples/work_item/CMakeLists.txt)):
|
||||
```
|
||||
...
|
||||
DEPENDS
|
||||
px4_work_queue
|
||||
```
|
||||
1. In addition to `ModuleBase`, the task should also derive from `ScheduledWorkItem` (included from [ScheduledWorkItem.hpp]( https://github.com/PX4/PX4-Autopilot/blob/main/platforms/common/include/px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp))
|
||||
1. In addition to `ModuleBase`, the task should also derive from `ScheduledWorkItem` (included from [ScheduledWorkItem.hpp](https://github.com/PX4/PX4-Autopilot/blob/main/platforms/common/include/px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp))
|
||||
1. Specify the queue to add the task to in the constructor initialisation.
|
||||
The [work_item](https://github.com/PX4/PX4-Autopilot/blob/main/src/examples/work_item/WorkItemExample.cpp#L42) example adds itself to the `wq_configurations::test1` work queue as shown below:
|
||||
|
||||
```cpp
|
||||
WorkItemExample::WorkItemExample() :
|
||||
ModuleParams(nullptr),
|
||||
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::test1)
|
||||
ModuleParams(nullptr),
|
||||
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::test1)
|
||||
{
|
||||
}
|
||||
```
|
||||
@@ -45,8 +47,6 @@ In summary:
|
||||
1. Implement the `task_spawn` method, specifying that the task is a work queue (using the `task_id_is_work_queue` id.
|
||||
1. Schedule the work queue task using one of the scheduling methods (in the example we use `ScheduleOnInterval` from within the `init` method).
|
||||
|
||||
|
||||
|
||||
## Tasks
|
||||
|
||||
PX4/PX4-Autopilot contains a template for writing a new application (module) that runs as a task on its own stack:
|
||||
|
||||
Reference in New Issue
Block a user