Skip to content

Commit ac2c4c4

Browse files
committed
Revert "Removing action server timeout duration after fixes to ROS 2, Reverts 3787 (#5183)"
This reverts commit c9438b4.
1 parent ce4cd90 commit ac2c4c4

File tree

9 files changed

+66
-12
lines changed

9 files changed

+66
-12
lines changed

nav2_behavior_tree/include/nav2_behavior_tree/bt_action_server_impl.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ BtActionServer<ActionT>::BtActionServer(
6666
if (!node->has_parameter("default_server_timeout")) {
6767
node->declare_parameter("default_server_timeout", 20);
6868
}
69+
if (!node->has_parameter("action_server_result_timeout")) {
70+
node->declare_parameter("action_server_result_timeout", 900.0);
71+
}
6972
if (!node->has_parameter("always_reload_bt_xml")) {
7073
node->declare_parameter("always_reload_bt_xml", false);
7174
}
@@ -164,13 +167,19 @@ bool BtActionServer<ActionT>::on_configure()
164167
node, "transform_tolerance", rclcpp::ParameterValue(0.1));
165168
nav2_util::copy_all_parameter_values(node, client_node_);
166169

170+
// set the timeout in seconds for the action server to discard goal handles if not finished
171+
double action_server_result_timeout =
172+
node->get_parameter("action_server_result_timeout").as_double();
173+
rcl_action_server_options_t server_options = rcl_action_server_get_default_options();
174+
server_options.result_timeout.nanoseconds = RCL_S_TO_NS(action_server_result_timeout);
175+
167176
action_server_ = std::make_shared<ActionServer>(
168177
node->get_node_base_interface(),
169178
node->get_node_clock_interface(),
170179
node->get_node_logging_interface(),
171180
node->get_node_waitables_interface(),
172181
action_name_, std::bind(&BtActionServer<ActionT>::executeCallback, this),
173-
nullptr, std::chrono::milliseconds(500), false);
182+
nullptr, std::chrono::milliseconds(500), false, server_options);
174183

175184
// Get parameters for BT timeouts
176185
int bt_loop_duration;

nav2_behaviors/include/nav2_behaviors/timed_behavior.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,19 @@ class TimedBehavior : public nav2_core::Behavior
135135
node->get_parameter("robot_base_frame", robot_base_frame_);
136136
node->get_parameter("transform_tolerance", transform_tolerance_);
137137

138+
if (!node->has_parameter("action_server_result_timeout")) {
139+
node->declare_parameter("action_server_result_timeout", 10.0);
140+
}
141+
142+
double action_server_result_timeout;
143+
node->get_parameter("action_server_result_timeout", action_server_result_timeout);
144+
rcl_action_server_options_t server_options = rcl_action_server_get_default_options();
145+
server_options.result_timeout.nanoseconds = RCL_S_TO_NS(action_server_result_timeout);
146+
138147
action_server_ = std::make_shared<ActionServer>(
139148
node, behavior_name_,
140149
std::bind(&TimedBehavior::execute, this), nullptr, std::chrono::milliseconds(
141-
500), false);
150+
500), false, server_options);
142151

143152
local_collision_checker_ = local_collision_checker;
144153
global_collision_checker_ = global_collision_checker;

nav2_bringup/params/nav2_params.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ bt_navigator:
4848
filter_duration: 0.3
4949
default_server_timeout: 20
5050
wait_for_service_timeout: 1000
51+
action_server_result_timeout: 900.0
5152
service_introspection_mode: "disabled"
5253
navigators: ["navigate_to_pose", "navigate_through_poses"]
5354
navigate_to_pose:
@@ -433,6 +434,7 @@ waypoint_follower:
433434
loop_rate: 20
434435
stop_on_failure: false
435436
service_introspection_mode: "disabled"
437+
action_server_result_timeout: 900.0
436438
waypoint_task_executor_plugin: "wait_at_waypoint"
437439
wait_at_waypoint:
438440
plugin: "nav2_waypoint_follower::WaitAtWaypoint"

nav2_controller/src/controller_server.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ ControllerServer::ControllerServer(const rclcpp::NodeOptions & options)
5151

5252
declare_parameter("controller_frequency", 20.0);
5353

54+
declare_parameter("action_server_result_timeout", 10.0);
55+
5456
declare_parameter("progress_checker_plugins", default_progress_checker_ids_);
5557
declare_parameter("goal_checker_plugins", default_goal_checker_ids_);
5658
declare_parameter("controller_plugins", default_ids_);
@@ -222,6 +224,11 @@ ControllerServer::on_configure(const rclcpp_lifecycle::State & state)
222224
odom_sub_ = std::make_unique<nav_2d_utils::OdomSubscriber>(node);
223225
vel_publisher_ = std::make_unique<nav2_util::TwistPublisher>(node, "cmd_vel", 1);
224226

