rclcpp_action  master
C++ ROS Action Client Library
client_goal_handle.hpp
Go to the documentation of this file.
1 // Copyright 2018 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCLCPP_ACTION__CLIENT_GOAL_HANDLE_HPP_
16 #define RCLCPP_ACTION__CLIENT_GOAL_HANDLE_HPP_
17 
18 #include <rcl_action/action_client.h>
19 
20 #include <action_msgs/msg/goal_status.hpp>
21 #include <rclcpp/macros.hpp>
22 #include <rclcpp/time.hpp>
23 
24 #include <functional>
25 #include <future>
26 #include <memory>
27 #include <mutex>
28 
29 #include "rclcpp_action/types.hpp"
31 
32 namespace rclcpp_action
33 {
35 enum class ResultCode : int8_t
36 {
37  UNKNOWN = action_msgs::msg::GoalStatus::STATUS_UNKNOWN,
38  SUCCEEDED = action_msgs::msg::GoalStatus::STATUS_SUCCEEDED,
39  CANCELED = action_msgs::msg::GoalStatus::STATUS_CANCELED,
40  ABORTED = action_msgs::msg::GoalStatus::STATUS_ABORTED
41 };
42 
43 
44 // Forward declarations
45 template<typename ActionT>
46 class Client;
47 
49 
57 template<typename ActionT>
59 {
60 public:
62 
63  // A wrapper that defines the result of an action
64  typedef struct WrappedResult
65  {
71  typename ActionT::Result::SharedPtr result;
72  } WrappedResult;
73 
74  using Feedback = typename ActionT::Feedback;
75  using Result = typename ActionT::Result;
76  using FeedbackCallback =
77  std::function<void (
80  using ResultCallback = std::function<void (const WrappedResult & result)>;
81 
82  virtual ~ClientGoalHandle();
83 
85  const GoalUUID &
86  get_goal_id() const;
87 
90  get_goal_stamp() const;
91 
93 
104  [[deprecated("use rclcpp_action::Client::async_get_result() instead")]]
106  async_result();
107 
109  int8_t
110  get_status();
111 
113  bool
115 
117  bool
118  is_result_aware();
119 
120 private:
121  // The templated Client creates goal handles
122  friend Client<ActionT>;
123 
125  const GoalInfo & info,
126  FeedbackCallback feedback_callback,
127  ResultCallback result_callback);
128 
129  void
130  set_feedback_callback(FeedbackCallback callback);
131 
132  void
133  set_result_callback(ResultCallback callback);
134 
135  void
136  call_feedback_callback(
137  typename ClientGoalHandle<ActionT>::SharedPtr shared_this,
138  typename std::shared_ptr<const Feedback> feedback_message);
139 
141 
151  async_get_result();
152 
154  bool
155  set_result_awareness(bool awareness);
156 
157  void
158  set_status(int8_t status);
159 
160  void
161  set_result(const WrappedResult & wrapped_result);
162 
163  void
164  invalidate();
165 
166  GoalInfo info_;
167 
168  bool is_result_aware_{false};
169  std::promise<WrappedResult> result_promise_;
170  std::shared_future<WrappedResult> result_future_;
171 
172  FeedbackCallback feedback_callback_{nullptr};
173  ResultCallback result_callback_{nullptr};
174  int8_t status_{GoalStatus::STATUS_ACCEPTED};
175 
176  std::mutex handle_mutex_;
177 };
178 } // namespace rclcpp_action
179 
180 #include <rclcpp_action/client_goal_handle_impl.hpp> // NOLINT(build/include_order)
181 #endif // RCLCPP_ACTION__CLIENT_GOAL_HANDLE_HPP_
std::shared_future
rclcpp_action::ClientGoalHandle::WrappedResult
struct rclcpp_action::ClientGoalHandle::WrappedResult WrappedResult
rclcpp_action::ClientGoalHandle::get_goal_id
const GoalUUID & get_goal_id() const
Get the unique ID for the goal.
Definition: client_goal_handle_impl.hpp:46
std::shared_ptr
rclcpp_action::ClientGoalHandle
Class for interacting with goals sent from action clients.
Definition: client_goal_handle.hpp:58
types.hpp
std::promise
rclcpp_action::ResultCode::CANCELED
@ CANCELED
rclcpp::Time
rclcpp_action::ClientGoalHandle::WrappedResult::result
ActionT::Result::SharedPtr result
User defined fields sent back with an action.
Definition: client_goal_handle.hpp:71
std::function< void(typename ClientGoalHandle< ActionT >::SharedPtr, const std::shared_ptr< const Feedback >)>
rclcpp_action
Definition: client.hpp:44
rclcpp_action::ClientGoalHandle::WrappedResult::goal_id
GoalUUID goal_id
The unique identifier of the goal.
Definition: client_goal_handle.hpp:67
rclcpp_action::ClientGoalHandle::is_feedback_aware
bool is_feedback_aware()
Check if an action client has subscribed to feedback for the goal.
Definition: client_goal_handle_impl.hpp:122
rclcpp_action::ClientGoalHandle::async_result
std::shared_future< WrappedResult > async_result()
Get a future to the goal result.
Definition: client_goal_handle_impl.hpp:60
rclcpp_action::ClientGoalHandle::WrappedResult
Definition: client_goal_handle.hpp:64
rclcpp_action::ClientGoalHandle::Feedback
typename ActionT::Feedback Feedback
Definition: client_goal_handle.hpp:74
std::array
rclcpp_action::ClientGoalHandle::WrappedResult::code
ResultCode code
A status to indicate if the goal was canceled, aborted, or suceeded.
Definition: client_goal_handle.hpp:69
rclcpp_action::GoalInfo
action_msgs::msg::GoalInfo GoalInfo
Definition: types.hpp:34
rclcpp_action::ClientGoalHandle::~ClientGoalHandle
virtual ~ClientGoalHandle()
Definition: client_goal_handle_impl.hpp:40
rclcpp_action::ResultCode::SUCCEEDED
@ SUCCEEDED
rclcpp_action::ClientGoalHandle::get_status
int8_t get_status()
Get the goal status code.
Definition: client_goal_handle_impl.hpp:106
visibility_control.hpp
rclcpp_action::ResultCode::ABORTED
@ ABORTED
client_goal_handle_impl.hpp
time.hpp
rclcpp_action::ClientGoalHandle::is_result_aware
bool is_result_aware()
Check if an action client has requested the result for the goal.
Definition: client_goal_handle_impl.hpp:130
std::mutex
rclcpp_action::ClientGoalHandle::ResultCallback
std::function< void(const WrappedResult &result)> ResultCallback
Definition: client_goal_handle.hpp:80
RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE
#define RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(...)
rclcpp_action::ClientGoalHandle::FeedbackCallback
std::function< void(typename ClientGoalHandle< ActionT >::SharedPtr, const std::shared_ptr< const Feedback >)> FeedbackCallback
Definition: client_goal_handle.hpp:79
rclcpp_action::ResultCode
ResultCode
The possible statuses that an action goal can finish with.
Definition: client_goal_handle.hpp:35
rclcpp_action::ResultCode::UNKNOWN
@ UNKNOWN
macros.hpp
rclcpp_action::Client
Action Client.
Definition: client.hpp:255
rclcpp_action::ClientGoalHandle::Result
typename ActionT::Result Result
Definition: client_goal_handle.hpp:75
rclcpp_action::ClientGoalHandle::get_goal_stamp
rclcpp::Time get_goal_stamp() const
Get the time when the goal was accepted.
Definition: client_goal_handle_impl.hpp:53