feat: per-marker dock_face_offset and pivot margin for dock_anchor mating_edge

The charger goal is the docked base_link pose, and the real charger face lies 0.40 m behind
it (detector offset_x). mating_edge measured the pivot sweep from a face assumed at
mating_extent (0.325 m) behind the goal, and still forced a terminal of at least
rear_extent. So the robot rotated with its centre about 0.725 m from the charger face.

Two optional keys, valid only with dock_anchor: mating_edge (rejected with center or face):
- dock_face_offset [m]: distance from the goal back to the real dock face. Default
  mating_extent.
- dock_pivot_safety_margin [m]: overrides maneuver/pivot_safety_margin for this marker.
A YAML null reads as unset, so move_base2 can clear a previous marker's value.

For mating_edge, the terminal floor becomes
max(mating_extent - face_offset, 0) + padding (floored at path_point_spacing), and the pivot
vertex becomes max(straight_distance, circumscribed - face_offset + margin). The costmap
rotation radius uses the same margin. center and face are unchanged.

KIT charger (face offset 0.40, margin 0.10, straight_length 0.2): vertex 0.2 m, robot centre
0.60 m from the charger face. Tests cover the three robot starts, the defaults, validation
and null handling. The test target now links yaml-cpp itself.
This commit is contained in:
2026-10-29 16:54:16 +07:00
parent 9d31c0e5db
commit 07e2fd3b38
8 changed files with 406 additions and 32 deletions

View File

