Skip to content

Merge downstream gimbal control for flight#48

Open
Embers-of-the-Fire wants to merge 5 commits intoAlliance-Algorithm:flightfrom
Embers-of-the-Fire:gimbal
Open

Merge downstream gimbal control for flight#48
Embers-of-the-Fire wants to merge 5 commits intoAlliance-Algorithm:flightfrom
Embers-of-the-Fire:gimbal

Conversation

@Embers-of-the-Fire
Copy link
Member

@Embers-of-the-Fire Embers-of-the-Fire commented Feb 14, 2026

合并下游 Gimbal 控制用于飞行

概述

本PR将下游 gimbal 分支的改动合并到 flight 分支,主要涉及飞行硬件集成、Gimbal 控制器增强以及开发环境优化。

主要改动

硬件集成

  • 新增 Flight 硬件组件 (rmcs_core/src/hardware/flight.cpp):实现了完整的飞行硬件管理器,集成了多个硬件子系统:

    • 两个 Gimbal 云台电机(YAW、PITCH)
    • 两个 DJI 摩擦轮电机(左、右)
    • DJI 弹丸供弹器
    • DR16 遥控器接收
    • BMI088 IMU 传感器
    • TF 坐标变换树初始化
    • CAN 和 UART 通信接口
    • 视觉伺服和自瞄控制集成
  • 插件注册:新增 Flight 和 GimbalTfPublisher 两个组件插件

Gimbal 控制器增强

  • 双轴云台求解器升级 (two_axis_gimbal_solver.hpp):

    • 新增 YAW 轴上下限约束参数
    • 添加 gimbal_yaw_angle 输入接口
    • 增强偏转方向计算,确保 YAW 轴约束在距阵后应用
  • Hero 和 Simple 云台控制器更新:适配新的求解器参数接口

配置系统

  • 飞行配置文件 (flight.yaml):
    • 定义了完整的飞行执行器参数
    • 配置所有硬件、控制器和广播器的映射和参数
    • 包含自瞄控制(auto_aim)的详细配置、视觉跟踪、PnP 求解、模型路径等

环境和部署优化

  • 环境设置

    • ROS_LOCALHOST_ONLY 替换为 ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST
    • 新增 Zsh shell 配置支持(env_setup.zsh),包含自动补全设置
  • 脚本增强

    • 新增 play-autoaim 脚本,支持参数化用户监控、远程 SDP、复制控制、IP 监控等功能
    • 新增 foxglove 启动脚本,用于可视化桥接(端口 8765)
    • 新增 Zsh 自动补全脚本
  • Docker 配置

    • 升级 LLVM 工具链至最新稳定版(clang-22、clangd-22 等)
    • 添加 CMake 4.2.3 支持
    • 更新 docker-compose 配置:用户权限改为 1000:1000,移除特权模式,调整 Wayland 卷挂载
  • IP 配置:添加特定网络地址 (169.254.233.233)

文档更新

  • 在 README 中添加快速开始链接

框架改进

  • Component 基类优化 (rmcs_executor/component.hpp):
    • 虚析构函数现在使用 defaulted 析构函数
    • register_outputcreate_partner_component 模板添加构造约束

持续集成

  • 移除了 Docker 镜像自动构建工作流

技术亮点

  • 完整的飞行硬件抽象层设计
  • 多轴云台约束控制改进
  • ROS2 和 RMCS 框架的深度集成
  • 国际化(中文)脚本支持

@coderabbitai
Copy link

coderabbitai bot commented Feb 14, 2026

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.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

总体概览

这个PR引入了Flight硬件组件、增强了脚本功能、更新了Docker配置和环境设置、删除了GitHub Actions工作流,并添加了新的RMCS飞行配置。跨越基础设施、脚本、容器配置和核心硬件控制等多个方面。

变更

