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 
30 #include "rclcpp_action/types.hpp"
32 
33 namespace rclcpp_action
34 {
36 enum class ResultCode : int8_t
37 {
38  UNKNOWN = action_msgs::msg::GoalStatus::STATUS_UNKNOWN,
39  SUCCEEDED = action_msgs::msg::GoalStatus::STATUS_SUCCEEDED,
40  CANCELED = action_msgs::msg::GoalStatus::STATUS_CANCELED,
41  ABORTED = action_msgs::msg::GoalStatus::STATUS_ABORTED
42 };
43 
44 
45 // Forward declarations
46 template<typename ActionT>
47 class Client;
48 
50 
58 template<typename ActionT>
60 {
61 public:
63 
64  // A wrapper that defines the result of an action
65  typedef struct WrappedResult
66  {
72  typename ActionT::Result::SharedPtr result;
73  } WrappedResult;
74 
75  using Feedback = typename ActionT::Feedback;
76  using Result = typename ActionT::Result;
77  using FeedbackCallback =
78  std::function<void (
81  using ResultCallback = std::function<void (const WrappedResult & result)>;
82 
83  virtual ~ClientGoalHandle();
84 
86  const GoalUUID &
87  get_goal_id() const;
88 
91  get_goal_stamp() const;
92 
94  int8_t
95  get_status();
96 
98  bool
100 
102  bool
103  is_result_aware();
104 
105 private:
106  // The templated Client creates goal handles
107  friend Client<ActionT>;
108 
110  const GoalInfo & info,
111  FeedbackCallback feedback_callback,
112  ResultCallback result_callback);
113 
114  void
115  set_feedback_callback(FeedbackCallback callback);
116 
117  void
118  set_result_callback(ResultCallback callback);
119 
120  void
121  call_feedback_callback(
122  typename ClientGoalHandle<ActionT>::SharedPtr shared_this,
123  typename std::shared_ptr<const Feedback> feedback_message);
124 
126 
136  async_get_result();
137 
139  bool
140  set_result_awareness(bool awareness);
141 
142  void
143  set_status(int8_t status);
144 
145  void
146  set_result(const WrappedResult & wrapped_result);
147 
148  void
149  invalidate(const exceptions::UnawareGoalHandleError & ex);
150 
151  bool
152  is_invalidated() const;
153 
154  GoalInfo info_;
155 
156  std::exception_ptr invalidate_exception_{nullptr};
157 
158  bool is_result_aware_{false};
159  std::promise<WrappedResult> result_promise_;
160  std::shared_future<WrappedResult> result_future_;
161 
162  FeedbackCallback feedback_callback_{nullptr};
163  ResultCallback result_callback_{nullptr};
164  int8_t status_{GoalStatus::STATUS_ACCEPTED};
165 
166  std::mutex handle_mutex_;
167 };
168 } // namespace rclcpp_action
169 
170 #include <rclcpp_action/client_goal_handle_impl.hpp> // NOLINT(build/include_order)
171 #endif // RCLCPP_ACTION__CLIENT_GOAL_HANDLE_HPP_
std::shared_future
std::exception_ptr
rclcpp_action::ClientGoalHandle::WrappedResult
struct rclcpp_action::ClientGoalHandle::WrappedResult WrappedResult
exceptions.hpp
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:59
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:72
std::function< void(typename ClientGoalHandle< ActionT >::SharedPtr, const std::shared_ptr< const Feedback >)>
rclcpp_action
Definition: client.hpp:46
rclcpp_action::ClientGoalHandle::WrappedResult::goal_id
GoalUUID goal_id
The unique identifier of the goal.
Definition: client_goal_handle.hpp:68
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:115
rclcpp_action::ClientGoalHandle::WrappedResult
Definition: client_goal_handle.hpp:65
rclcpp_action::exceptions::UnawareGoalHandleError
Definition: exceptions.hpp:34
rclcpp_action::ClientGoalHandle::Feedback
typename ActionT::Feedback Feedback
Definition: client_goal_handle.hpp:75
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:70
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:99
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:123
std::mutex
rclcpp_action::ClientGoalHandle::ResultCallback
std::function< void(const WrappedResult &result)> ResultCallback
Definition: client_goal_handle.hpp:81
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:80
rclcpp_action::ResultCode
ResultCode
The possible statuses that an action goal can finish with.
Definition: client_goal_handle.hpp:36
rclcpp_action::ResultCode::UNKNOWN
@ UNKNOWN
macros.hpp
rclcpp_action::Client
Action Client.
Definition: client.hpp:262
rclcpp_action::ClientGoalHandle::Result
typename ActionT::Result Result
Definition: client_goal_handle.hpp:76
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