1 #ifndef _RAPID_ROS_ACTION_CLIENT_H_
2 #define _RAPID_ROS_ACTION_CLIENT_H_
6 #include "actionlib/action_definition.h"
7 #include "actionlib/client/simple_action_client.h"
8 #include "actionlib/client/simple_client_goal_state.h"
16 template <
class ActionSpec>
19 ACTION_DEFINITION(ActionSpec)
24 virtual actionlib::SimpleClientGoalState
getState() = 0;
26 virtual void sendGoal(
const Goal& goal) = 0;
28 const ros::Duration& timeout = ros::Duration(0, 0)) = 0;
30 const ros::Duration& timeout = ros::Duration(0, 0)) = 0;
34 template <
class ActionSpec>
37 ACTION_DEFINITION(ActionSpec)
38 actionlib::SimpleActionClient<ActionSpec> client_;
41 ActionClient(
const std::string& name,
bool spin_thread =
true);
43 actionlib::SimpleClientGoalState
getState();
46 bool waitForResult(
const ros::Duration& timeout = ros::Duration(0, 0));
47 bool waitForServer(
const ros::Duration& timeout = ros::Duration(0, 0));
56 template <
class ActionSpec>
59 ACTION_DEFINITION(ActionSpec)
62 ros::Duration result_delay_;
63 ros::Duration server_delay_;
64 actionlib::SimpleClientGoalState state_;
65 bool is_server_connected_;
71 actionlib::SimpleClientGoalState
getState();
74 bool waitForResult(
const ros::Duration& timeout = ros::Duration(0, 0));
75 bool waitForServer(
const ros::Duration& timeout = ros::Duration(0, 0));
81 void set_result(
const Result& result) { result_ = result; }
85 is_server_connected_ = connected;
89 void set_state(
const actionlib::SimpleClientGoalState& state) {
96 template <
class ActionSpec>
99 : client_(name, spin_thread) {}
101 template <
class ActionSpec>
104 return client_.getResult();
107 template <
class ActionSpec>
109 return client_.getState();
112 template <
class ActionSpec>
114 return client_.isServerConnected();
117 template <
class ActionSpec>
119 client_.sendGoal(goal);
122 template <
class ActionSpec>
124 return client_.waitForResult(timeout);
127 template <
class ActionSpec>
129 return client_.waitForServer(timeout);
133 template <
class ActionSpec>
137 state_(actionlib::SimpleClientGoalState::SUCCEEDED),
140 is_server_connected_(true) {}
142 template <
class ActionSpec>
145 return ResultConstPtr(
new Result(result_));
148 template <
class ActionSpec>
153 template <
class ActionSpec>
155 if (!is_server_connected_) {
156 ROS_ERROR(
"Sent goal even though server isn't connected!");
162 template <
class ActionSpec>
164 if (!is_server_connected_) {
165 ROS_ERROR(
"Waiting for result even though server isn't connected!");
168 if (timeout > result_delay_) {
171 if (timeout.isZero()) {
173 "waitForResult given infinite timeout, are you sure that's what you "
180 template <
class ActionSpec>
182 if (!is_server_connected_) {
183 ROS_ERROR(
"Waiting for server even though server isn't connected!");
186 if (timeout > server_delay_) {
189 if (timeout.isZero()) {
191 "waitForServer given infinite timeout, are you sure that's what you "
198 #endif // _RAPID_ROS_ACTION_CLIENT_H_
bool set_server_connected(bool connected)
void sendGoal(const Goal &goal)
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0))
void sendGoal(const Goal &goal)
bool waitForResult(const ros::Duration &timeout=ros::Duration(0, 0))
actionlib::SimpleClientGoalState getState()
void set_server_delay(const ros::Duration &delay)
virtual bool isServerConnected()=0
void set_state(const actionlib::SimpleClientGoalState &state)
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0))
ResultConstPtr getResult()
void set_result_delay(const ros::Duration &delay)
virtual ResultConstPtr getResult()=0
virtual actionlib::SimpleClientGoalState getState()=0
virtual void sendGoal(const Goal &goal)=0
actionlib::SimpleClientGoalState getState()
bool waitForResult(const ros::Duration &timeout=ros::Duration(0, 0))
ActionClient(const std::string &name, bool spin_thread=true)
ResultConstPtr getResult()
virtual bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0))=0
virtual bool waitForResult(const ros::Duration &timeout=ros::Duration(0, 0))=0
void set_result(const Result &result)
virtual ~ActionClientInterface()