Skip to content

Conversation

@1Feishu
Copy link

@1Feishu 1Feishu commented Dec 30, 2025

add flight.cpp and flight.yaml to control drone's gimbal
add GimbalFrequencySweep.cpp to Frequency sweep
update two_axis_gimbal_solver.hpp to limit yaw

无人机云台控制功能集成

核心改动

本PR添加了无人机(飞行器)云台控制的完整实现,包括硬件驱动、控制算法和配置参数。

主要文件变更

1. 硬件驱动层(flight.cpp)

  • 新增 rmcs_core::hardware::Flight 硬件组件(247行)
  • 集成多种硬件设备:云台偏航/俯仰电机(LK电机)、左右摩擦轮(DJI电机)、弹丸装填器、DR16遥控接收器、BMI088 IMU传感器
  • 实现UART/CAN通信接口、设备初始化和实时更新、传感器数据处理(加速度计、陀螺仪回调)
  • 通过嵌套的FlightCommand组件处理命令更新,支持云台标定订阅

2. 云台频率扫描模块(GimbalFrequencySweep.cpp)

  • 新增 rmcs_core::controller::gimbal::GimbalFrequencySweep 控制器(196行)
  • 实现扫频功能:通过正弦波控制信号驱动云台,频率从低到高逐步递增(分段:低频0.5Hz增量、中频2Hz增量、高频4Hz增量)
  • 包含CSV数据记录功能,记录实际速度和控制力矩用于性能分析
  • 通过遥控器开关(左/右)控制扫频启动和重置

3. 配置文件(flight.yaml)

  • 新增ROS2执行器配置文件(200行)
  • 定义了rmcs_executor框架配置:更新率1000Hz、各组件的话题重映射
  • 配置所有控制子模块参数:
    • 云台控制器:俯仰/偏航运动限制
    • PID控制器:偏航/俯仰角度与速度控制的PID增益(Kp、Ki、Kd)
    • 摩擦轮/弹丸装填器:速度、软启动/停止时间
    • 热量控制:单发热量、保留热量
    • 自动瞄准:视频配置、相机内参、目标追踪参数、模型路径等

4. 云台求解器增强(two_axis_gimbal_solver.hpp)

  • 添加偏航角限制支持:新增 yaw_upper_limit_yaw_lower_limit_ 成员变量
  • 扩展构造函数:接收偏航上下限参数
  • 增强 clamp_control_direction() 方法:在计算控制方向时强制应用偏航角范围约束

5. 控制器更新

  • hero_gimbal_controller.cppsimple_gimbal_controller.cpp:更新云台求解器初始化调用,传入新的偏航限制参数

6. 插件注册(plugins.xml)

  • 注册三个新的ROS2组件插件:
    • rmcs_core::hardware::Flight
    • rmcs_core::controller::gimbal::GimbalFrequencySweep
    • GimbalTfPublisher

技术特点

  • 采用ROS2组件框架(rmcs_executor)实现模块化设计
  • 支持多硬件协调:电机、IMU、遥控等
  • 完整的数据记录与分析能力(CSV日志)
  • 灵活的参数配置系统,支持不同机型定制

代码审查难度

  • 硬件集成层:中等难度
  • 控制算法层:中等难度
  • 配置与参数:低难度

@coderabbitai
Copy link

coderabbitai bot commented Dec 30, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

总体说明

本次变更引入了新的硬件集成组件、云台频扫功能、偏航控制限制参数,以及飞行平台配置文件和诊断输出文件。

变更内容

组件/文件 变更摘要
诊断图表输出文件
frames_2025-11-27_16.09.16.gvframes_2025-11-27_16.24.56.gvframes_2025-11-27_16.25.48.gvframes_2025-11-27_16.27.10.gvframes_2025-12-02_19.18.18.gv
新增5个Graphviz DOT格式文件,各包含单个有向图节点"No tf data received",用于诊断可视化输出。
网络配置
ip.conf
添加IP地址169.254.233.233一行。
飞行配置文件
rmcs_ws/src/rmcs_bringup/config/flight.yaml
新增ROS 2飞行配置,定义rmcs_executor执行器配置、组件重映射、云台控制器参数、PID控制器增益、摩擦轮控制器、热量管理、弹药装填器、自动瞄准系统等全面配置。
云台频扫控制器
rmcs_ws/src/rmcs_core/src/controller/gimbal/GimbalFrequencySweep.cpp
新增ROS 2组件类,实现云台频率扫描功能,包括CSV数据记录、正弦控制信号生成、频率渐进式递增逻辑。
双轴云台求解器增强
rmcs_ws/src/rmcs_core/src/controller/gimbal/two_axis_gimbal_solver.hpp
添加偏航角限制支持,构造函数扩展偏航上下限参数,新增偏航角输入接口和边界约束计算逻辑。
云台控制器参数调整
rmcs_ws/src/rmcs_core/src/controller/gimbal/hero_gimbal_controller.cpprmcs_ws/src/rmcs_core/src/controller/gimbal/simple_gimbal_controller.cpp
修改imu/two_axis云台求解器初始化调用,传递偏航限制参数。
硬件集成
rmcs_ws/src/rmcs_core/src/hardware/flight.cpp
新增Flight硬件组件类,集成LK电机、DJi摩擦轮、装填器、DR16遥控器、BMI088 IMU、变换框架系统、UART/CAN接口与事件线程处理。
插件注册
rmcs_ws/src/rmcs_core/plugins.xml
新增三个导出类条目:rmcs_core::hardware::Flightrmcs_core::controller::gimbal::GimbalFrequencySweepGimbalTfPublisher
子模块更新
rmcs_ws/src/rmcs_core/librmcs
librmcs子模块指针更新,无功能变更。

