feat(sim): integrate Gazebo Classic with Point-LIO and SCAN navigation

Import the complete field and a simplified omnidirectional robot in sim_ws.
Reuse original Point-LIO, SCAN and controller implementations with isolated
simulation profiles, timed MID360/IMU data, readiness and command guards.
Support known-corridor terrain paths, optional sensor stress profiles and
separate physics/algorithm launch processes.

Remove retired Fortress resources and operating instructions; add build,
usage, scope and durable validation documentation.

Validation: full build script; 8 adapter tests and 4 SCAN CTest targets;
8 continuous mild-noise routes; red/blue terrain 4 cases each; noise 9/9;
visibility characterization 9/9; default sensors 16/16; loss-stop and
post-build straight navigation. Real wheels/network remain unverified.
This commit is contained in:
2026-11-08 19:04:32 +08:00
parent b6f84ac118
commit 664eaa81e5
83 changed files with 16948 additions and 12 deletions
@@ -64,6 +64,9 @@ if(BUILD_TESTING)
find_package(ament_cmake_pytest REQUIRED)
find_package(launch_testing_ament_cmake REQUIRED)
ament_add_gtest(test_rectangle_footprint test/test_rectangle_footprint.cpp)
ament_add_gtest(test_terrain_velocity test/test_terrain_velocity.cpp)
target_include_directories(test_terrain_velocity PRIVATE include)
target_link_libraries(test_terrain_velocity Eigen3::Eigen)
ament_target_dependencies(test_rectangle_footprint plan_env rclcpp)
ament_add_gtest(test_goal_execution_utils test/test_goal_execution_utils.cpp)
target_include_directories(test_goal_execution_utils PRIVATE include)
@@ -43,6 +43,7 @@ namespace scan_planner
private:
rclcpp::Node *node_{nullptr};
double min_replan_distance_{0.2};
/* main planning algorithms & modules */
PlanningVisualization::Ptr visualization_;
@@ -90,6 +90,7 @@ namespace scan_planner
double goal_tolerance_{0.08}, blocked_timeout_{10.0}, blocked_retry_period_{0.5};
bool require_perception_ready_{false}, perception_ready_{false};
bool require_controller_feedback_{false};
bool terrain_motion_{false};
bool last_trajectory_final_{false};
bool target_yaw_valid_{false};
double target_yaw_{0.0};
@@ -0,0 +1,28 @@
#pragma once
#include <cmath>
#include <Eigen/Eigen>
namespace scan_planner
{
// Odometry twist is expressed in child_frame_id, including on a slope.
inline Eigen::Vector3d terrainBodyVelocityToWorld(
const Eigen::Quaterniond &body_orientation, const Eigen::Vector3d &body_velocity)
{
return body_orientation.normalized() * body_velocity;
}
// A surface vehicle actuates body X/Y. Invert their horizontal projection,
// instead of pretending a pitched body X axis is a horizontal unit vector.
inline bool terrainWorldXYToBodyXY(const Eigen::Quaterniond &body_orientation,
const Eigen::Vector2d &world_xy,
Eigen::Vector2d &body_xy)
{
if (!body_orientation.coeffs().allFinite() || body_orientation.norm() < 1e-6 ||
!world_xy.allFinite()) return false;
const Eigen::Matrix2d horizontal = body_orientation.normalized().toRotationMatrix().topLeftCorner<2,2>();
if (horizontal.determinant() < 0.5) return false; // Tipped or nearly singular.
body_xy = horizontal.inverse() * world_xy;
return body_xy.allFinite();
}
} // namespace scan_planner
@@ -17,6 +17,7 @@
#include <tf2/utils.hpp>
#include "bspline_opt/uniform_bspline.h"
#include "plan_manage/terrain_velocity_utils.h"
namespace scan_planner
{
@@ -63,6 +64,9 @@ public:
require_trajectory_status_ = declare_parameter<bool>("require_trajectory_status", false);
require_perception_ready_ = declare_parameter<bool>("require_perception_ready", false);
require_locked_heading_ = declare_parameter<bool>("require_locked_heading", false);
terrain_motion_ = declare_parameter<bool>("terrain_motion", false);
if (terrain_motion_ && !require_locked_heading_)
throw std::runtime_error("Terrain motion requires locked-heading safety grants");
bspline_sub_ = create_subscription<scan_planner_msgs::msg::Bspline>(
"planning/bspline", 10,
@@ -207,6 +211,12 @@ private:
const double bvx = msg->twist.twist.linear.x;
const double bvy = msg->twist.twist.linear.y;
odom_vel_world_ << c * bvx - s * bvy, s * bvx + c * bvy;
if (terrain_motion_) {
const auto &q = msg->pose.pose.orientation;
odom_orientation_ = Eigen::Quaterniond(q.w,q.x,q.y,q.z).normalized();
odom_vel_world_ = terrainBodyVelocityToWorld(odom_orientation_, Eigen::Vector3d(
bvx, bvy, msg->twist.twist.linear.z)).head<2>();
}
odom_update_ = now();
have_odom_ = true;
}
@@ -330,6 +340,16 @@ private:
geometry_msgs::msg::Twist command;
command.linear.x = std::clamp(c * vel_world.x() + s * vel_world.y(), -max_vx_, max_vx_);
command.linear.y = std::clamp(-s * vel_world.x() + c * vel_world.y(), -max_vy_, max_vy_);
if (terrain_motion_) {
Eigen::Vector2d body_command;
if (!terrainWorldXYToBodyXY(odom_orientation_, vel_world, body_command)) {
publishExecutionFrozen(true);
publishStop();
return;
}
command.linear.x = std::clamp(body_command.x(), -max_vx_, max_vx_);
command.linear.y = std::clamp(body_command.y(), -max_vy_, max_vy_);
}
command.angular.z = yaw_command;
// 到达判定用**到轨迹终点的距离**(上面已算),而不是"到当前参考点的距离 + 时间走完"。
//
@@ -398,6 +418,8 @@ private:
rclcpp::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr goal_sub_;
rclcpp::TimerBase::SharedPtr cmd_timer_;
bool require_locked_heading_{false};
bool terrain_motion_{false};
Eigen::Quaterniond odom_orientation_{Eigen::Quaterniond::Identity()};
rclcpp::Time odom_update_{0, 0, RCL_ROS_TIME};
bool receive_traj_{false};
bool have_odom_{false};
@@ -3,6 +3,8 @@
#include <plan_manage/polyline_trajectory_utils.h>
#include <chrono>
#include <thread>
#include <cmath>
#include <stdexcept>
namespace scan_planner
{
@@ -62,6 +64,9 @@ namespace scan_planner
pp_.feasibility_tolerance_ = get_double("manager.feasibility_tolerance", 0.0);
pp_.ctrl_pt_dist = get_double("manager.control_points_distance", -1.0);
pp_.planning_horizon_ = get_double("manager.planning_horizon", 5.0);
min_replan_distance_ = get_double("manager.min_replan_distance", 0.2);
if (!std::isfinite(min_replan_distance_) || min_replan_distance_ <= 0)
throw std::invalid_argument("manager.min_replan_distance must be finite and positive");
local_data_.traj_id_ = 0;
grid_map_.reset(new GridMap);
@@ -92,7 +97,7 @@ namespace scan_planner
cout << "start: " << start_pt.transpose() << ", " << start_vel.transpose() << "\ngoal:" << local_target_pt.transpose() << ", " << local_target_vel.transpose()
<< endl;
if ((start_pt - local_target_pt).norm() < 0.2)
if ((start_pt - local_target_pt).norm() < min_replan_distance_)
{
cout << "Close to goal" << endl;
continuous_failures_count_++;
@@ -49,6 +49,7 @@ namespace scan_planner
blocked_retry_period_ = load_parameter<double>(node_, "fsm.blocked_retry_period", 0.5);
require_perception_ready_ = load_parameter<bool>(node_, "fsm.require_perception_ready", false);
require_controller_feedback_ = load_parameter<bool>(node_, "fsm.require_controller_feedback", false);
terrain_motion_ = load_parameter<bool>(node_, "fsm.terrain_motion", false);
if (goal_tolerance_ <= 0 || blocked_timeout_ <= 0 || blocked_retry_period_ <= 0)
throw std::runtime_error("goal tolerance and blocked retry/timeout must be positive");
self_inflation_z_up_ = load_parameter<double>(node_, "grid_map.obstacles_inflation_z_up", 0.0);
@@ -81,8 +82,10 @@ namespace scan_planner
planner_manager_.reset(new SCANPlannerManager);
planner_manager_->initPlanModules(node_, visualization_);
if (planner_manager_->grid_map_->usesRectangleFootprint() &&
(navi_mode_ != NAVI_MODE::MANUAL_TARGET || !require_controller_feedback_ || !require_perception_ready_))
throw std::runtime_error("Rectangle mode requires manual goals, controller feedback and perception readiness");
((navi_mode_ != NAVI_MODE::MANUAL_TARGET &&
!(terrain_motion_ && navi_mode_ == NAVI_MODE::REFERENCE_PATH)) ||
!require_controller_feedback_ || !require_perception_ready_))
throw std::runtime_error("Rectangle mode requires manual goals (or explicit terrain reference paths), controller feedback and perception readiness");
/* callback */
exec_timer_ = node_->create_wall_timer(std::chrono::milliseconds(10),
@@ -519,6 +522,11 @@ namespace scan_planner
const double vx = odom_vel_.x(), vy = odom_vel_.y();
odom_vel_.x() = std::cos(yaw)*vx - std::sin(yaw)*vy;
odom_vel_.y() = std::sin(yaw)*vx + std::cos(yaw)*vy;
if (terrain_motion_) {
// Preserve the vertical velocity and pitched body-axis projection.
odom_vel_ = odom_orient_ * Eigen::Vector3d(
msg->twist.twist.linear.x, msg->twist.twist.linear.y, msg->twist.twist.linear.z);
}
if (!have_odom_) {
planner_manager_->grid_map_->setFootprintHeading(getOdomYaw());
publishTrajectoryStatus(scan_planner_msgs::msg::TrajectoryStatus::HOLD, "waiting_for_target");
@@ -0,0 +1,34 @@
#include <gtest/gtest.h>
#include <plan_manage/terrain_velocity_utils.h>
using namespace scan_planner;
TEST(TerrainVelocity, PreservesFullOdometryRotation)
{
const Eigen::Quaterniond q(Eigen::AngleAxisd(0.4,Eigen::Vector3d::UnitZ()) *
Eigen::AngleAxisd(0.17,Eigen::Vector3d::UnitY()) *
Eigen::AngleAxisd(-0.06,Eigen::Vector3d::UnitX()));
const Eigen::Vector3d body(0.3,-0.1,0.02);
const auto world = terrainBodyVelocityToWorld(q,body);
EXPECT_NEAR((q.inverse()*world-body).norm(),0,1e-12);
EXPECT_GT(std::abs(world.z()-body.z()),0.02);
}
TEST(TerrainVelocity, HorizontalCommandSurvivesPitchAndYaw)
{
const Eigen::Quaterniond q(Eigen::AngleAxisd(1.2,Eigen::Vector3d::UnitZ()) *
Eigen::AngleAxisd(0.17,Eigen::Vector3d::UnitY()));
const Eigen::Vector2d wanted(0.2,-0.1);
Eigen::Vector2d command;
ASSERT_TRUE(terrainWorldXYToBodyXY(q,wanted,command));
const Eigen::Vector3d result=q*Eigen::Vector3d(command.x(),command.y(),0);
EXPECT_LT((result.head<2>()-wanted).norm(),1e-12);
}
TEST(TerrainVelocity, RejectsTippingAndInvalidQuaternions)
{
Eigen::Vector2d command;
EXPECT_FALSE(terrainWorldXYToBodyXY(Eigen::Quaterniond(0,0,0,0),{0.2,0},command));
EXPECT_FALSE(terrainWorldXYToBodyXY(Eigen::Quaterniond(
Eigen::AngleAxisd(1.4,Eigen::Vector3d::UnitY())),{0.2,0},command));
}