refactor & optimal

This commit is contained in:
2026-08-14 14:04:47 +07:00
parent 539fc5da16
commit 2a16606c27
18 changed files with 613 additions and 1664 deletions

View File

@@ -16,7 +16,6 @@ set(CMAKE_CXX_EXTENSIONS OFF)
# Find dependencies. Boost is header-only here (boost/dll/alias.hpp exports the
# plugin symbol); no Boost component library is linked.
find_package(Eigen3 REQUIRED)
find_package(Boost REQUIRED)
find_package(yaml-cpp REQUIRED)
# librobot_time.so calls pthread_create but does not export the dependency;
@@ -61,7 +60,7 @@ else()
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS robot_geometry_msgs robot_time data_convert robot_costmap_2d robot_nav_core robot_cpp
DEPENDS Eigen3 Boost
DEPENDS Boost
)
endif()
@@ -72,9 +71,6 @@ add_library(${PROJECT_NAME} SHARED
src/dock_planner.cpp
src/dock_planner_config.cpp
src/dock_calc.cpp
src/utils/curve_common.cpp
src/utils/pose.cpp
src/utils/line_common.cpp
)
target_include_directories(${PROJECT_NAME}
@@ -92,7 +88,7 @@ if(BUILDING_WITH_CATKIN)
target_link_libraries(${PROJECT_NAME}
PUBLIC ${catkin_LIBRARIES} Threads::Threads
PRIVATE Eigen3::Eigen yaml-cpp
PRIVATE yaml-cpp
)
else()
@@ -102,7 +98,6 @@ else()
${STANDALONE_DEP_TARGETS}
Threads::Threads
PRIVATE
Eigen3::Eigen
yaml-cpp
)
@@ -180,6 +175,6 @@ else()
message(STATUS "Project: ${PROJECT_NAME}")
message(STATUS "Version: ${PROJECT_VERSION}")
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
message(STATUS "Dependencies: robot_geometry_msgs, robot_time, data_convert, robot_costmap_2d, robot_nav_core, robot_cpp, Eigen3, Boost (headers), yaml-cpp")
message(STATUS "Dependencies: robot_geometry_msgs, robot_time, data_convert, robot_costmap_2d, robot_nav_core, robot_cpp, Boost (headers), yaml-cpp")
message(STATUS "=================================")
endif()

147
README.md
View File

@@ -1,52 +1,52 @@
# Dock Planner
Global planner tạo đường tiếp cận dock bằng hai đoạn NURBS bậc 2. Phiên bản hiện
tại chỉ tính hình học; chưa kiểm tra collision/free space trên costmap.
Global planner cho docking Ackermann theo một maneuver xác định:
```text
start -- tiến theo cung tròn --> cusp -- lùi thẳng --> goal
```
Planner chỉ sinh hình học. Collision/free-space checking chưa được implement.
## Luồng xử lý
```mermaid
flowchart TD
A["DockPlanner::initialize"] --> B["Kiểm tra costmap và global frame"]
B --> C["Load và validate DockPlannerConfig"]
C --> D["Load footprint_dock nếu có"]
D --> E["DockPlanner::makePlan"]
E --> F["Kiểm tra start/goal cùng global frame"]
F --> G["Lấy robot footprint từ costmap"]
G --> H["DockCalc::makePlanMoveToDock"]
H --> I["Tính trục tiếp cận và angle threshold"]
I --> J["Sinh reference curve NURBS"]
J --> K["Chọn 3 control points cho segment 1"]
K --> L["Sinh segment 1 và segment 2"]
L --> M["Ghép path, bỏ điểm trùng và đóng dấu frame/time"]
```
1. `DockPlanner::initialize()` load và validate config.
2. Lấy `wheel_base` từ TF `front_axle_frame -> rear_axle_frame`, giống
`StanleyControl`.
3. Tính giới hạn động học bicycle:
Mỗi đoạn NURBS dùng đúng 3 control points và bậc 2 với knot vector clamped
`[0, 0, 0, 1, 1, 1]`. Đây là bất biến của thuật toán, không phải tham số
tuning.
```text
minimum_turning_radius = wheel_base / tan(max_steering_angle)
```
## Hợp đồng đầu vào
4. `DockCalc` đổi start sang hệ tọa độ goal: longitudinal dọc trục dock và
lateral vuông góc trục dock.
5. Chọn cusp ở phía trước start, đủ xa dock và đủ xa để cung tiếp cận có bán
kính không nhỏ hơn `minimum_turning_radius`.
6. Lấy mẫu cung tiến. Pose yaw luôn cùng chiều tangent của cung, không dùng yaw
hiện tại của robot.
7. Lấy mẫu đoạn thẳng từ cusp về goal. Pose yaw giữ bằng goal yaw nên controller
phân loại đoạn này là chạy lùi.
8. Ghép hai đoạn, bỏ điểm cusp trùng và đóng dấu frame/time.
- `start` và `goal` phải có pose hữu hạn, quaternion hợp lệ và cùng
`global_frame` của costmap.
- Robot footprint phải có ít nhất 3 điểm, có kích thước X/Y dương. Footprint
được phép lệch tâm so với base_link (ví dụ forklift có càng chìa một phía):
khoảng tiếp cận dùng extent của mép dẫn đầu theo chiều chạy segment cuối
(tiến → mép +x, lùi → mép −x), không dùng nửa bounding box.
- `dock_anchor` (`center` mặc định | `face`) khai goal nằm ở tâm footprint dock
hay ngay trên mặt tiếp cận. `face` thì dock không đóng góp vào khoảng tiếp
cận và `footprint_dock` bị bỏ qua.
- `footprint_dock` là tuỳ chọn, chỉ dùng khi `dock_anchor: center`, toạ độ
trong frame của goal. Nếu không có, planner cảnh báo và coi extent dock bằng
`0 m` khi tính khoảng tiếp cận.
- Pose đầu giữ đúng vị trí start, nhưng orientation lấy theo tangent và chiều
chuyển động của segment đầu; yaw hiện tại của robot không được chèn vào path.
- Mọi segment phải sinh thành công. Nếu có giá trị NaN/Inf, spline suy biến hoặc
segment rỗng, planner trả `false` và không trả partial path.
## Hợp đồng hình học
`footprint_dock` và `dock_anchor` được runtime cập nhật từ
- Goal yaw phải chỉ từ dock ra phía robot tiếp cận. Start phải có longitudinal
dương trong frame goal; planner từ chối start nằm phía sau dock thay vì âm
thầm đảo goal yaw.
- Robot footprint phải có ít nhất ba điểm, hữu hạn, có X/Y extent dương. Đoạn
cuối luôn lùi nên khoảng cách cusp tối thiểu dùng `rear_extent` của robot.
- `dock_anchor: center` cộng near-face `front_extent` của `footprint_dock` vào
khoảng cách cusp. `dock_anchor: face` bỏ qua dock footprint.
- Cung đầu luôn chạy tiến và có `radius >= minimum_turning_radius`.
- Đoạn cuối nằm đúng trên trục dock, chạy lùi và có yaw bằng goal yaw.
- Path có đúng một lần đổi chiều tại cusp.
- Mọi lỗi TF, NaN/Inf, footprint sai, bán kính sai hoặc maneuver vượt giới hạn
đều trả `false`; planner không trả partial path.
`footprint_dock` và `dock_anchor` được move_base2 copy từ
`docking_marker_profiles/<marker>/` vào namespace `DockPlanner` trước khi tạo
plugin; vì vậy file config không khai báo footprint hay anchor cố định.
plugin.
## Tham số cấu hình
@@ -54,55 +54,32 @@ File mặc định: `config/dock_global_params.yaml`.
| Tham số | Mặc định | Đơn vị | Mô tả |
|---|---:|---|---|
| `approach/alignment_distance_padding` | `0.0` | m | Khoảng căn thẳng thêm sau nửa tổng chiều dài robot và dock |
| `approach/lateral_distance_near` | `0.10` | m | Cận dưới của miền nội suy angle threshold |
| `approach/lateral_distance_far` | `1.00` | m | Cận trên của miền nội suy angle threshold |
| `approach/angle_threshold_near` | `2.35619449019` | rad | Ngưỡng góc tại lateral distance gần |
| `approach/angle_threshold_far` | `1.09955742876` | rad | Ngưỡng góc tại lateral distance xa |
| `approach/direction_angle_hysteresis` | `0.05` | rad | Biên trễ khi phân loại hướng nối vào reference path |
| `approach/direction_distance_tolerance` | `0.10` | m | Biên khoảng cách khi loại điểm nối gần cuối reference path |
| `sampling/path_point_spacing` | `0.05` | m | Khoảng cách mục tiêu giữa các pose được lấy mẫu |
| `kinematics/front_axle_frame` | `steer_link` | frame | Frame tâm trục lái |
| `kinematics/rear_axle_frame` | `base_link` | frame | Frame tâm trục sau/reference |
| `kinematics/max_steering_angle` | `0.50` | rad | Góc lái bicycle lớn nhất khi robot đang chạy |
| `maneuver/minimum_forward_distance` | `0.25` | m | Đoạn tiến tối thiểu trước cusp |
| `maneuver/maximum_forward_extension` | `3.0` | m | Độ mở rộng cusp tối đa tính từ start |
| `terminal/reverse_distance_padding` | `0.0` | m | Khoảng lùi thẳng cộng thêm ngoài robot/dock extent |
| `sampling/path_point_spacing` | `0.05` | m | Khoảng cách lấy mẫu mục tiêu |
Quan hệ bắt buộc:
`wheel_base` và `minimum_turning_radius` là giá trị dẫn xuất, không khai trong
YAML để tránh cấu hình mâu thuẫn.
- `0 <= lateral_distance_near < lateral_distance_far`
- `0 < angle_threshold_far < angle_threshold_near < pi`
- `0 <= direction_angle_hysteresis < angle_threshold_far`
- `0 < path_point_spacing <= 1.0`
- Các khoảng cách còn lại phải không âm; tất cả giá trị phải hữu hạn.
Điều kiện bắt buộc:
Angle threshold được nội suy từ giá trị `near` đến `far` theo lateral distance
và clamp ngoài miền cấu hình. Mật độ path được tính theo chiều dài ước lượng của
đường cong, đồng thời luôn giữ hai endpoint.
- Hai axle frame khác nhau và không rỗng.
- `0 < max_steering_angle < pi/2`.
- `0 < minimum_forward_distance <= maximum_forward_extension`.
- `reverse_distance_padding >= 0`.
- `0 < path_point_spacing <= 1.0`.
## Tham số cố ý không tồn tại
`max_steering_angle` phải là góc lái tương đương theo bicycle model, không phải
servo tick hay góc pivot đặc biệt tại vận tốc bằng không. Giá trị mặc định chỉ
là điểm bắt đầu cho APM; phải thay bằng số đo trên robot thật.
## Phạm vi an toàn hiện tại
`check_free_space`, `cost_threshold`, `allow_unknown` và
`calib_safety_distance` không được đọc và không nên khai báo. Collision checker
chưa được implement; giữ các key này sẽ tạo cảm giác an toàn sai. Khi bổ sung
collision checking, cần định nghĩa lại hợp đồng costmap và test riêng trước khi
đưa các tham số này vào config.
## Cấu trúc chính
```text
include/dock_planner/
dock_planner.h Plugin interface
dock_planner_config.h Load, validate và nội suy config
dock_calc.h Core hình học độc lập với plugin
utils/curve_common.h Đánh giá NURBS tối thiểu (setup + CalculateCurvePoint)
src/
dock_planner.cpp
dock_planner_config.cpp
dock_calc.cpp
utils/curve_common.cpp
test/
dock_planner_test.cpp
config/
dock_global_params.yaml
```
`utils/curve_common` chỉ giữ phần đánh giá điểm trên spline mà `DockCalc` dùng
(`curveIsValid`, `ReadSplineInf`, `CalculateCurvePoint`). Các hàm derivative,
curvature và visualization của bản gốc đã bị loại bỏ cùng với code không còn
được gọi.
`calib_safety_distance` không được đọc. Cung tiến có thể quét một vùng lớn phía
trước và bên hông robot; chưa được phép coi path hợp lệ về collision chỉ vì core
hình học trả thành công.

View File

