Robowflex  v0.1
Making MoveIt Easy
services.h
Go to the documentation of this file.
1 /* Author: Zachary Kingston */
2 
3 #ifndef ROBOWFLEX_MOVEGROUP_SERVICES_
4 #define ROBOWFLEX_MOVEGROUP_SERVICES_
5 
6 #include <ros/node_handle.h>
7 
8 #include <moveit_msgs/MoveGroupActionGoal.h>
9 #include <moveit_msgs/MoveGroupActionResult.h>
10 #include <moveit_msgs/ExecuteTrajectoryAction.h>
11 
12 #include <actionlib/client/simple_action_client.h>
13 
16 
17 namespace robowflex
18 {
19  /** \brief Move group interaction related classes and features.
20  */
21  namespace movegroup
22  {
23  /** \brief A helper class that allows for pulling and pushing of scenes, robots, and trajectories to
24  * move group.
25  */
27  {
28  public:
29  /** \brief A container struct for all relevant information about a motion planning request to move
30  * group.
31  */
32  struct Action
33  {
34  std::string id; ///< Goal ID.
35  ScenePtr scene; ///< Scene used for planning.
36  moveit_msgs::MotionPlanRequest request; ///< Motion planning request.
37  bool success; ///< Planning success.
38  double time; ///< Planning time.
39  moveit_msgs::RobotTrajectory trajectory; ///< Planned trajectory on success.
40 
41  /** \brief Load a recorded action from a YAML file.
42  * \param[in] filename Filename to load from.
43  * \return True on success, false on failure.
44  */
45  bool fromYAMLFile(const std::string &filename);
46 
47  /** \brief Save a recorded action to a YAML file.
48  * \param[in] filename Filename to save as.
49  * \return True on success, false on failure.
50  */
51  bool toYAMLFile(const std::string &filename);
52  };
53 
55 
56  /** \brief Constructor. Sets up service clients.
57  * \param[in] move_group Name of the move group namespace.
58  */
59  MoveGroupHelper(const std::string &move_group = MOVE_GROUP);
60 
61  /** \brief Destructor. Cleans up services.
62  */
64 
65  /** \brief Sets a callback function that is called whenever a motion plan request is serviced by
66  * move group.
67  * \param[in] callback Callback function to call upon move group requests.
68  */
70 
71  /** \brief Executes a planned trajectory through move group.
72  * \param[in] path Path to execute.
73  * \return True on success, false on failure.
74  */
76 
77  /** \brief Pulls the current robot state from move group.
78  * \param[out] robot Robot whose state to set.
79  * \return True on success, false on failure.
80  */
81  bool pullState(RobotPtr robot);
82 
83  /** \brief Pulls the current planning scene from move group.
84  * \param[out] scene Scene to set to the current scene observed by move group.
85  * \return True on success, false on failure.
86  */
87  bool pullScene(ScenePtr scene);
88 
89  /** \brief Pushes the current planning scene to move group.
90  * \param[in] scene Scene to use to set move group's current scene.
91  * \return True on success, false on failure.
92  */
93  bool pushScene(const SceneConstPtr &scene);
94 
95  /** \brief Clears the octomap in the planning scene of the movegroup.
96  * \return True on success, false on failure.
97  */
98  bool clearOctomap();
99 
100  private:
101  /** \brief Callback function for a move group goal.
102  * \param[in] msg Goal message.
103  */
104  void moveGroupGoalCallback(const moveit_msgs::MoveGroupActionGoal &msg);
105 
106  /** \brief Callback function for a move group result.
107  * \param[in] msg Result message.
108  */
109  void moveGroupResultCallback(const moveit_msgs::MoveGroupActionResult &msg);
110 
111  ros::NodeHandle nh_; ///< Node handle.
112  ros::Subscriber goal_sub_; ///< Move group goal subscriber.
113  ros::Subscriber result_sub_; ///< Move group result subscriber.
114  ros::ServiceClient gpsc_; ///< Get planning scene service.
115  ros::ServiceClient apsc_; ///< Apply planning scene service.
116  ros::ServiceClient co_; ///< Clear octomap service.
117 
118  actionlib::SimpleActionClient<moveit_msgs::ExecuteTrajectoryAction> eac_; ///< Execute trajectory
119  ///< client.
120 
121  ResultCallback callback_; ///< Callback function for move group results.
122 
123  std::map<std::string, Action> requests_; ///< Move group requests
124 
125  RobotPtr robot_; ///< Robot on the parameter server used by move group.
126 
127  static const std::string MOVE_GROUP; ///< Name of move_group namespace.
128  static const std::string GET_SCENE; ///< Name of get scene service.
129  static const std::string APPLY_SCENE; ///< Name of apply scene service.
130  static const std::string CLEAR_OCTOMAP; ///< Name of clear octomap service.
131  static const std::string EXECUTE; ///< Name of execute trajectory service.
132  };
133  } // namespace movegroup
134 } // namespace robowflex
135 
136 #endif
A shared pointer wrapper for robowflex::Robot.
A const shared pointer wrapper for robowflex::Scene.
A shared pointer wrapper for robowflex::Scene.
A helper class that allows for pulling and pushing of scenes, robots, and trajectories to move group.
Definition: services.h:27
static const std::string EXECUTE
Name of execute trajectory service.
Definition: services.h:131
MoveGroupHelper(const std::string &move_group=MOVE_GROUP)
Constructor. Sets up service clients.
Definition: services.cpp:74
bool pushScene(const SceneConstPtr &scene)
Pushes the current planning scene to move group.
Definition: services.cpp:182
ResultCallback callback_
Callback function for move group results.
Definition: services.h:121
ros::ServiceClient gpsc_
Get planning scene service.
Definition: services.h:114
std::function< void(Action &)> ResultCallback
Definition: services.h:54
RobotPtr robot_
Robot on the parameter server used by move group.
Definition: services.h:125
ros::ServiceClient co_
Clear octomap service.
Definition: services.h:116
void moveGroupGoalCallback(const moveit_msgs::MoveGroupActionGoal &msg)
Callback function for a move group goal.
Definition: services.cpp:199
bool executeTrajectory(const robot_trajectory::RobotTrajectory &path)
Executes a planned trajectory through move group.
Definition: services.cpp:112
ros::Subscriber result_sub_
Move group result subscriber.
Definition: services.h:113
ros::Subscriber goal_sub_
Move group goal subscriber.
Definition: services.h:112
void setResultCallback(const ResultCallback &callback)
Sets a callback function that is called whenever a motion plan request is serviced by move group.
Definition: services.cpp:107
void moveGroupResultCallback(const moveit_msgs::MoveGroupActionResult &msg)
Callback function for a move group result.
Definition: services.cpp:213
bool pullScene(ScenePtr scene)
Pulls the current planning scene from move group.
Definition: services.cpp:158
~MoveGroupHelper()
Destructor. Cleans up services.
Definition: services.cpp:98
bool pullState(RobotPtr robot)
Pulls the current robot state from move group.
Definition: services.cpp:142
ros::NodeHandle nh_
Node handle.
Definition: services.h:111
static const std::string CLEAR_OCTOMAP
Name of clear octomap service.
Definition: services.h:130
actionlib::SimpleActionClient< moveit_msgs::ExecuteTrajectoryAction > eac_
Definition: services.h:118
static const std::string GET_SCENE
Name of get scene service.
Definition: services.h:128
std::map< std::string, Action > requests_
Move group requests.
Definition: services.h:123
static const std::string APPLY_SCENE
Name of apply scene service.
Definition: services.h:129
static const std::string MOVE_GROUP
Name of move_group namespace.
Definition: services.h:127
ros::ServiceClient apsc_
Apply planning scene service.
Definition: services.h:115
bool clearOctomap()
Clears the octomap in the planning scene of the movegroup.
Definition: services.cpp:191
Functions for loading and animating robots in Blender.
Main namespace. Contains all library classes and functions.
Definition: scene.cpp:25
Functions for loading and animating scenes in Blender.
A container struct for all relevant information about a motion planning request to move group.
Definition: services.h:33
moveit_msgs::MotionPlanRequest request
Motion planning request.
Definition: services.h:36
bool toYAMLFile(const std::string &filename)
Save a recorded action to a YAML file.
Definition: services.cpp:46
bool fromYAMLFile(const std::string &filename)
Load a recorded action from a YAML file.
Definition: services.cpp:24
ScenePtr scene
Scene used for planning.
Definition: services.h:35
moveit_msgs::RobotTrajectory trajectory
Planned trajectory on success.
Definition: services.h:39
void callback(movegroup::MoveGroupHelper::Action &action)
Definition: tapedeck.cpp:20