Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions opennav_docking/include/opennav_docking/docking_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <memory>
#include <string>
#include <mutex>
#include <functional>

#include "rclcpp/rclcpp.hpp"
#include "nav2_util/lifecycle_node.hpp"
Expand Down
2 changes: 2 additions & 0 deletions opennav_docking/include/opennav_docking/navigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <vector>
#include <memory>
#include <string>
#include <functional>

#include "rclcpp/rclcpp.hpp"
#include "rclcpp_action/rclcpp_action.hpp"
Expand Down Expand Up @@ -72,6 +73,7 @@ class Navigator
void goToPose(
const geometry_msgs::msg::PoseStamped & pose,
const rclcpp::Duration & max_staging_duration,
std::function<bool()> isPreempted,
bool recursed = false);

protected:
Expand Down
9 changes: 8 additions & 1 deletion opennav_docking/src/docking_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,15 @@ void DockingServer::dockRobot()
{
RCLCPP_INFO(get_logger(), "Robot already within pre-staging pose tolerance for dock");
} else {
std::function<bool()> isPreempted = [this]() {
return checkAndWarnIfCancelled(docking_action_server_, "dock_robot") ||
checkAndWarnIfPreempted(docking_action_server_, "dock_robot");
};

navigator_->goToPose(
initial_staging_pose, rclcpp::Duration::from_seconds(goal->max_staging_time));
initial_staging_pose,
rclcpp::Duration::from_seconds(goal->max_staging_time),
isPreempted);
RCLCPP_INFO(get_logger(), "Successful navigation to staging pose");
}

Expand Down
37 changes: 29 additions & 8 deletions opennav_docking/src/navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ void Navigator::deactivate()
void Navigator::goToPose(
const geometry_msgs::msg::PoseStamped & pose,
const rclcpp::Duration & max_staging_duration,
std::function<bool()> isPreempted,
bool recursed)
{
auto node = node_.lock();

Nav2Pose::Goal goal;
goal.pose = pose;
goal.behavior_tree = navigator_bt_xml_;
const auto timeout = max_staging_duration.to_chrono<std::chrono::milliseconds>();
const auto start_time = node->now();

// Wait for server to be active
nav_to_pose_client_->wait_for_action_server(1s);
Expand All @@ -66,19 +69,37 @@ void Navigator::goToPose(
future_goal_handle, 2s) == rclcpp::FutureReturnCode::SUCCESS)
{
auto future_result = nav_to_pose_client_->async_get_result(future_goal_handle.get());
if (executor_.spin_until_future_complete(
future_result, timeout) == rclcpp::FutureReturnCode::SUCCESS)
{
auto result = future_result.get();
if (result.code == rclcpp_action::ResultCode::SUCCEEDED && result.result->error_code == 0) {
return; // Success!

while (rclcpp::ok()) {
if (isPreempted()) {
auto cancel_future = nav_to_pose_client_->async_cancel_goal(future_goal_handle.get());
executor_.spin_until_future_complete(cancel_future, 1s);
throw opennav_docking_core::FailedToStage("Navigation request to staging pose preempted.");
}

if (node->now() - start_time > max_staging_duration) {
nav_to_pose_client_->async_cancel_goal(future_goal_handle.get());
Comment thread
SteveMacenski marked this conversation as resolved.
Outdated
throw opennav_docking_core::FailedToStage("Navigation request to staging pose timed out.");
Comment thread
SteveMacenski marked this conversation as resolved.
}

if (executor_.spin_until_future_complete(
future_result, 100ms) == rclcpp::FutureReturnCode::SUCCESS)
Comment thread
SteveMacenski marked this conversation as resolved.
Outdated
{
auto result = future_result.get();
if (result.code == rclcpp_action::ResultCode::SUCCEEDED &&
result.result->error_code == 0)
{
return; // Success!
} else {
throw opennav_docking_core::FailedToStage("Navigation request to staging pose failed.");
Comment thread
SteveMacenski marked this conversation as resolved.
Outdated
}
}
}
}

// Attempt to retry once using single iteration recursion
if (!recursed) {
goToPose(pose, max_staging_duration, true);
goToPose(pose, max_staging_duration, isPreempted, true);
return;
}

Expand Down