@@ -1,4 +1,4 @@
# DockPlanner plugin and approach-curve parameters.
# DockPlanner: forward curve, one direction change, then reverse straight.
#
# Collision/free-space checking is intentionally not configured here yet:
# DockPlanner currently generates geometry only. Do not add cost_threshold,
@@ -7,42 +7,37 @@ DockPlanner:
# Boost.DLL library containing the exported symbol "DockPlanner".
library_path: libdock_planner
approach:
# [m] Extra straight alignment distance beyond half the combined robot/dock
# X extents. Increase if the robot must align earlier before entering a dock.
alignment_distance_padding: 0.0
kinematics:
# Axle frames used to measure wheel_base from TF, matching StanleyControl.
front_axle_frame: "steer_link"
rear_axle_frame: "base_link"
# [m] Lateral-distance range used to interpolate angle_threshold_*.
# Values outside this range are clamped, so behavior remains bounded.
lateral_distance_near: 0.10
lateral_distance_far: 1.00
# [rad] Maximum equivalent bicycle steering angle while driving the
# approach curve. Measure this on the real robot; this is not a servo tick,
# steering-wheel angle, or the special standstill-pivot angle.
max_steering_angle: 0.50
# [rad] Permitted joining angle at the near/far lateral-distance limits.
# Required relation: 0 < far < near < pi.
angle_threshold_near: 2.35619449019 # 0.75*pi
angle_threshold_far: 1.09955742876 # 0.35*pi
maneuver:
# [m] The cusp is placed at least this far forward from the start. This
# guarantees a real forward leg before the reverse terminal segment.
minimum_forward_distance: 0.25
# [rad] Relaxes the forward direction test relative to the reverse test.
# Required: 0 <= value < angle_threshold_far.
direction_angle_hysteresis: 0.05
# [m] Reject a maneuver that has to extend farther than this from the start
# to satisfy the turning-radius and dock-clearance constraints.
maximum_forward_extension: 3.0
# [m] Distance margin used when rejecting a reference-path joining point
# that is already too close to the end of the approach curve.
direction_distance_tolerance: 0.10
terminal:
# [m] Extra reverse-straight distance beyond the robot rear extent and, for
# dock_anchor=center, the dock near-face extent.
reverse_distance_padding: 0.0
sampling:
# [m] Target spacing between generated path poses. The curve is sampled by
# arc-length estimate and always includes both endpoints.
# [m] Maximum target spacing along both the forward arc and reverse line.
path_point_spacing: 0.05
# footprint_dock and dock_anchor are intentionally not declared here. They
# describe the physical dock, not the robot, and move_base2 copies the values
# selected from docking_marker_profiles/<marker>/ into this namespace before
# constructing the planner.
# footprint_dock and dock_anchor are selected per marker by move_base2 and
# copied into this namespace before the plugin is constructed.
#
# dock_anchor: 'center' (default) — goal is the dock footprint center; the
# near-face extent of footprint_dock is added to the approach distance.
# 'face' — goal already sits on the approach face; footprint_dock is
# ignored entirely.
# With anchor 'center' and footprint_dock absent, dock size contributes 0 m
# and DockPlanner emits a warning.
# near-face extent of footprint_dock contributes to cusp clearance.
# 'face' — goal already sits on the approach face; footprint_dock is ignored.

View File

@@ -1,14 +1,12 @@
#ifndef DOCK_PLANNER_DOCK_CALC_H_
#define DOCK_PLANNER_DOCK_CALC_H_
#include <memory>
#include <mutex>
#include <vector>
#include <robot_geometry_msgs/PoseStamped.h>
#include "dock_planner/dock_planner_config.h"
#include "dock_planner/utils/curve_common.h"
namespace dock_planner
{
@@ -42,53 +40,29 @@ public:
std::vector<robot_geometry_msgs::Pose>& plan);
private:
static constexpr int kNurbsDegree = 2;
std::unique_ptr<Spline_Inf> input_spline_inf_;
std::unique_ptr<CurveCommon> curve_design_;
DockPlannerConfig config_;
std::mutex calculation_mutex_;
static double distance(const robot_geometry_msgs::Pose& first,
const robot_geometry_msgs::Pose& second);
static double angleBetweenPoints(double x1, double y1, double x2, double y2);
static double normalizeAngle(double angle);
static bool isFinitePose(const robot_geometry_msgs::Pose& pose);
static RobotGeometry computeGeometry(const std::vector<robot_geometry_msgs::Point>& footprint);
static robot_geometry_msgs::Pose offsetPoint(const robot_geometry_msgs::Pose& pose,
double yaw, double distance);
static double pointToLineDistance(const robot_geometry_msgs::Pose& point,
const robot_geometry_msgs::Pose& line_start,
const robot_geometry_msgs::Pose& line_end);
static double signedAngle(const robot_geometry_msgs::Pose& first,
const robot_geometry_msgs::Pose& vertex,
const robot_geometry_msgs::Pose& second);
static bool projectionRatio(const robot_geometry_msgs::Pose& point,
const robot_geometry_msgs::Pose& line_start,
const robot_geometry_msgs::Pose& line_end,
double& ratio);
static robot_geometry_msgs::Pose extrapolate(const robot_geometry_msgs::Pose& line_start,
const robot_geometry_msgs::Pose& line_end,
double ratio);
bool setupSpline(const std::vector<robot_geometry_msgs::Pose>& control_points);
double calculateNurbsLength(double sample_step = 0.02);
bool sampleCurve(const std::vector<robot_geometry_msgs::Pose>& control_points,
std::vector<robot_geometry_msgs::Pose>& path,
bool reverse_orientation);
bool sampleTemporaryCurve(const std::vector<robot_geometry_msgs::Pose>& control_points,
std::vector<robot_geometry_msgs::Pose>& path);
bool findNurbsControlPoints(int& direction,
std::vector<robot_geometry_msgs::Pose>& control_points,
const robot_geometry_msgs::Pose& start_pose,
const std::vector<robot_geometry_msgs::Pose>& reference_path,
double angle_threshold);
int findNearestPointOnPath(int& direction, std::size_t& nearest_index,
const robot_geometry_msgs::Pose& pose,
const std::vector<robot_geometry_msgs::Pose>& path,
double angle_threshold) const;
bool sampleForwardApproach(const robot_geometry_msgs::Pose& start,
const robot_geometry_msgs::Pose& goal,
double goal_yaw, double start_longitudinal,
double start_lateral, double minimum_cusp_distance,
double minimum_turning_radius,
std::vector<robot_geometry_msgs::Pose>& path,
double& cusp_distance, double& curve_radius) const;
bool sampleReverseTerminal(const robot_geometry_msgs::Pose& cusp,
const robot_geometry_msgs::Pose& goal,
double goal_yaw,
std::vector<robot_geometry_msgs::Pose>& path) const;
};
} // namespace dock_planner

View File

@@ -33,14 +33,15 @@ enum class DockAnchor
*/
struct DockPlannerConfig
{
double alignment_distance_padding = 0.0; // [m]
double lateral_distance_near = 0.10; // [m]
double lateral_distance_far = 1.00; // [m]
double angle_threshold_near = 2.35619449019; // [rad], 0.75*pi
double angle_threshold_far = 1.09955742876; // [rad], 0.35*pi
double direction_angle_hysteresis = 0.05; // [rad]
double direction_distance_tolerance = 0.10; // [m]
double path_point_spacing = 0.05; // [m]
std::string front_axle_frame = "steer_link";
std::string rear_axle_frame = "base_link";
double max_steering_angle = 0.50; // [rad], equivalent bicycle steering angle
double wheel_base = 0.0; // [m], resolved from axle TF by DockPlanner
double reverse_distance_padding = 0.0; // [m], additional cusp clearance from dock
double minimum_forward_distance = 0.25; // [m], guarantees a forward leg before reversing
double maximum_forward_extension = 3.0; // [m], rejects unexpectedly large maneuvers
double path_point_spacing = 0.05; // [m]
/**
* Per-marker key copied down by move_base2 (like footprint_dock).
@@ -54,8 +55,8 @@ struct DockPlannerConfig
/** Validate values supplied directly by tests or another non-YAML adapter. */
bool validate(std::string& error) const;
/** Interpolate and clamp the approach-angle threshold by lateral distance. */
double angleThreshold(double lateral_distance) const;
/** Radius at the rear-axle reference point for the bicycle model. */
double minimumTurningRadius() const;
};
} // namespace dock_planner

View File

@@ -1,34 +0,0 @@
#ifndef COLOR_H_
#define COLOR_H_
#include <robot_std_msgs/ColorRGBA.h>
namespace agv_visualization
{
class Color : public robot_std_msgs::ColorRGBA
{
public:
Color() : robot_std_msgs::ColorRGBA() {}
Color(double red, double green, double blue) : Color(red, green, blue, 1.0) {}
Color(double red, double green, double blue, double alpha) : Color() {
r = red;
g = green;
b = blue;
a = alpha;
}
static const Color White() { return Color(1.0, 1.0, 1.0); }
static const Color Black() { return Color(0.0, 0.0, 0.0); }
static const Color Gray() { return Color(0.5, 0.5, 0.5); }
static const Color Red() { return Color(1.0, 0.0, 0.0); }
static const Color Green() { return Color(0.0, 1.0, 0.0); }
static const Color Blue() { return Color(0.0, 0.0, 1.0); }
static const Color Yellow() { return Color(1.0, 1.0, 0.0); }
static const Color Orange() { return Color(1.0, 0.5, 0.0); }
static const Color Purple() { return Color(0.5, 0.0, 1.0); }
static const Color Chartreuse() { return Color(0.5, 1.0, 0.0); }
static const Color Teal() { return Color(0.0, 1.0, 1.0); }
static const Color Pink() { return Color(1.0, 0.0, 0.5); }
};
}
#endif //COLOR_H_

View File