变更组 / 文件 摘要
GitHub Actions工作流
.github/workflows/update-image.yml
删除了负责构建和推送RMCS Docker镜像的工作流文件。
Zsh完成脚本
.script/complete/_play-autoaim, .script/complete/_set-remote
新增了两个zsh补全脚本:play-autoaim(支持--user、--remote、--no-copy、--ip参数)和set-remote(包含远程主机地址解析逻辑)。
可执行脚本
.script/foxglove, .script/play-autoaim
添加了foxglove启动脚本,增强了play-autoaim脚本以支持参数驱动流程、远程SCP传输、用户输入验证和条件化文件传输。
环境配置
.script/template/env_setup.bash, .script/template/env_setup.zsh
将ROS发现变量从ROS_LOCALHOST_ONLY替换为ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST;env_setup.zsh改用zsh且新增zsh补全初始化逻辑。
容器和镜像
Dockerfile, docker-compose.yml
Dockerfile更新LLVM工具链至clang-22并添加cmake 4.2.3;docker-compose.yml将rmcs-develop容器用户固定为1000:1000,移除特权模式,更新Wayland卷挂载。
文档和配置
README.md, ip.conf
README新增中文快速开始链接;ip.conf添加IP地址169.254.233.233。
RMCS配置
rmcs_ws/src/rmcs_bringup/config/flight.yaml
新增详细的飞行模式配置,映射硬件、云台控制器、摩擦轮、热管理、自动瞄准等多个子系统的参数。
插件和核心组件
rmcs_ws/src/rmcs_core/plugins.xml
注册两个新插件类:rmcs_core::hardware::Flight和GimbalTfPublisher。
云台控制器
rmcs_ws/src/rmcs_core/src/controller/gimbal/hero_gimbal_controller.cpp, rmcs_ws/src/rmcs_core/src/controller/gimbal/simple_gimbal_controller.cpp
更新云台控制器初始化以支持独立的yaw上下限参数。
云台求解器
rmcs_ws/src/rmcs_core/src/controller/gimbal/two_axis_gimbal_solver.hpp
扩展TwoAxisGimbalSolver构造函数以接受yaw角度限制,新增yaw角度输入接口和yaw约束应用逻辑。
Flight硬件组件
rmcs_ws/src/rmcs_core/src/hardware/flight.cpp
新增Flight硬件管理组件,集成CAN驱动、UART通信、IMU数据处理、云台电机控制、裁判系统接口、TF坐标框架和事件处理。
执行器组件库
rmcs_ws/src/rmcs_executor/include/rmcs_executor/component.hpp
为register_output和create_partner_component模板添加std::constructible_from约束;更新虚析构函数为默认定义。

序列图

sequenceDiagram
    participant CAN as CAN总线
    participant Flight as Flight硬件组件
    participant Motor as 电机驱动<br/>(云台/摩擦轮)
    participant IMU as IMU传感器
    participant TF as TF坐标框架
    participant UART as UART通信<br/>(裁判系统)

    Flight->>Motor: 初始化电机参数<br/>(yaw/pitch/摩擦轮)
    Flight->>TF: 构建坐标树<br/>(基座/轮/云台)
    Flight->>UART: 连接裁判系统<br/>(环形缓冲)
    
    rect rgb(100, 200, 150, 0.5)
    Note over Flight: 主循环update()
    Flight->>Motor: 读取电机状态
    Motor-->>Flight: 返回电机反馈
    Flight->>IMU: 更新IMU数据
    IMU-->>Flight: 返回加速度/角速度
    Flight->>TF: 发布IMU坐标变换
    end
    
    rect rgb(150, 150, 200, 0.5)
    Note over Flight: 命令更新command_update()
    Flight->>CAN: 组装CAN消息<br/>(yaw/pitch/执行器)
    CAN-->>Flight: 响应CAN传输
    end
    
    CAN-->>Flight: CAN回调<br/>(ID解析)
    Flight->>Flight: 缓存电机状态
    UART-->>Flight: UART回调<br/>(裁判数据)
    Flight->>Flight: 更新裁判状态缓冲
Loading

审查工作量估计

🎯 4 (复杂) | ⏱️ ~60 分钟

相关PR

建议审查者

  • qzhhhi

诗歌

