diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bc0e690..591717e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,130 +1,13 @@ -name: XRobot Module Build Test - +name: Module CI on: push: pull_request: - schedule: - - cron: '0 3 1 * *' # 每月1日凌晨3点(UTC)自动触发 - + workflow_dispatch: jobs: build: - runs-on: ubuntu-latest - container: - image: ghcr.io/xrobot-org/docker-image-linux:main - options: --user 0 - - env: - XR_MODULE_NAME: ${{ github.event.repository.name }} - - steps: - - name: Checkout current module repo to ./Modules/${{ env.XR_MODULE_NAME }} - uses: actions/checkout@v4 - with: - path: Modules/${{ env.XR_MODULE_NAME }} - - - name: Create main.cpp - run: | - cat > main.cpp <<'EOF' - #include - #include "xrobot_main.hpp" - #include "libxr.hpp" - - int main() { - LibXR::PlatformInit(); - LibXR::STDIO::Printf<"This is XRobot Module Template Test\n">(); - LibXR::HardwareContainer hw; - XRobotMain(hw); - return 0; - } - EOF - - - name: Create minimal CMakeLists.txt - run: | - cat > CMakeLists.txt <<'EOF' - project(xrobot_mod_test CXX) - set(CMAKE_CXX_STANDARD 20) - add_executable(xr_test main.cpp) - set(XROBOT_MODULES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Modules/) - add_subdirectory(libxr) - target_include_directories(xr_test PUBLIC $ ${CMAKE_SOURCE_DIR}/User) - target_link_libraries(xr_test PUBLIC xr) - EOF - - - name: Pull libxr to ./libxr - run: git clone --depth=1 https://github.com/Jiu-xiao/libxr ./libxr - - - name: Checkout CMD module - uses: actions/checkout@v4 - with: - repository: QDU-Robomaster/CMD - path: Modules/CMD - - - name: Setup Python & Install deps - run: | - python3 -m pip install --upgrade pip - pip3 install pyyaml requests - - - name: Add XRobot tools to PATH - run: | - echo "$HOME/.local/bin" >> $GITHUB_PATH - - - name: Install xrobot toolchain - run: | - pip3 install xrobot libxr - - - name: Run xrobot_setup - run: | - xrobot_setup || true - - - name: Run xrobot_init_mod - run: | - xrobot_init_mod - - - name: Add BlinkLED module - run: | - xrobot_add_mod BlinkLED --instance-id BlinkLED_0 - xrobot_add_mod CMD --instance-id cmd - - - name: Add this repo module - run: | - xrobot_add_mod ${{ env.XR_MODULE_NAME }} && cat User/xrobot.yaml - - - name: Generate main again - run: | - xrobot_setup - - - name: Build - run: | - mkdir -p build - cd build - cmake .. - make - - - name: Create Tag via GitHub API - if: ${{ success() && github.event_name != 'pull_request' }} - uses: actions/github-script@v7 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const moduleTag = process.env.XR_MODULE_NAME; - const date = new Date(); - const yyyy = date.getUTCFullYear(); - const mm = String(date.getUTCMonth() + 1).padStart(2, '0'); - const dd = String(date.getUTCDate()).padStart(2, '0'); - const HH = String(date.getUTCHours()).padStart(2, '0'); - const MM = String(date.getUTCMinutes()).padStart(2, '0'); - const SS = String(date.getUTCSeconds()).padStart(2, '0'); - const tagName = `${moduleTag}-${yyyy}${mm}${dd}-${HH}${MM}${SS}`; - - // 获取当前 commit sha - const sha = process.env.GITHUB_SHA; - - // 创建 tag reference - await github.rest.git.createRef({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: `refs/tags/${tagName}`, - sha: sha - }); - console.log(`Created tag: ${tagName} on sha: ${sha}`); - + uses: xrobot-org/XRobot/.github/workflows/module-ci.yml@dev + with: + xrobot-ref: dev + libxr-ref: dev + dependency-ref: refs/heads/dev + template-args: '[]' diff --git a/HostData.hpp b/HostData.hpp index cc92075..ccec702 100644 --- a/HostData.hpp +++ b/HostData.hpp @@ -2,21 +2,14 @@ // clang-format off /* === MODULE MANIFEST V2 === -module_description: No description provided -constructor_args: - - cmd: '@nullptr' - - host_euler_topic_name: "target_eulr" - - host_chassis_data_topic_name: "host_chassis_data" - - host_fire_topic_name: "host_fire_notify" -template_args: [] -required_hardware: [] +module_description: 上位机数据接入模块:把上位机发来的云台目标、底盘速度和发射命令汇总为 CMD 的 AI 控制数据 / Host data Module that combines the gimbal target, chassis speed and fire command from the host into AI control data for CMD depends: - - qdu-future/CMD +- id: QDU-Robomaster/CMD + ref: same-or-dev === END MANIFEST === */ // clang-format on #include "CMD.hpp" -#include "app_framework.hpp" #include "libxr_cb.hpp" #include "libxr_def.hpp" #include "libxr_time.hpp" @@ -30,62 +23,80 @@ required_hardware: [] #include "transform.hpp" /** - * @brief 上位机数据接入模块 - * @details 将上位机发送的云台、底盘、发射命令转换为 CMD::Data 并喂给 CMD 模块。 + * @brief 上位机数据接入模块:把上位机发来的云台目标、底盘速度和发射命令汇总为 + * `CMD::Data`,通过 CMD 的 AI 控制入口提交。 + * Host data Module that combines the gimbal target, chassis speed and fire command + * from the host into `CMD::Data` and submits it through the AI control entry of + * CMD. */ -class HostData : public LibXR::Application { +class HostData +{ public: - struct HostChassisTarget { - float vx; - float vy; - float w; + /** + * @brief 上位机给出的底盘目标速度。 + * Chassis target speed from the host. + */ + struct HostChassisTarget + { + float vx; ///< x 方向速度 Velocity along x + float vy; ///< y 方向速度 Velocity along y + float w; ///< 旋转角速度 Rotation angular velocity }; - struct LauncherCMD { - bool isfire; + /** + * @brief 上位机给出的发射命令。 + * Fire command from the host. + */ + struct LauncherCMD + { + bool isfire; ///< 是否开火 Whether to fire }; - struct HostGimbalTarget { - float rol, pit, yaw; - float rol_dot, pit_dot, yaw_dot; - float rol_ddot, pit_ddot, yaw_ddot; + /** + * @brief 上位机给出的云台目标欧拉角及其一阶、二阶导数。 + * Gimbal target Euler angles from the host with their first and second + * derivatives. + */ + struct HostGimbalTarget + { + float rol; ///< 目标 roll Target roll + float pit; ///< 目标 pitch Target pitch + float yaw; ///< 目标 yaw Target yaw + float rol_dot; ///< roll 一阶导数 First derivative of roll + float pit_dot; ///< pitch 一阶导数 First derivative of pitch + float yaw_dot; ///< yaw 一阶导数 First derivative of yaw + float rol_ddot; ///< roll 二阶导数 Second derivative of roll + float pit_ddot; ///< pitch 二阶导数 Second derivative of pitch + float yaw_ddot; ///< yaw 二阶导数 Second derivative of yaw }; /** - * @brief 构造 HostData 模块 - * @param hw 硬件容器 - * @param app 应用管理器 - * @param cmd CMD 模块引用 - * @param host_euler_topic_name 云台目标欧拉角 Topic - * @param host_chassis_data_topic_name 底盘目标速度 Topic - * @param host_fire_topic_name 发射控制 Topic + * @brief 构造 HostData,创建三个 Topic 并注册回调。 + * Construct HostData, create the three Topics and register the callbacks. + * + * @param cmd CMD 实例,接收 AI 控制数据。 + * CMD instance that receives the AI control data. + * @param host_gimbal_topic_name 云台目标 Topic 名称。 + * Name of the gimbal target Topic. + * @param host_chassis_data_topic_name 底盘目标速度 Topic 名称。 + * Name of the chassis target speed Topic. + * @param host_fire_topic_name 发射命令 Topic 名称。 + * Name of the fire command Topic. */ - HostData(LibXR::HardwareContainer& hw, LibXR::ApplicationManager& app, - CMD* cmd, const char* host_gimbal_topic_name, - const char* host_chassis_data_topic_name, - const char* host_fire_topic_name) - : cmd_(cmd) { - UNUSED(hw); - - ASSERT(cmd_ != nullptr); - - host_gimbal_data_tp_ = LibXR::Topic::CreateTopic( - host_gimbal_topic_name); - host_chassis_data_tp_ = LibXR::Topic::CreateTopic( - host_chassis_data_topic_name); - host_fire_notify_tp_ = - LibXR::Topic::CreateTopic(host_fire_topic_name); - + HostData(CMD& cmd, const char* host_gimbal_topic_name = "target_euler", + const char* host_chassis_data_topic_name = "host_chassis_data", + const char* host_fire_topic_name = "host_fire_notify") + : cmd_(&cmd), + host_gimbal_data_tp_( + LibXR::Topic::CreateTopic(host_gimbal_topic_name)), + host_chassis_data_tp_( + LibXR::Topic::CreateTopic(host_chassis_data_topic_name)), + host_fire_notify_tp_(LibXR::Topic::CreateTopic(host_fire_topic_name)) + { auto euler_callback = LibXR::Topic::Callback::Create( - [](bool in_isr, HostData* host_data, LibXR::RawData& raw_data) { - if (host_data == nullptr || raw_data.addr_ == nullptr || - raw_data.size_ < sizeof(HostGimbalTarget)) { - return; - } - HostGimbalTarget t; - LibXR::Memory::FastCopy(&t, raw_data.addr_, sizeof(t)); - host_data->host_euler_ = - LibXR::EulerAngle(t.rol, t.pit, t.yaw); + [](bool in_isr, HostData* host_data, const HostGimbalTarget& t) + { + host_data->host_euler_ = LibXR::EulerAngle(t.rol, t.pit, t.yaw); host_data->host_gyro_ = Eigen::Matrix(t.rol_dot, t.pit_dot, t.yaw_dot); host_data->host_accl_ = @@ -96,26 +107,18 @@ class HostData : public LibXR::Application { this); auto chassis_callback = LibXR::Topic::Callback::Create( - [](bool in_isr, HostData* host_data, LibXR::RawData& raw_data) { - if (host_data == nullptr || raw_data.addr_ == nullptr || - raw_data.size_ < sizeof(HostChassisTarget)) { - return; - } - LibXR::Memory::FastCopy(&host_data->host_chassis_data_, - raw_data.addr_, sizeof(HostChassisTarget)); + [](bool in_isr, HostData* host_data, const HostChassisTarget& chassis) + { + host_data->host_chassis_data_ = chassis; host_data->last_chassis_time_ = LibXR::Timebase::GetMilliseconds(); host_data->HostCMD(in_isr); }, this); auto fire_callback = LibXR::Topic::Callback::Create( - [](bool in_isr, HostData* host_data, LibXR::RawData& raw_data) { - if (host_data == nullptr || raw_data.addr_ == nullptr || - raw_data.size_ < sizeof(LauncherCMD)) { - return; - } - LibXR::Memory::FastCopy(&host_data->host_fire_notify_, raw_data.addr_, - sizeof(LauncherCMD)); + [](bool in_isr, HostData* host_data, const LauncherCMD& fire) + { + host_data->host_fire_notify_ = fire; host_data->last_fire_time_ = LibXR::Timebase::GetMilliseconds(); host_data->HostCMD(in_isr); }, @@ -124,40 +127,42 @@ class HostData : public LibXR::Application { host_gimbal_data_tp_.RegisterCallback(euler_callback); host_chassis_data_tp_.RegisterCallback(chassis_callback); host_fire_notify_tp_.RegisterCallback(fire_callback); - - app.Register(*this); } - HostData(LibXR::HardwareContainer& hw, LibXR::ApplicationManager& app, - CMD& cmd, const char* host_gimbal_topic_name, - const char* host_chassis_data_topic_name, - const char* host_fire_topic_name) - : HostData(hw, app, &cmd, host_gimbal_topic_name, - host_chassis_data_topic_name, host_fire_topic_name) {} - /** - * @brief 汇总并下发 Host 命令 - * @param in_isr 是否在中断上下文(当前未使用) + * @brief 用三路最新数据组成一帧 `CMD::Data` 并调用 `cmd.FeedAI()`。 + * Compose one `CMD::Data` frame from the latest data of the three Topics and + * call `cmd.FeedAI()`. + * + * @param in_isr 是否在中断上下文。 + * Whether called from interrupt context. */ - void HostCMD(bool in_isr) { + void HostCMD(bool in_isr) + { UNUSED(in_isr); CMD::Data host_cmd; if (host_chassis_data_.vx == 0.0f && host_chassis_data_.vy == 0.0f && - host_chassis_data_.w == 0.0f) { + host_chassis_data_.w == 0.0f) + { host_cmd.chassis = {0, 0, 0}; host_cmd.chassis_online = false; - } else { + } + else + { host_cmd.chassis.x = host_chassis_data_.vx; host_cmd.chassis.y = host_chassis_data_.vy; host_cmd.chassis.z = host_chassis_data_.w; host_cmd.chassis_online = true; } - if (host_euler_.Pitch() == 0.0f && host_euler_.Yaw() == 0.0f) { + if (host_euler_.Pitch() == 0.0f && host_euler_.Yaw() == 0.0f) + { host_cmd.gimbal = {0, 0, 0, 0, 0, 0, 0, 0, 0}; host_cmd.gimbal_online = false; - } else { + } + else + { host_cmd.gimbal.pit = host_euler_.Pitch(); host_cmd.gimbal.yaw = host_euler_.Yaw(); host_cmd.gimbal.pit_dot = host_gyro_.y(); @@ -173,11 +178,6 @@ class HostData : public LibXR::Application { cmd_->FeedAI(host_cmd); } - /** - * @brief 监控回调 - */ - void OnMonitor() override {} - private: CMD* cmd_; HostChassisTarget host_chassis_data_; diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index c53bb9b..0dce5ea 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,101 @@ # HostData -## 1. 模块作用 -上位机数据接入模块。把主机侧目标转换为 CMD 输入。 - -## 2. 主要函数说明 -1. HostCMD: 汇总云台/底盘/发射数据并喂给 CMD。 -2. 构造函数中的三个 Topic 回调: 接收 euler、chassis、fire 数据。 -3. OnMonitor: 监控钩子(当前为空实现)。 - -## 3. 接入步骤 -1. 添加模块并配置 host 侧 Topic 名称。 -2. 保证上位机发布数据结构与本模块一致。 -3. 检查 CMD 是否收到 AI 控制输入。 - -标准命令流程: - xrobot_add_mod HostData --instance-id hostdata - xrobot_gen_main - cube-cmake --build /home/leo/Documents/bsp-dev-c/build/debug -- - -## 4. 配置示例(YAML) -module: HostData -entry_header: Modules/HostData/HostData.hpp -constructor_args: - - cmd: '@cmd' - - host_euler_topic_name: "target_eulr" - - host_chassis_data_topic_name: "host_chassis_data" - - host_fire_topic_name: "host_fire_notify" -template_args: -[] - -## 5. 依赖与硬件 -Required Hardware: -[] - -Depends: -[] - -## 6. 代码入口 -Modules/HostData/HostData.hpp +上位机数据接入模块:把上位机发来的云台目标、底盘速度和发射命令汇总为 CMD 的 AI 控制数据 / Host data Module that combines the gimbal target, chassis speed and fire command from the host into AI control data for CMD + +## 1. 模块作用 / Purpose + +构造时,HostData 按构造参数给出的名字创建三个 Topic 并在其上注册回调。上位机链路(例如 `xrobot-org/SharedTopic`)向这些 Topic 发布数据,数据结构与第 3 节的类型一致。 + +任一 Topic 收到数据时,回调用三路最新数据组成一帧 `CMD::Data`,`ctrl_source` 设为 `CMD::ControlSource::CTRL_SOURCE_AI`,并调用 `cmd.FeedAI()`: + +- 底盘:`vx, vy, w` 写入 `chassis.x / y / z`;三者全为 0 时 `chassis_online = false`,否则为 `true`。 +- 云台:写入 `pit`、`yaw` 及 `pit_dot`、`pit_ddot`、`yaw_dot`、`yaw_ddot`;pitch 与 yaw 都为 0 时 `gimbal_online = false` 且云台数据清零,否则为 `true`。 +- 发射:`launcher.isfire` 取最近一次发射命令。 + +回调在发布方的上下文中执行。 + +Upon construction, HostData creates three Topics with the names given by the constructor parameters and registers a callback on each. The host link (for example `xrobot-org/SharedTopic`) publishes data to these Topics, with data structures matching the types in section 3. + +When any Topic receives data, the callback composes one `CMD::Data` frame from the latest data of the three Topics, sets `ctrl_source` to `CMD::ControlSource::CTRL_SOURCE_AI`, and calls `cmd.FeedAI()`: + +- Chassis: `vx, vy, w` are written to `chassis.x / y / z`; `chassis_online = false` when all three are 0, otherwise `true`. +- Gimbal: `pit`, `yaw`, `pit_dot`, `pit_ddot`, `yaw_dot` and `yaw_ddot` are written; `gimbal_online = false` and the gimbal data is cleared when pitch and yaw are both 0, otherwise `true`. +- Fire: `launcher.isfire` takes the latest fire command. + +The callbacks run in the context of the publisher. + +## 2. 构造接口 / Constructor + +```cpp +HostData(CMD& cmd, + const char* host_gimbal_topic_name = "target_euler", + const char* host_chassis_data_topic_name = "host_chassis_data", + const char* host_fire_topic_name = "host_fire_notify"); +``` + +依赖: + +- `cmd`:`CMD` 实例,接收 AI 控制数据。 + +配置参数: + +- `host_gimbal_topic_name`:云台目标 Topic 名称,默认 `"target_euler"`。 +- `host_chassis_data_topic_name`:底盘速度 Topic 名称,默认 `"host_chassis_data"`。 +- `host_fire_topic_name`:发射命令 Topic 名称,默认 `"host_fire_notify"`。 + +Dependencies: + +- `cmd`: the `CMD` instance that receives the AI control data. + +Configuration parameters: + +- `host_gimbal_topic_name`: name of the gimbal target Topic, default `"target_euler"`. +- `host_chassis_data_topic_name`: name of the chassis speed Topic, default `"host_chassis_data"`. +- `host_fire_topic_name`: name of the fire command Topic, default `"host_fire_notify"`. + +## 3. Topic + +| Topic | 方向 | 类型 | 说明 | +| --- | --- | --- | --- | +| `host_gimbal_topic_name`(默认 `target_euler`) | 创建并订阅 | `HostData::HostGimbalTarget` | 目标 `rol, pit, yaw` 及其一阶(`*_dot`)、二阶(`*_ddot`)导数 | +| `host_chassis_data_topic_name`(默认 `host_chassis_data`) | 创建并订阅 | `HostData::HostChassisTarget` | 底盘速度 `vx, vy, w` | +| `host_fire_topic_name`(默认 `host_fire_notify`) | 创建并订阅 | `HostData::LauncherCMD` | 发射命令 `isfire` | + +| Topic | Direction | Type | Meaning | +| --- | --- | --- | --- | +| `host_gimbal_topic_name` (default `target_euler`) | Create and subscribe | `HostData::HostGimbalTarget` | Target `rol, pit, yaw` with their first (`*_dot`) and second (`*_ddot`) derivatives | +| `host_chassis_data_topic_name` (default `host_chassis_data`) | Create and subscribe | `HostData::HostChassisTarget` | Chassis speed `vx, vy, w` | +| `host_fire_topic_name` (default `host_fire_notify`) | Create and subscribe | `HostData::LauncherCMD` | Fire command `isfire` | + +## 4. 配置示例 / Configuration Example + +`xrobot instance add QDU-Robomaster/HostData` 写入的实例,`cmd` 填写为 `QDU-Robomaster/CMD` 实例的 id,该实例在 `modules:` 中排在本实例之前。Topic 名称与上位机链路使用的名称一致;示例中的 `fire_notify` 与 Dart 订阅的发射命令 Topic 名称相同。 + +An instance written by `xrobot instance add QDU-Robomaster/HostData`, with `cmd` set to the id of the `QDU-Robomaster/CMD` instance, which is listed before this instance in `modules:`. The Topic names match the names used by the host link; `fire_notify` in the example is the fire command Topic name that Dart subscribes to. + +```yaml +modules: + - module: QDU-Robomaster/HostData + id: hostdata + args: + - cmd: cmd + - host_gimbal_topic_name: "target_euler" + - host_chassis_data_topic_name: "chassis_data" + - host_fire_topic_name: "fire_notify" +``` + +## 5. 依赖与硬件 / Dependencies and Hardware + +依赖: + +- `QDU-Robomaster/CMD`:`CMD::Data` 类型与 `FeedAI()` 入口。 +- LibXR。 + +硬件:无。 + +Dependencies: + +- `QDU-Robomaster/CMD`: the `CMD::Data` type and the `FeedAI()` entry. +- LibXR. + +Hardware: none.