@@ -1,472 +0,0 @@
#ifndef _VDA_5050_COMMON_H_INCLUDE_
#define _VDA_5050_COMMON_H_INCLUDE_
#include <iostream>
#include <vector>
namespace vda_5050
{
enum class OrderType
{
Base,
Horizon
};
struct NodePosition
{
double x, y, theta;
double allowedDeviationXY, allowedDeviationTheta;
std::string mapId, mapDescription;
};
struct ActionParameter
{
std::string key;
std::string value;
};
struct Action
{
std::string actionType;
std::string actionId;
std::string actionDescription;
std::string blockingType;
std::vector<ActionParameter> actionParameters;
};
struct Node
{
std::string nodeId;
int sequenceId;
std::string nodeDescription;
bool released;
NodePosition nodePosition;
std::vector<std::shared_ptr<Action>> actions;
};
struct Corridor
{
double leftWidth;
double rightWidth;
std::string corridorRefPoint;
};
struct ControlPoint
{
double x, y, weight;
};
struct Trajectory
{
int degree;
std::vector<double> knotVector;
std::vector<ControlPoint> controlPoints;
};
struct Edge
{
std::string edgeId;
int sequenceId;
std::string edgeDescription;
bool released;
std::string startNodeId;
std::string endNodeId;
double maxSpeed;
double maxHeight;
double minHeight;
double orientation;
std::string orientationType;
std::string direction;
bool rotationAllowed;
double maxRotationSpeed;
Trajectory trajectory;
double length;
Corridor corridor;
std::vector<Action> actions;
};
struct Order
{
int headerId;
std::string timestamp;
std::string version;
std::string manufacturer;
std::string serialNumber;
std::string orderId;
int orderUpdateId;
std::string zoneSetId;
std::vector<Node> nodes;
std::vector<Edge> edges;
OrderType getTypeOrder()
{
for (auto &edge : edges)
{
if (!edge.released)
return OrderType::Horizon;
}
for (auto &node : nodes)
{
if (!node.released)
return OrderType::Horizon;
}
return OrderType::Base;
}
};
struct InstantAction
{
int headerId;
std::string timestamp;
std::string version;
std::string manufacturer;
std::string serialNumber;
std::vector<std::shared_ptr<Action>> actions;
};
struct AGVPosition
{
double x;
double y;
double theta;
std::string mapId;
bool positionInitialized;
double localizationScore;
double deviationRange;
};
struct Velocity
{
double vx;
double vy;
double omega;
};
struct BatteryState
{
double batteryCharge;
double batteryVoltage;
int8_t batteryHealth;
bool charging;
uint32_t reach;
};
struct SafetyState
{
std::string eStop;
bool fieldViolation;
std::string AUTO_ACK = "autoAck";
std::string MANUAL = "manual";
std::string REMOTE = "remote";
std::string NONE = "none";
};
struct ErrorReference
{
std::string referenceKey;
std::string referenceValue;
};
struct Error
{
struct ErrorLevel
{
enum ErrorLevel_EN
{
WARNING,
FATAL
};
operator ErrorLevel_EN() const { return level; }
ErrorLevel &operator=(const ErrorLevel_EN &newType)
{
level = newType;
return *this;
}
private:
ErrorLevel_EN level;
public:
// Function to convert ActionStatus to string
std::string _toString() const
{
switch (level)
{
case WARNING:
return "WARNING";
case FATAL:
return "FATAL";
default:
return "";
}
}
};
std::string errorType;
std::vector<ErrorReference> errorReferences;
std::string errorDescription;
ErrorLevel errorLevel;
};
struct NodeState
{
std::string nodeId;
int32_t sequenceId;
std::string nodeDescription;
NodePosition nodePosition;
bool released;
};
struct EdgeState
{
std::string edgeId;
uint32_t sequenceId;
std::string edgeDescription;
bool released;
Trajectory trajectory;
};
struct ActionState
{
struct ActionStatus
{
public:
enum ActionStatus_EN
{
WAITING,
INITIALIZING,
RUNNING,
PAUSED,
FINISHED,
FAILED
};
operator ActionStatus_EN() const { return type; }
ActionStatus &operator=(const ActionStatus_EN &newType)
{
type = newType;
return *this;
}
bool operator==(const ActionStatus_EN &otherType) const
{
return type == otherType;
}
private:
ActionStatus_EN type;
public:
// Function to convert ActionStatus to string
std::string _toString() const
{
switch (type)
{
case WAITING:
return "WAITING";
case INITIALIZING:
return "INITIALIZING";
case RUNNING:
return "RUNNING";
case PAUSED:
return "PAUSED";
case FINISHED:
return "FINISHED";
case FAILED:
return "FAILED";
default:
return "";
}
}
};
std::string actionId;
std::string actionType;
std::string actionDescription;
ActionStatus actionStatus;
std::string resultDescription;
};
struct InfoReference
{
std::string referenceKey;
std::string referenceValue;
};
struct Info
{
std::string infoType;
std::vector<InfoReference> infoReferences;
std::string infoDescription;
std::string infoLevel;
std::string DEBUG = "DEBUG";
std::string INFO = "INFO";
};
struct BoundingBoxReference
{
double x;
double y;
double z;
double theta;
};
struct LoadDimensions
{
double length;
double width;
double height;
};
struct Load
{
std::string loadId;
std::string loadType;
std::string loadPosition;
BoundingBoxReference boundingBoxReference;
LoadDimensions loadDimensions;
uint32_t weight;
};
struct State
{
struct OperatingMode
{
enum OperatingMode_EN
{
AUTOMATIC,
SEMIAUTOMATIC,
MANUAL,
SERVICE,
TEACHING
};
private:
OperatingMode_EN type;
public:
// Constructor mặc định
OperatingMode() : type(SERVICE) {}
// Toán tử chuyển đổi sang enum
operator OperatingMode_EN() const { return type; }
OperatingMode &operator=(const OperatingMode_EN &newType)
{
type = newType;
return *this;
}
bool operator==(const OperatingMode_EN &otherType) const
{
return type == otherType;
}
// Chuyển đổi sang chuỗi
std::string _toString() const
{
switch (type)
{
case AUTOMATIC:
return "AUTOMATIC";
case SEMIAUTOMATIC:
return "SEMIAUTOMATIC";
case MANUAL:
return "MANUAL";
case SERVICE:
return "SERVICE";
case TEACHING:
return "TEACHING";
default:
return "SERVICE";
}
}
};
State()
{
headerId = 1;
version = "1.0.0";
manufacturer = "Phenikaa-X";
serialNumber = "";
velocity.vx = 0;
velocity.vy = 0;
velocity.omega = 0;
batteryState.batteryCharge = 100;
batteryState.batteryVoltage = 48;
batteryState.batteryHealth = 100;
batteryState.charging = false;
batteryState.reach = 0;
std::vector<Error> errors_;
errors = errors_;
}
uint32_t headerId;
std::string timestamp;
std::string version;
std::string manufacturer;
std::string serialNumber;
std::string orderId;
uint32_t orderUpdateId;
std::string zoneSetId;
std::string lastNodeId;
uint32_t lastNodeSequenceId;
bool driving;
bool paused;
bool newBaseRequest;
double distanceSinceLastNode;
OperatingMode operatingMode;
std::vector<NodeState> nodeStates;
std::vector<EdgeState> edgeStates;
std::vector<std::shared_ptr<vda_5050::ActionState>> actionStates;
AGVPosition agvPosition;
Velocity velocity;
std::vector<Load> loads;
BatteryState batteryState;
std::vector<Error> errors;
std::vector<Info> information;
SafetyState safetyState;
OrderType getTypeOrder()
{
for (auto &edge : edgeStates)
{
if (!edge.released)
return OrderType::Horizon;
}
for (auto &node : nodeStates)
{
if (!node.released)
return OrderType::Horizon;
}
return OrderType::Base;
}
};
struct Visualization
{
Visualization()
{
headerId = 1;
version = "1.0.0";
manufacturer = "Phenikaa-X";
serialNumber = "AMR2WS";
velocity.vx = 0;
velocity.vy = 0;
velocity.omega = 0;
}
uint32_t headerId;
std::string timestamp;
std::string version;
std::string manufacturer;
std::string serialNumber;
AGVPosition agvPosition;
Velocity velocity;
};
}
#endif // _VDA_5050_COMMON_H_INCLUDE_

View File

@@ -1,62 +0,0 @@
#ifndef DOCK_PLANNER_UTILS_CURVE_COMMON_H_
#define DOCK_PLANNER_UTILS_CURVE_COMMON_H_
#include <vector>
#include <Eigen/Eigen>
#include <robot_geometry_msgs/Point.h>
namespace dock_planner
{
/**
* @brief State for evaluating one clamped B-spline/NURBS curve.
*
* N_double_vec is scratch space reused by CalculateCurvePoint; it is not part
* of the curve definition and holds the basis values of the last evaluation.
*/
struct Spline_Inf
{
int order = 0;
std::vector<double> knot_vector;
std::vector<double> weight;
std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>> control_point;
std::vector<double> N_double_vec;
};
/**
* @brief Minimal NURBS evaluation used by DockCalc.
*
* Only curve setup, validity checking, and point evaluation are provided.
* Derivatives, curvature, and visualization helpers were removed together
* with the code paths that used them.
*/
class CurveCommon
{
public:
CurveCommon();
/** Check degree and the knot/control-point count relation. */
bool curveIsValid(int degree, const std::vector<double>& knot_vector,
const std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>>& control_points);
/** Store order, knot vector, and control points into spline_inf. */
void ReadSplineInf(Spline_Inf* spline_inf, int order,
const std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>>& control_point,
const std::vector<double>& knot_vector);
/** Store the NURBS weights; must be called after the control points. */
void ReadSplineInf(Spline_Inf* spline_inf, const std::vector<double>& weight_vector,
bool use_limit_derivative_fitting);
/**
* Evaluate the curve at parameter u_data in [0, 1]. Returns a NaN point on
* invalid input (null/empty spline, non-finite u, degenerate denominator).
*/
robot_geometry_msgs::Point CalculateCurvePoint(Spline_Inf* spline_inf, double u_data,
bool UsingNURBS);
};
} // namespace dock_planner
#endif // DOCK_PLANNER_UTILS_CURVE_COMMON_H_

View File

@@ -1,13 +0,0 @@
#ifndef __LINE_COMMON_H_
#define __LINE_COMMON_H_
#include <cmath>
namespace vda_5050_utils
{
double distanceFromPointToLine(double x0, double y0, double x1, double y1, double x2, double y2);
bool isPointOnSegment(double x0, double y0, double x1, double y1, double x2, double y2, const double tolerance);
}
#endif

View File

@@ -1,66 +0,0 @@
#ifndef AMR_CONTROL_POSE_H
#define AMR_CONTROL_POSE_H
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <vector>
#include <fstream>
#include <math.h>
#include <cmath>
namespace vda_5050
{
class Pose {
private:
double x_, y_, yaw_;
double v_max_, accuracy_;
void modifyYaw(void) {
while (yaw_ < -M_PI)
yaw_ += 2.0 * M_PI;
while (yaw_ > M_PI)
yaw_ -= 2.0 * M_PI;
}
public:
Pose() :
x_(0.0), y_(0.0), yaw_(0.0), v_max_(0.0), accuracy_(0.0) {
};
Pose(double x, double y, double yaw) :
x_(x), y_(y), yaw_(yaw), v_max_(0.0), accuracy_(0.0) {
};
Pose(double x, double y, double yaw, double v_max, double accuracy) :
x_(x), y_(y), yaw_(yaw), v_max_(v_max), accuracy_(accuracy) {
};
~Pose() {};
inline void setX(double x) { x_ = x; }
inline void setY(double y) { y_ = y; }
inline void setYaw(double yaw) { yaw_ = yaw, modifyYaw(); }
inline void setVmax(double v_max) { v_max_ = v_max; }
inline void setAccuracy(double accuracy) { accuracy_ = accuracy; }
inline void setPose(double x, double y, double yaw) { x_ = x, y_ = y, yaw_ = yaw, modifyYaw(); }
inline void setPose(double x, double y, double yaw, double v_max, double accuracy)
{
x_ = x, y_ = y, yaw_ = yaw, v_max_ = v_max, accuracy_ = accuracy, modifyYaw();
}
inline void setPose(Pose p) { x_ = p.x_, y_ = p.y_, yaw_ = p.yaw_, modifyYaw(); }
inline double getX(void) { return x_; }
inline double getY(void) { return y_; }
inline double getYaw(void) { return yaw_; }
inline double getVmax(void) { return v_max_; }
inline double getAccuracy(void) { return accuracy_; }
inline Pose getPose(void) { return Pose(x_, y_, yaw_, v_max_, accuracy_); }
bool SavePoseAsFile(const std::string& file_name);
bool LoadPoseFromFile(const std::string& file_name);
}; // class Pose
}
#endif

View File

@@ -2,7 +2,7 @@
<package format="2">
<name>dock_planner</name>
<version>0.7.11</version>
<description>Global planner that generates a quadratic NURBS approach path for docking.</description>
<description>Global planner that generates an Ackermann forward-curve then reverse-straight docking path.</description>
<maintainer email="xroboticdevs@gmail.com">duongtd</maintainer>
<license>BSD</license>

View File