🐰 云台转身,电机舞蹈,
CAN总线传递灵魂,
IMU眼睛看世界,
TF框架映天地,
Flight软件展翅飞翔!✨

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题准确反映了主要变更内容:合并云台控制相关的多个下游改动到flight分支,包括新增Flight硬件组件、云台求解器扩展、环境配置调整等。
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into flight

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
rmcs_ws/src/rmcs_executor/include/rmcs_executor/component.hpp (1)

138-149: ⚠️ Potential issue | 🟠 Major

添加显式 <concepts> 包含以保证 std::constructible_from 的可用性。
代码在第 138-149 行使用了 std::constructible_from 的 requires 约束,但当前头文件未显式包含 <concepts> 头文件。虽然某些标准库实现可能通过间接包含提供此概念,但为保证代码在不同编译器和标准库实现下的可移植性和稳定性,应显式包含此头文件。

建议修复
 `#include` <map>
 `#include` <memory>
 `#include` <new>
+#include <concepts>
 `#include` <stdexcept>
 `#include` <string>
 `#include` <type_traits>
🤖 Fix all issues with AI agents
In @.script/play-autoaim:
- Around line 63-68: The script uses set -e which causes the shell to exit
before the custom error message runs when scp fails; replace the separate scp
then "$?" check with a single conditional that captures scp's failure (for
example: if ! scp "${SDP_PATH}" "${MONITOR_USER}@${MONITOR_HOST}:${SDP_PATH}";
then echo " scp 拷贝失败"; exit 1; fi) or temporarily disable errexit around the
scp (set +e; scp ... || { echo "..."; exit 1; }; set -e). Update the block that
references SKIP_COPY and the scp command so the error message is printed
reliably on failure.
- Around line 48-60: The script sets set -e which causes the scp command to
abort the whole script before your manual error handling runs; modify the scp
invocation so its failure is caught instead of triggering errexit — for example
change the scp line to run in a conditional (if ! scp remote:${SDP_PATH}
${SDP_PATH}; then …) or temporarily disable errexit around scp (set +e before
scp and set -e after) and then keep the existing $? -ne 0 branch that prompts
the user; ensure you reference the USE_REMOTE check and the scp
remote:${SDP_PATH} ${SDP_PATH} invocation and preserve the subsequent
interactive prompt logic.

In `@Dockerfile`:
- Around line 96-108: Replace the third-party Tsinghua mirror URL used when
adding the LLVM apt source with the official apt.llvm.org URL: update the echo
that writes the sources list (the line creating
/etc/apt/sources.list.d/llvm.list) to use "http://apt.llvm.org/noble/"
(preserving the [signed-by=/etc/apt/keyrings/llvm-snapshot.gpg] token and the
"llvm-toolchain-noble-22 main" suite), keep the existing GPG key fetch (the wget
| gpg --dearmor step) and the subsequent apt-get
install/update-alternatives/cleanup commands unchanged so the rest of the RUN
block (installing clang-22, clangd-22, clang-format-22, lldb-22 and configuring
update-alternatives) continues to work as before.

In `@rmcs_ws/src/rmcs_core/src/controller/gimbal/two_axis_gimbal_solver.hpp`:
- Line 3: 头文件 librmcs/utility/logging.hpp 在 two_axis_gimbal_solver.hpp
中被包含但未使用,因为所有 LOG_INFO 调用已被注释(参见被注释的 LOG_INFO 在第 113-115 行和第 212-213
行);请修复:要么直接移除该 include 语句以消除未使用包含和静态分析警告,要么恢复这些被注释的 LOG_INFO 调用(保留正确的上下文变量)以重新使用
logging.hpp;在修复时参考包含语句和 LOG_INFO 标识符以定位修改点。
- Around line 183-198: The yaw-limit branch currently only scales the x
component (using yaw_projection.x()), which breaks directional consistency
versus the pitch-limit logic; change the branches that handle y_ >
yaw_upper_limit_.y() and y_ < yaw_lower_limit_.y() to scale the entire
yaw_projection vector (e.g., scaled = yaw_projection * yaw_upper_limit_.x() or *
yaw_lower_limit_.x()) and then assign both x and y from that scaled vector,
while scaling z_ by the same factor to preserve the x/z ratio; update references
to control_direction, yaw_projection, yaw_upper_limit_, and yaw_lower_limit_
accordingly.