227+
double action_server_result_timeout;
228+
get_parameter("action_server_result_timeout", action_server_result_timeout);
229+
rcl_action_server_options_t server_options = rcl_action_server_get_default_options();
230+
server_options.result_timeout.nanoseconds = RCL_S_TO_NS(action_server_result_timeout);
231+
225232
double costmap_update_timeout_dbl;
226233
get_parameter("costmap_update_timeout", costmap_update_timeout_dbl);
227234
costmap_update_timeout_ = rclcpp::Duration::from_seconds(costmap_update_timeout_dbl);
@@ -235,8 +242,7 @@ ControllerServer::on_configure(const rclcpp_lifecycle::State & state)
235242
std::bind(&ControllerServer::computeControl, this),
236243
nullptr,
237244
std::chrono::milliseconds(500),
238-
true /*spin thread*/, rcl_action_server_get_default_options(),
239-
use_realtime_priority_ /*soft realtime*/);
245+
true /*spin thread*/, server_options, use_realtime_priority_ /*soft realtime*/);
240246
} catch (const std::runtime_error & e) {
241247
RCLCPP_ERROR(get_logger(), "Error creating action server! %s", e.what());
242248
on_cleanup(state);

nav2_docking/opennav_docking/src/docking_server.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,25 @@ DockingServer::on_configure(const rclcpp_lifecycle::State & state)
8585
get_parameter("odom_topic", odom_topic);
8686
odom_sub_ = std::make_unique<nav_2d_utils::OdomSubscriber>(node, odom_topic);
8787

88+
double action_server_result_timeout;
89+
nav2_util::declare_parameter_if_not_declared(
90+
node, "action_server_result_timeout", rclcpp::ParameterValue(10.0));
91+
get_parameter("action_server_result_timeout", action_server_result_timeout);
92+
rcl_action_server_options_t server_options = rcl_action_server_get_default_options();
93+
server_options.result_timeout.nanoseconds = RCL_S_TO_NS(action_server_result_timeout);
94+
8895
// Create the action servers for dock / undock
8996
docking_action_server_ = std::make_unique<DockingActionServer>(
9097
node, "dock_robot",
9198
std::bind(&DockingServer::dockRobot, this),
9299
nullptr, std::chrono::milliseconds(500),
93-
true);
100+
true, server_options);
94101

95102
undocking_action_server_ = std::make_unique<UndockingActionServer>(
96103
node, "undock_robot",
97104
std::bind(&DockingServer::undockRobot, this),
98105
nullptr, std::chrono::milliseconds(500),
99-
true);
106+
true, server_options);
100107

101108
// Create composed utilities
102109
mutex_ = std::make_shared<std::mutex>();

nav2_planner/src/planner_server.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ PlannerServer::PlannerServer(const rclcpp::NodeOptions & options)
5252
// Declare this node's parameters
5353
declare_parameter("planner_plugins", default_ids_);
5454
declare_parameter("expected_planner_frequency", 1.0);
55+
declare_parameter("action_server_result_timeout", 10.0);
5556
declare_parameter("costmap_update_timeout", 1.0);
5657

5758
get_parameter("planner_plugins", planner_ids_);
@@ -147,6 +148,11 @@ PlannerServer::on_configure(const rclcpp_lifecycle::State & state)
147148
// Initialize pubs & subs
148149
plan_publisher_ = create_publisher<nav_msgs::msg::Path>("plan", 1);
149150

151+
double action_server_result_timeout;
152+
get_parameter("action_server_result_timeout", action_server_result_timeout);
153+
rcl_action_server_options_t server_options = rcl_action_server_get_default_options();
154+
server_options.result_timeout.nanoseconds = RCL_S_TO_NS(action_server_result_timeout);
155+
150156
double costmap_update_timeout_dbl;
151157
get_parameter("costmap_update_timeout", costmap_update_timeout_dbl);
152158
costmap_update_timeout_ = rclcpp::Duration::from_seconds(costmap_update_timeout_dbl);
@@ -158,15 +164,15 @@ PlannerServer::on_configure(const rclcpp_lifecycle::State & state)
158164
std::bind(&PlannerServer::computePlan, this),
159165
nullptr,
160166
std::chrono::milliseconds(500),
161-
true);
167+
true, server_options);
162168

163169
action_server_poses_ = std::make_unique<ActionServerThroughPoses>(
164170
shared_from_this(),
165171
"compute_path_through_poses",
166172
std::bind(&PlannerServer::computePlanThroughPoses, this),
167173
nullptr,
168174
std::chrono::milliseconds(500),
169-
true);
175+
true, server_options);
170176

171177
return nav2_util::CallbackReturn::SUCCESS;
172178
}

