Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ jobs:
tar -C "${GITHUB_WORKSPACE}" --exclude=".git" -cf - . \
| tar -C /tmp/RMCS/rmcs_ws/src/skills/rmcs-navigation -xf -

- name: Clone rmcs_relocation dependency
shell: bash
run: |
set -euo pipefail
git clone --depth 1 --branch main \
https://github.com/Alliance-Algorithm/rmcs_relocation.git \
/tmp/RMCS/rmcs_ws/src/skills/rmcs_relocation

- name: Build rmcs-navigation with colcon
shell: bash
working-directory: /tmp/RMCS/rmcs_ws
Expand Down
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.30)
cmake_minimum_required(VERSION 3.28)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Expand Down Expand Up @@ -30,6 +30,7 @@ find_package(nav2_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(rmcs_msgs REQUIRED)
find_package(rmcs_relocation REQUIRED)
find_package(std_srvs REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(tf2_ros REQUIRED)
Expand Down Expand Up @@ -64,6 +65,7 @@ target_include_directories(
${rmcs_executor_INCLUDE_DIRS}
${geometry_msgs_INCLUDE_DIRS}
${rmcs_msgs_INCLUDE_DIRS}
${rmcs_relocation_INCLUDE_DIRS}
${std_srvs_INCLUDE_DIRS}
${ament_index_cpp_INCLUDE_DIRS}
${tf2_ros_INCLUDE_DIRS}
Expand All @@ -88,6 +90,7 @@ target_link_libraries(
${geometry_msgs_LIBRARIES}
${std_srvs_LIBRARIES}
${rmcs_msgs_LIBRARIES}
${rmcs_relocation_LIBRARIES}
${tf2_ros_LIBRARIES}
${rclcpp_action_LIBRARIES}
${nav2_msgs_LIBRARIES}
Expand Down
3 changes: 2 additions & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
<exec_depend>rclpy</exec_depend>
<exec_depend>tf2_ros</exec_depend>
<exec_depend>rmcs_local_map</exec_depend>

<depend>rmcs_relocation</depend>

<export>
<build_type>ament_cmake</build_type>
</export>
Expand Down
53 changes: 52 additions & 1 deletion src/cxx/component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
#endif

#include "cxx/context.hh"
#include "cxx/util/localization/engine.hh"
#include "cxx/util/navigation/navigation.hh"
#include "cxx/util/node_mixin.hh"

#include <atomic>
#include <filesystem>
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <vector>

#include <Eigen/Geometry>
#include <ament_index_cpp/get_package_share_directory.hpp>
Expand Down Expand Up @@ -43,6 +49,8 @@ class Navigation

details::Context context;
details::Navigation navigation;
std::unique_ptr<Localization> localization;
bool relocalization_enabled = true;

struct Command {
using ChassisMode = rmcs_msgs::ChassisMode;
Expand Down Expand Up @@ -108,6 +116,34 @@ class Navigation
api.set_function("update_chassis_vel", [this](double x, double y) {
*command.chassis_speed = Eigen::Vector2d{x, y};
});
// 三个 mode 共享同一个 disabled-guard + 委托模板。lua 端别名(initial / local_ / wide)
const auto bind_relocalize = [this, &api](std::string_view name, RelocalizeMode mode) {
api.set_function(
std::string{name}, [this, name, mode](double x, double y, double yaw) {
if (!relocalization_enabled || !localization) {
warn("{} ignored: disabled", name);
return false;
}
return localization->relocalize(mode, x, y, yaw);
});
};
bind_relocalize("relocalize_initial", RelocalizeMode::Initial);
bind_relocalize("relocalize_local", RelocalizeMode::Local);
bind_relocalize("relocalize_wide", RelocalizeMode::Wide);

// status 转 lua table:disabled/enabled。
api.set_function("relocalize_status", [this]() {
const auto status = (relocalization_enabled && localization)
? localization->relocalize_status()
: RelocalizeStatus{.message = "disabled"};
return lua->create_table_with(
"state", static_cast<int>(status.state), "success", status.success,
"message", status.message, "fitness_score", status.fitness_score, "confidence",
status.confidence, "estimated_x", status.estimated_x, "estimated_y",
status.estimated_y, "estimated_z", status.estimated_z, "estimated_qx",
status.estimated_qx, "estimated_qy", status.estimated_qy, "estimated_qz",
status.estimated_qz, "estimated_qw", status.estimated_qw);
});
Comment on lines +134 to +146
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

disabled 分支返回的 stateIDLE 而非终态

RelocalizeStatus{.message = "disabled"} 会得到默认的 state = IDLE,但语义上"功能被关闭"应该是一个终态(FAILED 或新增的 DISABLED)。Lua 端 send_and_await 不会走到这里(disabled 时 relocalize_* 已直接返回 false),但任何只查询 relocalize_status() 的调用方会看到 state==IDLE / message=="disabled" 的奇怪组合。

🛠️ 建议
-            const auto status = (relocalization_enabled && localization)
-                                  ? localization->relocalize_status()
-                                  : RelocalizeStatus{.message = "disabled"};
+            const auto status = (relocalization_enabled && localization)
+                                  ? localization->relocalize_status()
+                                  : RelocalizeStatus{
+                                        .state   = RelocalizeState::FAILED,
+                                        .success = false,
+                                        .message = "disabled",
+                                    };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/cxx/component.cc` around lines 134 - 146, The disabled branch in the
api.set_function("relocalize_status") lambda returns RelocalizeStatus{.message =
"disabled"} which leaves state at the default IDLE; update that branch to return
a status with an explicit terminal state (e.g., RelocalizeState::FAILED or add a
new RelocalizeState::DISABLED) and a suitable message so callers of
relocalize_status() see a consistent terminal state; change the returned
RelocalizeStatus construction in the disabled path inside the relocalize_status
lambda (or add a new enum value if choosing DISABLED) so the "state" field is
not left as IDLE.

}

auto make_option_injection() {
Expand Down Expand Up @@ -238,6 +274,21 @@ class Navigation
, navigation{*this} {

mock_context = param<bool>("mock_context");
relocalization_enabled =
has_parameter("enable_relocalization")
? get_parameter_or<bool>("enable_relocalization", true)
: true;
if (relocalization_enabled) {
auto config = Localization::Config{ .rclcpp = *this };
if (has_parameter("localization.service_name"))
config.service_name = get_parameter("localization.service_name").as_string();
if (has_parameter("localization.request_timeout_sec"))
config.request_timeout_sec =
get_parameter("localization.request_timeout_sec").as_double();
localization = std::make_unique<Localization>(std::move(config));
} else {
warn("relocalization is disabled by parameter enable_relocalization=false");
}

context.init(io_mutex, mock_context);
command.init(*this);
Expand Down
Loading