@@ -133,7 +133,9 @@ if(BUILD_DOCK_PLANNER_TESTS AND
enable_testing()
endif()
add_executable(${PROJECT_NAME}_test test/dock_planner_test.cpp)
target_link_libraries(${PROJECT_NAME}_test PRIVATE ${PROJECT_NAME})
# The test builds YAML nodes for the config loader directly; the library links
# yaml-cpp PRIVATE and does not pass it on, so the test links it itself.
target_link_libraries(${PROJECT_NAME}_test PRIVATE ${PROJECT_NAME} yaml-cpp)
if(BUILDING_WITH_CATKIN)
add_dependencies(${PROJECT_NAME}_test ${catkin_EXPORTED_TARGETS})
endif()

View File

@@ -93,14 +93,29 @@ frame `steer_link` mà robot vi sai không có.
## Điểm xoay đặt ở đâu
```text
Xv = max( độ dài đoạn thẳng cuối,
circumscribed_radius + nửa thân dock phía tiếp cận + pivot_safety_margin )
margin_eff = dock_pivot_safety_margin khi mating_edge và được khai; còn lại dùng pivot_safety_margin
center / face:
Xv = max( straight_distance,
circumscribed_radius + dock_extent + margin_eff )
mating_edge:
Xv = max( straight_distance,
circumscribed_radius - face_offset + margin_eff )
face_offset = dock_face_offset nếu được khai, nếu không dùng mating_extent
mating_edge terminal floor = max( max(mating_extent - face_offset, 0)
+ reverse_distance_padding,
path_point_spacing )
```
Xoay tại chỗ quay **mọi** điểm footprint quanh `base_link`, nên kích thước phải
dùng là **bán kính ngoại tiếp**, không phải `front_extent`/`rear_extent`. Với
footprint 1.65 / −0.35 × ±0.40: ngoại tiếp `hypot(1.65, 0.40) = 1.698 m` trong
khi mép sau chỉ 0.35 m. Đặt điểm xoay theo mép sau là góc robot cắt vào dock.
Với `mating_edge`, `dock_face_offset` đo từ goal quay về mặt dock thật nên offset
lớn hơn sẽ đưa điểm xoay và terminal floor gần dock hơn. Giá trị phải khớp số đo;
khai lớn quá có thể làm robot quét vào dock.
`circumscribed_radius` là max `hypot(x, y)` trên các đỉnh footprint. Chính xác
tuyệt đối, kể cả footprint lõm: khoảng cách là hàm lồi nên cực đại trên đa giác
@@ -159,6 +174,8 @@ File mặc định đi kèm gói: `config/dock_global_params.yaml`. Cây đang c
| `maneuver/direct_entry_min_curve_room` | `0.0` | m | cả hai | 0 = tắt kiểu 1 |
| `maneuver/pivot_fallback_extension` | `0.0` | m | cả hai | 0 = tắt kiểu 2 (bỏ qua khi `turns_in_place`) |
| `maneuver/pivot_safety_margin` | `0.15` | m | cả hai | Khe hở vòng quét khi xoay ↔ mặt dock |
| `dock_face_offset` | unset | m | `mating_edge` | Goal lùi về mặt dock thật; hợp lệ trong `(0, 2]`, unset dùng `mating_extent` |
| `dock_pivot_safety_margin` | unset | m | `mating_edge` | Override per-marker cho khe hở; hợp lệ trong `[0, 1]` |
| `maneuver/pivot_backoff_max_distance` | `0.0` | m | differential | 0 = tắt back-off pivot; tối đa 3 m |
| `maneuver/pivot_check_costmap` | `false` | bool | cả hai pivot | Kiểm tra lethal trên các đoạn thẳng và vùng xoay |
| `terminal/reverse_distance_padding` | `0.0` | m | cả hai | Khoảng hở cộng thêm cho đoạn cuối |
@@ -169,15 +186,27 @@ File mặc định đi kèm gói: `config/dock_global_params.yaml`. Cây đang c
`footprint_dock` và `dock_anchor` cũng không khai ở đây — `move_base2` chọn theo
từng marker rồi rót vào namespace `DockPlanner` trước khi dựng plugin.
Hai khoá tuỳ chọn `dock_face_offset` và `dock_pivot_safety_margin` cũng nằm ở
root của planner namespace, được `move_base2` chép riêng theo marker. Khi marker
không khai một trong hai khoá, `move_base2` ghi YAML `null` để xoá override còn
sót từ marker trước; DockPlanner đọc `null` như chưa khai.
Chỉ có tác dụng khi `dock_anchor: mating_edge`. Khai với `center` hoặc `face` thì
DockPlanner từ chối khởi động.
`dock_anchor: center` cộng nửa thân dock phía tiếp cận vào khoảng hở;
`dock_anchor: face` bỏ qua `footprint_dock` hoàn toàn.
`dock_anchor: mating_edge` cũng bỏ qua `footprint_dock`. Nó dành cho goal đã được tầng
trên offset sẵn thành vị trí `base_link` lúc dock xong (ví dụ trạm sạc dò bằng lidar với
`offset_x`): mặt dock nằm sát mép robot đi vào tại goal, sau goal đúng `rear_extent`
(lùi vào) hoặc `front_extent` (tiến vào). Chỉ điểm xoay của kiểu thẳng + xoay + thẳng
(và kiểu lùi ra rồi xoay) đổi: `max(straight_length, bán kính ngoại tiếp − extent mép +
pivot_safety_margin)`, thay vì đo từ goal như `face`. Robot KIT 0.65 × 0.69, trạm sạc:
điểm xoay 0.4 m thay vì 0.624 m. Đường vào thẳng và đường cusp không đổi.
`offset_x`): mặt dock nằm phía sau goal một khoảng `dock_face_offset`, hoặc `rear_extent`
(lùi vào) / `front_extent` (tiến vào) nếu offset không khai. Terminal floor không còn
ép `rear_extent`: nó dùng khoảng cách còn lại từ mặt thật tới mating edge, padding, và
ít nhất một `path_point_spacing`. Khi `straight_length` lớn hơn floor, nó ấn định độ dài
terminal. Công thức pivot ở trên áp dụng cho `straight_pivot_straight` và back-off pivot;
đường direct-entry và cusp không đổi.
Ví dụ KIT 0.65 × 0.69, `dock_face_offset: 0.40`,
`dock_pivot_safety_margin: 0.10`, `straight_length: 0.2`:
`minimum_cusp_distance = max(0.325 - 0.40, 0)`, rồi floored ở `0.05 m`;
terminal là `0.2 m`, và `Xv = max(0.2, 0.474 - 0.40 + 0.10) = 0.2 m`.
Điều kiện validate:
@@ -189,6 +218,10 @@ pivot_safety_margin)`, thay vì đo từ goal như `face`. Robot KIT 0.65 × 0.6
`pivot_safety_margin >= 0`, `0 <= pivot_backoff_max_distance <= 3 m`,
`reverse_distance_padding >= 0`,
`straight_length >= 0`, `0 < path_point_spacing <= 1.0`.
- Cả `dock_face_offset` và `dock_pivot_safety_margin` chỉ hợp lệ với
`dock_anchor: mating_edge`; khai cùng `center` hoặc `face` thì DockPlanner từ
chối khởi động. `dock_face_offset` phải hữu hạn và thuộc `(0, 2] m`, còn
`dock_pivot_safety_margin` phải hữu hạn và thuộc `[0, 1] m`.
`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 tại vận tốc bằng không. Giá trị mặc định chỉ là điểm
@@ -219,7 +252,7 @@ chênh nhau hơn một mét ở đầu xe là chuyện có thật, và chênh đ
`pivot_check_costmap` mặc định `false`. Khi bật, cả `straight_pivot_straight`
và `backoff_pivot_straight` kiểm tra:
- Vùng tròn bán kính `circumscribed_radius + pivot_safety_margin` tại mỗi điểm
- Vùng tròn bán kính `circumscribed_radius + margin_eff` tại mỗi điểm
xoay; mọi cell LETHAL giao với vùng tròn hoặc phần vùng quét ngoài bản đồ sẽ
loại kiểu pivot.
- Footprint đã rasterize tại mọi sample của các đoạn tiếp cận: back-off và đoạn
@@ -235,7 +268,7 @@ và `backoff_pivot_straight` kiểm tra:
**không được đọc**. Kiểm tra pivot không làm các path hình học khác thành path
đã kiểm tra va chạm:
- `pivot_safety_margin` chỉ chặn phía **gần dock** — bảo đảm vòng quét khi xoay
- `margin_eff` (override chỉ ở `mating_edge`, nếu không là `pivot_safety_margin`) chỉ chặn phía **gần dock** — bảo đảm vòng quét khi xoay
không chạm mặt dock. Nó không biết gì về tường, kệ hay người bên cạnh.
- Kiểu 1 và 3 không được kiểm tra costmap. Kiểu back-off có giới hạn chiều dài,
nhưng vẫn cần đủ không gian trống phía sau robot.

