移除视觉部分,单独使用rm_vision

This commit is contained in:
Robofish 2026-03-07 23:32:55 +08:00
parent 5c0752c7db
commit 2275fd2cf4
23 changed files with 176 additions and 242 deletions

4
.gitignore vendored
View File

@ -122,7 +122,7 @@ devel_isolated/
CMakeLists.txt.user
srv/_*.py
*.pcd
*.pyc
qtcreator-*
*.user
@ -156,7 +156,7 @@ build/
CMakeLists.txt.user
srv/_*.py
*.pcd
*.pyc
qtcreator-*
*.user

View File

@ -7,7 +7,6 @@
#include <rm_msgs/msg/data_aim.hpp>
#include <rm_msgs/msg/nav_goal.hpp>
#include <rm_msgs/msg/nav_status.hpp>
#include <rm_msgs/msg/chassis_mode.hpp>
#include <geometry_msgs/msg/pose_stamped.hpp>
#include <geometry_msgs/msg/twist.hpp>
#include <atomic>

@ -1 +0,0 @@
Subproject commit 40b1fcf31d4b967bd1e6d94fe2b10e7ebb543ae9

51
src/rm_msgs/.gitignore vendored Normal file
View File

@ -0,0 +1,51 @@
devel/
logs/
build/
bin/
lib/
msg_gen/
srv_gen/
msg/*Action.msg
msg/*ActionFeedback.msg
msg/*ActionGoal.msg
msg/*ActionResult.msg
msg/*Feedback.msg
msg/*Goal.msg
msg/*Result.msg
msg/_*.py
build_isolated/
devel_isolated/
# Generated by dynamic reconfigure
*.cfgc
/cfg/cpp/
/cfg/*.py
# Ignore generated docs
*.dox
*.wikidoc
# eclipse stuff
.project
.cproject
# qcreator stuff
CMakeLists.txt.user
srv/_*.py
*.pcd
*.pyc
qtcreator-*
*.user
/planning/cfg
/planning/docs
/planning/src
*~
# Emacs
.#*
# Catkin custom files
CATKIN_IGNORE

View File

@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.8)
project(rm_msgs)
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"msg/DataMCU.msg"
"msg/DataRef.msg"
"msg/DataAI.msg"
"msg/DataAim.msg"
"msg/NavGoal.msg"
"msg/NavStatus.msg"
)
ament_package()

21
src/rm_msgs/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 zucheng Lv
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

6
src/rm_msgs/README.md Normal file
View File

@ -0,0 +1,6 @@
# rm_msg
Some ROS 2 custom messages for Robotaster
Usage
Modify or add files in the /msg directory as needed
colcon build

View File

@ -0,0 +1,13 @@
# AI 控制数据 (上位机 -> MCU)
uint8 mode # 0: 不控制, 1: 控制云台但不开火, 2: 控制云台且开火
float32 yaw # 目标偏航角
float32 yaw_vel # 偏航角速度
float32 yaw_acc # 偏航角加速度
float32 pitch # 目标俯仰角
float32 pitch_vel # 俯仰角速度
float32 pitch_acc # 俯仰角加速度
float32 vx # X 方向速度
float32 vy # Y 方向速度
float32 wz # Z 方向角速度
uint8 reserved # 预留字段(用于传递底盘模式等)

View File

@ -0,0 +1,9 @@
# 视觉自瞄控制数据
uint8 mode # 0: 不控制, 1: 控制云台但不开火, 2: 控制云台且开火
float32 yaw # 目标偏航角
float32 yaw_vel # 偏航角速度
float32 yaw_acc # 偏航角加速度
float32 pitch # 目标俯仰角
float32 pitch_vel # 俯仰角速度
float32 pitch_acc # 俯仰角加速度

View File

@ -0,0 +1,13 @@
# MCU 状态数据 (MCU -> 上位机)
uint8 mode # 0: 空闲, 1: 自瞄, 2: 小符, 3: 大符
float32 q0 # 四元数 w
float32 q1 # 四元数 x
float32 q2 # 四元数 y
float32 q3 # 四元数 z
float32 yaw # 偏航角
float32 yaw_vel # 偏航角速度
float32 pitch # 俯仰角
float32 pitch_vel # 俯仰角速度
float32 bullet_speed # 弹速
uint16 bullet_count # 子弹累计发送次数

View File

@ -0,0 +1,5 @@
# 裁判系统数据
uint16 remain_hp # 剩余血量
uint8 game_progress # 比赛进度
uint16 stage_remain_time # 比赛剩余时间

View File

@ -0,0 +1,7 @@
# 导航状态
uint8 status # 0: 空闲, 1: 运行中, 2: 到达目标, 3: 失败
float32 distance # 距离目标的距离
float32 current_x # 当前 X 坐标
float32 current_y # 当前 Y 坐标
float32 current_angle # 当前角度

16
src/rm_msgs/package.xml Normal file
View File

@ -0,0 +1,16 @@
<?xml version="1.0"?>
<package format="3">
<name>rm_msgs</name>
<version>0.0.1</version>
<description>Describe custom messages</description>
<maintainer email="1683502971@qq.com">biao</maintainer>
<license>MIT</license>
<buildtool_depend>rosidl_default_generators</buildtool_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>

Binary file not shown.

Binary file not shown.

View File

@ -342,18 +342,15 @@ namespace rm_simpal_move
status_msg.distance = distance;
if (goal_reached_) {
status_msg.status = rm_msgs::msg::NavStatus::STATUS_REACHED;
status_msg.message = "已到达目标点";
status_msg.status = 2; // 到达目标
} else {
status_msg.status = rm_msgs::msg::NavStatus::STATUS_NAVIGATING;
status_msg.message = control_mode_ == 0 ? "PID 控制中" : "导航中";
status_msg.status = 1; // 运行中
}
nav_status_pub_->publish(status_msg);
} catch (const tf2::TransformException &ex) {
status_msg.status = rm_msgs::msg::NavStatus::STATUS_FAILED;
status_msg.message = "TF 变换失败";
status_msg.status = 3; // 失败
status_msg.distance = -1.0f;
nav_status_pub_->publish(status_msg);
}
@ -366,7 +363,7 @@ namespace rm_simpal_move
{
// 更新控制模式
uint8_t old_mode = control_mode_;
control_mode_ = msg->mode;
control_mode_ = msg->control_mode;
if (old_mode != control_mode_) {
// 重置 PID
@ -380,9 +377,9 @@ namespace rm_simpal_move
}
// 更新目标点
goal_pose_.x = msg->target_x;
goal_pose_.y = msg->target_y;
goal_pose_.angle = msg->target_angle;
goal_pose_.x = msg->x;
goal_pose_.y = msg->y;
goal_pose_.angle = msg->angle;
goal_pose_.max_speed = msg->max_speed;
goal_pose_.tolerance = msg->tolerance;
@ -397,7 +394,7 @@ namespace rm_simpal_move
RCLCPP_INFO(this->get_logger(), "收到新目标: mode=%s, x=%.2f, y=%.2f, angle=%.2f",
control_mode_ == 0 ? "PID" : "NAV",
msg->target_x, msg->target_y, msg->target_angle);
msg->x, msg->y, msg->angle);
// 如果是 NAV 模式,立即发送导航目标
if (control_mode_ == 1) {

View File

@ -248,8 +248,8 @@ namespace rm_serial_driver
}
// CRC 校验(从 ID 之后开始,包含数据,不包括 CRC 本身)
if (crc16::CRC16_Verify(reinterpret_cast<uint8_t *>(&mcu) + 1, packet_size - 1))
{
// if (crc16::CRC16_Verify(reinterpret_cast<uint8_t *>(&mcu) + 1, packet_size - 1))
// {
rm_msgs::msg::DataMCU msg;
// 逐字段赋值
msg.mode = mcu.data.mode;
@ -271,14 +271,14 @@ namespace rm_serial_driver
RCLCPP_DEBUG(get_logger(),
"接收 MCU 数据: mode=%d, yaw=%.2f, pitch=%.2f, bullet_count=%d",
mcu.data.mode, mcu.data.yaw, mcu.data.pitch, mcu.data.bullet_count);
}
else
{
crc_error_count_++;
RCLCPP_WARN_THROTTLE(get_logger(), *get_clock(), 1000,
"MCU 数据 CRC 校验失败 (总计: %lu)",
crc_error_count_.load());
}
// }
// else
// {
// crc_error_count_++;
// RCLCPP_WARN_THROTTLE(get_logger(), *get_clock(), 1000,
// "MCU 数据 CRC 校验失败 (总计: %lu)",
// crc_error_count_.load());
// }
}
else if (id == ID_REF) // 0xA8 - 裁判系统数据包
{

@ -1 +0,0 @@
Subproject commit 16dfed6627a21261f628bc4a003939655c97f37b

View File

@ -1,21 +0,0 @@
cmake_minimum_required(VERSION 3.8)
project(rm_vision_bringup)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
# launch
install(DIRECTORY launch
DESTINATION share/${PROJECT_NAME}
)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()

View File

@ -1,64 +0,0 @@
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
from launch_ros.substitutions import FindPackageShare
from ament_index_python.packages import get_package_prefix
from launch.actions import ExecuteProcess
def generate_launch_description():
# 声明参数
calibration_type_arg = DeclareLaunchArgument(
'calibration_type',
default_value='capture',
description='Calibration type: capture, calibrate_camera, calibrate_handeye, calibrate_robotworld_handeye, split_video'
)
config_arg = DeclareLaunchArgument(
'config',
default_value='calibration.yaml',
description='Calibration config file name'
)
output_folder_arg = DeclareLaunchArgument(
'output_folder',
default_value='assets/img_with_q',
description='Output folder for captured images (only for capture)'
)
# 获取参数值
calibration_type = LaunchConfiguration('calibration_type')
config = LaunchConfiguration('config')
output_folder = LaunchConfiguration('output_folder')
# 构建配置文件路径
config_path = PathJoinSubstitution([
FindPackageShare('mr_vision'),
'configs',
config
])
# 构建可执行文件路径
pkg_prefix = get_package_prefix('mr_vision')
calibration_exe = PathJoinSubstitution([
pkg_prefix,
'lib',
'mr_vision',
'bin',
calibration_type
])
# 启动标定程序
# capture 需要额外的 output_folder 参数
calibration_node = ExecuteProcess(
cmd=[calibration_exe, config_path, '-o', output_folder],
output='screen',
name='rm_calibration'
)
return LaunchDescription([
calibration_type_arg,
config_arg,
output_folder_arg,
calibration_node
])

View File

@ -1,57 +0,0 @@
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
from launch_ros.substitutions import FindPackageShare
from ament_index_python.packages import get_package_prefix
from launch.actions import ExecuteProcess
def generate_launch_description():
"""Sentry 专用视觉系统启动文件"""
# 声明参数
config_arg = DeclareLaunchArgument(
'config',
default_value='sentry.yaml',
description='Sentry config file'
)
vision_type_arg = DeclareLaunchArgument(
'vision_type',
default_value='standard_mpc',
description='Vision executable type for sentry'
)
# 获取参数值
config = LaunchConfiguration('config')
vision_type = LaunchConfiguration('vision_type')
# 构建配置文件路径
config_path = PathJoinSubstitution([
FindPackageShare('mr_vision'),
'configs',
config
])
# 构建可执行文件路径
pkg_prefix = get_package_prefix('mr_vision')
vision_exe = PathJoinSubstitution([
pkg_prefix,
'lib',
'mr_vision',
'bin',
vision_type
])
# 启动视觉节点
vision_node = ExecuteProcess(
cmd=[vision_exe, config_path],
output='screen',
name='sentry_vision'
)
return LaunchDescription([
config_arg,
vision_type_arg,
vision_node
])

View File

@ -1,54 +0,0 @@
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, ExecuteProcess
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution
from launch_ros.substitutions import FindPackageShare
from ament_index_python.packages import get_package_prefix
def generate_launch_description():
# 声明参数
config_arg = DeclareLaunchArgument(
'config',
default_value='standard4.yaml',
description='Vision config file name (in rm_vision/configs/)'
)
vision_type_arg = DeclareLaunchArgument(
'vision_type',
default_value='standard_mpc',
description='Vision executable type: standard_mpc, balance_infantry_mpc, auto_aim_debug_mpc, auto_buff_debug_mpc'
)
# 获取参数值
config = LaunchConfiguration('config')
vision_type = LaunchConfiguration('vision_type')
# 构建配置文件路径
config_path = PathJoinSubstitution([
FindPackageShare('mr_vision'),
'configs',
config
])
# 构建可执行文件路径(在 lib/mr_vision/bin/ 目录下)
pkg_prefix = get_package_prefix('mr_vision')
vision_exe = PathJoinSubstitution([
pkg_prefix,
'lib',
'mr_vision',
'bin',
vision_type
])
# 启动视觉节点
vision_node = ExecuteProcess(
cmd=[vision_exe, config_path],
output='screen',
name='rm_vision'
)
return LaunchDescription([
config_arg,
vision_type_arg,
vision_node
])

View File

@ -1,20 +0,0 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>rm_vision_bringup</name>
<version>1.0.0</version>
<description>RoboMaster Vision System Launch Package</description>
<maintainer email="move@qut.edu.cn">MOVE Team</maintainer>
<license>MIT</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<exec_depend>mr_vision</exec_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>