In `@rmcs_ws/src/rmcs_core/src/hardware/flight.cpp`:
- Around line 75-82: The wheel transform coordinates in flight.cpp are incorrect
for LeftBackWheelLink, RightBackWheelLink, and RightFrontWheelLink; update the
Eigen::Translation3d arguments passed to tf_->set_transform for the specific
templates LeftBackWheelLink, RightBackWheelLink, and RightFrontWheelLink so they
match the standard layout used in infantry.cpp (front = +x, back = -x, left =
+y, right = -y): ensure LeftBackWheelLink uses (-rotor_distance_x/2,
+rotor_distance_y/2, 0), RightBackWheelLink uses (-rotor_distance_x/2,
-rotor_distance_y/2, 0), and RightFrontWheelLink uses (+rotor_distance_x/2,
-rotor_distance_y/2, 0) while leaving LeftFrontWheelLink unchanged.
🧹 Nitpick comments (7)
.script/template/env_setup.zsh (1)

20-22: 建议:考虑添加 compinit 缓存以优化启动性能。

每次 shell 启动时执行 compinit 可能会导致轻微的性能开销。可以考虑添加缓存检查:

♻️ 可选优化
 fpath=(${RMCS_PATH}/.script/complete $fpath)
 autoload -Uz compinit
-compinit
+if [[ -n ${ZDOTDIR}/.zcompdump(`#qN.mh`+24) ]]; then
+  compinit
+else
+  compinit -C
+fi

这将在缓存文件超过 24 小时时才重新生成补全缓存,可显著加速 shell 启动。

.script/foxglove (1)

1-5: 建议:添加错误处理并统一 shebang 格式。

  1. Shebang 格式 #! /bin/bash 与其他脚本(如 env_setup.bash 使用 #!/bin/bash)不一致
  2. 如果 env_setup.bash 不存在,脚本会静默失败
♻️ 建议修改
-#! /bin/bash
+#!/bin/bash
+
+set -e
 
-source ~/env_setup.bash
+if [[ -f ~/env_setup.bash ]]; then
+    source ~/env_setup.bash
+else
+    echo "Error: ~/env_setup.bash not found" >&2
+    exit 1
+fi
 
 ros2 launch foxglove_bridge foxglove_bridge_launch.xml port:=8765
docker-compose.yml (1)

4-4: 注意:硬编码的用户 ID 假设。

user${CONTAINER_USER} 改为硬编码的 "1000:1000" 假设主机用户的 UID/GID 始终为 1000。如果开发者的 UID 不同,可能会导致权限问题。

鉴于这是开发容器配置,此简化是可以接受的,但建议在文档或注释中说明此假设。

Based on learnings: "In the RMCS repository, development containers are configured via docker-compose.yml. For development environments, it is acceptable to mount broader user config directories..."

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

213-219: 建议将 flight_ 成员设为私有。

FlightCommand 类中的 flight_ 成员当前为 public,但只在 update() 方法内部使用。将其设为 private 可以更好地封装内部状态。

♻️ 建议修改
 class FlightCommand : public rmcs_executor::Component {
 public:
     explicit FlightCommand(Flight& flight)
         : flight_(flight) {}
     void update() override { flight_.command_update(); }
+
+private:
     Flight& flight_;
 };

42-42: 建议为 BMI088 初始化参数添加注释或命名常量。

bmi088_(500.0, 0.3, 0.005) 中的魔法数字含义不明确,建议添加注释说明各参数的用途(如采样率、滤波系数等)。

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

11-13: 建议更新插件描述。

description 当前为 "Test plugin.",建议更新为更具描述性的内容,如 "Flight hardware component for gimbal control"。

rmcs_ws/src/rmcs_bringup/config/flight.yaml (1)

64-69: 限位参数命名可能引起混淆。