nav2_smoother/src/nav2_smoother.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ SmootherServer::SmootherServer(const rclcpp::NodeOptions & options)
5353
rclcpp::ParameterValue(std::string("base_link")));
5454
declare_parameter("transform_tolerance", rclcpp::ParameterValue(0.1));
5555
declare_parameter("smoother_plugins", default_ids_);
56+
57+
declare_parameter("action_server_result_timeout", 10.0);
5658
}
5759

5860
SmootherServer::~SmootherServer()
@@ -83,7 +85,7 @@ SmootherServer::on_configure(const rclcpp_lifecycle::State & state)
8385
transform_listener_ = std::make_shared<tf2_ros::TransformListener>(*tf_);
8486

8587
std::string costmap_topic, footprint_topic, robot_base_frame;
86-
double transform_tolerance = 0.1;
88+
double transform_tolerance;
8789
this->get_parameter("costmap_topic", costmap_topic);
8890
this->get_parameter("footprint_topic", footprint_topic);
8991
this->get_parameter("transform_tolerance", transform_tolerance);
@@ -105,14 +107,19 @@ SmootherServer::on_configure(const rclcpp_lifecycle::State & state)
105107
// Initialize pubs & subs
106108
plan_publisher_ = create_publisher<nav_msgs::msg::Path>("plan_smoothed", 1);
107109

110+
double action_server_result_timeout;
111+
get_parameter("action_server_result_timeout", action_server_result_timeout);
112+
rcl_action_server_options_t server_options = rcl_action_server_get_default_options();
113+
server_options.result_timeout.nanoseconds = RCL_S_TO_NS(action_server_result_timeout);
114+
108115
// Create the action server that we implement with our smoothPath method
109116
action_server_ = std::make_unique<ActionServer>(
110117
shared_from_this(),
111118
"smooth_path",
112119
std::bind(&SmootherServer::smoothPlan, this),
113120
nullptr,
114121
std::chrono::milliseconds(500),
115-
true);
122+
true, server_options);
116123

117124
return nav2_util::CallbackReturn::SUCCESS;
118125
}

nav2_system_tests/src/system/nav2_system_params.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ bt_navigator:
4646
bt_loop_duration: 10
4747
filter_duration: 0.3
4848
default_server_timeout: 20
49+
action_server_result_timeout: 900.0
4950
navigators: ["navigate_to_pose", "navigate_through_poses"]
5051
navigate_to_pose:
5152
plugin: "nav2_bt_navigator::NavigateToPoseNavigator"
@@ -290,6 +291,7 @@ waypoint_follower:
290291
ros__parameters:
291292
loop_rate: 20
292293
stop_on_failure: false
294+
action_server_result_timeout: 900.0
293295
waypoint_task_executor_plugin: "wait_at_waypoint"
294296
wait_at_waypoint:
295297
plugin: "nav2_waypoint_follower::WaitAtWaypoint"

nav2_waypoint_follower/src/waypoint_follower.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ WaypointFollower::WaypointFollower(const rclcpp::NodeOptions & options)
3737
declare_parameter("stop_on_failure", true);
3838
declare_parameter("loop_rate", 20);
3939

40+
declare_parameter("action_server_result_timeout", 900.0);
41+
4042
declare_parameter("global_frame_id", "map");
4143

4244
nav2_util::declare_parameter_if_not_declared(
@@ -76,6 +78,10 @@ WaypointFollower::on_configure(const rclcpp_lifecycle::State & state)
7678
get_node_waitables_interface(),
7779
"navigate_to_pose", callback_group_);
7880

81+
double action_server_result_timeout = get_parameter("action_server_result_timeout").as_double();
82+
rcl_action_server_options_t server_options = rcl_action_server_get_default_options();
83+
server_options.result_timeout.nanoseconds = RCL_S_TO_NS(action_server_result_timeout);
84+
7985
xyz_action_server_ = std::make_unique<ActionServer>(
8086
get_node_base_interface(),
8187
get_node_clock_interface(),
@@ -84,7 +90,7 @@ WaypointFollower::on_configure(const rclcpp_lifecycle::State & state)
8490
"follow_waypoints", std::bind(
8591
&WaypointFollower::followWaypointsCallback,
8692
this), nullptr, std::chrono::milliseconds(
87-
500), false);
93+
500), false, server_options);
8894

8995
from_ll_to_map_client_ = std::make_unique<
9096
nav2_util::ServiceClient<robot_localization::srv::FromLL,
@@ -102,7 +108,7 @@ WaypointFollower::on_configure(const rclcpp_lifecycle::State & state)
102108
std::bind(
103109
&WaypointFollower::followGPSWaypointsCallback,
104110
this), nullptr, std::chrono::milliseconds(
105-
500), false);
111+
500), false, server_options);
106112

107113
try {
108114
waypoint_task_executor_type_ = nav2_util::get_plugin_type_param(

0 commit comments

Comments
 (0)