@@ -31,18 +31,33 @@ void appendUnique(std::vector<robot_geometry_msgs::Pose>& output,
}
}
} // namespace
DockCalc::DockCalc()
: input_spline_inf_(std::make_unique<Spline_Inf>()),
curve_design_(std::make_unique<CurveCommon>())
double positiveAngle(double angle)
{
const double period = 2.0 * kPi;
angle = std::fmod(angle, period);
return angle < 0.0 ? angle + period : angle;
}
robot_geometry_msgs::Pose poseFromDockCoordinates(
const robot_geometry_msgs::Pose& goal, double goal_yaw,
double longitudinal, double lateral, double body_yaw)
{
robot_geometry_msgs::Pose pose;
const double cos_yaw = std::cos(goal_yaw);
const double sin_yaw = std::sin(goal_yaw);
pose.position.x = goal.position.x + longitudinal * cos_yaw - lateral * sin_yaw;
pose.position.y = goal.position.y + longitudinal * sin_yaw + lateral * cos_yaw;
pose.position.z = goal.position.z;
pose.orientation = data_convert::createQuaternionMsgFromYaw(body_yaw);
return pose;
}
} // namespace
DockCalc::DockCalc() = default;
DockCalc::DockCalc(const DockPlannerConfig& config)
: input_spline_inf_(std::make_unique<Spline_Inf>()),
curve_design_(std::make_unique<CurveCommon>()),
config_(config)
: config_(config)
{
}
@@ -61,11 +76,6 @@ double DockCalc::distance(const robot_geometry_msgs::Pose& first,
first.position.y - second.position.y);
}
double DockCalc::angleBetweenPoints(double x1, double y1, double x2, double y2)
{
return std::atan2(y2 - y1, x2 - x1);
}
double DockCalc::normalizeAngle(double angle)
{
return std::remainder(angle, 2.0 * kPi);
@@ -73,10 +83,14 @@ double DockCalc::normalizeAngle(double angle)
bool DockCalc::isFinitePose(const robot_geometry_msgs::Pose& pose)
{
const auto& q = pose.orientation;
const double quaternion_norm = q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
return finitePoint(pose.position) && std::isfinite(q.x) && std::isfinite(q.y) &&
std::isfinite(q.z) && std::isfinite(q.w) && quaternion_norm > kEpsilon;
const auto& quaternion = pose.orientation;
const double quaternion_norm = quaternion.x * quaternion.x +
quaternion.y * quaternion.y +
quaternion.z * quaternion.z +
quaternion.w * quaternion.w;
return finitePoint(pose.position) && std::isfinite(quaternion.x) &&
std::isfinite(quaternion.y) && std::isfinite(quaternion.z) &&
std::isfinite(quaternion.w) && quaternion_norm > kEpsilon;
}
RobotGeometry DockCalc::computeGeometry(
@@ -112,8 +126,8 @@ RobotGeometry DockCalc::computeGeometry(
return geometry;
}
robot_geometry_msgs::Pose DockCalc::offsetPoint(const robot_geometry_msgs::Pose& pose,
double yaw, double offset)
robot_geometry_msgs::Pose DockCalc::offsetPoint(
const robot_geometry_msgs::Pose& pose, double yaw, double offset)
{
robot_geometry_msgs::Pose result = pose;
result.position.x += offset * std::cos(yaw);
@@ -121,173 +135,119 @@ robot_geometry_msgs::Pose DockCalc::offsetPoint(const robot_geometry_msgs::Pose&
return result;
}
double DockCalc::pointToLineDistance(const robot_geometry_msgs::Pose& point,
const robot_geometry_msgs::Pose& line_start,
const robot_geometry_msgs::Pose& line_end)
{
const double line_x = line_end.position.x - line_start.position.x;
const double line_y = line_end.position.y - line_start.position.y;
const double line_length = std::hypot(line_x, line_y);
if (line_length <= kEpsilon)
{
return std::numeric_limits<double>::quiet_NaN();
}
const double point_x = point.position.x - line_start.position.x;
const double point_y = point.position.y - line_start.position.y;
return std::fabs(line_x * point_y - line_y * point_x) / line_length;
}
double DockCalc::signedAngle(const robot_geometry_msgs::Pose& first,
const robot_geometry_msgs::Pose& vertex,
const robot_geometry_msgs::Pose& second)
{
const double first_x = vertex.position.x - first.position.x;
const double first_y = vertex.position.y - first.position.y;
const double second_x = vertex.position.x - second.position.x;
const double second_y = vertex.position.y - second.position.y;
return std::atan2(first_x * second_y - first_y * second_x,
first_x * second_x + first_y * second_y);
}
bool DockCalc::projectionRatio(const robot_geometry_msgs::Pose& point,
const robot_geometry_msgs::Pose& line_start,
const robot_geometry_msgs::Pose& line_end,
double& ratio)
{
const double line_x = line_end.position.x - line_start.position.x;
const double line_y = line_end.position.y - line_start.position.y;
const double denominator = line_x * line_x + line_y * line_y;
if (denominator <= kEpsilon)
{
return false;
}
ratio = ((point.position.x - line_start.position.x) * line_x +
(point.position.y - line_start.position.y) * line_y) /
denominator;
return std::isfinite(ratio);
}
robot_geometry_msgs::Pose DockCalc::extrapolate(
const robot_geometry_msgs::Pose& line_start,
const robot_geometry_msgs::Pose& line_end,
double ratio)
{
robot_geometry_msgs::Pose result = line_start;
result.position.x += ratio * (line_end.position.x - line_start.position.x);
result.position.y += ratio * (line_end.position.y - line_start.position.y);
return result;
}
bool DockCalc::setupSpline(const std::vector<robot_geometry_msgs::Pose>& control_points)
{
if (control_points.size() != static_cast<std::size_t>(kNurbsDegree + 1))
{
robot::log_error("[dock_calc] A quadratic docking curve requires exactly three control points.\n");
return false;
}
std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>> eigen_points;
eigen_points.reserve(control_points.size());
for (const auto& control_point : control_points)
{
if (!finitePoint(control_point.position))
{
robot::log_error("[dock_calc] NURBS control point contains NaN/Inf.\n");
return false;
}
eigen_points.emplace_back(control_point.position.x, control_point.position.y, 0.0);
}
const std::vector<double> knot_vector = {0.0, 0.0, 0.0, 1.0, 1.0, 1.0};
if (!curve_design_->curveIsValid(kNurbsDegree, knot_vector, eigen_points))
{
return false;
}
input_spline_inf_->knot_vector.clear();
input_spline_inf_->control_point.clear();
input_spline_inf_->weight.clear();
curve_design_->ReadSplineInf(input_spline_inf_.get(), kNurbsDegree + 1,
eigen_points, knot_vector);
curve_design_->ReadSplineInf(input_spline_inf_.get(),
std::vector<double>(control_points.size(), 1.0), false);
return input_spline_inf_->weight.size() == control_points.size();
}
double DockCalc::calculateNurbsLength(double sample_step)
{
const int sample_count = std::max(2, static_cast<int>(std::ceil(1.0 / sample_step)));
double length = 0.0;
robot_geometry_msgs::Point previous;
bool have_previous = false;
for (int index = 0; index <= sample_count; ++index)
{
const double parameter = static_cast<double>(index) / sample_count;
const auto current = curve_design_->CalculateCurvePoint(input_spline_inf_.get(),
parameter, true);
if (!finitePoint(current))
{
robot::log_error(
"[dock_calc][diag] NURBS length sampling produced a non-finite point "
"at u=%.12g: point=(%.12g, %.12g, %.12g).\n",
parameter, current.x, current.y, current.z);
return std::numeric_limits<double>::quiet_NaN();
}
if (have_previous)
{
length += std::hypot(current.x - previous.x, current.y - previous.y);
}
previous = current;
have_previous = true;
}
return length;
}
bool DockCalc::sampleCurve(const std::vector<robot_geometry_msgs::Pose>& control_points,
std::vector<robot_geometry_msgs::Pose>& path,
bool reverse_orientation)
bool DockCalc::sampleForwardApproach(
const robot_geometry_msgs::Pose& start,
const robot_geometry_msgs::Pose& goal,
double goal_yaw,
double start_longitudinal,
double start_lateral,
double minimum_cusp_distance,
double minimum_turning_radius,
std::vector<robot_geometry_msgs::Pose>& path,
double& cusp_distance,
double& curve_radius) const
{
path.clear();
if (!setupSpline(control_points))
cusp_distance = std::numeric_limits<double>::quiet_NaN();
curve_radius = std::numeric_limits<double>::infinity();
const double lateral = std::fabs(start_lateral);
double forward_extension = config_.minimum_forward_distance;
// A circle tangent to the dock axis at the cusp and passing through the
// start has R = (dx^2 + lateral^2) / (2*lateral). Select the smallest dx
// that guarantees R >= the Ackermann limit. If lateral >= 2*R_min, the
// lateral offset alone already makes the circle conservative enough.
if (lateral > kEpsilon)
{
return false;
const double radicand = 2.0 * minimum_turning_radius * lateral -
lateral * lateral;
if (radicand > 0.0)
{
forward_extension = std::max(forward_extension, std::sqrt(radicand));
}
}
const double curve_length = calculateNurbsLength();
if (!std::isfinite(curve_length) || curve_length <= kEpsilon)
cusp_distance = std::max(minimum_cusp_distance,
start_longitudinal + forward_extension);
const double actual_extension = cusp_distance - start_longitudinal;
if (!std::isfinite(actual_extension) || actual_extension <= kEpsilon ||
actual_extension > config_.maximum_forward_extension + kEpsilon)
{
robot::log_error(
"[dock_calc][diag] NURBS curve has invalid or zero length: "
"length=%.12g m, epsilon=%.12g m, spacing=%.6f m, "
"cp0=(%.9f, %.9f), cp1=(%.9f, %.9f), cp2=(%.9f, %.9f).\n",
curve_length, kEpsilon, config_.path_point_spacing,
control_points[0].position.x, control_points[0].position.y,
control_points[1].position.x, control_points[1].position.y,
control_points[2].position.x, control_points[2].position.y);
"[dock_calc] Forward cusp extension %.3f m is outside (0, %.3f] m "
"(start_longitudinal=%.3f m, minimum_cusp=%.3f m).\n",
actual_extension, config_.maximum_forward_extension,
start_longitudinal, minimum_cusp_distance);
return false;
}
const robot_geometry_msgs::Pose cusp = offsetPoint(goal, goal_yaw, cusp_distance);
if (lateral <= kEpsilon)
{
const double line_length = distance(start, cusp);
const int sample_count = std::max(
1, static_cast<int>(std::ceil(line_length / config_.path_point_spacing)));
path.reserve(static_cast<std::size_t>(sample_count + 1));
for (int index = 0; index <= sample_count; ++index)
{
const double ratio = static_cast<double>(index) / sample_count;
robot_geometry_msgs::Pose pose;
pose.position.x = start.position.x + ratio * (cusp.position.x - start.position.x);
pose.position.y = start.position.y + ratio * (cusp.position.y - start.position.y);
pose.position.z = start.position.z + ratio * (cusp.position.z - start.position.z);
pose.orientation = data_convert::createQuaternionMsgFromYaw(goal_yaw);
appendUnique(path, pose);
}
return path.size() >= 2;
}
curve_radius = (actual_extension * actual_extension + lateral * lateral) /
(2.0 * lateral);
if (!std::isfinite(curve_radius) ||
curve_radius + 1e-7 < minimum_turning_radius)
{
robot::log_error(
"[dock_calc] Forward arc radius %.6f m violates minimum turning radius %.6f m.\n",
curve_radius, minimum_turning_radius);
return false;
}
const double turn_sign = start_lateral > 0.0 ? 1.0 : -1.0;
const double center_longitudinal = cusp_distance;
const double center_lateral = turn_sign * curve_radius;
const double start_angle = std::atan2(start_lateral - center_lateral,
start_longitudinal - center_longitudinal);
const double end_angle = -turn_sign * kPi / 2.0;
const double angle_delta = turn_sign > 0.0
? positiveAngle(end_angle - start_angle)
: -positiveAngle(start_angle - end_angle);
if (!std::isfinite(angle_delta) || std::fabs(angle_delta) <= kEpsilon ||
std::fabs(angle_delta) > kPi + 1e-7)
{
robot::log_error(
"[dock_calc] Forward arc sweep %.6f rad is invalid; check start side and cusp geometry.\n",
angle_delta);
return false;
}
const double arc_length = curve_radius * std::fabs(angle_delta);
const int sample_count = std::max(
2, static_cast<int>(std::ceil(curve_length / config_.path_point_spacing)));
2, static_cast<int>(std::ceil(arc_length / config_.path_point_spacing)));
path.reserve(static_cast<std::size_t>(sample_count + 1));
for (int index = 0; index <= sample_count; ++index)
{
const double parameter = static_cast<double>(index) / sample_count;
const auto point = curve_design_->CalculateCurvePoint(input_spline_inf_.get(), parameter, true);
if (!finitePoint(point))
{
robot::log_error("[dock_calc] NURBS produced NaN/Inf at u=%f.\n", parameter);
path.clear();
return false;
}
robot_geometry_msgs::Pose pose;
pose.position = point;
pose.orientation = data_convert::createQuaternionMsgFromYaw(0.0);
appendUnique(path, pose);
const double ratio = static_cast<double>(index) / sample_count;
const double angle = start_angle + ratio * angle_delta;
const double longitudinal = center_longitudinal + curve_radius * std::cos(angle);
const double local_lateral = center_lateral + curve_radius * std::sin(angle);
const double tangent_yaw = normalizeAngle(goal_yaw + angle +
turn_sign * kPi / 2.0);
appendUnique(path, poseFromDockCoordinates(goal, goal_yaw,
longitudinal, local_lateral,
tangent_yaw));
}
if (path.size() < 2)
@@ -296,154 +256,39 @@ bool DockCalc::sampleCurve(const std::vector<robot_geometry_msgs::Pose>& control
return false;
}
for (std::size_t index = 0; index + 1 < path.size(); ++index)
{
const auto& current = path[index];
const auto& next = path[index + 1];
const double yaw = reverse_orientation
? angleBetweenPoints(next.position.x, next.position.y,
current.position.x, current.position.y)
: angleBetweenPoints(current.position.x, current.position.y,
next.position.x, next.position.y);
path[index].orientation = data_convert::createQuaternionMsgFromYaw(yaw);
}
path.back().orientation = path[path.size() - 2].orientation;
path.front().position = start.position;
path.back() = cusp;
path.back().orientation = data_convert::createQuaternionMsgFromYaw(goal_yaw);
return true;
}
bool DockCalc::sampleTemporaryCurve(
const std::vector<robot_geometry_msgs::Pose>& control_points,
std::vector<robot_geometry_msgs::Pose>& path)
bool DockCalc::sampleReverseTerminal(
const robot_geometry_msgs::Pose& cusp,
const robot_geometry_msgs::Pose& goal,
double goal_yaw,
std::vector<robot_geometry_msgs::Pose>& path) const
{
return sampleCurve(control_points, path, false);
}
bool DockCalc::findNurbsControlPoints(
int& direction, std::vector<robot_geometry_msgs::Pose>& control_points,
const robot_geometry_msgs::Pose& start_pose,
const std::vector<robot_geometry_msgs::Pose>& reference_path,
double angle_threshold)
{
if (reference_path.empty())
path.clear();
const double terminal_length = distance(cusp, goal);
if (!std::isfinite(terminal_length) || terminal_length <= kEpsilon)
{
return false;
}
std::size_t nearest_index = 0;
const int index = findNearestPointOnPath(direction, nearest_index, start_pose,
reference_path, angle_threshold);
auto poseAt = [](double x, double y)
const int sample_count = std::max(
1, static_cast<int>(std::ceil(terminal_length / config_.path_point_spacing)));
path.reserve(static_cast<std::size_t>(sample_count + 1));
for (int index = 0; index <= sample_count; ++index)
{
const double ratio = static_cast<double>(index) / sample_count;
robot_geometry_msgs::Pose pose;
pose.position.x = x;
pose.position.y = y;
pose.orientation = data_convert::createQuaternionMsgFromYaw(0.0);
return pose;
};
control_points.clear();
if (index >= 0)
{
const std::size_t middle_index = static_cast<std::size_t>(index);
control_points.push_back(start_pose);
control_points.push_back(poseAt(reference_path[middle_index].position.x,
reference_path[middle_index].position.y));
const double target_distance = distance(start_pose, reference_path[middle_index]);
if (direction == 1)
{
std::size_t end_index = middle_index;
for (std::size_t candidate = middle_index;; --candidate)
{
if (distance(reference_path[middle_index], reference_path[candidate]) >= target_distance ||
candidate == 0)
{
end_index = candidate;
break;
}
}
control_points.push_back(poseAt(reference_path[end_index].position.x,
reference_path[end_index].position.y));
}
else if (direction == -1)
{
control_points.push_back(poseAt(reference_path.back().position.x,
reference_path.back().position.y));
}
pose.position.x = cusp.position.x + ratio * (goal.position.x - cusp.position.x);
pose.position.y = cusp.position.y + ratio * (goal.position.y - cusp.position.y);
pose.position.z = cusp.position.z + ratio * (goal.position.z - cusp.position.z);
pose.orientation = data_convert::createQuaternionMsgFromYaw(goal_yaw);
appendUnique(path, pose);
}
if (control_points.size() != 3)
{
const auto& nearest = reference_path[nearest_index];
control_points.clear();
control_points.push_back(start_pose);
control_points.push_back(poseAt((start_pose.position.x + nearest.position.x) / 2.0,
(start_pose.position.y + nearest.position.y) / 2.0));
control_points.push_back(nearest);
direction = 0;
}
return distance(control_points[0], control_points[1]) > kEpsilon &&
distance(control_points[1], control_points[2]) > kEpsilon;
}
int DockCalc::findNearestPointOnPath(
int& direction, std::size_t& nearest_index,
const robot_geometry_msgs::Pose& pose,
const std::vector<robot_geometry_msgs::Pose>& path,
double angle_threshold) const
{
direction = 0;
nearest_index = 0;
if (path.size() < 2)
{
return -1;
}
double min_distance = std::numeric_limits<double>::max();
for (std::size_t index = 0; index < path.size(); ++index)
{
const double candidate = distance(path[index], pose);
if (candidate < min_distance)
{
min_distance = candidate;
nearest_index = index;
}
}
for (std::size_t index = nearest_index; index >= 1; --index)
{
if (std::fabs(signedAngle(pose, path[index], path[index - 1])) >=
std::fabs(angle_threshold))
{
const double pose_distance = distance(pose, path[index]);
const double prefix_distance = distance(path.front(), path[index]);
if (prefix_distance >= pose_distance)
{
direction = 1;
return static_cast<int>(index);
}
break;
}
}
const double forward_threshold = std::max(
0.0, std::fabs(angle_threshold) - config_.direction_angle_hysteresis);
for (std::size_t index = nearest_index; index + 1 < path.size(); ++index)
{
if (std::fabs(signedAngle(pose, path[index], path[index + 1])) >= forward_threshold)
{
const double pose_distance = distance(pose, path[index]);
const double suffix_distance = distance(path[index], path.back());
if (suffix_distance + config_.direction_distance_tolerance < pose_distance)
{
return -1;
}
direction = -1;
return static_cast<int>(index);
}
}
return -1;
return path.size() >= 2;
}
bool DockCalc::makePlanMoveToDock(
@@ -455,6 +300,7 @@ bool DockCalc::makePlanMoveToDock(
{
std::lock_guard<std::mutex> lock(calculation_mutex_);
plan.clear();
std::string config_error;
if (!config_.validate(config_error))
{
@@ -462,6 +308,16 @@ bool DockCalc::makePlanMoveToDock(
config_error.c_str());
return false;
}
const double minimum_turning_radius = config_.minimumTurningRadius();
if (!std::isfinite(minimum_turning_radius) || minimum_turning_radius <= kEpsilon)
{
robot::log_error(
"[dock_calc] Kinematics are unresolved: wheel_base=%.6f m, "
"max_steering_angle=%.6f rad.\n",
config_.wheel_base, config_.max_steering_angle);
return false;
}
if (!isFinitePose(start.pose) || !isFinitePose(goal.pose))
{
robot::log_error("[dock_calc] Start or goal pose contains NaN/Inf or an invalid quaternion.\n");
@@ -469,199 +325,102 @@ bool DockCalc::makePlanMoveToDock(
}
const RobotGeometry robot = computeGeometry(footprint_robot);
if (robot.length <= kEpsilon || robot.width <= kEpsilon)
if (robot.length <= kEpsilon || robot.width <= kEpsilon ||
robot.rear_extent <= kEpsilon)
{
robot::log_error("[dock_calc] Robot footprint is missing or geometrically invalid.\n");
return false;
}
// With dock_anchor == kFace the goal already sits on the approach face, so
// the dock never contributes to the approach distance and footprint_dock
// is ignored entirely.
RobotGeometry dock;
if (config_.dock_anchor == DockAnchor::kCenter && !footprint_dock.empty())
{
dock = computeGeometry(footprint_dock);
if (dock.length <= kEpsilon || dock.width <= kEpsilon)
if (dock.length <= kEpsilon || dock.width <= kEpsilon || dock.front_extent < 0.0)
{
robot::log_error("[dock_calc] Dock footprint is geometrically invalid.\n");
return false;
}
}
// Select the approach side from the goal orientation first: which side the
// start lies on decides the driving direction of the final segment, and
// therefore which robot/dock extents lead. The sign of the projection does
// not depend on the probe length.
double goal_yaw = normalizeAngle(data_convert::getYaw(goal.pose.orientation));
double side_ratio = 0.0;
if (!projectionRatio(start.pose, goal.pose, offsetPoint(goal.pose, goal_yaw, 1.0),
side_ratio))
{
robot::log_error("[dock_calc] Goal orientation is degenerate.\n");
return false;
}
bool goal_side_forward = true;
if (side_ratio < 0.0)
{
goal_yaw = normalizeAngle(goal_yaw + kPi);
goal_side_forward = false;
}
const double goal_yaw = normalizeAngle(data_convert::getYaw(goal.pose.orientation));
const double relative_x = start.pose.position.x - goal.pose.position.x;
const double relative_y = start.pose.position.y - goal.pose.position.y;
const double start_longitudinal = relative_x * std::cos(goal_yaw) +
relative_y * std::sin(goal_yaw);
const double start_lateral = -relative_x * std::sin(goal_yaw) +
relative_y * std::cos(goal_yaw);
// goal_side_forward == true means the final segment is driven backward
// (path orientations reversed in sampleCurve), so the robot's rear edge
// leads; forward approaches lead with the front edge. The dock's near face
// is the one on the approach side of the goal frame.
const double robot_extent = goal_side_forward ? robot.rear_extent : robot.front_extent;
const double dock_extent = goal_side_forward ? dock.front_extent : dock.rear_extent;
const double alignment_distance =
robot_extent + dock_extent + config_.alignment_distance_padding;
if (!std::isfinite(alignment_distance) || alignment_distance <= kEpsilon)
// This planner now has one explicit contract: the goal yaw points from the
// dock toward the approach side, and the terminal leg is always reverse.
// Flipping the axis would silently finish with the opposite robot heading.
if (!std::isfinite(start_longitudinal) || start_longitudinal <= kEpsilon)
{
robot::log_error(
"[dock_calc] Alignment distance is not positive (robot_extent=%.3f m, "
"dock_extent=%.3f m, padding=%.3f m); check footprints and dock_anchor.\n",
robot_extent, dock_extent, config_.alignment_distance_padding);
"[dock_calc] Start is not on the reverse-docking side of the goal "
"(longitudinal=%.6f m in goal frame).\n",
start_longitudinal);
return false;
}
const robot_geometry_msgs::Pose alignment_pose =
offsetPoint(goal.pose, goal_yaw, alignment_distance);
double projection_ratio = 0.0;
if (!projectionRatio(start.pose, goal.pose, alignment_pose, projection_ratio))
{
robot::log_error("[dock_calc] Goal and alignment pose are degenerate.\n");
return false;
}
if (projection_ratio <= 1.0)
{
robot::log_error("[dock_calc] Start is too close to the dock axis (projection=%f).\n",
projection_ratio);
return false;
}
const auto projected_pose = extrapolate(goal.pose, alignment_pose, projection_ratio);
const double lateral_distance = pointToLineDistance(start.pose, goal.pose, alignment_pose);
const double angle_threshold = config_.angleThreshold(lateral_distance);
if (!std::isfinite(lateral_distance) || !std::isfinite(angle_threshold))
{
return false;
}
const double half_complement = (kPi - angle_threshold) / 2.0;
const double tangent = std::tan(half_complement);
if (!std::isfinite(tangent) || std::fabs(tangent) <= kEpsilon)
{
return false;
}
const double projected_distance = distance(alignment_pose, projected_pose);
const double lateral_extension = lateral_distance / tangent;
const double reference_distance = alignment_distance + projected_distance + lateral_extension;
if (!std::isfinite(reference_distance))
{
return false;
}
const auto reference_end = offsetPoint(goal.pose, goal_yaw, reference_distance);
robot_geometry_msgs::Pose reference_mid = alignment_pose;
reference_mid.position.x = (alignment_pose.position.x + reference_end.position.x) / 2.0;
reference_mid.position.y = (alignment_pose.position.y + reference_end.position.y) / 2.0;
std::vector<robot_geometry_msgs::Pose> reference_path;
if (!sampleTemporaryCurve({alignment_pose, reference_mid, reference_end}, reference_path))
const double dock_extent = config_.dock_anchor == DockAnchor::kCenter
? dock.front_extent : 0.0;
const double minimum_cusp_distance = robot.rear_extent + dock_extent +
config_.reverse_distance_padding;
if (!std::isfinite(minimum_cusp_distance) || minimum_cusp_distance <= kEpsilon)
{
robot::log_error(
"[dock_calc][diag] Failed to generate approach reference curve: "
"start=(%.9f, %.9f, yaw=%.9f), goal=(%.9f, %.9f, yaw=%.9f), "
"robot=(front=%.3f m, rear=%.3f m, width=%.3f m), "
"dock=(front=%.3f m, rear=%.3f m, anchor=%s), padding=%.6f m, "
"alignment_distance=%.9f m, alignment=(%.9f, %.9f), "
"projection_ratio=%.12g, goal_side=%s, projected=(%.9f, %.9f), "
"projected_distance=%.12g m, lateral_distance=%.12g m, "
"angle_threshold=%.12g rad, lateral_extension=%.12g m, "
"reference_distance=%.12g m, reference_end=(%.9f, %.9f).\n",
start.pose.position.x, start.pose.position.y,
data_convert::getYaw(start.pose.orientation),
goal.pose.position.x, goal.pose.position.y,
data_convert::getYaw(goal.pose.orientation),
robot.front_extent, robot.rear_extent, robot.width,
dock.front_extent, dock.rear_extent,
config_.dock_anchor == DockAnchor::kFace ? "face" : "center",
config_.alignment_distance_padding, alignment_distance,
alignment_pose.position.x, alignment_pose.position.y,
projection_ratio, goal_side_forward ? "forward" : "backward",
projected_pose.position.x, projected_pose.position.y,
projected_distance, lateral_distance, angle_threshold,
lateral_extension, reference_distance,
reference_end.position.x, reference_end.position.y);
"[dock_calc] Minimum cusp distance is invalid (rear=%.3f m, dock=%.3f m, "
"padding=%.3f m).\n",
robot.rear_extent, dock_extent, config_.reverse_distance_padding);
return false;
}
int direction = 0;
std::vector<robot_geometry_msgs::Pose> first_control_points;
if (!findNurbsControlPoints(direction, first_control_points, start.pose,
reference_path, angle_threshold))
std::vector<robot_geometry_msgs::Pose> forward_segment;
double cusp_distance = 0.0;
double curve_radius = 0.0;
if (!sampleForwardApproach(start.pose, goal.pose, goal_yaw,
start_longitudinal, start_lateral,
minimum_cusp_distance, minimum_turning_radius,
forward_segment, cusp_distance, curve_radius))
{
robot::log_error("[dock_calc] Failed to select first-segment control points.\n");
robot::log_error("[dock_calc] Failed to generate the forward approach segment.\n");
return false;
}
const bool first_reverse_orientation =
(direction == -1 && !goal_side_forward) ||
((direction == 1 || direction == 0) && goal_side_forward);
std::vector<robot_geometry_msgs::Pose> first_segment;
if (!sampleCurve(first_control_points, first_segment, first_reverse_orientation))
std::vector<robot_geometry_msgs::Pose> reverse_segment;
if (!sampleReverseTerminal(forward_segment.back(), goal.pose, goal_yaw,
reverse_segment))
{
robot::log_error("[dock_calc] Failed to generate the reverse terminal segment.\n");
return false;
}
robot_geometry_msgs::Pose second_mid = first_segment.back();
second_mid.position.x = (first_segment.back().position.x + goal.pose.position.x) / 2.0;
second_mid.position.y = (first_segment.back().position.y + goal.pose.position.y) / 2.0;
std::vector<robot_geometry_msgs::Pose> second_segment;
if (!sampleCurve({first_segment.back(), second_mid, goal.pose}, second_segment,
goal_side_forward))
{
robot::log_error("[dock_calc] Failed to generate the final docking segment.\n");
return false;
}
plan.reserve(1 + first_segment.size() + second_segment.size());
appendUnique(plan, start.pose);
for (const auto& pose : first_segment)
plan.reserve(forward_segment.size() + reverse_segment.size());
for (const auto& pose : forward_segment)
{
appendUnique(plan, pose);
}
for (const auto& pose : second_segment)
for (const auto& pose : reverse_segment)
{
appendUnique(plan, pose);
}
if (distance(plan.back(), goal.pose) <= kEpsilon)
{
plan.back() = goal.pose;
}
else
{
plan.push_back(goal.pose);
}
if (plan.size() < 2)
if (plan.size() < 3)
{
plan.clear();
return false;
}
plan.front().position = start.pose.position;
plan.back() = goal.pose;
// Preserve the exact requested start position, but use the generated
// segment orientation. Keeping start.pose.orientation here would inject
// the robot's current yaw into the path and could make the controller
// classify the first segment with the wrong driving direction.
plan.front().orientation = first_segment.front().orientation;
robot::log_info("[dock_calc] Generated docking path with %zu unique poses.\n", plan.size());
robot::log_info(
"[dock_calc] Generated forward-then-reverse path: poses=%zu, "
"wheel_base=%.4f m, max_steer=%.4f rad, min_radius=%.4f m, "
"start=(long=%.3f m, lateral=%.3f m), cusp=%.3f m, arc_radius=%.4f m.\n",
plan.size(), config_.wheel_base, config_.max_steering_angle,
minimum_turning_radius, start_longitudinal, start_lateral,
cusp_distance, curve_radius);
return true;
}

View File

@@ -133,6 +133,47 @@ bool DockPlanner::initialize(std::string name,
return false;
}
try
{
// Match StanleyControl's axle-TF contract: lookup the front axle in
// the rear-axle frame, then use the planar translation norm.
const tf3::TransformStampedMsg axle_transform =
costmap_robot->getTfBuffer().lookupTransform(
loaded_config.rear_axle_frame,
loaded_config.front_axle_frame,
tf3::Time());
loaded_config.wheel_base = std::hypot(
axle_transform.transform.translation.x,
axle_transform.transform.translation.y);
}
catch (const tf3::TransformException& exception)
{
robot::log_error(
"[dock_planner] Cannot resolve wheel base from TF %s -> %s: %s.\n",
loaded_config.front_axle_frame.c_str(),
loaded_config.rear_axle_frame.c_str(), exception.what());
return false;
}
if (!std::isfinite(loaded_config.wheel_base) || loaded_config.wheel_base <= 0.0)
{
robot::log_error(
"[dock_planner] Wheel base resolved to %.6f m from TF %s -> %s.\n",
loaded_config.wheel_base, loaded_config.front_axle_frame.c_str(),
loaded_config.rear_axle_frame.c_str());
return false;
}
const double minimum_turning_radius = loaded_config.minimumTurningRadius();
if (!std::isfinite(minimum_turning_radius) || minimum_turning_radius <= 0.0)
{
robot::log_error(
"[dock_planner] Cannot derive minimum turning radius from wheel_base=%.6f m "
"and max_steering_angle=%.6f rad.\n",
loaded_config.wheel_base, loaded_config.max_steering_angle);
return false;
}
std::vector<robot_geometry_msgs::Point> loaded_footprint;
if (loaded_config.dock_anchor == DockAnchor::kFace)
{
@@ -164,6 +205,13 @@ bool DockPlanner::initialize(std::string name,
footprint_dock_ = std::move(loaded_footprint);
dock_calc_.setConfig(loaded_config);
initialized_ = true;
robot::log_info(
"[dock_planner] Initialized forward-then-reverse maneuver: TF %s -> %s, "
"wheel_base=%.4f m, max_steering_angle=%.4f rad, minimum_turning_radius=%.4f m.\n",
loaded_config.front_axle_frame.c_str(), loaded_config.rear_axle_frame.c_str(),
loaded_config.wheel_base, loaded_config.max_steering_angle,
minimum_turning_radius);
return true;
}

View File

@@ -1,7 +1,7 @@
#include "dock_planner/dock_planner_config.h"
#include <algorithm>
#include <cmath>
#include <limits>
namespace dock_planner
{
@@ -26,6 +26,24 @@ bool readOptionalDouble(const robot::NodeHandle& nh, const std::string& key,
return true;
}
bool readOptionalString(const robot::NodeHandle& nh, const std::string& key,
std::string& value, std::string& error)
{
if (!nh.hasParam(key))
{
return true;
}
std::string parsed;
if (!nh.getParam(key, parsed, std::string()))
{
error = "parameter '" + key + "' must be a string";
return false;
}
value = parsed;
return true;
}
bool readDockAnchor(const robot::NodeHandle& nh, DockAnchor& anchor, std::string& error)
{
if (!nh.hasParam("dock_anchor"))
@@ -69,20 +87,18 @@ bool DockPlannerConfig::load(const robot::NodeHandle& nh, DockPlannerConfig& con
std::string& error)
{
DockPlannerConfig loaded;
if (!readOptionalDouble(nh, "approach/alignment_distance_padding",
loaded.alignment_distance_padding, error) ||
!readOptionalDouble(nh, "approach/lateral_distance_near",
loaded.lateral_distance_near, error) ||
!readOptionalDouble(nh, "approach/lateral_distance_far",
loaded.lateral_distance_far, error) ||
!readOptionalDouble(nh, "approach/angle_threshold_near",
loaded.angle_threshold_near, error) ||
!readOptionalDouble(nh, "approach/angle_threshold_far",
loaded.angle_threshold_far, error) ||
!readOptionalDouble(nh, "approach/direction_angle_hysteresis",
loaded.direction_angle_hysteresis, error) ||
!readOptionalDouble(nh, "approach/direction_distance_tolerance",
loaded.direction_distance_tolerance, error) ||
if (!readOptionalString(nh, "kinematics/front_axle_frame",
loaded.front_axle_frame, error) ||
!readOptionalString(nh, "kinematics/rear_axle_frame",
loaded.rear_axle_frame, error) ||
!readOptionalDouble(nh, "kinematics/max_steering_angle",
loaded.max_steering_angle, error) ||
!readOptionalDouble(nh, "terminal/reverse_distance_padding",
loaded.reverse_distance_padding, error) ||
!readOptionalDouble(nh, "maneuver/minimum_forward_distance",
loaded.minimum_forward_distance, error) ||
!readOptionalDouble(nh, "maneuver/maximum_forward_extension",
loaded.maximum_forward_extension, error) ||
!readOptionalDouble(nh, "sampling/path_point_spacing",
loaded.path_point_spacing, error))
{
@@ -111,13 +127,11 @@ bool DockPlannerConfig::validate(std::string& error) const
const char* name;
double value;
} values[] = {
{"approach/alignment_distance_padding", alignment_distance_padding},
{"approach/lateral_distance_near", lateral_distance_near},
{"approach/lateral_distance_far", lateral_distance_far},
{"approach/angle_threshold_near", angle_threshold_near},
{"approach/angle_threshold_far", angle_threshold_far},
{"approach/direction_angle_hysteresis", direction_angle_hysteresis},
{"approach/direction_distance_tolerance", direction_distance_tolerance},
{"kinematics/max_steering_angle", max_steering_angle},
{"kinematics/wheel_base", wheel_base},
{"terminal/reverse_distance_padding", reverse_distance_padding},
{"maneuver/minimum_forward_distance", minimum_forward_distance},
{"maneuver/maximum_forward_extension", maximum_forward_extension},
{"sampling/path_point_spacing", path_point_spacing},
};
@@ -129,31 +143,39 @@ bool DockPlannerConfig::validate(std::string& error) const
}
}
if (alignment_distance_padding < 0.0)
if (front_axle_frame.empty() || rear_axle_frame.empty())
{
error = "parameter 'approach/alignment_distance_padding' must be >= 0 m";
error = "kinematics axle frame names must not be empty";
return false;
}
if (lateral_distance_near < 0.0 || lateral_distance_far <= lateral_distance_near)
if (front_axle_frame == rear_axle_frame)
{
error = "approach lateral distances must satisfy 0 <= near < far";
error = "kinematics front_axle_frame and rear_axle_frame must be different";
return false;
}
if (angle_threshold_far <= 0.0 || angle_threshold_near >= kPi ||
angle_threshold_near <= angle_threshold_far)
if (max_steering_angle <= 0.0 || max_steering_angle >= kPi / 2.0)
{
error = "approach angle thresholds must satisfy 0 < far < near < pi";
error = "parameter 'kinematics/max_steering_angle' must be in (0, pi/2) rad";
return false;
}
if (direction_angle_hysteresis < 0.0 ||
direction_angle_hysteresis >= angle_threshold_far)
if (wheel_base < 0.0)
{
error = "parameter 'approach/direction_angle_hysteresis' must be >= 0 and smaller than angle_threshold_far";
error = "resolved kinematics wheel_base must be >= 0 m";
return false;
}
if (direction_distance_tolerance < 0.0)
if (reverse_distance_padding < 0.0)
{
error = "parameter 'approach/direction_distance_tolerance' must be >= 0 m";
error = "parameter 'terminal/reverse_distance_padding' must be >= 0 m";
return false;
}
if (minimum_forward_distance <= 0.0)
{
error = "parameter 'maneuver/minimum_forward_distance' must be > 0 m";
return false;
}
if (maximum_forward_extension < minimum_forward_distance)
{
error = "maneuver maximum_forward_extension must be >= minimum_forward_distance";
return false;
}
if (path_point_spacing <= 0.0 || path_point_spacing > 1.0)
@@ -166,13 +188,14 @@ bool DockPlannerConfig::validate(std::string& error) const
return true;
}
double DockPlannerConfig::angleThreshold(double lateral_distance) const
double DockPlannerConfig::minimumTurningRadius() const
{
const double clamped = std::clamp(lateral_distance, lateral_distance_near,
lateral_distance_far);
const double ratio = (clamped - lateral_distance_near) /
(lateral_distance_far - lateral_distance_near);
return angle_threshold_near + ratio * (angle_threshold_far - angle_threshold_near);
if (!(wheel_base > 0.0) || !(max_steering_angle > 0.0) ||
!(max_steering_angle < kPi / 2.0))
{
return std::numeric_limits<double>::quiet_NaN();
}
return wheel_base / std::tan(max_steering_angle);
}
} // namespace dock_planner

View File

@@ -1,186 +0,0 @@
#include "dock_planner/utils/curve_common.h"
#include <cmath>
#include <limits>
#include <robot/robot.h>
namespace dock_planner
{
CurveCommon::CurveCommon()
{
}
bool CurveCommon::curveIsValid(int degree, const std::vector<double>& knot_vector,
const std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>>& control_points)
{
if (degree < 1 || degree > 9)
{
robot::log_warning("degree is invalid value");
return false;
}
if (!((knot_vector.size() - degree - 1) == control_points.size()))
{
robot::log_warning("relation between degree, number of knots, and number of control points is invalid");
return false;
}
return true;
}
void CurveCommon::ReadSplineInf(Spline_Inf* spline_inf, int order,
const std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>>& control_point,
const std::vector<double>& knot_vector)
{
spline_inf->order = order;
spline_inf->knot_vector.assign(knot_vector.begin(), knot_vector.end());
spline_inf->control_point.assign(control_point.begin(), control_point.end());
}
void CurveCommon::ReadSplineInf(Spline_Inf* spline_inf, const std::vector<double>& weight_vector,
bool use_limit_derivative_fitting)
{
if (!use_limit_derivative_fitting)
{
if (spline_inf->control_point.size() != weight_vector.size())
{
robot::log_error("[curve_common] weight vector size (%zu) does not match control point count (%zu).\n",
weight_vector.size(), spline_inf->control_point.size());
return;
}
spline_inf->weight.assign(weight_vector.begin(), weight_vector.end());
return;
}
std::vector<double> padded_weight(weight_vector);
padded_weight.push_back(1.0);
padded_weight.push_back(1.0);
spline_inf->weight.assign(padded_weight.begin(), padded_weight.end());
}
robot_geometry_msgs::Point CurveCommon::CalculateCurvePoint(Spline_Inf* spline_inf, double u_data, bool UsingNURBS)
{
robot_geometry_msgs::Point curve_point;
if (spline_inf == nullptr || spline_inf->control_point.empty() || !std::isfinite(u_data))
{
curve_point.x = std::numeric_limits<double>::quiet_NaN();
curve_point.y = std::numeric_limits<double>::quiet_NaN();
return curve_point;
}
// A clamped spline evaluates exactly to its boundary control points. Handling
// the boundaries explicitly also avoids the zero NURBS denominator at u=1.
if (u_data <= 0.0)
{
curve_point.x = spline_inf->control_point.front()(0);
curve_point.y = spline_inf->control_point.front()(1);
return curve_point;
}
if (u_data >= 1.0)
{
curve_point.x = spline_inf->control_point.back()(0);
curve_point.y = spline_inf->control_point.back()(1);
return curve_point;
}
int p_degree = spline_inf->order - 1;
int m = spline_inf->knot_vector.size() - 1; // The last knot vector index number
double left_denom = 0, right_denom = 0;
double left_term = 0, right_term = 0;
std::vector<double> temp_basic_function;
double degree_basis_value;
double sum_nurbs_denom = 0;
double sum_x = 0, sum_y = 0;
// Calculate degree = 0's basic function
spline_inf->N_double_vec.clear();
spline_inf->N_double_vec.resize(m);
for (int i = 0; i < m; i++)
{
if (spline_inf->knot_vector.at(i) != spline_inf->knot_vector.at(i + 1))
{
if (spline_inf->knot_vector.at(i) <= u_data && u_data < spline_inf->knot_vector.at(i + 1))
degree_basis_value = 1;
else
degree_basis_value = 0;
}
else
{
if (spline_inf->knot_vector.at(i) <= u_data && u_data <= spline_inf->knot_vector.at(i + 1))
degree_basis_value = 1;
else
degree_basis_value = 0;
}
spline_inf->N_double_vec.at(i) = degree_basis_value;
}
// Calculate the rest of basic function
for (int p = 1; p <= p_degree; p++)
{
temp_basic_function.clear();
for (int i = 0; i < (m - p); i++)
{
left_denom = spline_inf->knot_vector.at(p + i) - spline_inf->knot_vector.at(i);
right_denom = spline_inf->knot_vector.at(i + p + 1) - spline_inf->knot_vector.at(i + 1);
if (left_denom == 0)
{
left_term = 0;
}
else
{
left_term = (u_data - spline_inf->knot_vector.at(i)) * spline_inf->N_double_vec.at(i) / left_denom;
}
if (right_denom == 0)
{
right_term = 0;
}
else
{
right_term = (spline_inf->knot_vector.at(i + p + 1) - u_data) * spline_inf->N_double_vec.at(i + 1) / right_denom;
}
temp_basic_function.push_back(left_term + right_term); // Calculate Ni,p
}
spline_inf->N_double_vec.assign(temp_basic_function.begin(), temp_basic_function.end());
}
if (!UsingNURBS)
{
for (std::size_t i = 0; i < spline_inf->N_double_vec.size(); i++)
{
sum_x += spline_inf->control_point.at(i)(0) * spline_inf->N_double_vec.at(i);
sum_y += spline_inf->control_point.at(i)(1) * spline_inf->N_double_vec.at(i);
}
curve_point.x = sum_x;
curve_point.y = sum_y;
return curve_point;
}
if (spline_inf->weight.empty())
{
robot::log_error("[curve_common] weight vector is empty; call ReadSplineInf with weights first.\n");
curve_point.x = std::numeric_limits<double>::quiet_NaN();
curve_point.y = std::numeric_limits<double>::quiet_NaN();
return curve_point;
}
for (std::size_t i = 0; i < spline_inf->N_double_vec.size(); i++)
{
sum_nurbs_denom += spline_inf->N_double_vec.at(i) * spline_inf->weight.at(i);
sum_x += spline_inf->control_point.at(i)(0) * spline_inf->N_double_vec.at(i) * spline_inf->weight.at(i);
sum_y += spline_inf->control_point.at(i)(1) * spline_inf->N_double_vec.at(i) * spline_inf->weight.at(i);
}
if (!std::isfinite(sum_nurbs_denom) || std::fabs(sum_nurbs_denom) <= 1e-12)
{
curve_point.x = std::numeric_limits<double>::quiet_NaN();
curve_point.y = std::numeric_limits<double>::quiet_NaN();
return curve_point;
}
curve_point.x = sum_x / sum_nurbs_denom;
curve_point.y = sum_y / sum_nurbs_denom;
return curve_point;
}
} // namespace dock_planner

View File

@@ -1,26 +0,0 @@
#include "dock_planner/utils/line_common.h"
double vda_5050_utils::distanceFromPointToLine(double x0, double y0, double x1, double y1, double x2, double y2)
{
double A = y2 - y1;
double B = -(x2 - x1);
double C = -A * x1 - B * y1;
return fabs(A * x0 + B * y0 + C) / sqrt(A * A + B * B);
}
bool vda_5050_utils::isPointOnSegment(double x0, double y0, double x1, double y1, double x2, double y2, const double tolerance)
{
double crossProduct = distanceFromPointToLine(x0, y0, x1, y1, x2, y2);
if (fabs(crossProduct) > fabs(tolerance))
return false;
// Kiểm tra tọa độ của P có nằm giữa A và B không
if (x0 >= std::min(x1, x2) && x0 <= std::max(x1, x2) &&
y0 >= std::min(y1, y2) && y0 <= std::max(y1, y2))
{
return true;
}
return false;
}

View File

@@ -1,39 +0,0 @@
#include "dock_planner/utils/pose.h"
bool vda_5050::Pose::SavePoseAsFile(const std::string& file_name)
{
bool result = false;
std::ofstream file(file_name);
if (file.is_open())
{
file << x_ << " " << y_ << " " << yaw_ << "\n";
file.close();
result = true;
}
else
{
result = false;
}
return result;
}
bool vda_5050::Pose::LoadPoseFromFile(const std::string& file_name)
{
bool result = false;
std::ifstream file(file_name);
if (file.is_open())
{
double x, y, yaw;
file >> x >> y >> yaw;
setPose(x, y, yaw);
file.close();
result = true;
}
else
{
result = false;
}
return result;
}

View File

@@ -1,3 +1,4 @@
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
@@ -12,6 +13,7 @@
namespace
{
constexpr double kPi = 3.14159265358979323846;
int failures = 0;
void check(bool condition, const char* expression, int line)
@@ -43,26 +45,121 @@ robot_geometry_msgs::PoseStamped pose(double x, double y, double yaw)
return result;
}
bool near(double first, double second, double tolerance = 1e-9)
bool near(double first, double second, double tolerance = 1e-8)
{
return std::fabs(first - second) <= tolerance;
}
double normalizeAngle(double angle)
{
return std::remainder(angle, 2.0 * 3.14159265358979323846);
return std::remainder(angle, 2.0 * kPi);
}
void checkGeneratedPath(dock_planner::DockCalc& calculator,
const robot_geometry_msgs::PoseStamped& start,
const robot_geometry_msgs::PoseStamped& goal,
const std::vector<robot_geometry_msgs::Point>& robot_footprint,
const std::vector<robot_geometry_msgs::Point>& dock_footprint)
double longitudinal(const robot_geometry_msgs::Pose& value,
const robot_geometry_msgs::Pose& goal)
{
const double yaw = data_convert::getYaw(goal.orientation);
const double dx = value.position.x - goal.position.x;
const double dy = value.position.y - goal.position.y;
return dx * std::cos(yaw) + dy * std::sin(yaw);
}
double lateral(const robot_geometry_msgs::Pose& value,
const robot_geometry_msgs::Pose& goal)
{
const double yaw = data_convert::getYaw(goal.orientation);
const double dx = value.position.x - goal.position.x;
const double dy = value.position.y - goal.position.y;
return -dx * std::sin(yaw) + dy * std::cos(yaw);
}
bool edgeIsForward(const robot_geometry_msgs::Pose& first,
const robot_geometry_msgs::Pose& second)
{
const double motion_yaw = std::atan2(second.position.y - first.position.y,
second.position.x - first.position.x);
const double body_yaw = data_convert::getYaw(first.orientation);
return std::cos(normalizeAngle(motion_yaw - body_yaw)) > 0.0;
}
double threePointCurvature(const robot_geometry_msgs::Pose& first,
const robot_geometry_msgs::Pose& middle,
const robot_geometry_msgs::Pose& last)
{
const double ab = std::hypot(middle.position.x - first.position.x,
middle.position.y - first.position.y);
const double bc = std::hypot(last.position.x - middle.position.x,
last.position.y - middle.position.y);
const double ac = std::hypot(last.position.x - first.position.x,
last.position.y - first.position.y);
if (ab <= 1e-12 || bc <= 1e-12 || ac <= 1e-12)
{
return 0.0;
}
const double twice_area = std::fabs(
(middle.position.x - first.position.x) * (last.position.y - first.position.y) -
(middle.position.y - first.position.y) * (last.position.x - first.position.x));
return 2.0 * twice_area / (ab * bc * ac);
}
std::size_t checkForwardThenReverse(
const std::vector<robot_geometry_msgs::Pose>& path,
const robot_geometry_msgs::Pose& goal,
double maximum_curvature)
{
CHECK(path.size() > 3);
std::size_t cusp_index = path.size();
int direction_changes = 0;
bool previous_forward = edgeIsForward(path[0], path[1]);
CHECK(previous_forward);
for (std::size_t index = 1; index + 1 < path.size(); ++index)
{
const bool current_forward = edgeIsForward(path[index], path[index + 1]);
if (current_forward != previous_forward)
{
++direction_changes;
cusp_index = index;
}
previous_forward = current_forward;
}
CHECK(direction_changes == 1);
CHECK(cusp_index > 0);
CHECK(cusp_index + 1 < path.size());
for (std::size_t index = 0; index < cusp_index; ++index)
{
CHECK(edgeIsForward(path[index], path[index + 1]));
}
for (std::size_t index = cusp_index; index + 1 < path.size(); ++index)
{
CHECK(!edgeIsForward(path[index], path[index + 1]));
CHECK(std::fabs(lateral(path[index], goal)) < 1e-7);
CHECK(std::fabs(normalizeAngle(
data_convert::getYaw(path[index].orientation) -
data_convert::getYaw(goal.orientation))) < 1e-7);
}
for (std::size_t index = 1; index < cusp_index; ++index)
{
CHECK(threePointCurvature(path[index - 1], path[index], path[index + 1]) <=
maximum_curvature + 1e-5);
}
return cusp_index;
}
std::vector<robot_geometry_msgs::Pose> generatePath(
dock_planner::DockCalc& calculator,
const robot_geometry_msgs::PoseStamped& start,
const robot_geometry_msgs::PoseStamped& goal,
const std::vector<robot_geometry_msgs::Point>& robot_footprint,
const std::vector<robot_geometry_msgs::Point>& dock_footprint)
{
std::vector<robot_geometry_msgs::Pose> path;
CHECK(calculator.makePlanMoveToDock(start, goal, robot_footprint,
dock_footprint, path));
CHECK(path.size() > 2);
CHECK(path.size() > 3);
CHECK(near(path.front().position.x, start.pose.position.x));
CHECK(near(path.front().position.y, start.pose.position.y));
CHECK(near(path.back().position.x, goal.pose.position.x));
@@ -81,6 +178,16 @@ void checkGeneratedPath(dock_planner::DockCalc& calculator,
current.position.y - path[index - 1].position.y) > 1e-9);
}
}
return path;
}
dock_planner::DockPlannerConfig apmConfig()
{
dock_planner::DockPlannerConfig config;
config.wheel_base = 1.3268;
config.max_steering_angle = 0.50;
config.path_point_spacing = 0.05;
return config;
}
void testConfig()
@@ -89,98 +196,82 @@ void testConfig()
std::string error;
CHECK(config.validate(error));
CHECK(error.empty());
CHECK(near(config.angleThreshold(0.0), config.angle_threshold_near));
CHECK(near(config.angleThreshold(10.0), config.angle_threshold_far));
CHECK(near(config.angleThreshold(0.55),
(config.angle_threshold_near + config.angle_threshold_far) / 2.0));
CHECK(std::isnan(config.minimumTurningRadius()));
config.path_point_spacing = 0.0;
config.wheel_base = 1.3268;
CHECK(near(config.minimumTurningRadius(),
config.wheel_base / std::tan(config.max_steering_angle)));
config.max_steering_angle = 0.0;
CHECK(!config.validate(error));
CHECK(!error.empty());
config = dock_planner::DockPlannerConfig{};
config.angle_threshold_far = config.angle_threshold_near;
config.front_axle_frame = config.rear_axle_frame;
CHECK(!config.validate(error));
config = dock_planner::DockPlannerConfig{};
config.lateral_distance_far = std::numeric_limits<double>::quiet_NaN();
config.maximum_forward_extension = config.minimum_forward_distance - 0.01;
CHECK(!config.validate(error));
config = dock_planner::DockPlannerConfig{};
config.path_point_spacing = std::numeric_limits<double>::quiet_NaN();
CHECK(!config.validate(error));
}
void testPathGeneration()
{
dock_planner::DockPlannerConfig config;
config.path_point_spacing = 0.05;
dock_planner::DockPlannerConfig config = apmConfig();
dock_planner::DockCalc calculator(config);
const std::vector<robot_geometry_msgs::Point> robot_footprint = {
point(0.50, -0.35), point(0.50, 0.35),
point(-0.50, 0.35), point(-0.50, -0.35)};
point(1.65, -0.40), point(1.65, 0.40),
point(-0.35, 0.40), point(-0.35, -0.40)};
const std::vector<robot_geometry_msgs::Point> dock_footprint = {
point(0.50, -0.40), point(0.50, 0.40),
point(-0.50, 0.40), point(-0.50, -0.40)};
const auto start = pose(2.8, 0.6, 0.0);
const auto goal = pose(0.0, 0.0, 0.0);
checkGeneratedPath(calculator, start, goal, robot_footprint, dock_footprint);
checkGeneratedPath(calculator, pose(2.8, 0.0, 0.0), goal,
robot_footprint, dock_footprint);
checkGeneratedPath(calculator, pose(2.8, -0.6, 0.0), goal,
robot_footprint, dock_footprint);
checkGeneratedPath(calculator, pose(-2.8, 0.6, 0.0), goal,
robot_footprint, dock_footprint);
checkGeneratedPath(calculator, pose(0.6, 2.8, 1.5707963267948966),
pose(0.0, 0.0, 1.5707963267948966),
robot_footprint, dock_footprint);
const double maximum_curvature = 1.0 / config.minimumTurningRadius();
for (const auto& start : {pose(2.8, 0.6, -1.2),
pose(2.8, 0.0, 2.0),
pose(2.8, -0.6, 1.2)})
{
const auto path = generatePath(calculator, start, goal,
robot_footprint, dock_footprint);
const std::size_t cusp = checkForwardThenReverse(path, goal.pose,
maximum_curvature);
CHECK(longitudinal(path[cusp], goal.pose) > longitudinal(start.pose, goal.pose));
CHECK(std::fabs(normalizeAngle(
data_convert::getYaw(path.front().orientation) -
data_convert::getYaw(start.pose.orientation))) > 0.1);
}
const auto prealigned_start = pose(2.8, 0.6, -1.2);
std::vector<robot_geometry_msgs::Pose> orientation_path;
CHECK(calculator.makePlanMoveToDock(prealigned_start, goal, robot_footprint,
dock_footprint, orientation_path));
CHECK(orientation_path.size() > 2);
const double first_path_yaw = data_convert::getYaw(
orientation_path.front().orientation);
const double expected_reverse_path_yaw = std::atan2(
orientation_path.front().position.y - orientation_path[1].position.y,
orientation_path.front().position.x - orientation_path[1].position.x);
CHECK(near(normalizeAngle(first_path_yaw - expected_reverse_path_yaw), 0.0));
CHECK(std::fabs(normalizeAngle(
first_path_yaw - data_convert::getYaw(prealigned_start.pose.orientation))) > 0.1);
const auto rotated_goal = pose(0.0, 0.0, kPi / 2.0);
const auto rotated_path = generatePath(
calculator, pose(0.6, 2.8, 0.0), rotated_goal,
robot_footprint, dock_footprint);
checkForwardThenReverse(rotated_path, rotated_goal.pose, maximum_curvature);
// Regression for the integrated run where libamr_comunication_utils was
// loaded before DockPlanner and its global CurveCommon symbol was selected.
const std::vector<robot_geometry_msgs::Point> runtime_footprint = {
point(0.583, -0.48), point(0.583, 0.48),
point(-0.583, 0.48), point(-0.583, -0.48)};
checkGeneratedPath(calculator,
pose(9.914814184, 9.939527902, 0.015737065),
pose(8.411853097, 10.115902417, 0.015734468),
runtime_footprint, runtime_footprint);
// The previous projection<=1 failure is now valid: the robot first drives
// away from the dock until the curvature-safe cusp, then reverses straight.
const auto close_path = generatePath(calculator, pose(0.8, 0.2, 0.0), goal,
robot_footprint, dock_footprint);
checkForwardThenReverse(close_path, goal.pose, maximum_curvature);
std::vector<robot_geometry_msgs::Pose> path;
auto invalid_start = start;
CHECK(!calculator.makePlanMoveToDock(pose(-2.8, 0.6, 0.0), goal,
robot_footprint, dock_footprint, path));
CHECK(path.empty());
auto invalid_start = pose(2.8, 0.6, 0.0);
invalid_start.pose.position.x = std::numeric_limits<double>::infinity();
CHECK(!calculator.makePlanMoveToDock(invalid_start, goal, robot_footprint,
dock_footprint, path));
CHECK(path.empty());
CHECK(!calculator.makePlanMoveToDock(start, goal, {}, dock_footprint, path));
CHECK(path.empty());
CHECK(!calculator.makePlanMoveToDock(pose(0.8, 0.2, 0.0), goal,
robot_footprint, dock_footprint, path));
CHECK(path.empty());
// Slightly beyond the nominal 1.0 m alignment distance: projection_ratio
// passes the strict > 1 check, but the reference NURBS is still too short.
CHECK(!calculator.makePlanMoveToDock(pose(1.0 + 5e-10, 0.0, 0.0), goal,
robot_footprint, dock_footprint, path));
CHECK(path.empty());
config.path_point_spacing = 0.0;
calculator.setConfig(config);
CHECK(!calculator.makePlanMoveToDock(start, goal, robot_footprint,
CHECK(!calculator.makePlanMoveToDock(pose(2.8, 0.6, 0.0), goal, {},
dock_footprint, path));
config.maximum_forward_extension = 0.30;
calculator.setConfig(config);
CHECK(!calculator.makePlanMoveToDock(pose(2.8, 0.6, 0.0), goal,
robot_footprint, dock_footprint, path));
CHECK(path.empty());
}
@@ -204,63 +295,49 @@ bool pathsEqual(const std::vector<robot_geometry_msgs::Pose>& first,
return true;
}
// A stacker-style robot: base_link at the drive cluster, forks extending
// 1.2 m behind it (-x), body 0.8 m ahead (+x). The approach distance must use
// the extent of the leading edge, not half the bounding box.
void testAsymmetricFootprint()
{
dock_planner::DockPlannerConfig config;
config.wheel_base = 1.0;
config.max_steering_angle = 1.0;
dock_planner::DockCalc calculator(config);
const std::vector<robot_geometry_msgs::Point> stacker_footprint = {
point(0.8, -0.5), point(0.8, 0.5), point(-1.2, 0.5), point(-1.2, -0.5)};
const std::vector<robot_geometry_msgs::Point> rear_matched_footprint = {
point(1.2, -0.5), point(1.2, 0.5), point(-1.2, 0.5), point(-1.2, -0.5)};
const std::vector<robot_geometry_msgs::Point> front_matched_footprint = {
const std::vector<robot_geometry_msgs::Point> smaller_rear_footprint = {
point(0.8, -0.5), point(0.8, 0.5), point(-0.8, 0.5), point(-0.8, -0.5)};
const std::vector<robot_geometry_msgs::Point> dock_footprint = {
point(0.5, -0.4), point(0.5, 0.4), point(-0.5, 0.4), point(-0.5, -0.4)};
// Goal yaw points toward the start: backward approach, the rear edge
// (forks, 1.2 m) leads. The path must match a symmetric robot with the
// same rear extent, regardless of the front extent.
const auto backing_start = pose(4.0, 0.5, 0.0);
const auto start = pose(0.5, 0.5, 0.0);
const auto goal = pose(0.0, 0.0, 0.0);
std::vector<robot_geometry_msgs::Pose> asymmetric_path;
std::vector<robot_geometry_msgs::Pose> reference_path;
CHECK(calculator.makePlanMoveToDock(backing_start, goal, stacker_footprint,
CHECK(calculator.makePlanMoveToDock(start, goal, stacker_footprint,
dock_footprint, asymmetric_path));
CHECK(calculator.makePlanMoveToDock(backing_start, goal, rear_matched_footprint,
CHECK(calculator.makePlanMoveToDock(start, goal, rear_matched_footprint,
dock_footprint, reference_path));
CHECK(pathsEqual(asymmetric_path, reference_path));
CHECK(calculator.makePlanMoveToDock(backing_start, goal, front_matched_footprint,
CHECK(calculator.makePlanMoveToDock(start, goal, smaller_rear_footprint,
dock_footprint, reference_path));
CHECK(!pathsEqual(asymmetric_path, reference_path));
// Goal yaw points away from the start: the axis flips, the approach is
// forward and the front edge (0.8 m) leads.
const auto forward_goal = pose(0.0, 0.0, 3.14159265358979323846);
CHECK(calculator.makePlanMoveToDock(backing_start, forward_goal, stacker_footprint,
dock_footprint, asymmetric_path));
CHECK(calculator.makePlanMoveToDock(backing_start, forward_goal, front_matched_footprint,
dock_footprint, reference_path));
CHECK(pathsEqual(asymmetric_path, reference_path));
}
void testDockAnchor()
{
dock_planner::DockPlannerConfig config;
config.wheel_base = 1.0;
config.max_steering_angle = 1.0;
const std::vector<robot_geometry_msgs::Point> robot_footprint = {
point(0.50, -0.35), point(0.50, 0.35),
point(-0.50, 0.35), point(-0.50, -0.35)};
const std::vector<robot_geometry_msgs::Point> dock_footprint = {
point(0.9, -0.8), point(0.9, 0.8), point(-0.9, 0.8), point(-0.9, -0.8)};
const auto start = pose(4.0, 0.6, 0.0);
const auto start = pose(0.5, 0.4, 0.0);
const auto goal = pose(0.0, 0.0, 0.0);
// face: the goal already sits on the approach face, so the dock footprint
// must not contribute — identical to center with no dock footprint at all.
config.dock_anchor = dock_planner::DockAnchor::kFace;
dock_planner::DockCalc face_calculator(config);
std::vector<robot_geometry_msgs::Pose> face_path;
@@ -274,8 +351,6 @@ void testDockAnchor()
{}, no_dock_path));
CHECK(pathsEqual(face_path, no_dock_path));
// center with a real dock footprint must differ from face: the near-face
// extent (0.9 m) pushes the alignment pose further out.
std::vector<robot_geometry_msgs::Pose> center_path;
CHECK(center_calculator.makePlanMoveToDock(start, goal, robot_footprint,
dock_footprint, center_path));