-
Notifications
You must be signed in to change notification settings - Fork 37
Add relevant code for drone gimbal control #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: flight
Are you sure you want to change the base?
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 总体说明本次变更引入了新的硬件集成组件、云台频扫功能、偏航控制限制参数,以及飞行平台配置文件和诊断输出文件。 变更内容
代码审查工作量评估🎯 4 (Complex) | ⏱️ ~60 minutes 诗歌
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this 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
⛔ Files ignored due to path filters (5)
frames_2025-11-27_16.09.16.pdfis excluded by!**/*.pdfframes_2025-11-27_16.24.56.pdfis excluded by!**/*.pdfframes_2025-11-27_16.25.48.pdfis excluded by!**/*.pdfframes_2025-11-27_16.27.10.pdfis excluded by!**/*.pdfframes_2025-12-02_19.18.18.pdfis excluded by!**/*.pdf
📒 Files selected for processing (14)
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.gvip.confrmcs_ws/src/rmcs_bringup/config/flight.yamlrmcs_ws/src/rmcs_core/librmcsrmcs_ws/src/rmcs_core/plugins.xmlrmcs_ws/src/rmcs_core/src/controller/gimbal/GimbalFrequencySweep.cpprmcs_ws/src/rmcs_core/src/controller/gimbal/hero_gimbal_controller.cpprmcs_ws/src/rmcs_core/src/controller/gimbal/simple_gimbal_controller.cpprmcs_ws/src/rmcs_core/src/controller/gimbal/two_axis_gimbal_solver.hpprmcs_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等),但这些具体实现文件未在审核范围内。
需要验证以下事项:
- 确保完整的集成测试套件通过(尤其是与新的gimbal控制相关的测试)
- 确认librmcs子模块中的所有新增/修改代码与父项目兼容
- 文档化此次子模块更新的目的和所包含的主要功能变更
建议: 在提交消息或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 限制的处理方式不一致:
- Pitch 限制检查的是
z分量(控制方向的垂直投影),这是正确的。- 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: 占位符值可能导致运行时问题。
usb_pid: -1看起来是占位符值。在flight.cpp中,这会传递给librmcs::client::CBoard构造函数,可能导致设备初始化失败。
path: /dev/tty0是系统控制台设备,通常不是裁判系统串口。应该使用/dev/ttyUSB0或/dev/ttyACM0等实际串口设备。请确认这些值在实际部署时会被正确配置。
66-71: 限制值命名与数值关系需要确认。
upper_limit: -0.149小于lower_limit: 0.149,yaw_upper_limit: -0.349小于yaw_lower_limit: 0.349。如果这是由于坐标系约定(例如,角度正方向定义),这是可以接受的。但命名上 "upper" 通常意味着更大的值。建议:
- 添加注释说明坐标系约定
- 或者考虑重命名为更明确的名称(如
positive_limit/negative_limit)
115-118: heat_per_shot 值异常。
heat_per_shot: 10000对于 17mm 弹丸来说异常高。根据 RoboMaster 规则,17mm 弹丸通常每发热量为 10。如果这是测试配置或特殊用途,建议添加注释说明。
1-33: LGTM!组件列表配置合理,包含了硬件、控制器、裁判系统和广播器的完整映射。注释掉的组件(如
gimbal_frequency、auto_aim)保留了扩展性。
rmcs_ws/src/rmcs_core/src/controller/gimbal/GimbalFrequencySweep.cpp
Outdated
Show resolved
Hide resolved
rmcs_ws/src/rmcs_core/src/controller/gimbal/GimbalFrequencySweep.cpp
Outdated
Show resolved
Hide resolved
1Feishu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除了扫频部分的代码
Embers-of-the-Fire
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除 Graphviz 产物,包括 *.gv 和 *.pdf。
1Feishu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已删除*.gv文件
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行)2. 云台频率扫描模块(GimbalFrequencySweep.cpp)
rmcs_core::controller::gimbal::GimbalFrequencySweep控制器(196行)3. 配置文件(flight.yaml)
4. 云台求解器增强(two_axis_gimbal_solver.hpp)
yaw_upper_limit_和yaw_lower_limit_成员变量clamp_control_direction()方法:在计算控制方向时强制应用偏航角范围约束5. 控制器更新
hero_gimbal_controller.cpp和simple_gimbal_controller.cpp:更新云台求解器初始化调用,传入新的偏航限制参数6. 插件注册(plugins.xml)
rmcs_core::hardware::Flightrmcs_core::controller::gimbal::GimbalFrequencySweepGimbalTfPublisher技术特点
代码审查难度