View File

@@ -158,6 +158,7 @@ DockPlanner:
# Tăng lên thì robot có quãng thẳng dài hơn để chỉnh hết sai số hướng trước
# khi vào dock, ĐỔI LẠI ăn vào chỗ dành cho cung, nên đặt lớn quá sẽ đẩy plan
# sang kiểu có cusp hoặc kiểu xoay tại chỗ.
# Với mating_edge + dock_face_offset, terminal floor không còn là rear_extent nên straight_length (ví dụ 0.2 m) quyết định độ dài terminal.
straight_length: 0.0
sampling:

View File

@@ -1,6 +1,7 @@
#ifndef DOCK_PLANNER_DOCK_PLANNER_CONFIG_H_
#define DOCK_PLANNER_DOCK_PLANNER_CONFIG_H_
#include <optional>
#include <string>
#include <robot/node_handle.h>
@@ -19,9 +20,10 @@ inline constexpr double kPi = 3.14159265358979323846;
* kFace: goal is already on the approach face; footprint_dock does not
* contribute to the approach distance and is ignored entirely.
* kMatingEdge: goal is the docked base_link pose, already offset upstream
* (e.g. by the detector), and the dock face touches the robot's mating edge
* there. Same as kFace, except that the on-the-spot pivot clearance is measured
* from that real face, mating_extent behind the goal, instead of from the goal.
* (e.g. by the detector). Same as kFace, except that the on-the-spot pivot
* clearance is measured from the real dock face, dock_face_offset behind the
* goal (or mating_extent when the optional offset is unset), instead of from
* the goal.
* footprint_dock is ignored.
*/
enum class DockAnchor
@@ -83,8 +85,9 @@ struct DockPlannerConfig
/**
* [m] Requested length of the straight terminal leg. The effective length is
* max(straight_length, mating robot extent + dock near extent + padding), so
* 0 keeps the clearance-only behaviour.
* max(straight_length, terminal clearance floor), so 0 keeps the
* clearance-only behaviour. For mating_edge, the floor accounts for any
* remaining gap between dock_face_offset and the robot's mating extent.
*/
double straight_length = 0.0;
@@ -120,6 +123,16 @@ struct DockPlannerConfig
*/
double pivot_safety_margin = 0.15;
/**
* [m] Optional per-marker distance from the mating_edge goal back to the
* real dock face. Unset uses the robot mating extent; only valid for
* DockAnchor::kMatingEdge.
*/
std::optional<double> dock_face_offset = std::nullopt;
/** [m] Optional per-marker override for pivot_safety_margin. */
std::optional<double> dock_pivot_safety_margin = std::nullopt;
/** [m] Maximum straight back-off distance for the differential-only last-resort pivot. 0 disables it. */
double pivot_backoff_max_distance = 0.0;

View File

