mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 14:48:54 +08:00
New Crowdin translations - zh-CN (#25590)
Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
This commit is contained in:
co-authored by
Crowdin Bot
parent
9980dccf43
commit
db58ecb5eb
@@ -1,108 +1,108 @@
|
||||
# PX4 ROS 2 Control Interface
|
||||
# PX4 ROS 2 控制接口
|
||||
|
||||
<0/> <1/>
|
||||
|
||||
:::warning
|
||||
Experimental
|
||||
At the time of writing, parts of the PX4 ROS 2 Control Interface are experimental, and hence subject to change:
|
||||
在撰写本文时,PX4 ROS 2 控制接口的部分内容仍处于实验阶段,因此可能会发生变动:
|
||||
|
||||
- The architecture and core interfaces for defining modes in ROS 2 modes are largely stable, and are tested in CI.
|
||||
The library offers significant benefits over using offboard mode in its current state.
|
||||
- Only a few setpoint types have settled (the others are still under development).
|
||||
You may need to use internal PX4 topics which may not remain backwards-compatible over time.
|
||||
- The API is not fully documented.
|
||||
- ROS 2 模式中用于定义模式的架构及核心接口在很大程度上已趋于稳定,且会在CI中进行测试
|
||||
相比当前状态下的离板模式,该代码库具有显著优势
|
||||
- 仅有少数几种设定点类型已趋于稳定。(其余设定点类型仍在开发中)
|
||||
您可能需要使用内部的 PX4 主题,这些主题可能不会随着时间的推移而保持与后方兼容。
|
||||
- 该 API没有完整的文档
|
||||
|
||||
:::
|
||||
|
||||
The [PX4 ROS 2 Interface Library](../ros2/px4_ros2_interface_lib.md) is a C++ library that simplifies controlling PX4 from ROS 2.
|
||||
这[PX4 ROS 2接口库](../ros2/px4_ros2_interface_lib.md)是一个 C++ 库,可简化从 ROS 2 控制 PX4 的操作。
|
||||
|
||||
Developers use the library to create and dynamically register modes written using ROS 2.
|
||||
These modes are dynamically registered with PX4, and appear to be part of PX4 to a ground station or other external system.
|
||||
They can even replace the default modes in PX4 with enhanced ROS 2 versions, falling back to the original version if the ROS2 mode fails.
|
||||
开发者可使用该库创建并动态注册以 ROS 2 编写的模式。
|
||||
这些模式会动态注册到 PX4 中,并且对于地面站或其他外部系统而言,它们看起来就像是 PX4 的一部分。
|
||||
开发者甚至可以用功能增强的 ROS 2 版本模式替换 PX4 中的默认模式,且若 ROS 2 模式失效,系统会回退到原始版本的模式。
|
||||
|
||||
The library also provides classes for sending different types of setpoints, ranging from high-level navigation tasks all the way down to direct actuator controls.
|
||||
These classes abstract the internal setpoints used by PX4, and that can therefore be used to provide a consistent ROS 2 interface for future PX4 and ROS releases.
|
||||
该库还提供了用于发送不同类型设定点的类,其涵盖范围从高层级的导航任务一直到直接的执行器控制。
|
||||
这些类对 PX4 所使用的内部设定点进行了抽象处理,因此可用于为未来的 PX4 和 ROS 版本提供统一的 ROS 2 接口。
|
||||
|
||||
PX4 ROS 2 modes are easier to implement and maintain than PX4 internal modes, and provide more resources for developers in terms of processing power and pre-existing libraries.
|
||||
Unless the mode is safety-critical, requires strict timing or very high update rates, or your vehicle doesn't have a companion computer, you should [consider using PX4 ROS 2 modes in preference to PX4 internal modes](../concept/flight_modes.md#internal-vs-external-modes).
|
||||
PX4 ROS 2 模式相较于 PX4 内部模式,更易于实现和维护,并且在处理能力与既有代码库资源方面,能为开发者提供更丰富的支持。
|
||||
除非该模式属于安全关键型、对时序有严格要求或需要极高的更新速率,或者你的飞行器没有搭载伴随计算机,否则你应优先[考虑使用 PX4 ROS 2 模式,而非 PX4 内部模式](参考链接:../concept/flight_modes.md#internal-vs-external-modes)。
|
||||
|
||||
## 综述
|
||||
|
||||
This diagram provides a conceptual overview of how the control interface modes and mode executors interact with PX4.
|
||||
该图从概念层面概述了控制接口模式与模式执行器如何与 PX4 进行交互。
|
||||
|
||||

|
||||

|
||||
|
||||
<!-- Source: https://docs.google.com/drawings/d/1WByCfgcytnaow7r41VhYJL8OGrw1RjFO51GoPMQBCNA/edit -->
|
||||
|
||||
The following sections define and explain the terms used in the diagram.
|
||||
以下章节对图表中使用的术语进行定义和解释。
|
||||
|
||||
### Definitions
|
||||
### 定义
|
||||
|
||||
#### Mode
|
||||
#### 模式
|
||||
|
||||
A mode defined using the interface library has the following properties:
|
||||
使用接口库定义的模式具有以下特性:
|
||||
|
||||
- A mode is a component that can send setpoints to the vehicle in order to control its motion (such as velocity or direct actuator commands).
|
||||
- A mode selects a setpoint type and sends it while it is active.
|
||||
It can switch between multiple setpoint types.
|
||||
- A mode can't activate other modes, and must be activated by the user (through RC/GCS), the flight controller in a failsafe situation, a _mode executor_, or some other external system.
|
||||
- Has a name displayed by the GCS.
|
||||
- Can configure its mode requirements (for example that it requires a valid position estimate).
|
||||
- A mode can perform different tasks, such as flying to a target, lowering a winch, releasing a payload and then fly back.
|
||||
- A mode can replace a mode defined in PX4.
|
||||
- 模式是一种组件,它可以向载具发送设定值以控制其运动(例如速度指令或直接执行器指令)。
|
||||
- 模式在激活状态下会选择一种设定值类型并发送该设定值。
|
||||
它能够在多种设定值类型之间进行切换。
|
||||
- 一种模式无法激活其他模式,其必须由以下对象激活:用户(通过RC/GCS)、处于故障保护状态下的飞控、mode executor_,或其他某种外部系统。
|
||||
- 具有一个由GCS显示的名称。
|
||||
- 可配置其模式要求(例如,要求具备有效的位置估算值)
|
||||
- 一种模式可执行不同任务,例如飞往目标点、下放绞盘、释放有效载荷,之后返航。
|
||||
- 一种模式可替换 PX4 中已定义的模式。
|
||||
|
||||
#### Mode Executor
|
||||
#### 模式执行器
|
||||
|
||||
A mode executor is an optional component for scheduling modes.
|
||||
For example, the mode executor for a custom payload delivery or survey mode might first trigger a take-off, then switch to the custom mode, and when that completes trigger an RTL.
|
||||
模式执行器是用于调度模式的可选组件。
|
||||
例如,用于自定义有效载荷投放或测绘模式的模式执行器,可能会先触发起飞,随后切换至该自定义模式,待模式完成后再触发RTL。
|
||||
|
||||
Specifically, it has the following properties:
|
||||
具体而言,它具有以下特性:
|
||||
|
||||
- A mode executor is an optional component one level higher than a mode.
|
||||
It is a state machine that can activate modes, and wait for their completion.
|
||||
- It can only do so while it is in charge.
|
||||
For that, an executor has exactly one _owned mode_ (and a mode can be owned by at most one executor).
|
||||
This mode serves as activation for the executor: when the user selects the mode, the owning executor gets activated and can select any mode.
|
||||
It stays in charge until the user switches modes (by RC or from a GCS), or a failsafe triggers a mode switch.
|
||||
Should the failsafe clear, the executor gets reactivated.
|
||||
- This allows multiple executors to coexist.
|
||||
- Executors cannot activate other executors.
|
||||
- Within the library, a mode executor is always implemented in combination with a custom mode.
|
||||
- 模式执行器是一种可选组件,其层级比模式高一级。
|
||||
它是一种状态机,能够激活模式并等待模式完成。
|
||||
- 它仅能在负责状态下执行此操作。
|
||||
为此,一个执行器恰好拥有一个_owned mode_(且一个模式最多只能被一个执行器拥有)。
|
||||
该模式可作为执行器的激活触发条件:当用户选择此模式时,其所属的执行器会被激活,进而能够选择任意模式。
|
||||
它会一直处于管控状态,直至用户(通过遥控器或从地面控制站)切换模式,或故障保护机制触发模式切换。
|
||||
若故障保护状态解除,执行器将重新激活。
|
||||
- 这允许多个执行器共存。
|
||||
- 执行器无法激活其他执行器。
|
||||
- 在该库中,模式执行器始终需结合自定义模式来实现。
|
||||
|
||||
::: info
|
||||
|
||||
- These definitions guarantee that a user can take away control from a custom mode or executor at any point in time by commanding a mode switch through RC or a GCS.
|
||||
- A mode executor is transparent to the user.
|
||||
It gets indirectly selected and activated through the owning mode, and thus the mode should be named accordingly.
|
||||
- 这些定义确保用户可在任意时刻通过RC或GCS发送模式切换指令,从而夺回对自定义模式或执行器的控制权。
|
||||
- 模式执行器对用户而言是透明的。
|
||||
它通过所属模式被间接选择并激活,因此该模式应相应地命名。
|
||||
|
||||
:::
|
||||
|
||||
#### Configuration Overrides
|
||||
#### 配置覆盖
|
||||
|
||||
Both modes and executors can define configuration overrides, allowing customisation of certain behaviors while the mode or executor is active.
|
||||
模式和执行器均可定义配置覆盖,从而能在模式或执行器处于激活状态时,对特定行为进行自定义设置。
|
||||
|
||||
These are currently implemented:
|
||||
这些措施目前正在实施:
|
||||
|
||||
- _Disabling auto-disarm_.
|
||||
This permits landing and then taking off again (e.g. to release a payload).
|
||||
这允许着陆,然后再次起飞(例如释放有效载荷)。
|
||||
- _Ability to defer non-essential failsafes_.
|
||||
This allows an executor to run an action without being interrupted by non-critical failsafe.
|
||||
For example, ignoring a low-battery failsafe so that a winch operation can complete.
|
||||
这使得执行器能够执行某项操作,且不会被非关键故障保护中断。
|
||||
例如,忽略低电量故障保护(机制),以便绞车操作能够完成。
|
||||
|
||||
### Comparison to Offboard Control
|
||||
### 与离板控制的比较
|
||||
|
||||
The above concepts provide a number of advantages over traditional [offboard control](../ros/offboard_control.md):
|
||||
上述概念提供了一些优点,而不是传统的[离板控制](../ros/offboard_control.md):
|
||||
|
||||
- Multiple nodes or applications can coexist and even run at the same time.
|
||||
But only one node can _control the vehicle_ at a given time, and this node is well defined.
|
||||
- Modes have a distinct name and be displayed/selected in the GCS.
|
||||
- Modes are integrated with the failsafe state machine and arming checks.
|
||||
- The setpoint types that can be sent are well defined.
|
||||
- ROS 2 modes can replace flight controller internal modes (such as [Return mode](../flight_modes/return.md)).
|
||||
- 多个节点或应用程序可以共存,甚至能同时运行。
|
||||
但在特定时刻,仅能有一个节点对载具进行控制,且该节点的定义是明确的。
|
||||
- 模式具有独特的名称,并且可在GCS中显示 / 选择。
|
||||
- 模式与故障保护状态机及解锁检查功能相集成。
|
||||
- 可发送的设定值类型定义明确。
|
||||
- ROS 2 模式可以替换飞行控制器内部模式(如[返回模式](../flight_modes/return.md))。
|
||||
|
||||
## Installation and First Test
|
||||
## 安装与首次测试
|
||||
|
||||
The following steps are required to get started:
|
||||
开始使用前,需完成以下步骤:
|
||||
|
||||
1. 请确保您在 ROS 2 工作区中有 [ROS 2 设置](../ros2/user_guide.md) 与 [`px4_msgs`](https://github.com/PX4/px4_msgs]。
|
||||
|
||||
@@ -127,35 +127,35 @@ The following steps are required to get started:
|
||||
source install/setup.bash
|
||||
```
|
||||
|
||||
4. In a different shell, start PX4 SITL:
|
||||
4. 在另一个外壳中,启动 PX4 SITL:
|
||||
|
||||
```sh
|
||||
cd $px4-autopilot
|
||||
make px4_sitl gazebo-classic
|
||||
```
|
||||
|
||||
(here we use Gazebo-Classic, but you can use any model or simulator)
|
||||
(这里我们使用Gazebo-Classic,但你可以使用任何模型或模拟器)
|
||||
|
||||
5. Run the micro XRCE agent in a new shell (you can keep it running afterward):
|
||||
5. 在新的 shell 中运行微XRCE 代理 (您可以在以后继续运行):
|
||||
|
||||
```sh
|
||||
MicroXRCEAgent udp4 -p 8888
|
||||
```
|
||||
|
||||
6. Start QGroundControl.
|
||||
6. 启动QGroundControl。
|
||||
|
||||
::: info
|
||||
Use QGroundControl Daily, which supports dynamically updating the list of modes.
|
||||
|
||||
:::
|
||||
|
||||
7. Back in the ROS 2 terminal, run one of the example modes:
|
||||
7. 回到ROS2终端,运行一个示例模式:
|
||||
|
||||
```sh
|
||||
ros2 run example_mode_manual_cpp example_mode_manual
|
||||
ros2 运行 example_mode_manual_cpp example_mode_manual
|
||||
```
|
||||
|
||||
You should get an output like this showing 'My Manual Mode' mode being registered:
|
||||
你应会看到类似如下的输出,其中显示 “我的手动模式"已注册:
|
||||
|
||||
```sh
|
||||
[DEBUG] [example_mode_manual]: Checking message compatibility...
|
||||
@@ -168,13 +168,13 @@ The following steps are required to get started:
|
||||
[DEBUG] [example_mode_manual]: Arming check request (id=1, only printed once)
|
||||
```
|
||||
|
||||
8. On the PX4 shell, you can check that PX4 registered the new mode:
|
||||
8. 在 PX4 外壳上,您可以检查 PX4 是否注册了新模式:
|
||||
|
||||
```sh
|
||||
commander status
|
||||
指挥官状态
|
||||
```
|
||||
|
||||
The output should contain:
|
||||
输出应包含:
|
||||
|
||||
```plain
|
||||
INFO [commander] Disarmed
|
||||
@@ -184,29 +184,29 @@ The following steps are required to get started:
|
||||
INFO [commander] External Mode 1: nav_state: 23, name: My Manual Mode
|
||||
```
|
||||
|
||||
9. At this point you should be able to see the mode in QGroundControl as well:
|
||||
9. 在这一点上,您也应该能够在 QGroundControl 中看到模式:
|
||||
|
||||

|
||||
|
||||
10. Select the mode, make sure you have a manual control source (physical or virtual joystick), and arm the vehicle.
|
||||
The mode will then activate, and it should print the following output:
|
||||
10. 选择该模式,确保你拥有手动控制源(物理或虚拟操纵杆),并为载具解锁
|
||||
然后模式将激活,它将打印以下输出:
|
||||
|
||||
```sh
|
||||
[DEBUG] [example_mode_manual]: Mode 'My Manual Mode' activated
|
||||
[DEBUG] [example_mode_manual]: 模式“我的手动模式” 已激活
|
||||
```
|
||||
|
||||
11. Now you are ready to create your own mode.
|
||||
11. 现在您已准备好创建自己的模式。
|
||||
|
||||
## How to use the Library
|
||||
## 如何使用代码库
|
||||
|
||||
The following sections describe specific functionality provided by this library.
|
||||
In addition, any other PX4 topic can be subscribed or published.
|
||||
以下各节介绍该库提供的特定功能。
|
||||
此外,任何其他PX4主题都可以订阅或发布。
|
||||
|
||||
### Mode Class Definition
|
||||
### 模式类定义
|
||||
|
||||
This section steps through an example of how to create a class for a custom mode.
|
||||
此部分通过如何为自定义模式创建类的示例。
|
||||
|
||||
For a complete application, check out the [examples in the `Auterion/px4-ros2-interface-lib` repository](https://github.com/Auterion/px4-ros2-interface-lib/tree/main/examples/cpp), such as [examples/cpp/modes/manual](https://github.com/Auterion/px4-ros2-interface-lib/blob/main/examples/cpp/modes/manual/include/mode.hpp).
|
||||
若要完整的应用程序,请查看[示例在 `Auterion/px4-ros2-interfacee-lib` 仓库中](https://github.com/Auterion/px4-ros2-interface-lib/tree/main/examples/cpp),例如[示例/cpp/mod/manual](https://github.com/Auterion/px4-ros2-interface-lib/blob/main/examples/cpp/modes/manual/include/mode.hpp)。
|
||||
|
||||
```cpp{1,5,7-9,24-31}
|
||||
class MyMode : public px4_ros2::ModeBase // [1]
|
||||
@@ -248,19 +248,19 @@ private:
|
||||
};
|
||||
```
|
||||
|
||||
- `[1]`: First we create a class that inherits from [`px4_ros2::ModeBase`](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1ModeBase.html).
|
||||
- `[2]`: In the constructor, we pass the mode name. This also allows us to configure some other things, like replacing a flight controller internal mode.
|
||||
- `[3]`: This is where we create all objects that we want to use later on.
|
||||
This can be RC input, setpoint type(s), or telemetry. `*this` is passed as a `Context` to each object, which associates the object with the mode.
|
||||
- `[4]`: Whenever the mode is active, this method gets called regularly (the update rate depends on the setpoint type).
|
||||
Here is where we can do our work and generate a new setpoint.
|
||||
- [1]`: 首先创建一个从 [`px4_ros2:::ModeBase\` ](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1ModeBase.html )继承的类。
|
||||
- [2]\`: 在构造函数中,我们传递模式名称。 这也使我们能够配置一些其他内容,例如替换飞行控制器的内置模式。
|
||||
- [3]:我们在此处创建后续想要使用的所有对象。
|
||||
这可以是 RC 输入、设置点类型(s)或遥测数据。 `*this` 作为`Context`传递给每个对象,将对象与模式联系起来。
|
||||
- [4]:每当该模式处于激活状态时,此方法会定期被调用(更新频率取决于设定值类型)。
|
||||
我们可以在这里开展工作并产生一个新的设定点。
|
||||
|
||||
After creating an instance of that mode, `mode->doRegister()` must be called which does the actual registration with the flight controller and returns `false` if it fails.
|
||||
In case a mode executor is used, `doRegister()` must be called on the mode executor, instead of for the mode.
|
||||
创建此模式的实例后, `mode->doRegister()` 必须被调用,在飞行控制器中进行实际注册,如果失败则返回 `false` 。
|
||||
如果使用模式执行器,`doRegister()`必须调用模式执行器而不是模式。
|
||||
|
||||
### Mode Executor Class Definition
|
||||
### 模式执行器类定义
|
||||
|
||||
This section steps through an example of how to create a mode executor class.
|
||||
本节逐步讲解如何创建模式执行器类的示例。
|
||||
|
||||
```cpp{1,4-5,9-16,20,33-57}
|
||||
class MyModeExecutor : public px4_ros2::ModeExecutorBase // [1]
|
||||
@@ -327,74 +327,74 @@ private:
|
||||
};
|
||||
```
|
||||
|
||||
- `[1]`: First we create a class that inherits from [`px4_ros2::ModeExecutorBase`](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1ModeExecutorBase.html).
|
||||
- `[2]`: The constructor takes our custom mode that is associated with the executor and passes it to the constructor of `ModeExecutorBase`.
|
||||
- `[3]`: We define an enum for the states we want to run through.
|
||||
- `[4]`: `onActivate` gets called when the executor becomes active. At this point we can start to run through our states.
|
||||
How you do this is up to you, in this example a method `runState` is used to execute the next state.
|
||||
- `[5]`: On switching to a state we call an asynchronous method from `ModeExecutorBase` to start the desired mode: `run`, `takeoff`, `rtl`, and so on.
|
||||
These methods are passed a function that is called on completion; the callback provides a `Result` argument that tells you whether the operation succeeded or not.
|
||||
The callback runs the next state on success.
|
||||
- `[6]`: We use the `scheduleMode()` method to start the executor's "owned mode", following the same pattern as the other state handlers.
|
||||
- [1]`: 首先创建一个从 [`px4_ros2:::ModeExecutorBase\` ](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1ModeExecutorBase.html ) 继承的类。
|
||||
- [2]`: 构造函数采用与执行器相关联的自定义模式,并传递给`ModeExecutorBase\`的构造函数。
|
||||
- [3]\`: 我们为想要运行的状态定义一个枚举。
|
||||
- [4]`: `onActivate`在执行器激活时被调用。 此时,我们可以开始遍历这些状态了。
|
||||
你是如何操作的,在这个示例中使用`runState\` 方法来执行下一个状态。
|
||||
- [5]`: 在切换到状态时,我们会调用 `ModeExecutorBase` 中的异步方法来启动所需的模式:`run`, “eff”、“rtl”、“等等”。
|
||||
这些方法被传递了一个被要求完成的函数; 回调提供一个 `Result\` 参数,告诉您操作是否成功。
|
||||
回调运行下一个成功状态。
|
||||
- [6]`: 我们使用 `scheduleMode()\` 方法来启动执行者"拥有模式", 遵循与其他状态处理器相同的模式。
|
||||
|
||||
### Setpoint Types
|
||||
### 设置点类型
|
||||
|
||||
A mode can choose its setpoint type(s) it wants to use to control the vehicle.
|
||||
The used types also define the compatibility with different vehicle types.
|
||||
模式可选择其用于控制载具的设定值类型。
|
||||
所用类型还界定了与不同类型载具的兼容性。
|
||||
|
||||
The following sections provide a list of supported setpoint types:
|
||||
以下章节提供了支持的设置点类型列表:
|
||||
|
||||
- [GotoSetpointType](#go-to-setpoint-gotosetpointtype): Smooth position and (optionally) heading control
|
||||
- [FwLateralLongitudinalSetpointType](#fixed-wing-lateral-and-longitudinal-setpoint-fwlaterallongitudinalsetpointtype): <Badge type="tip" text="main (planned for: PX4 v1.17)" /> Direct control of lateral and longitudinal fixed wing dynamics
|
||||
- [DirectActuatorsSetpointType](#direct-actuator-control-setpoint-directactuatorssetpointtype): Direct control of motors and flight surface servo setpoints
|
||||
- [GotoSetpointType](#go-to-setpoint-gotosetpointtype): 平稳的位置控制以及(可选的)航向控制
|
||||
- [FwLateralLongitudinalSetpointType](#fixed-wing-lateral-and-longitudinal-setpoint-fwlaterallongitudinalsetpointtype): <Badge type="tip" text="main (planned for: PX4 v1.17)" /> 对横向和纵向固定翼动态的直接控制
|
||||
- [DirectActuatorsSetpointType](#direct-actuator-control-setpoint-directactuatorssetpointtype):直接控制发动机和飞行地面servo setpoints
|
||||
|
||||
:::tip
|
||||
The other setpoint types are currently experimental, and can be found in: [px4_ros2/control/setpoint_types/experimental](https://github.com/Auterion/px4-ros2-interface-lib/tree/main/px4_ros2_cpp/include/px4_ros2/control/setpoint_types/experimental).
|
||||
其他设置点类型目前是实验性的,可在以下网址找到:[px4_ros2/control/setpoint_types/experimental](https://github.com/Auterion/px4-ros2-interface-lib/tree/main/px4_ros2_cpp/include/px4_ros2/control/setpoint_types/experimental)。
|
||||
|
||||
You can add your own setpoint types by adding a class that inherits from `px4_ros2::SetpointBase`, sets the configuration flags according to what the setpoint requires, and then publishes any topic containing a setpoint.
|
||||
您可以通过添加一个从 `px4_ros2::SetpointBase` 继承的类来添加您自己的 setpoint 类型, 根据设置点的要求设置配置标志,然后发布任何包含设置点的主题。
|
||||
:::
|
||||
|
||||
#### Go-to Setpoint (GotoSetpointType)
|
||||
#### 转到设置点 (GotoSetpointType)
|
||||
|
||||
:::info
|
||||
This setpoint type is currently only supported for multicopters.
|
||||
当前,此设定值类型仅支持多旋翼飞行器。
|
||||
:::
|
||||
|
||||
Smoothly control position and (optionally) heading setpoints with the [`px4_ros2::GotoSetpointType`](https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/control/setpoint_types/goto.hpp) setpoint type.
|
||||
The setpoint type is streamed to FMU based position and heading smoothers formulated with time-optimal, maximum-jerk trajectories, with velocity and acceleration constraints.
|
||||
以[`px4_ros2:::GotoSetpootType`](https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/control/setpoint_types/goto.hpp) 设置点类型平滑控制位置和(可选) 设置点。
|
||||
该设定值类型会传输至FMU,用于基于位置和航向的平滑控制器;该平滑控制器采用时间最优、最大加加速度轨迹设计,并设有速度和加速度约束。
|
||||
|
||||
The most trivial use is simply inputting a 3D position into the update method:
|
||||
最简单的用法就是直接向update method中输入一个3D 位置
|
||||
|
||||
```cpp
|
||||
const Eigen::Vector3f target_position_m{-10.F, 0.F, 3.F};
|
||||
_goto_setpoint->update(target_position_m);
|
||||
```
|
||||
|
||||
In this case, heading will remain _uncontrolled_.
|
||||
To additionally control heading, specify it as the second input argument:
|
||||
在这种情况下,航向将保持不受控制的状态。
|
||||
若要额外控制航向,可将其指定为第二个输入参数:
|
||||
|
||||
```cpp
|
||||
const Eigen::Vector3f target_position_m{-10.F, 0.F, 3.F};
|
||||
const Eigen:::Vector3f target_position_m{-10.F, 0.F, 3.F};
|
||||
const float heading_rad = 3.14F;
|
||||
_goto_setpoint->update(
|
||||
target_position_m,
|
||||
heading_rad);
|
||||
```
|
||||
|
||||
An additional feature of the go-to setpoint is dynamic control on the underlying smoothers' speed limits (i.e. maximum horizontal and vertical translational velocities as well as heading rate).
|
||||
If, as above, left unspecified, the smoothers will default to the vehicle's default maximums (typically set to the physical limitations).
|
||||
The smoothers will _only_ decrease speed limits, never increase.
|
||||
“前往设定值”(go-to setpoint)的一项额外功能是,可对底层平滑控制器的速度限制进行动态控制(即对最大水平和平动速度、最大垂直平动速度以及航向速率进行动态控制)。
|
||||
若如上文所述未指定(该参数),则平滑控制器将默认采用设备的默认最大值(通常设定为其物理极限值)
|
||||
平滑控制器仅会降低速度限制,绝不会提高速度限制。
|
||||
|
||||
```cpp
|
||||
_goto_setpoint->update(
|
||||
target_position_m,
|
||||
heading_rad,
|
||||
max_horizontal_velocity_m_s,
|
||||
max_水平_velocity_m_s,
|
||||
max_vertical_velocity_m_s,
|
||||
max_heading_rate_rad_s);
|
||||
```
|
||||
|
||||
All arguments in the update method except the position are templated as `std::optional<float>`, meaning that if one desires constraining the heading rate, but not the translating velocities, this is possible using a `std::nullopt`:
|
||||
更新方法中,除位置外的所有参数均被模板化为 std::optional<float> 类型。这意味着,若需限制航向速率但不限制平动速度,可通过 std::nullopt 实现这一需求。
|
||||
|
||||
```cpp
|
||||
_goto_setpoint->update(
|
||||
@@ -405,58 +405,58 @@ _goto_setpoint->update(
|
||||
max_heading_rate_rad_s);
|
||||
```
|
||||
|
||||
#### Fixed-Wing Lateral and Longitudinal Setpoint (FwLateralLongitudinalSetpointType)
|
||||
#### 固定翼横向与纵向设定值(FwLateralLongitudinalSetpointType,固定翼横向纵向设定值类型)
|
||||
|
||||
<Badge type="warning" text="Fixed wing only" /> <Badge type="tip" text="main (planned for: PX4 v1.17)" />
|
||||
|
||||
:::info
|
||||
This setpoint type is supported for fixed-wing vehicles and for VTOLs in fixed-wing mode.
|
||||
此设定值类型支持固定翼飞行器,以及处于固定翼模式下的垂直起降飞行器(VTOL)。
|
||||
:::
|
||||
|
||||
Use the [`px4_ros2::FwLateralLongitudinalSetpointType`](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1FwLateralLongitudinalSetpointType.html) to directly control the lateral and longitudinal dynamics of a fixed-wing vehicle — that is, side-to-side motion (turning/banking) and forward/vertical motion (speeding up and climbing/descending), respectively.
|
||||
This setpoint is streamed to the PX4 [_FwLateralLongitudinalControl_ module](../modules/modules_controller.md#fw-lat-lon-control), which decouples lateral and longitudinal inputs while ensuring that vehicle limits are respected.
|
||||
使用[`px4_ros2::FwLateralLongitudinalSetpointType`](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1FwLateralLongitudinalSetpointType.html)直接控制固定翼飞行器的横向与纵向动力学特性,即分别控制其侧向运动(转弯 / 倾斜)和前向 / 垂直运动(加速及爬升 / 下降)。
|
||||
这个设置点被传输到 PX4 [_FwLateralLongitudinalControl_module](../modules/modules_controller.md#fw-lat-lon-control),该模块会对横向与纵向输入进行解耦处理,同时确保不超出飞行器的各项限制范围。
|
||||
|
||||
To control the vehicle, at least one lateral **and** one longitudinal setpoint must be provided:
|
||||
为了控制载具,必须提供至少一个横向**和**一个纵向设定值:
|
||||
|
||||
1. Of the longitudinal inputs: either `altitude` or `height_rate` must be finite to control vertical motion.
|
||||
If both are set to `NAN`, the vehicle will maintain its current altitude.
|
||||
2. Of the lateral inputs: at least one of `course`, `airspeed_direction`, or `lateral_acceleration` must be finite.
|
||||
1. 在纵向输入中:必须至少有一个 “高度”(altitude)或 “高度速率”(height_rate)为有限值,才能实现垂直运动控制。
|
||||
若二者均设为 NAN,则载具将保持当前高度。
|
||||
2. 在横向输入中:“航线角”(course)、“空速方向”(airspeed_direction)或 “横向加速度”(lateral_acceleration)这三者中,至少有一个必须为有限值。
|
||||
|
||||
For a detailed description of the controllable parameters, please refer to message definitions ([FixedWingLateralSetpoint](../msg_docs/FixedWingLateralSetpoint.md) and [FixedWingLongitudinalSetpoint](../msg_docs/FixedWingLongitudinalSetpoint.md)).
|
||||
关于可控参数的详细说明,请参考消息定义([FixedWingLateralSetpoint](../msg_docs/FixedWingLateralSetpoint.md) 和 [FixedWingLongitudinalSetpoint](../msg_docs/FixedWingLongitudinalSetpoint.md))。
|
||||
|
||||
##### 基本用法
|
||||
|
||||
This type has a number of update methods, each allowing you to specify an increasing number of setpoints.
|
||||
该类型包含多个更新方法,每种方法可支持你指定的设定值数量逐步增加。
|
||||
|
||||
The simplest method is `updateWithAltitude()`, which allows you to specify a `course` and `altitude` target setpoint:
|
||||
最简单的方法是 updateWithAltitude(),该方法可让你指定 “航线角”(course)和 “高度”(altitude)这两个目标设定值。
|
||||
|
||||
```cpp
|
||||
const float altitude_msl = 500.F;
|
||||
const float altextede_msl = 500.F;
|
||||
const float course = 0.F; // due North
|
||||
_fw_lateral_longitudinal_setpoint->updateWithAltitude(altitude_msl, course);
|
||||
_fw_later_longitudinal_setpoint->updateWAltitude(altyde_msl, course);
|
||||
```
|
||||
|
||||
PX4 uses the setpoints to compute the _roll angle_, _pitch angle_ and _throttle_ setpoints that are sent to lower level controllers.
|
||||
Note that the commanded flight is expected to be relatively gentle/unaggressive when using this method.
|
||||
This is done as follows:
|
||||
PX4 会利用这些设定值计算出横滚角(roll angle)、俯仰角(pitch angle)和油门(throttle)设定值,并将其发送至底层控制器。
|
||||
需注意,使用此方法时,预期的指令飞行会相对平缓 / 不激进。
|
||||
此操作按如下方式执行:
|
||||
|
||||
- Lateral control output:
|
||||
- 横向控制输出:
|
||||
|
||||
course setpoint (set by user) → airspeed direction (heading) setpoint → lateral acceleration setpoint → roll angle setpoint.
|
||||
航线角设定值(由用户设定)→ 空速方向 (航向) 设定值 → 横向加速设定值 → 滚动角度设定值
|
||||
|
||||
- Longitudinal control output:
|
||||
- 纵向控制输出:
|
||||
|
||||
altitude setpoint (set by user) → height rate setpoint → pitch angle setpoint and throttle settings.
|
||||
高度设定值(由用户设定) → 高度速率设定值 → 俯仰角设定值及油门设定。
|
||||
|
||||
The `updateWithHeightRate()` method allows you to set a target `course` and `height_rate` (this is useful if the speed of ascent or descent matters, or needs to be dynamically controlled):
|
||||
updateWithHeightRate() 方法允许你设置目标 “航线角”(course)和 “高度速率”(height_rate)(当爬升或下降速度至关重要,或需要对其进行动态控制时,此方法非常实用):
|
||||
|
||||
```cpp
|
||||
const float height_rate = 2.F;
|
||||
const float course = 0.F; // due North
|
||||
_fw_lateral_longitudinal_setpoint->updateWithHeightRate(height_rate, course);
|
||||
const float course = 0.F; //due North
|
||||
_fw_lateral_longitudinal_setpoint->updateWheightRate(high_rate course);
|
||||
```
|
||||
|
||||
The `updateWithAltitude()` and `updateWithHeightRate()` methods allow you to additionally control the equivalent airspeed or lateral acceleration by specifying them as the third and fourth arguments, respectively:
|
||||
updateWithAltitude() 和 updateWithHeightRate() 这两种方法还允许你分别将 “等效空速”(equivalent airspeed)或 “横向加速度”(lateral acceleration)指定为第三个和第四个参数,从而对其进行控制:
|
||||
|
||||
```cpp
|
||||
const float altitude_msl = 500.F;
|
||||
@@ -470,44 +470,44 @@ _fw_lateral_longitudinal_setpoint->updateWithAltitude(altitude_msl,
|
||||
lateral_acceleration);
|
||||
```
|
||||
|
||||
The equivalent airspeed and lateral acceleration arguments are defined as `std::optional<float>`, so you can omit any of them by passing `std::nullopt`.
|
||||
等效的空速和横向加速参数定义为 `std::opulatory<float>`, 所以你可以通过 `std::nullopt` 省略其中任何一个。
|
||||
|
||||
:::tip
|
||||
If both lateral acceleration and course setpoints are provided, the lateral acceleration setpoint will be used as feedforward.
|
||||
若同时提供了横向加速度设定值和航线角设定值,横向加速度设定值将被用作前馈(feedforward)
|
||||
:::
|
||||
|
||||
##### Full Control Using the Setpoint Struct
|
||||
##### 使用设定值结构体实现完全控制
|
||||
|
||||
For full flexibility, you can create and pass a [`FwLateralLongitudinalSetpoint`](https://auterion.github.io/px4-ros2-interface-lib/structpx4__ros2_1_1FwLateralLongitudinalSetpoint.html) struct.
|
||||
Each field is templated with `std::optional<float>`.
|
||||
为实现充分的灵活性,你可以创建并传递一个[`FwLateralLongitudinalSetpoint` ](https://auterion.github.io/px4-ros2-interface-lib/structpx4__ros2_1_1FwLateralLongitudinalSetpoint.html) 结构体。
|
||||
每个字段都使用 "std::opulatory<float> "模板。
|
||||
|
||||
:::tip
|
||||
If both course and airspeed direction are set: airspeed direction takes precedence, course is not controlled.
|
||||
Lateral acceleration is treated as feedforward if either course or airspeed direction are also finite.
|
||||
If both altitude and height rate are set: height rate takes precedence, altitude is not controlled.
|
||||
若同时设置了航线角(course)和空速方向(airspeed direction),则空速方向优先,航线角不进行控制。
|
||||
若航线角或空速方向中任意一个为有限值,则横向加速度会被视为前馈。
|
||||
若同时设置了高度和高度速率,则高度速率优先,高度不进行控制。
|
||||
:::
|
||||
|
||||
```cpp
|
||||
px4_ros2::FwLateralLongitudinalSetpoint setpoint_s;
|
||||
px4_ros2:::FwLateralLongitudinalSetpoint setpoint_s;
|
||||
|
||||
setpoint_s.withCourse(0.F);
|
||||
// setpoint_s.withAirspeedDirection(0.2F); // uncontrolled
|
||||
setpoint_s.withLateralAcceleration(2.F); // feedforward
|
||||
//setpoint_s.withAltitude(500.F); // uncontrolled
|
||||
setpoint_s.withHeightRate(2.F);
|
||||
setpoint_s.withEquivalentAirspeed(15.F);
|
||||
settpoint_s.withCourse(0.F);
|
||||
// setpoint_s.withAirspeedDirection(0.2F); // 失控
|
||||
setpoint_s.withLateralActivation(2.F); // feedforward
|
||||
/setpoint_s.withAltude(500.F); // 失控
|
||||
setpoint_s.withightRate(2.F);
|
||||
settpoint_s.withequivalentAirspeed(15.F);
|
||||
|
||||
_fw_lateral_longitudinal_setpoint->update(setpoint_s);
|
||||
_fw_lateral_longitudinal_sett->upate(settpoint_
|
||||
```
|
||||
|
||||
The diagram below illustrates the interaction between the `FwLateralLongitudinalSetpointType` and PX4 when all inputs are set.
|
||||
下图展示了在所有输入均已设定的情况下,FwLateralLongitudinalSetpointType 与 PX4 之间的交互关系。
|
||||
|
||||

|
||||

|
||||
|
||||
##### Advanced Configuration (Optional)
|
||||
##### 高级配置(可选)
|
||||
|
||||
You can also pass a [`FwControlConfiguration`](https://auterion.github.io/px4-ros2-interface-lib/structpx4__ros2_1_1FwControlConfiguration.html) struct along with the setpoint to override default controller settings and constraints such as pitch limits, throttle limits, and target sink/climb rates.
|
||||
This is intended for advanced users:
|
||||
你还可以传递一个[`FwControlConfiguration`](https://auterion.github.io/px4-ros2-interface-lib/structpx4__ros2_1_1FwControlConfiguration.html) 结构体以及设定值,以覆盖默认的控制器设置和约束条件,例如俯仰角限制、油门限制以及目标下降 / 爬升速率。
|
||||
这是针对高级用户的:
|
||||
|
||||
```cpp
|
||||
px4_ros2::FwLateralLongitudinalSetpoint setpoint_s;
|
||||
@@ -526,47 +526,47 @@ config_s.withThrottleLimits(0.4F, 0.6F);
|
||||
_fw_lateral_longitudinal_setpoint->update(setpoint_s, config_s);
|
||||
```
|
||||
|
||||
All configuration fields are defined as `std::optional<float>`.
|
||||
Unset values will default to the PX4 configuration.
|
||||
See [LateralControlConfiguration](../msg_docs/LateralControlConfiguration.md) and [FixedWingLongitudinalConfiguration](../msg_docs/LongitudinalControlConfiguration.md) for more information on configuration options.
|
||||
所有配置字段都定义为 "std::opulatory<float>"。
|
||||
未设置的值将默认采用 PX4 的配置。
|
||||
更多关于配置选项的信息,请参阅 [LateralControlConfiguration](../msg_docs/LateralControlConfiguration.md) 和 [FixedWingLongitudinalConfiguration](../msg_docs/LongitudinalControlConfiguration.md)。
|
||||
|
||||
:::info
|
||||
For safety, PX4 automatically limits configuration values to stay within the vehicle’s constraints.
|
||||
For example, throttle overrides are clamped to remain between [`FW_THR_MIN`](../advanced_config/parameter_reference.md#FW_THR_MIN)
|
||||
and [`FW_THR_MAX`](../advanced_config/parameter_reference.md#FW_THR_MAX).
|
||||
为保障安全,PX4 会自动将配置值限制在飞行器的约束范围内。
|
||||
例如,油门覆盖值会被限制在[`FW_THR_MIN`](../advanced_config/parameter_reference.md#FW_THR_MIN)
|
||||
和 [`FW_THR_MAX`](../advanced_config/parameter_reference.md#FW_THR_MAX)之间。
|
||||
:::
|
||||
|
||||
#### Direct Actuator Control Setpoint (DirectActuatorsSetpointType)
|
||||
#### 直接执行器控制设定点(DirectActuatorsSetpointType)
|
||||
|
||||
Actuators can be directly controlled using the [px4_ros2::DirectActuatorsSetpointType](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1DirectActuatorsSetpointType.html) setpoint type.
|
||||
Motors and servos can be set independently.
|
||||
Be aware that the assignment is vehicle and setup-specific.
|
||||
For example to control a quadrotor, you need to set the first 4 motors according to its [output configuration](../concept/control_allocation.md).
|
||||
可以使用 [px4_ros2::DirectActActorsSetpootType](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1DirectActuatorsSetpointType.html) 设置点类型直接控制执行器。
|
||||
电机和舵机可独立设置。
|
||||
请注意,该分配(设置 / 指派)具有载具和配置特定性。
|
||||
例如,要控制一架四旋翼飞行器,你需要根据其 [输出配置] (../concept/control_allocation.md )来设置前 4 个电机。
|
||||
|
||||
:::info
|
||||
If you want to control an actuator that does not control the vehicle's motion, but for example a payload servo, see [below](#controlling-an-independent-actuator-servo).
|
||||
若你想控制的执行器并非用于控制飞行器的运动(例如,而是用于控制有效载荷舵机),请参阅 [below](#controlling-an-independent-actuator-servo)。
|
||||
:::
|
||||
|
||||
### Controlling a VTOL
|
||||
### 控制VTOL
|
||||
|
||||
<Badge type="tip" text="main (planned for: PX4 v1.17)" /> <Badge type="warning" text="Experimental" />
|
||||
|
||||
To control a VTOL in an external flight mode, ensure you're returning the correct setpoint type based on the current flight configuration:
|
||||
要在外部飞行模式下控制VTOL,需确保根据当前飞行配置返回正确的设定值类型:
|
||||
|
||||
- Multicopter mode: use a setpoint type that is compatible with multicopter control. For example: either the [`GotoSetpointType`](#go-to-setpoint-gotosetpointtype) or the [`TrajectorySetpointType`](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1TrajectorySetpointType.html).
|
||||
- Fixed-wing mode: Use the [`FwLateralLongitudinalSetpointType`](#fixed-wing-lateral-and-longitudinal-setpoint-fwlaterallongitudinalsetpointtype).
|
||||
- 多旋翼模式:使用与多旋翼控制兼容的设定值类型。 例如:要么[`GotoSetpootType`](#go-to-setpoint-gotosetpointtype) 要么[`TracjectorySettpointType`](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1TrajectorySetpointType.html)。
|
||||
- 固定翼形模式:使用 [`FwLateralLongitudinalSetpointType` ](#fixed-wing-lateral-and-longitudinal-setpoint-fwlaterallongitudinalsetpointtype)。
|
||||
|
||||
As long as the VTOL remains in either multicopter or fixed-wing mode throughout the external mode, no additional handling is required.
|
||||
只要VTOL在整个外部模式期间始终处于多旋翼模式或固定翼模式中的任意一种,就无需额外处理。
|
||||
|
||||
If you would like to command a VTOL transition in your external mode, you need to use the [VTOL API](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1VTOL.html). The VTOL API provides the functionality to command a transition and query the current state of the vehicle.
|
||||
如果您想要在您的外部模式中命令一个 VTAL 过渡,您需要使用 [VTOL API](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1VTOL.html)。 VTAL API具备下达转换指令和查询载具当前状态的功能。
|
||||
|
||||
Use this API with caution!
|
||||
Commanding transitions externally makes the user partially responsible for ensuring smooth and safe behavior, unlike onboard transitions (e.g. via RC switch) where PX4 handles the full process:
|
||||
谨慎使用此 API !
|
||||
通过外部下达转换指令时,用户需部分负责确保(飞行器)运行平稳且安全;这与机上转换(例如通过遥控器开关实现)不同,在机上转换模式下,整个过程由 PX4 全权处理。
|
||||
|
||||
1. Ensure that both the `TrajectorySetpointType` and the `FwLateralLongitudinalSetpointType` are available to your mode.
|
||||
2. Create an instance of `px4_ros2::VTOL` in the constructor of your mode.
|
||||
3. To command a transition, you can use the `toMulticopter()` or `toFixedwing()` methods on your VTOL object to set the desired state.
|
||||
4. During transition, send the following combination of setpoints:
|
||||
1. 确保你的模式可调用 TrajectorySetpointType(轨迹设定值类型)和 FwLateralLongitudinalSetpointType(固定翼横纵向设定值类型)这两种设定值类型。
|
||||
2. 在您模式的构造函数中创建 `px4_ros2::VTOL` 的实例。
|
||||
3. 要下达转换指令,你可以在 VTOL 对象上调用 toMulticopter() 或 toFixedwing() 方法,以设置所需状态。
|
||||
4. 在转换过程中,发送以下设定值组合:
|
||||
|
||||
```cpp
|
||||
// Assuming the instance of the px4_ros2::VTOL object is called vtol
|
||||
@@ -584,35 +584,35 @@ Commanding transitions externally makes the user partially responsible for ensur
|
||||
_fw_lateral_longitudinal_setpoint->updateWithAltitude(NAN, course_sp)
|
||||
```
|
||||
|
||||
This will ensure that the transition is handled properly within PX4.
|
||||
You can optionally pass a deceleration setpoint to `computeAccelerationSetpointDuringTransition()` to be used during back-transitions.
|
||||
这将确保转换过程在 PX4 系统内部得到妥善处理。
|
||||
你可以选择性地将一个减速度设定值传递给 computeAccelerationSetpointDuringTransition(),以便在反向转换过程中使用。
|
||||
|
||||
To check the current state of the vehicle, use the `getCurrentState()` method on your `px4_ros2::VTOL` object.
|
||||
要查询载具的当前状态,可在 px4_ros2::VTOL 对象上调用 getCurrentState() 方法。
|
||||
|
||||
See [this external flight mode implementation](https://github.com/Auterion/px4-ros2-interface-lib/tree/main/examples/cpp/modes/vtol) for a practical example on how to use this API.
|
||||
请参阅[此外部飞行模式实现](https://github.com/Auterion/px4-ros2-interface-lib/tree/main/examples/cpp/modes/vtol)有关如何使用此 API 的实际示例。
|
||||
|
||||
### Controlling an Independent Actuator/Servo
|
||||
### 控制独立执行器/Servo
|
||||
|
||||
If you want to control an independent actuator (a servo), follow these steps:
|
||||
如果您想要控制一个独立执行器(aservo),遵循以下步骤:
|
||||
|
||||
1. [Configure the output](../payloads/generic_actuator_control.md#generic-actuator-control-with-mavlink).
|
||||
2. Create an instance of [px4_ros2::PeripheralActuatorControls](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1PeripheralActuatorControls.html) in the constructor of your mode.
|
||||
3. Call the `set()` method to control the actuator(s).
|
||||
This can be done independently of any active setpoints.
|
||||
2. 在您的模式的构造函数中创建一个实例[px4_ros2::PeripheralActorControls](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1PeripheralActuatorControls.html)。
|
||||
3. 调用`set()` 方法以控制执行器
|
||||
此操作可独立于任何活跃的设定点执行。
|
||||
|
||||
### Telemetry
|
||||
### 数传
|
||||
|
||||
You can access PX4 telemetry topics directly via the following classes:
|
||||
你可以通过以下类直接访问 PX4 遥测主题:
|
||||
|
||||
- [OdometryGlobalPosition](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1OdometryGlobalPosition.html): Global position
|
||||
- [OdometryLocalPosition](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1OdometryLocalPosition.html): Local position, velocity, acceleration, and heading
|
||||
- [OdometryAttitude](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1OdometryAttitude.html): Vehicle attitude
|
||||
- [OdometryAirspeed](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1OdometryAirspeed.html): Airspeed
|
||||
- [OdometryGlobalPosition](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1OdometryGlobalPosition.html): 全球位置
|
||||
- [OdometryLocalPosition](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1OdometryLocalPosition.html): 本地位置、速度、加速度和航向
|
||||
- [OdometryAttitude](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1OdometryAttitude.html): 载具状态
|
||||
- [OdometryAirspeed](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1OdometryAirspeed.html):空速
|
||||
|
||||
For example, you can query the vehicle's current position estimate as follows:
|
||||
例如,你可以通过以下方式查询飞行器当前的位置估算值:
|
||||
|
||||
```cpp
|
||||
std::shared_ptr<px4_ros2::OdometryLocalPosition> _vehicle_local_position;
|
||||
std::shared_ptr<0> _vehicle_local_position;
|
||||
...
|
||||
|
||||
// Get vehicle's last local position
|
||||
@@ -623,55 +623,55 @@ _vehicle_local_position->positionXYValid();
|
||||
```
|
||||
|
||||
:::info
|
||||
These topics provide a wrapper around the internal PX4 topics, allowing the library to maintain compatibility if the internal topics change.
|
||||
Check [px4_ros2/odometry](https://github.com/Auterion/px4-ros2-interface-lib/tree/main/px4_ros2_cpp/include/px4_ros2/odometry) for new topics, and of course you can use any ROS 2 topic published from PX4.
|
||||
这些主题围绕内部的 PX4 主题提供了一个包装程序,使代码库能够在内部主题发生变化时保持兼容性。
|
||||
检查 [px4_ros2/odometry](https://github.com/Auterion/px4-ros2-interface-lib/tree/main/px4_ros2_cpp/include/px4_ros2/odometry) 新主题,当然你也可以使用任何由 PX4 发布的 ROS 2 主题。
|
||||
:::
|
||||
|
||||
### Failsafes and Mode Requirements
|
||||
### 故障保护与模式要求
|
||||
|
||||
Each mode has a set of requirement flags.
|
||||
These are generally automatically set, depending on which objects are used within the context of a mode.
|
||||
For example when adding manual control input with the code below the requirement flag for manual control gets set:
|
||||
每种模式都有一组需求标志。
|
||||
这些(需求标志)通常会根据模式语境下所使用的对象自动设置。
|
||||
例如,当通过以下代码添加手动控制输入时,手动控制的需求标志会被设置:
|
||||
|
||||
```cpp
|
||||
_manual_control_input = std::make_shared<px4_ros2::ManualControlInput>(*this);
|
||||
```
|
||||
|
||||
Specifically, setting a flag has the following consequences in PX4, if the condition is not met:
|
||||
具体而言,在 PX4 中,若条件未满足,设置某个标志会产生以下结果:
|
||||
|
||||
- arming is not allowed, while the mode is selected
|
||||
- when already armed, the mode cannot be selected
|
||||
- when armed and the mode is selected, the relevant failsafe is triggered (e.g. RC loss for the manual control requirement).
|
||||
Check the [safety page](../config/safety.md) for how to configure failsafe behavior.
|
||||
A failsafe is also triggered when the mode crashes or becomes unresponsive while it is selected.
|
||||
- 在选定模式时不允许进行解锁操作
|
||||
- 当已处于武装状态时,该模式无法被选择。
|
||||
- 当载具已解锁且该模式被选中时,相关的故障保护机制会被触发(例如,针对手动控制需求的遥控器信号丢失故障保护)。
|
||||
检查 [safety page] (../config/safety.md) 如何配置故障安全行为。
|
||||
当某模式已被选中,且该模式发生崩溃或失去响应时,也会触发故障保护机制。
|
||||
|
||||
This is the corresponding flow diagram for the manual control flag:
|
||||
这是手动控制标志对应的流程图:
|
||||
|
||||

|
||||
|
||||
<!-- source: https://drive.google.com/file/d/1g_NlQlw7ROLP_mAi9YY2nDwP0zTNsFlB/view -->
|
||||
|
||||
It is possible to manually update any mode requirement after the mode is registered.
|
||||
For example to add home position as requirement:
|
||||
在模式注册后,可以手动更新任意模式要求。
|
||||
例如,要将返航点(home position)添加为一项要求:
|
||||
|
||||
```cpp
|
||||
modeRequirements().home_position = true;
|
||||
```
|
||||
|
||||
The full list of flags can be found in [requirement_flags.hpp](https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/common/requirement_flags.hpp).
|
||||
标记的完整列表可以在 [requirement_flags.hpp](https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/include/px4_ros2/common/requirement_flags.hpp 中找到。
|
||||
|
||||
#### Deferring Failsafes
|
||||
#### 延迟故障保护
|
||||
|
||||
A mode or mode executor can temporarily defer non-essential failsafes by calling the method [`deferFailsafesSync()`](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1ModeExecutorBase.html#a16ec5be6ebe70e1d0625bf696c3e29ae).
|
||||
To get notified when a failsafe would be triggered, override the method [`void onFailsafeDeferred()`](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1ModeExecutorBase.html#ad80a234c8cb2f4c186fa2b7bffd1a1dd).
|
||||
模式或模式执行器可以通过调用该方法暂时延迟非必要的故障保护。 [`deferFailsafesSync()`](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1ModeExecutorBase.html#a16ec5be6ebe70e1d0625bf696c3e29ae).
|
||||
若想在故障保护即将被触发时收到通知,需重写该方法。 [`void onFailsafeDeferred()`](https://auterion.github.io/px4-ros2-interface-lib/classpx4__ros2_1_1ModeExecutorBase.html#ad80a234c8cb2f4c186fa2b7bffd1a1dd).
|
||||
|
||||
Check the [integration test](https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/test/integration/overrides.cpp) for an example.
|
||||
例如检查[integration test](https://github.com/Auterion/px4-ros2-interface-lib/blob/main/px4_ros2_cpp/test/integration/overrides.cpp)。
|
||||
|
||||
### Assigning a Mode to an RC Switch or Joystick Action
|
||||
### 将模式指派给 RC 切换或操纵动作
|
||||
|
||||
External modes can be assigned to [RC switches](../config/flight_mode.md) or joystick actions.
|
||||
When assigning a mode to an RC switch, you need to know the index (because the parameter metadata does not contain the dynamic mode name).
|
||||
Use `commander status` while the mode is running to get that information.
|
||||
外部模式可以被分配给[RC switches](../config/flight_mode.md) 或操纵杆动作。
|
||||
当将模式分配给RC开关时,你需要知道其索引(因为参数元数据中不包含动态模式名称)。
|
||||
在模式运行期间,使用 'commander status'(指令状态)来获取该信息。
|
||||
|
||||
例如:
|
||||
|
||||
@@ -679,23 +679,23 @@ Use `commander status` while the mode is running to get that information.
|
||||
INFO [commander] External Mode 1: nav_state: 23, name: My Manual Mode
|
||||
```
|
||||
|
||||
means you would select **External Mode 1** in QGC:
|
||||
意味着你需要在 QGC中选择外部模式 1(External Mode 1) :
|
||||
|
||||

|
||||

|
||||
|
||||
:::info
|
||||
PX4 ensures a given mode is always assigned to the same index by storing a hash of the mode name.
|
||||
This makes it independent of startup ordering in case of multiple external modes.
|
||||
PX4通过存储模式名称的散列确保指定模式始终分配到同一索引。
|
||||
这使它独立于多个外部模式下的启动订购。
|
||||
:::
|
||||
|
||||
### Replacing an Internal Mode
|
||||
### 替换内部模式
|
||||
|
||||
An external mode can replace an existing internal mode, such as [Return](../flight_modes/return.md) mode (RTL).
|
||||
By doing so, whenever RTL gets selected (through the user or a failsafe situation), the external mode is used instead of the internal one.
|
||||
The internal one is only used as a fallback when the external one becomes unresponsive or crashes.
|
||||
外部模式可替换现有的内部模式,例如[Return](../flight_modes/return.md) mode (RTL).
|
||||
这样做,每当选择RTL(通过用户或故障安全情况),就使用外部模式而不是内部模式。
|
||||
当外部模式失去响应或发生崩溃时,内部模式仅用作备用模式。
|
||||
|
||||
The replacement mode can be set in the settings of the `ModeBase` constructor:
|
||||
替换模式可在' ModeBase '构造函数的设置中进行配置:
|
||||
|
||||
```cpp
|
||||
Settings{kName, false, ModeBase::kModeIDRtl}
|
||||
设置{kName, false, ModeBase::kModeIDRtl}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user