代码审查工作量评估

🎯 4 (Complex) | ⏱️ ~60 minutes

诗歌

🐰 新硬件启航天空,
频扫云台展神功,
偏航限制守边界,
飞行配置齐备妥,
摄像头瞄准更精准!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: adding gimbal control code including flight.cpp, flight.yaml, GimbalFrequencySweep.cpp, and solver updates.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@1Feishu 1Feishu changed the title Flight Add relevant code for drone gimbal control Dec 31, 2025
@Embers-of-the-Fire
Copy link
Member

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Dec 31, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

♻️ Duplicate comments (4)
frames_2025-11-27_16.27.10.gv (1)

1-1: 移除调试输出文件。

与 frames_2025-12-02_19.18.18.gv 相同的问题:这是 ROS tf 诊断工具生成的调试文件,不应提交到仓库。

frames_2025-11-27_16.24.56.gv (1)

1-1: 移除调试输出文件。

这是另一个不应提交的 ROS tf 诊断输出文件。

frames_2025-11-27_16.09.16.gv (1)

1-1: 移除调试输出文件。

这是另一个不应提交的 ROS tf 诊断输出文件。

frames_2025-11-27_16.25.48.gv (1)

1-1: 移除调试输出文件。

这是最后一个不应提交的 ROS tf 诊断输出文件。

🧹 Nitpick comments (7)
rmcs_ws/src/rmcs_core/src/controller/gimbal/GimbalFrequencySweep.cpp (3)

1-4: 移除注释掉的代码。

这些被注释的 #include 语句应该被删除,而不是保留在代码中。

🔎 建议的修改
-// #include <chrono>
-// #include <fstream>
-// #include <vector>
-

66-68: 魔法数字 0.0002 需要解释或定义为常量。

0.0002 的含义不明确。建议将其定义为具名常量并添加注释说明其用途。

🔎 建议的修改
+static constexpr double TIME_INIT_THRESHOLD = 0.0002;  // 初始化阈值(秒)
+
 // 在 update() 中使用:
-if (last_time <= 0.0002) {
+if (last_time <= TIME_INIT_THRESHOLD) {

169-174: 使用标准库的 Pi 常量。

自定义 Pi = 3.1415926 精度有限,建议使用 M_PI 或 C++20 的 std::numbers::pi

🔎 建议的修改
-static constexpr double Pi       = 3.1415926;
+static constexpr double Pi       = M_PI;  // 或使用 std::numbers::pi (C++20)
rmcs_ws/src/rmcs_core/src/hardware/flight.cpp (1)

213-219: FlightCommand 的 flight_ 成员应声明为 private。

虽然 FlightCommand 类本身是 private 的,但将 flight_ 成员声明为 public 不符合封装原则。

🔎 建议的修改
 class FlightCommand : public rmcs_executor::Component {
 public:
     explicit FlightCommand(Flight& flight)
         : flight_(flight) {}
     void update() override { flight_.command_update(); }
+
+private:
     Flight& flight_;
 };
rmcs_ws/src/rmcs_core/src/controller/gimbal/simple_gimbal_controller.cpp (1)

23-26: 代码格式不一致。

逗号后缺少空格,与代码库其他部分的格式不一致。

🔎 建议的修改
         , two_axis_gimbal_solver(
               *this, get_parameter("upper_limit").as_double(),
-              get_parameter("lower_limit").as_double(),get_parameter("yaw_upper_limit").as_double()
-            ,get_parameter("yaw_lower_limit").as_double()) {
+              get_parameter("lower_limit").as_double(),
+              get_parameter("yaw_upper_limit").as_double(),
+              get_parameter("yaw_lower_limit").as_double()) {

功能上,新增的 yaw 限制参数传递是正确的,与 TwoAxisGimbalSolver 的更新一致。

rmcs_ws/src/rmcs_core/src/controller/gimbal/hero_gimbal_controller.cpp (1)

26-32: 代码格式不一致。

simple_gimbal_controller.cpp 相同的格式问题。建议统一格式。

🔎 建议的修改
         , imu_gimbal_solver(
               *this, get_parameter("upper_limit").as_double(),
-              get_parameter("lower_limit").as_double(),get_parameter("yaw_upper_limit").as_double()
-            ,get_parameter("yaw_lower_limit").as_double())
+              get_parameter("lower_limit").as_double(),
+              get_parameter("yaw_upper_limit").as_double(),
+              get_parameter("yaw_lower_limit").as_double())
         , encoder_gimbal_solver(

imu_gimbal_solver 使用更新后的 4 参数构造函数,而 encoder_gimbal_solver 保持原有的 2 参数签名(使用 PreciseTwoAxisGimbalSolver),这是正确的设计选择。

rmcs_ws/src/rmcs_core/src/controller/gimbal/two_axis_gimbal_solver.hpp (1)

113-117: 移除注释掉的调试代码。

建议使用条件编译宏(如 RCLCPP_DEBUG)替代注释掉的日志语句,或者完全移除这些注释。

🔎 建议使用 RCLCPP_DEBUG
// 在需要调试时使用:
RCLCPP_DEBUG(rclcpp::get_logger("two_axis_gimbal_solver"),
    "x: %f, y: %f, z: %f", control_direction->x(), control_direction->y(), control_direction->z());

Also applies to: 212-214

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d1268a2 and a0639e3.

⛔ Files ignored due to path filters (5)
  • frames_2025-11-27_16.09.16.pdf is excluded by !**/*.pdf
  • frames_2025-11-27_16.24.56.pdf is excluded by !**/*.pdf
  • frames_2025-11-27_16.25.48.pdf is excluded by !**/*.pdf
  • frames_2025-11-27_16.27.10.pdf is excluded by !**/*.pdf
  • frames_2025-12-02_19.18.18.pdf is excluded by !**/*.pdf
📒 Files selected for processing (14)
  • frames_2025-11-27_16.09.16.gv
  • frames_2025-11-27_16.24.56.gv
  • frames_2025-11-27_16.25.48.gv
  • frames_2025-11-27_16.27.10.gv
  • frames_2025-12-02_19.18.18.gv
  • ip.conf
  • rmcs_ws/src/rmcs_bringup/config/flight.yaml
  • rmcs_ws/src/rmcs_core/librmcs
  • rmcs_ws/src/rmcs_core/plugins.xml
  • rmcs_ws/src/rmcs_core/src/controller/gimbal/GimbalFrequencySweep.cpp
  • rmcs_ws/src/rmcs_core/src/controller/gimbal/hero_gimbal_controller.cpp
  • rmcs_ws/src/rmcs_core/src/controller/gimbal/simple_gimbal_controller.cpp
  • rmcs_ws/src/rmcs_core/src/controller/gimbal/two_axis_gimbal_solver.hpp
  • rmcs_ws/src/rmcs_core/src/hardware/flight.cpp
🧰 Additional context used
🧬 Code graph analysis (2)
rmcs_ws/src/rmcs_core/src/controller/gimbal/two_axis_gimbal_solver.hpp (2)
rmcs_ws/src/rmcs_core/src/controller/pid/smart_input.hpp (2)
  • component (37-48)
  • component (37-37)
rmcs_ws/src/rmcs_core/src/controller/chassis/chassis_controller.cpp (1)
  • gimbal_yaw_angle_ (45-55)
rmcs_ws/src/rmcs_core/src/controller/gimbal/GimbalFrequencySweep.cpp (3)
rmcs_ws/src/rmcs_core/src/hardware/flight.cpp (2)
  • rmcs_description (135-146)
  • RCLCPP_INFO (157-164)
rmcs_ws/src/rmcs_core/src/controller/gimbal/simple_gimbal_controller.cpp (1)
  • switch_right (46-75)
rmcs_ws/src/rmcs_core/src/controller/gimbal/hero_gimbal_controller.cpp (1)
  • switch_left (51-92)
🔇 Additional comments (10)
ip.conf (1)

1-1: 此文件似乎未被使用,请确认其意图。

ip.conf 中的 IP 地址 169.254.233.233 确实位于链路本地地址范围内。但是,经过代码审查,发现此文件在整个代码库中没有被引用或使用。实际的远程主机配置是通过 .script/set-remote 脚本完成的,该脚本接受 IPv4/IPv6 地址作为参数并更新 SSH 配置文件,而非读取 ip.conf。

若此文件无实际用途,建议删除;若有特定目的,请添加文档说明其用途。

Likely an incorrect or invalid review comment.

rmcs_ws/src/rmcs_core/librmcs (1)

1-1: 子模块更新需要充分验证和文档说明。

当前提供的只是子模块指针变更,无法审核子模块内部的实际改动。根据PR描述,此更新应引入飞行云台控制相关功能(flight.cpp、GimbalFrequencySweep.cpp等),但这些具体实现文件未在审核范围内。

需要验证以下事项:

  1. 确保完整的集成测试套件通过(尤其是与新的gimbal控制相关的测试)
  2. 确认librmcs子模块中的所有新增/修改代码与父项目兼容
  3. 文档化此次子模块更新的目的和所包含的主要功能变更

建议: 在提交消息或PR描述中详细说明子模块更新引入的关键功能和API变更,以便future维护者理解此次更新的设计决策。

rmcs_ws/src/rmcs_core/plugins.xml (1)

11-13: LGTM!

Flight 和 GimbalFrequencySweep 插件条目遵循现有的命名空间模式,与其他条目保持一致。

Also applies to: 41-43

rmcs_ws/src/rmcs_core/src/hardware/flight.cpp (2)

28-105: LGTM!

构造函数正确初始化了所有硬件设备(电机、IMU、DR16),配置了 TF 变换,并设置了 CAN/UART 通信接口。初始化列表顺序与成员声明顺序一致。


107-117: LGTM!

析构函数正确地停止事件处理并等待事件线程结束,遵循 RAII 原则。update() 方法正确调用了电机、IMU 和 DR16 的状态更新。

rmcs_ws/src/rmcs_core/src/controller/gimbal/two_axis_gimbal_solver.hpp (1)

182-198: Yaw 限制逻辑可能存在问题。

当前的 yaw 限制实现与 pitch 限制的处理方式不一致:

  1. Pitch 限制检查的是 z 分量(控制方向的垂直投影),这是正确的。
  2. Yaw 限制检查的是 y_ 分量,但 yaw_upper_limit_yaw_lower_limit_.y()-sin(angle),而 y_ 是在 YawLink 坐标系中的方向分量。

建议验证:

  • 确认 y_ 分量确实对应 yaw 角度的正弦值
  • 确认限制逻辑与 pitch 限制保持数学一致性

另外,代码格式不一致(缺少空格):

🔎 建议的格式修改
-       const auto& [x_,y_,z_] = *control_direction;
+       const auto& [x_, y_, z_] = *control_direction;

-        Eigen::Vector2d yaw_projection{x_,y_};
+        Eigen::Vector2d yaw_projection{x_, y_};

-            yaw_projection /=yaw_norm;
+            yaw_projection /= yaw_norm;

-        else{
-            control_enabled_ =false;
+        else {
+            control_enabled_ = false;
rmcs_ws/src/rmcs_bringup/config/flight.yaml (4)

56-64: 占位符值可能导致运行时问题。

  1. usb_pid: -1 看起来是占位符值。在 flight.cpp 中,这会传递给 librmcs::client::CBoard 构造函数,可能导致设备初始化失败。

  2. path: /dev/tty0 是系统控制台设备,通常不是裁判系统串口。应该使用 /dev/ttyUSB0/dev/ttyACM0 等实际串口设备。

请确认这些值在实际部署时会被正确配置。


66-71: 限制值命名与数值关系需要确认。

upper_limit: -0.149 小于 lower_limit: 0.149yaw_upper_limit: -0.349 小于 yaw_lower_limit: 0.349

如果这是由于坐标系约定(例如,角度正方向定义),这是可以接受的。但命名上 "upper" 通常意味着更大的值。建议:

  1. 添加注释说明坐标系约定
  2. 或者考虑重命名为更明确的名称(如 positive_limit / negative_limit

115-118: heat_per_shot 值异常。

heat_per_shot: 10000 对于 17mm 弹丸来说异常高。根据 RoboMaster 规则,17mm 弹丸通常每发热量为 10。如果这是测试配置或特殊用途,建议添加注释说明。


1-33: LGTM!

组件列表配置合理,包含了硬件、控制器、裁判系统和广播器的完整映射。注释掉的组件(如 gimbal_frequencyauto_aim)保留了扩展性。

Copy link
Author

@1Feishu 1Feishu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除了扫频部分的代码

Copy link
Member

@Embers-of-the-Fire Embers-of-the-Fire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

删除 Graphviz 产物,包括 *.gv 和 *.pdf。

Copy link
Author

@1Feishu 1Feishu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已删除*.gv文件

@creeper5820 creeper5820 requested a review from qzhhhi January 6, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants