Skip to content

Commit 45d7243

Browse files
committed
abstract action base class
1 parent 21013c1 commit 45d7243

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*********************************************************************
2+
* BSD 3-Clause License
3+
*
4+
* Copyright (c) 2020 PickNik LLC.
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* * Redistributions of source code must retain the above copyright notice, this
11+
* list of conditions and the following disclaimer.
12+
*
13+
* * Redistributions in binary form must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation
15+
* and/or other materials provided with the distribution.
16+
*
17+
* * Neither the name of the copyright holder nor the names of its
18+
* contributors may be used to endorse or promote products derived from
19+
* this software without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*********************************************************************/
32+
33+
/* Author: Boston Cleek
34+
Desc: Abstact class for stages using a simple action client.
35+
*/
36+
37+
#pragma once
38+
39+
#include <memory>
40+
#include <string>
41+
42+
#include <actionlib/client/simple_action_client.h>
43+
44+
45+
namespace moveit {
46+
namespace task_constructor {
47+
48+
/**
49+
* @brief Interface allowing stages to use a simple action client
50+
* @param ActionSpec - action message (action message name + "ACTION")
51+
* @details Some stages may require an action client. This class wraps the
52+
* simple client action interface and exposes event based execution callbacks.
53+
*/
54+
template<class ActionSpec>
55+
class ActionBase
56+
{
57+
private:
58+
ACTION_DEFINITION(ActionSpec);
59+
60+
public:
61+
/**
62+
* @brief Constructor
63+
* @param name - action name
64+
* @param server_timeout - connection to server time out (0 is considered infinite timeout)
65+
* @param goal_timeout - goal to completed time out (0 is considered infinite timeout)
66+
* @param spin_thread - spins a thread to service this action's subscriptions
67+
* @details Initialize the action client and time out parameters
68+
*/
69+
ActionBase(const std::string &name,
70+
double server_timeout = 0.0,
71+
double goal_timeout = 0.0,
72+
bool spin_thread = true);
73+
74+
/* @brief Destructor */
75+
virtual ~ActionBase() = default;
76+
77+
/* @brief Called when goal becomes active */
78+
virtual void activeCallback() = 0;
79+
80+
/**
81+
* @brief Called every time feedback is received for the goal
82+
* @param feedback - pointer to the feedback message
83+
*/
84+
virtual void feedbackCallback(const FeedbackConstPtr &feedback) = 0;
85+
86+
/**
87+
* @brief Called once when the goal completes
88+
* @param state - state info for goal
89+
* @param result - pointer to result message
90+
*/
91+
virtual void doneCallback(const actionlib::SimpleClientGoalState& state,
92+
const ActionResultConstPtr &result) = 0;
93+
94+
protected:
95+
std::unique_ptr<actionlib::SimpleActionClient<ActionSpec>> clientPtr_; // action client
96+
ActionGoal goal_; // goal message
97+
double server_timeout_, goal_timeout_; // connection and goal completed time out
98+
};
99+
100+
101+
} // namespace task_constructor
102+
} // namespace moveit

core/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_library(${PROJECT_NAME}
2+
${PROJECT_INCLUDE}/action_base.h
23
${PROJECT_INCLUDE}/container.h
34
${PROJECT_INCLUDE}/container_p.h
45
${PROJECT_INCLUDE}/cost_queue.h

0 commit comments

Comments
 (0)