upper_limit: -0.149 的数值比 lower_limit: 0.149 小,这种命名方式容易造成误解。建议在配置文件中添加注释说明这些值的含义(如角度方向约定)。

Comment on lines +75 to +82
tf_->set_transform<BaseLink, LeftFrontWheelLink>(
Eigen::Translation3d{rotor_distance_x / 2, rotor_distance_y / 2, 0});
tf_->set_transform<BaseLink, LeftBackWheelLink>(
Eigen::Translation3d{rotor_distance_x / 2, -rotor_distance_y / 2, 0});
tf_->set_transform<BaseLink, RightBackWheelLink>(
Eigen::Translation3d{-rotor_distance_x / 2, rotor_distance_y / 2, 0});
tf_->set_transform<BaseLink, RightFrontWheelLink>(
Eigen::Translation3d{-rotor_distance_x / 2, -rotor_distance_y / 2, 0});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, find and examine the flight.cpp file
find . -name "flight.cpp" -type f | head -5

Repository: Alliance-Algorithm/RMCS

Length of output: 114


🏁 Script executed:

# Search for the specific file mentioned
find . -path "*rmcs_core/src/hardware/flight.cpp" -type f

Repository: Alliance-Algorithm/RMCS

Length of output: 114


🏁 Script executed:

# Broader search for flight-related files
find . -name "*flight*" -type f | grep -E "\.(cpp|hpp|h)$"

Repository: Alliance-Algorithm/RMCS

Length of output: 114


🏁 Script executed:

# Search for WheelLink references in the codebase
rg -n "WheelLink" --type cpp -C 2

Repository: Alliance-Algorithm/RMCS

Length of output: 11568


🏁 Script executed:

# Look for any coordinate system or wheel position documentation
rg -n "(wheel|coordinate|position)" --type cpp -i | head -50

Repository: Alliance-Algorithm/RMCS

Length of output: 5837


🏁 Script executed:

# Verify the exact lines once more to be absolutely certain
sed -n '75,82p' ./rmcs_ws/src/rmcs_core/src/hardware/flight.cpp

Repository: Alliance-Algorithm/RMCS

Length of output: 630


🏁 Script executed:

# Check infantry.cpp for comparison
sed -n '93,100p' ./rmcs_ws/src/rmcs_core/src/hardware/infantry.cpp

Repository: Alliance-Algorithm/RMCS

Length of output: 630


轮子位置坐标全部错误,需要立即修正。

infantry.cpptunnel_infantry.cpp 中的标准布局对比,flight.cpp 中三个轮子的坐标均不正确:

轮子 当前坐标 正确坐标 说明
LeftFrontWheelLink (+x/2, +y/2) (+x/2, +y/2) ✓ 正确
LeftBackWheelLink (+x/2, -y/2) (-x/2, +y/2) ✗ x坐标错误
RightBackWheelLink (-x/2, +y/2) (-x/2, -y/2) ✗ y坐标错误
RightFrontWheelLink (-x/2, -y/2) (+x/2, -y/2) ✗ x坐标错误

标准约定:前轮在 +x,后轮在 -x;左轮在 +y,右轮在 -y。

参考实现可查看 infantry.cpp 第 93-100 行的正确布局。

🤖 Prompt for AI Agents
In `@rmcs_ws/src/rmcs_core/src/hardware/flight.cpp` around lines 75 - 82, The
wheel transform coordinates in flight.cpp are incorrect for LeftBackWheelLink,
RightBackWheelLink, and RightFrontWheelLink; update the Eigen::Translation3d
arguments passed to tf_->set_transform for the specific templates
LeftBackWheelLink, RightBackWheelLink, and RightFrontWheelLink so they match the
standard layout used in infantry.cpp (front = +x, back = -x, left = +y, right =
-y): ensure LeftBackWheelLink uses (-rotor_distance_x/2, +rotor_distance_y/2,
0), RightBackWheelLink uses (-rotor_distance_x/2, -rotor_distance_y/2, 0), and
RightFrontWheelLink uses (+rotor_distance_x/2, -rotor_distance_y/2, 0) while
leaving LeftFrontWheelLink unchanged.

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