@@ -781,20 +781,41 @@ bool DockCalc::makePlanMoveToDock(
return false;
}
const bool mating_edge = config_.dock_anchor == DockAnchor::kMatingEdge;
const double face_offset = mating_edge
? config_.dock_face_offset.value_or(mating_extent)
: 0.0;
const double effective_pivot_safety_margin =
mating_edge && config_.dock_pivot_safety_margin.has_value()
? *config_.dock_pivot_safety_margin
: config_.pivot_safety_margin;
const double requested_cusp_floor =
mating_edge
? std::max(mating_extent - face_offset, 0.0) +
config_.reverse_distance_padding
: mating_extent + dock_extent + config_.reverse_distance_padding;
// For mating_edge, only a positive difference between mating_extent and the
// measured face offset contributes to the terminal floor. Keep a positive
// sampleable floor even when the configured offset reaches or passes the edge.
const double minimum_cusp_distance = mating_edge
? std::max(requested_cusp_floor,
config_.path_point_spacing)
: requested_cusp_floor;
const std::string effective_face_offset_text =
mating_edge ? std::to_string(face_offset) + " m" : "n/a";
robot::log_info(
"[dock_calc] Docking edge=%s (lead-in drives %s, terminal drives %s), "
"derived from goal-frame longitudinal=%.3f m. Cusp clearance uses robot "
"%s_extent=%.3f m + dock %s_extent=%.3f m + padding=%.3f m.\n",
"derived from goal-frame longitudinal=%.3f m. Cusp floor=%.3f m "
"(robot=%s_extent %.3f m, dock=%s_extent %.3f m, padding=%.3f m).\n",
dock_with_front ? "FRONT" : "REAR",
dock_with_front ? "REVERSE" : "FORWARD",
dock_with_front ? "FORWARD" : "REVERSE",
goal_longitudinal,
goal_longitudinal, minimum_cusp_distance,
dock_with_front ? "front" : "rear", mating_extent,
dock_with_front ? "rear" : "front", dock_extent,
config_.reverse_distance_padding);
const double minimum_cusp_distance = mating_extent + dock_extent +
config_.reverse_distance_padding;
if (!std::isfinite(minimum_cusp_distance) || minimum_cusp_distance <= kEpsilon)
{
robot::log_error(
@@ -821,14 +842,14 @@ bool DockCalc::makePlanMoveToDock(
// instead would drive a corner of the robot into the dock.
//
// With dock_anchor=mating_edge the goal is the docked base_link pose and the
// dock face sits at the robot's mating edge, mating_extent behind the goal.
// The sweep clearance is measured from that real face. face and center keep
// the face at the goal / at dock_extent, unchanged.
const double pivot_face_offset =
config_.dock_anchor == DockAnchor::kMatingEdge ? -mating_extent : dock_extent;
// dock face sits face_offset behind it (mating_extent when unset). The sweep
// clearance is measured from that real face. face and center keep their
// existing face-at-goal / dock_extent geometry.
const double pivot_face_offset = mating_edge ? -face_offset : dock_extent;
const double pivot_vertex_distance = std::max(
straight_distance,
robot.circumscribed_radius + pivot_face_offset + config_.pivot_safety_margin);
robot.circumscribed_radius + pivot_face_offset +
effective_pivot_safety_margin);
// The pivot shape needs a base that can change heading without moving. A
// differential base can exactly when its declared turning radius is 0; a
@@ -911,7 +932,7 @@ bool DockCalc::makePlanMoveToDock(
std::string safety_reason;
bool safe = checkPivotPathCostmap(
approach_segment,
robot.circumscribed_radius + config_.pivot_safety_margin,
robot.circumscribed_radius + effective_pivot_safety_margin,
true, safety_reason);
if (safe)
{
@@ -1103,7 +1124,8 @@ bool DockCalc::makePlanMoveToDock(
{
safe = checkPivotPathCostmap(
backoff_path,
robot.circumscribed_radius + config_.pivot_safety_margin,
robot.circumscribed_radius +
effective_pivot_safety_margin,
true, backoff_reason);
}
@@ -1140,12 +1162,13 @@ bool DockCalc::makePlanMoveToDock(
"min_radius=%.3f m, straight_distance=%.3f m, "
"cusp_reachable=%s (extension=%.3f m, max=%.3f m), "
"pivot_enabled=%s (vertex=%.3f m, circumscribed=%.3f m), "
"backoff_pivot=%s.\n",
"face_offset=%s, pivot_safety_margin=%.3f m, backoff_pivot=%s.\n",
differential ? "differential" : "ackermann",
start_longitudinal, start_lateral, minimum_turning_radius,
straight_distance, cusp_reachable ? "yes" : "no", cusp_extension,
config_.maximum_forward_extension, pivot_enabled ? "yes" : "no",
pivot_vertex_distance, robot.circumscribed_radius,
effective_face_offset_text.c_str(), effective_pivot_safety_margin,
backoff_status.c_str());
return false;
}
@@ -1191,14 +1214,15 @@ bool DockCalc::makePlanMoveToDock(
"min_radius=%.4f m, start=(long=%.3f m, lateral=%.3f m in approach frame), "
"curve_room=%.3f m, cusp_extension=%.3f m (pivot threshold=%.3f m), "
"arc_radius=%.4f m, pivot_vertex=%.3f m, pivot_angle=%.4f rad, "
"circumscribed_radius=%.3f m.\n",
"circumscribed_radius=%.3f m, face_offset=%s, pivot_safety_margin=%.3f m.\n",
dock_with_front ? "front" : "rear", shapeName(selected),
differential ? "differential" : "ackermann",
plan.size(), approach_segment.size(), terminal_segment.size(),
terminal_length, dock_with_front ? "forward" : "reverse",
minimum_turning_radius, start_longitudinal, start_lateral, curve_room,
cusp_extension, config_.pivot_fallback_extension, curve_radius,
pivot_vertex_distance, pivot_angle, robot.circumscribed_radius);
pivot_vertex_distance, pivot_angle, robot.circumscribed_radius,
effective_face_offset_text.c_str(), effective_pivot_safety_margin);
return true;
}

View File

@@ -2,6 +2,7 @@
#include <algorithm>
#include <cmath>
#include <optional>
#include <utility>
#include <boost/dll/alias.hpp>
@@ -93,6 +94,11 @@ FootprintLoadStatus loadDockFootprint(
return FootprintLoadStatus::kValid;
}
std::string optionalDistanceText(const std::optional<double>& value)
{
return value.has_value() ? std::to_string(*value) + " m" : "unset";
}
} // namespace
DockPlanner::DockPlanner() = default;
@@ -366,11 +372,16 @@ bool DockPlanner::initialize(std::string name,
});
initialized_ = true;
const std::string dock_face_offset_text =
optionalDistanceText(loaded_config.dock_face_offset);
const std::string dock_pivot_safety_margin_text =
optionalDistanceText(loaded_config.dock_pivot_safety_margin);
robot::log_info(
"[dock_planner] Initialized dock maneuver (docking edge is derived per plan "
"from the side the robot stands on): model=%s, TF %s -> %s, wheel_base=%.4f m, "
"max_steering_angle=%.4f rad, minimum_turning_radius=%.4f m, "
"pivot_fallback_extension=%.3f m, pivot_safety_margin=%.3f m, "
"dock_face_offset=%s, dock_pivot_safety_margin=%s, "
"pivot_backoff_max_distance=%.3f m, pivot_check_costmap=%s.\n",
loaded_config.requiresAxleTf() ? "ackermann" : "differential",
loaded_config.requiresAxleTf() ? loaded_config.front_axle_frame.c_str() : "-",
@@ -378,6 +389,7 @@ bool DockPlanner::initialize(std::string name,
loaded_config.wheel_base, loaded_config.max_steering_angle,
minimum_turning_radius, loaded_config.pivot_fallback_extension,
loaded_config.pivot_safety_margin,
dock_face_offset_text.c_str(), dock_pivot_safety_margin_text.c_str(),
loaded_config.pivot_backoff_max_distance,
loaded_config.pivot_check_costmap ? "true" : "false");
return true;

View File

@@ -3,6 +3,8 @@
#include <cmath>
#include <limits>
#include <yaml-cpp/yaml.h>
namespace dock_planner
{
namespace
@@ -26,6 +28,33 @@ bool readOptionalDouble(const robot::NodeHandle& nh, const std::string& key,
return true;
}
bool readNullableOptionalDouble(const robot::NodeHandle& nh, const std::string& key,
std::optional<double>& value, std::string& error)
{
YAML::Node node;
if (!nh.getParam(key, node) || !node.IsDefined() || node.IsNull())
{
value.reset();
return true;
}
if (!node.IsScalar())
{
error = "parameter '" + key + "' must be numeric or null";
return false;
}
try
{
value = node.as<double>();
}
catch (const YAML::Exception&)
{
error = "parameter '" + key + "' must be numeric or null";
return false;
}
return true;
}
bool readOptionalBool(const robot::NodeHandle& nh, const std::string& key,
bool& value, std::string& error)
{
@@ -173,7 +202,11 @@ bool DockPlannerConfig::load(const robot::NodeHandle& nh, DockPlannerConfig& con
return false;
}
if (!readDockAnchor(nh, loaded.dock_anchor, error))
if (!readDockAnchor(nh, loaded.dock_anchor, error) ||
!readNullableOptionalDouble(nh, "dock_face_offset",
loaded.dock_face_offset, error) ||
!readNullableOptionalDouble(nh, "dock_pivot_safety_margin",
loaded.dock_pivot_safety_margin, error))
{
return false;
}
@@ -217,6 +250,41 @@ bool DockPlannerConfig::validate(std::string& error) const
}
}
const char* anchor_name = dock_anchor == DockAnchor::kMatingEdge
? "mating_edge"
: (dock_anchor == DockAnchor::kFace ? "face" : "center");
if (dock_face_offset.has_value())
{
if (dock_anchor != DockAnchor::kMatingEdge)
{
error = std::string("dock_face_offset is only valid with dock_anchor: mating_edge (got ") +
anchor_name + ")";
return false;
}
if (!std::isfinite(*dock_face_offset) || *dock_face_offset <= 0.0 ||
*dock_face_offset > 2.0)
{
error = "parameter 'dock_face_offset' must be finite and in (0, 2.0] m";
return false;
}
}
if (dock_pivot_safety_margin.has_value())
{
if (dock_anchor != DockAnchor::kMatingEdge)
{
error = std::string(
"dock_pivot_safety_margin is only valid with dock_anchor: mating_edge (got ") +
anchor_name + ")";
return false;
}
if (!std::isfinite(*dock_pivot_safety_margin) ||
*dock_pivot_safety_margin < 0.0 || *dock_pivot_safety_margin > 1.0)
{
error = "parameter 'dock_pivot_safety_margin' must be finite and in [0, 1.0] m";
return false;
}
}
// A differential base has no steered axle: validating axle frames or a
// steering limit there would reject a perfectly valid configuration and
// stop the plugin from loading at all.

View File

@@ -6,6 +6,7 @@
#include <vector>
#include <data_convert/data_convert.h>
#include <robot/node_handle.h>
#include "dock_planner/dock_calc.h"
#include "dock_planner/dock_planner_config.h"
@@ -400,6 +401,56 @@ void testConfig()
config = dock_planner::DockPlannerConfig{};
config.pivot_safety_margin = -0.01;
CHECK(!config.validate(error));
for (const auto anchor : {dock_planner::DockAnchor::kCenter,
dock_planner::DockAnchor::kFace})
{
config = dock_planner::DockPlannerConfig{};
config.dock_anchor = anchor;
config.dock_face_offset = 0.4;
CHECK(!config.validate(error));
CHECK(error.find("dock_face_offset is only valid with dock_anchor: mating_edge") !=
std::string::npos);
CHECK(error.find(anchor == dock_planner::DockAnchor::kCenter ? "got center" : "got face") !=
std::string::npos);
}
config = dock_planner::DockPlannerConfig{};
config.dock_anchor = dock_planner::DockAnchor::kMatingEdge;
config.dock_face_offset = 0.0;
CHECK(!config.validate(error));
config.dock_face_offset = -0.01;
CHECK(!config.validate(error));
config.dock_face_offset = std::numeric_limits<double>::quiet_NaN();
CHECK(!config.validate(error));
config.dock_face_offset = 2.01;
CHECK(!config.validate(error));
config.dock_face_offset.reset();
config.dock_pivot_safety_margin = -0.01;
CHECK(!config.validate(error));
config.dock_pivot_safety_margin = std::numeric_limits<double>::quiet_NaN();
CHECK(!config.validate(error));
config.dock_pivot_safety_margin = 1.01;
CHECK(!config.validate(error));
// YAML null is the marker-binding clear value and must load exactly like an absent key.
robot::NodeHandle planner_nh;
planner_nh.setParam("dock_anchor", YAML::Node("mating_edge"));
planner_nh.setParam("dock_face_offset", YAML::Node(YAML::NodeType::Null));
planner_nh.setParam("dock_pivot_safety_margin", YAML::Node(YAML::NodeType::Null));
dock_planner::DockPlannerConfig loaded;
CHECK(dock_planner::DockPlannerConfig::load(planner_nh, loaded, error));
CHECK(!loaded.dock_face_offset.has_value());
CHECK(!loaded.dock_pivot_safety_margin.has_value());
planner_nh.setParam("dock_face_offset", 0.4);
planner_nh.setParam("dock_pivot_safety_margin", 0.1);
CHECK(dock_planner::DockPlannerConfig::load(planner_nh, loaded, error));
CHECK(loaded.dock_face_offset.has_value() && near(*loaded.dock_face_offset, 0.4));
CHECK(loaded.dock_pivot_safety_margin.has_value() &&
near(*loaded.dock_pivot_safety_margin, 0.1));
planner_nh.setParam("dock_anchor", YAML::Node("face"));
CHECK(!dock_planner::DockPlannerConfig::load(planner_nh, loaded, error));
CHECK(error.find("dock_face_offset is only valid with dock_anchor: mating_edge (got face)") !=
std::string::npos);
config = dock_planner::DockPlannerConfig{};
config.pivot_backoff_max_distance = -0.01;
CHECK(!config.validate(error));
@@ -635,6 +686,174 @@ void testMatingEdgeAnchor()
CHECK(mating_path.size() < face_path.size());
}
void testMatingEdgeFaceOffset()
{
const auto robot_footprint = robotFootprint065x069();
const std::vector<robot_geometry_msgs::Point> no_dock_footprint;
const auto goal = pose(0.0, 0.0, 0.0);
const double circumscribed = std::hypot(0.325, 0.345);
auto config = differentialBackoffConfig();
config.minimum_turning_radius = 0.0;
config.direct_entry_min_curve_room = 0.0;
config.straight_length = 0.2;
config.dock_anchor = dock_planner::DockAnchor::kMatingEdge;
config.dock_face_offset = 0.40;
config.dock_pivot_safety_margin = 0.10;
const double kit_minimum_cusp_distance = std::max(
std::max(0.325 - *config.dock_face_offset, 0.0) +
config.reverse_distance_padding,
config.path_point_spacing);
const double kit_straight_distance =
std::max(kit_minimum_cusp_distance, config.straight_length);
CHECK(near(kit_minimum_cusp_distance, 0.05));
CHECK(near(kit_straight_distance, 0.2));
const double kit_vertex = std::max(
kit_straight_distance,
circumscribed - *config.dock_face_offset +
*config.dock_pivot_safety_margin);
CHECK(near(kit_vertex, 0.2));
dock_planner::DockCalc kit_calculator(config);
for (const auto& start : {pose(0.579, 0.292, 0.0),
pose(0.427, 0.155, 0.0),
pose(0.375, -0.149, 0.17)})
{
std::vector<robot_geometry_msgs::Pose> path;
CHECK(kit_calculator.makePlanMoveToDock(start, goal, robot_footprint,
no_dock_footprint, path));
checkPivotPath(path, goal.pose, false, kit_vertex);
bool checked_terminal_length = false;
for (std::size_t index = 1; index < path.size(); ++index)
{
if (std::hypot(path[index].position.x - path[index - 1].position.x,
path[index].position.y - path[index - 1].position.y) <= 1e-9)
{
CHECK(near(std::fabs(longitudinal(path[index], goal.pose)), 0.2));
checked_terminal_length = true;
break;
}
}
CHECK(checked_terminal_length);
// The pivot lies between every start and the goal, so none of these paths backs off.
CHECK(longitudinal(path.front(), goal.pose) > kit_vertex);
}
// With no explicit offset, the mating edge remains the assumed face. A short
// terminal is therefore raised to the rotation-clearance vertex, 0.299 m.
config.dock_face_offset.reset();
config.dock_pivot_safety_margin.reset();
config.straight_length = 0.1;
const double default_offset_vertex = std::max(
config.straight_length,
circumscribed - 0.325 + config.pivot_safety_margin);
CHECK(near(default_offset_vertex, 0.299, 1e-3));
dock_planner::DockCalc default_offset_calculator(config);
std::vector<robot_geometry_msgs::Pose> default_offset_path;
CHECK(default_offset_calculator.makePlanMoveToDock(
pose(0.579, 0.292, 0.0), goal, robot_footprint,
no_dock_footprint, default_offset_path));
checkPivotPath(default_offset_path, goal.pose, false, default_offset_vertex);
}
void testDockPivotSafetyMarginOverride()
{
const auto robot_footprint = robotFootprint065x069();
const std::vector<robot_geometry_msgs::Point> trolley_footprint = {
point(0.375, -0.2735), point(0.375, 0.2735),
point(-0.375, 0.2735), point(-0.375, -0.2735)};
const auto start = pose(1.6, 0.4, 0.0);
const auto goal = pose(0.0, 0.0, 0.0);
const double circumscribed = std::hypot(0.325, 0.345);
auto center_config = differentialBackoffConfig();
center_config.minimum_turning_radius = 0.0;
center_config.direct_entry_min_curve_room = 0.0;
center_config.straight_length = 0.2;
center_config.dock_anchor = dock_planner::DockAnchor::kCenter;
center_config.dock_pivot_safety_margin.reset();
center_config.dock_face_offset.reset();
// With neither optional key set, preserve the prior center-anchor path pose for pose.
dock_planner::DockCalc center_default(center_config);
std::vector<robot_geometry_msgs::Pose> center_default_path;
CHECK(center_default.makePlanMoveToDock(start, goal, robot_footprint,
trolley_footprint, center_default_path));
auto center_no_keys_config = center_config;
center_no_keys_config.dock_face_offset.reset();
center_no_keys_config.dock_pivot_safety_margin.reset();
dock_planner::DockCalc center_no_keys(center_no_keys_config);
std::vector<robot_geometry_msgs::Pose> center_no_keys_path;
CHECK(center_no_keys.makePlanMoveToDock(start, goal, robot_footprint,
trolley_footprint, center_no_keys_path));
CHECK(pathsEqualExactly(center_default_path, center_no_keys_path));
const std::vector<robot_geometry_msgs::Point> no_dock_footprint;
auto face_config = center_config;
face_config.dock_anchor = dock_planner::DockAnchor::kFace;
dock_planner::DockCalc face_default(face_config);
std::vector<robot_geometry_msgs::Pose> face_default_path;
CHECK(face_default.makePlanMoveToDock(start, goal, robot_footprint,
no_dock_footprint, face_default_path));
// DockCalc itself also ignores an invalid non-mating-edge override. Plugin validation below
// still rejects these configs before initialize() succeeds.
for (const auto anchor : {dock_planner::DockAnchor::kCenter,
dock_planner::DockAnchor::kFace})
{
auto rejected_config = center_config;
rejected_config.dock_anchor = anchor;
rejected_config.dock_pivot_safety_margin = 0.10;
std::string error;
CHECK(!rejected_config.validate(error));
CHECK(error.find("dock_pivot_safety_margin is only valid with dock_anchor: mating_edge") !=
std::string::npos);
CHECK(error.find(anchor == dock_planner::DockAnchor::kCenter ? "got center" : "got face") !=
std::string::npos);
// DockCalc validates its config before planning, so an override declared on
// center/face is refused there too: no path, rather than a silently ignored key.
dock_planner::DockCalc refused_override(rejected_config);
std::vector<robot_geometry_msgs::Pose> refused_override_path;
const auto& dock_footprint = anchor == dock_planner::DockAnchor::kCenter
? trolley_footprint
: no_dock_footprint;
CHECK(!refused_override.makePlanMoveToDock(
start, goal, robot_footprint, dock_footprint, refused_override_path));
CHECK(refused_override_path.empty());
}
auto mating_config = center_config;
mating_config.dock_anchor = dock_planner::DockAnchor::kMatingEdge;
mating_config.dock_face_offset = 0.40;
mating_config.straight_length = 0.1;
mating_config.dock_pivot_safety_margin.reset();
std::string mating_config_error;
CHECK(mating_config.validate(mating_config_error));
dock_planner::DockCalc mating_default(mating_config);
std::vector<robot_geometry_msgs::Pose> mating_default_path;
CHECK(mating_default.makePlanMoveToDock(
pose(0.579, 0.292, 0.0), goal, robot_footprint, {}, mating_default_path));
mating_config.dock_pivot_safety_margin = 0.10;
dock_planner::DockCalc overridden(mating_config);
std::vector<robot_geometry_msgs::Pose> overridden_path;
CHECK(overridden.makePlanMoveToDock(
pose(0.579, 0.292, 0.0), goal, robot_footprint, {}, overridden_path));
const double face_offset = 0.40;
const double straight_distance = 0.1;
const double default_vertex = std::max(
straight_distance,
circumscribed - face_offset + center_config.pivot_safety_margin);
const double override_vertex = std::max(
straight_distance, circumscribed - face_offset + 0.10);
CHECK(near(default_vertex, 0.224, 1e-3));
CHECK(near(override_vertex, 0.174, 1e-3));
checkPivotPath(mating_default_path, goal.pose, false, default_vertex);
checkPivotPath(overridden_path, goal.pose, false, override_vertex);
CHECK(!pathsEqualExactly(mating_default_path, overridden_path));
}
void testExistingPlansUnchangedByBackoff()
{
const auto robot_footprint = apmFootprint();
@@ -1228,6 +1447,8 @@ int main()
testConfig();
testBackoffPivotRobotFailures();
testMatingEdgeAnchor();
testMatingEdgeFaceOffset();
testDockPivotSafetyMarginOverride();
testExistingPlansUnchangedByBackoff();
testBackoffPivotGates();
testCostmapCheckCallbacks();