Skip to content

Commit 4b9b711

Browse files
authored
Increase docking coverage && fix backward docking (#5097)
* Add dock_database tests Signed-off-by: Alberto Tudela <[email protected]> * Add utils test Signed-off-by: Alberto Tudela <[email protected]> * Improve filter tests Signed-off-by: Alberto Tudela <[email protected]> * Added simple charging tests Signed-off-by: Alberto Tudela <[email protected]> * Improve comments Signed-off-by: Alberto Tudela <[email protected]> * Fix backward and redo main test Signed-off-by: Alberto Tudela <[email protected]> * Change test period to reduce test time Signed-off-by: Alberto Tudela <[email protected]> * Revert "Change test period to reduce test time" This reverts commit ef1555e. Signed-off-by: Alberto Tudela <[email protected]> * Delete print pose Signed-off-by: Alberto Tudela <[email protected]> --------- Signed-off-by: Alberto Tudela <[email protected]>
1 parent eda0a8f commit 4b9b711

17 files changed

+448
-51
lines changed

nav2_docking/opennav_docking/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ install(DIRECTORY include/
169169
DESTINATION include/${PROJECT_NAME}
170170
)
171171

172-
install(FILES test/test_dock_file.yaml
172+
install(DIRECTORY test/dock_files
173173
DESTINATION share/${PROJECT_NAME}/
174174
)
175175

nav2_docking/opennav_docking/src/dock_database.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ bool DockDatabase::getDockInstances(const rclcpp_lifecycle::LifecycleNode::Share
203203
node->get_logger(), "Loading dock from database file %s.", dock_filepath.c_str());
204204
try {
205205
return utils::parseDockFile(dock_filepath, node, dock_instances_);
206-
} catch (YAML::ParserException & e) {
206+
} catch (YAML::BadConversion & e) {
207207
RCLCPP_ERROR(
208208
node->get_logger(),
209209
"Dock database (%s) is malformed: %s.", dock_filepath.c_str(), e.what());

nav2_docking/opennav_docking/src/docking_server.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -455,13 +455,6 @@ bool DockingServer::approachDock(
455455
geometry_msgs::msg::PoseStamped target_pose = dock_pose;
456456
target_pose.header.stamp = rclcpp::Time(0);
457457

458-
// Make sure that the target pose is pointing at the robot when moving backwards
459-
// This is to ensure that the robot doesn't try to dock from the wrong side
460-
if (backward) {
461-
target_pose.pose.orientation = nav2_util::geometry_utils::orientationAroundZAxis(
462-
tf2::getYaw(target_pose.pose.orientation) + M_PI);
463-
}
464-
465458
// The control law can get jittery when close to the end when atan2's can explode.
466459
// Thus, we backward project the controller's target pose a little bit after the
467460
// dock so that the robot never gets to the end of the spiral before its in contact
@@ -472,6 +465,13 @@ bool DockingServer::approachDock(
472465
target_pose.pose.position.y += sin(yaw) * backward_projection;
473466
tf2_buffer_->transform(target_pose, target_pose, base_frame_);
474467

468+
// Make sure that the target pose is pointing at the robot when moving backwards
469+
// This is to ensure that the robot doesn't try to dock from the wrong side
470+
if (backward) {
471+
target_pose.pose.orientation = nav2_util::geometry_utils::orientationAroundZAxis(
472+
tf2::getYaw(target_pose.pose.orientation) + M_PI);
473+
}
474+
475475
// Compute and publish controls
476476
auto command = std::make_unique<geometry_msgs::msg::TwistStamped>();
477477
command->header.stamp = now();
@@ -635,9 +635,19 @@ void DockingServer::undockRobot()
635635
return;
636636
}
637637

638+
bool dock_backward = dock_backwards_.has_value() ?
639+
dock_backwards_.value() :
640+
(dock->getDockDirection() == opennav_docking_core::DockDirection::BACKWARD);
641+
638642
// Get "dock pose" by finding the robot pose
639643
geometry_msgs::msg::PoseStamped dock_pose = getRobotPoseInFrame(fixed_frame_);
640644

645+
// Make sure that the staging pose is pointing in the same direction when moving backwards
646+
if (dock_backward) {
647+
dock_pose.pose.orientation = nav2_util::geometry_utils::orientationAroundZAxis(
648+
tf2::getYaw(dock_pose.pose.orientation) + M_PI);
649+
}
650+
641651
// Get staging pose (in fixed frame)
642652
geometry_msgs::msg::PoseStamped staging_pose =
643653
dock->getStagingPose(dock_pose.pose, dock_pose.header.frame_id);
@@ -669,9 +679,6 @@ void DockingServer::undockRobot()
669679
// Get command to approach staging pose
670680
auto command = std::make_unique<geometry_msgs::msg::TwistStamped>();
671681
command->header.stamp = now();
672-
bool dock_backward = dock_backwards_.has_value() ?
673-
dock_backwards_.value() :
674-
(dock->getDockDirection() == opennav_docking_core::DockDirection::BACKWARD);
675682

676683
if (getCommandToPose(
677684
command->twist, staging_pose, undock_linear_tolerance_, undock_angular_tolerance_, false,

nav2_docking/opennav_docking/test/CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,20 @@ target_link_libraries(test_docking_server_unit
111111
)
112112

113113
# Test docking server (smoke)
114-
ament_add_pytest_test("test_docking_server" test_docking_server.py)
114+
ament_add_pytest_test(test_docking_server_with_charging_dock test_docking_server.py
115+
ENV
116+
NON_CHARGING_DOCK=False
117+
BACKWARD=False
118+
)
119+
120+
ament_add_pytest_test(test_docking_server_with_non_charging_dock test_docking_server.py
121+
ENV
122+
NON_CHARGING_DOCK=True
123+
BACKWARD=False
124+
)
125+
126+
ament_add_pytest_test(test_docking_server_backward test_docking_server.py
127+
ENV
128+
NON_CHARGING_DOCK=False
129+
BACKWARD=True
130+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
docks:
2+
dock1:
3+
type: "dockv3"
4+
frame: "map"
5+
pose: [0.3, map, 0.0]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
docks:
2+
dock1:
3+
type: "dockv3"
4+
frame: "mapA"
5+
pose: [0.3, 0.3]
File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
docks:
2+
dock1:
3+
type: "dockv3"
4+
frame: "mapA"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
docks:
2+
dock1:
3+
frame: "mapA"
4+
pose: [0.3, 0.3, 0.0]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
no_docks:
2+
dock1:
3+
type: "dockv3"
4+
frame: "mapA"
5+
pose: [0.3, 0.3, 0.0]

0 commit comments

Comments
 (0)