rclcpp_action
master
C++ ROS Action Client Library
|
Go to the documentation of this file.
15 #ifndef RCLCPP_ACTION__SERVER_HPP_
16 #define RCLCPP_ACTION__SERVER_HPP_
18 #include <rcl_action/action_server.h>
19 #include <rosidl_runtime_c/action_type_support_struct.h>
20 #include <rosidl_typesupport_cpp/action_type_support.hpp>
30 #include <unordered_map>
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,
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)
341 typename ActionT::Impl::SendGoalService::Request>(message);
345 auto ros_response = std::make_shared<typename ActionT::Impl::SendGoalService::Response>();
357 auto element = goal_handles_.find(uuid);
358 if (element != goal_handles_.end()) {
361 resp = handle_cancel_(goal_handle);
363 goal_handle->_cancel_goal();
387 shared_this->publish_result(uuid, result_message);
389 shared_this->publish_status();
391 shared_this->notify_goal_terminal_state();
394 shared_this->goal_handles_.erase(uuid);
406 shared_this->publish_status();
416 shared_this->publish_feedback(std::static_pointer_cast<void>(feedback_msg));
420 const typename ActionT::Impl::SendGoalService::Request>(goal_request_message);
424 rcl_goal_handle, uuid, goal, on_terminal_state, on_executing,
publish_feedback));
427 goal_handles_[uuid] = goal_handle;
429 handle_accepted_(goal_handle);
437 static_cast<typename ActionT::Impl::SendGoalService::Request *
>(message)->goal_id.uuid;
452 static_cast<typename ActionT::Impl::GetResultService::Request *
>(message)->goal_id.uuid;
466 auto result = std::make_shared<typename ActionT::Impl::GetResultService::Response>();
467 result->status = status;
468 return std::static_pointer_cast<void>(result);
486 #endif // RCLCPP_ACTION__SERVER_HPP_
RCLCPP_ACTION_PUBLIC void publish_feedback(std::shared_ptr< void > feedback_msg)
virtual RCLCPP_ACTION_PUBLIC std::shared_ptr< void > create_goal_request()=0
GoalResponse
A response returned by an action server callback when a goal is requested.
Definition: server.hpp:43
@ ACCEPT_AND_EXECUTE
The server accepts the goal, and is going to begin execution immediately.
RCLCPP_ACTION_PUBLIC void notify_goal_terminal_state()
RCLCPP_ACTION_PUBLIC size_t get_number_of_ready_timers() override
virtual RCLCPP_ACTION_PUBLIC CancelResponse call_handle_cancel_callback(const GoalUUID &uuid)=0
virtual ~Server()=default
RCLCPP_ACTION_PUBLIC void publish_status()
@ REJECT
The server will not try to cancel the goal.
std::shared_ptr< void > create_result_request() override
Definition: server.hpp:457
virtual RCLCPP_ACTION_PUBLIC std::pair< GoalResponse, std::shared_ptr< void > > call_handle_goal_callback(GoalUUID &, std::shared_ptr< void > request)=0
RCLCPP_ACTION_PUBLIC void execute() override
std::shared_ptr< void > create_goal_request() override
Definition: server.hpp:442
RCLCPP_ACTION_PUBLIC bool is_ready(rcl_wait_set_t *) override
Definition: client.hpp:44
GoalUUID get_goal_id_from_goal_request(void *message) override
Definition: server.hpp:434
std::shared_ptr< void > create_result_response(decltype(action_msgs::msg::GoalStatus::status) status) override
Definition: server.hpp:464
virtual RCLCPP_ACTION_PUBLIC std::shared_ptr< void > create_result_request()=0
virtual RCLCPP_ACTION_PUBLIC GoalUUID get_goal_id_from_goal_request(void *message)=0
RCLCPP_ACTION_PUBLIC size_t get_number_of_ready_guard_conditions() override
T shared_from_this(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
@ REJECT
The goal is rejected and will not be executed.
virtual RCLCPP_ACTION_PUBLIC ~ServerBase()
T static_pointer_cast(T... args)
std::function< CancelResponse(std::shared_ptr< ServerGoalHandle< ActionT > >)> CancelCallback
Signature of a callback that accepts or rejects requests to cancel a goal.
Definition: server.hpp:277
virtual RCLCPP_ACTION_PUBLIC void call_goal_accepted_callback(std::shared_ptr< rcl_action_goal_handle_t > rcl_goal_handle, GoalUUID uuid, std::shared_ptr< void > goal_request_message)=0
virtual RCLCPP_ACTION_PUBLIC std::shared_ptr< void > create_result_response(decltype(action_msgs::msg::GoalStatus::status) status)=0
Action Server.
Definition: server.hpp:268
RCLCPP_ACTION_PUBLIC size_t get_number_of_ready_clients() override
CancelResponse call_handle_cancel_callback(const GoalUUID &uuid) override
Definition: server.hpp:353
std::function< GoalResponse(const GoalUUID &, std::shared_ptr< const typename ActionT::Goal >)> GoalCallback
Signature of a callback that accepts or rejects goal requests.
Definition: server.hpp:275
@ ACCEPT
The server has agreed to try to cancel the goal.
@ ACCEPT_AND_DEFER
The server accepts the goal, and is going to execute it later.
RCLCPP_ACTION_PUBLIC size_t get_number_of_ready_subscriptions() override
CancelResponse
A response returned by an action server callback when a goal has been asked to be canceled.
Definition: server.hpp:54
#define RCLCPP_ACTION_PUBLIC
Definition: visibility_control.hpp:50
virtual RCLCPP_ACTION_PUBLIC GoalUUID get_goal_id_from_result_request(void *message)=0
RCLCPP_ACTION_PUBLIC size_t get_number_of_ready_services() override
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...)
void call_goal_accepted_callback(std::shared_ptr< rcl_action_goal_handle_t > rcl_goal_handle, GoalUUID uuid, std::shared_ptr< void > goal_request_message) override
Definition: server.hpp:372
GoalUUID get_goal_id_from_result_request(void *message) override
Definition: server.hpp:449
Definition: server.hpp:70
std::pair< GoalResponse, std::shared_ptr< void > > call_handle_goal_callback(GoalUUID &uuid, std::shared_ptr< void > message) override
Definition: server.hpp:338
RCLCPP_ACTION_PUBLIC bool add_to_wait_set(rcl_wait_set_t *wait_set) override
RCLCPP_ACTION_PUBLIC ServerBase(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 rosidl_action_type_support_t *type_support, const rcl_action_server_options_t &options)
RCLCPP_ACTION_PUBLIC void publish_result(const GoalUUID &uuid, std::shared_ptr< void > result_msg)
std::function< void(std::shared_ptr< ServerGoalHandle< ActionT > >)> AcceptedCallback
Signature of a callback that is used to notify when the goal has been accepted.
Definition: server.hpp:279
Class to interact with goals on a server.
Definition: server_goal_handle.hpp:135