15 #ifndef RCLCPP_ACTION__SERVER_HPP_ 16 #define RCLCPP_ACTION__SERVER_HPP_ 19 #include <rosidl_generator_c/action_type_support_struct.h> 20 #include <rosidl_typesupport_cpp/action_type_support.hpp> 30 #include <unordered_map> 83 get_number_of_ready_subscriptions()
override;
89 get_number_of_ready_timers()
override;
95 get_number_of_ready_clients()
override;
101 get_number_of_ready_services()
override;
107 get_number_of_ready_guard_conditions()
override;
133 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base,
134 rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock,
135 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging,
137 const rosidl_action_type_support_t * type_support,
158 call_handle_cancel_callback(
const GoalID & uuid) = 0;
165 get_goal_id_from_goal_request(
void * message) = 0;
172 create_goal_request() = 0;
179 call_goal_accepted_callback(
188 get_goal_id_from_result_request(
void * message) = 0;
195 create_result_request() = 0;
202 create_result_response(decltype(action_msgs::msg::GoalStatus::status) status) = 0;
212 notify_goal_terminal_state();
232 execute_goal_request_received();
238 execute_cancel_request_received();
244 execute_result_request_received();
250 execute_check_expired_goals();
267 template<
typename ActionT>
308 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base,
309 rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock,
310 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging,
322 rosidl_typesupport_cpp::get_action_type_support_handle<ActionT>(),
324 handle_goal_(handle_goal),
325 handle_cancel_(handle_cancel),
326 handle_accepted_(handle_accepted)
330 virtual ~
Server() =
default;
343 "Assuming user fields were merged with goal request fields");
345 uuid, std::static_pointer_cast<typename ActionT::Goal>(message));
347 auto ros_response = std::make_shared<typename ActionT::GoalRequestService::Response>();
359 auto element = goal_handles_.find(uuid);
360 if (element != goal_handles_.end()) {
363 resp = handle_cancel_(goal_handle);
365 goal_handle->_set_canceling();
389 shared_this->publish_result(uuid, result_message);
391 shared_this->publish_status();
393 shared_this->notify_goal_terminal_state();
396 shared_this->goal_handles_.erase(uuid);
400 [weak_this](
const GoalID & uuid)
408 shared_this->publish_status();
418 shared_this->publish_feedback(std::static_pointer_cast<void>(feedback_msg));
423 rcl_goal_handle, uuid,
424 std::static_pointer_cast<const typename ActionT::Goal>(goal_request_message),
425 on_terminal_state, on_executing, publish_feedback));
428 goal_handles_[uuid] = goal_handle;
430 handle_accepted_(goal_handle);
438 static_cast<typename ActionT::GoalRequestService::Request *
>(message)->action_goal_id.uuid;
453 static_cast<typename ActionT::GoalResultService::Request *
>(message)->action_goal_id.uuid;
467 auto result = std::make_shared<typename ActionT::GoalResultService::Response>();
468 result->action_status = status;
487 #endif // RCLCPP_ACTION__SERVER_HPP_
GoalResponse
A response returned by an action server callback when a goal is requested.
Definition: server.hpp:43
GoalID get_goal_id_from_result_request(void *message) override
Definition: server.hpp:450
std::shared_ptr< void > create_result_response(decltype(action_msgs::msg::GoalStatus::status) status) override
Definition: server.hpp:465
CancelResponse
A response returned by an action server callback when a goal has been asked to be canceled...
Definition: server.hpp:54
std::pair< GoalResponse, std::shared_ptr< void > > call_handle_goal_callback(GoalID &uuid, std::shared_ptr< void > message) override
Definition: server.hpp:338
Action Server.
Definition: server.hpp:268
The server has agreed to try to cancel the goal.
Class to interact with goals on a server.
Definition: server_goal_handle.hpp:135
Definition: server.hpp:70
The goal is rejected and will not be executed.
std::shared_ptr< void > create_goal_request() override
Definition: server.hpp:443
GoalID get_goal_id_from_goal_request(void *message) override
Definition: server.hpp:435
T static_pointer_cast(T... args)
Server(rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base, rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock, rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging, const std::string &name, const rcl_action_server_options_t &options, GoalCallback handle_goal, CancelCallback handle_cancel, AcceptedCallback handle_accepted)
Construct an action server.
Definition: server.hpp:307
#define RCLCPP_ACTION_PUBLIC
Definition: visibility_control.hpp:50
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...)
std::shared_ptr< void > create_result_request() override
Definition: server.hpp:458
The server accepts the goal, and is going to execute it later.
Definition: client.hpp:44
CancelResponse call_handle_cancel_callback(const GoalID &uuid) override
Definition: server.hpp:355
void call_goal_accepted_callback(std::shared_ptr< rcl_action_goal_handle_t > rcl_goal_handle, GoalID uuid, std::shared_ptr< void > goal_request_message) override
Definition: server.hpp:374
The server accepts the goal, and is going to begin execution immediately.