Robowflex  v0.1
Making MoveIt Easy
robowflex::movegroup::MoveGroupHelper Class Reference

A helper class that allows for pulling and pushing of scenes, robots, and trajectories to move group. More...

#include <services.h>

Classes

struct  Action
 A container struct for all relevant information about a motion planning request to move group. More...
 

Public Types

typedef std::function< void(Action &)> ResultCallback
 

Public Member Functions

 MoveGroupHelper (const std::string &move_group=MOVE_GROUP)
 Constructor. Sets up service clients. More...
 
 ~MoveGroupHelper ()
 Destructor. Cleans up services. More...
 
void setResultCallback (const ResultCallback &callback)
 Sets a callback function that is called whenever a motion plan request is serviced by move group. More...
 
bool executeTrajectory (const robot_trajectory::RobotTrajectory &path)
 Executes a planned trajectory through move group. More...
 
bool pullState (RobotPtr robot)
 Pulls the current robot state from move group. More...
 
bool pullScene (ScenePtr scene)
 Pulls the current planning scene from move group. More...
 
bool pushScene (const SceneConstPtr &scene)
 Pushes the current planning scene to move group. More...
 
bool clearOctomap ()
 Clears the octomap in the planning scene of the movegroup. More...
 

Private Member Functions

void moveGroupGoalCallback (const moveit_msgs::MoveGroupActionGoal &msg)
 Callback function for a move group goal. More...
 
void moveGroupResultCallback (const moveit_msgs::MoveGroupActionResult &msg)
 Callback function for a move group result. More...
 

Private Attributes

ros::NodeHandle nh_
 Node handle. More...
 
ros::Subscriber goal_sub_
 Move group goal subscriber. More...
 
ros::Subscriber result_sub_
 Move group result subscriber. More...
 
ros::ServiceClient gpsc_
 Get planning scene service. More...
 
ros::ServiceClient apsc_
 Apply planning scene service. More...
 
ros::ServiceClient co_
 Clear octomap service. More...
 
actionlib::SimpleActionClient< moveit_msgs::ExecuteTrajectoryAction > eac_
 
ResultCallback callback_
 Callback function for move group results. More...
 
std::map< std::string, Actionrequests_
 Move group requests. More...
 
RobotPtr robot_
 Robot on the parameter server used by move group. More...
 

Static Private Attributes

static const std::string MOVE_GROUP {"/move_group"}
 Name of move_group namespace. More...
 
static const std::string GET_SCENE {"get_planning_scene"}
 Name of get scene service. More...
 
static const std::string APPLY_SCENE {"apply_planning_scene"}
 Name of apply scene service. More...
 
static const std::string CLEAR_OCTOMAP {"clear_octomap"}
 Name of clear octomap service. More...
 
static const std::string EXECUTE {"/execute_trajectory"}
 Name of execute trajectory service. More...
 

Detailed Description

A helper class that allows for pulling and pushing of scenes, robots, and trajectories to move group.

Definition at line 26 of file services.h.

Member Typedef Documentation

◆ ResultCallback

Constructor & Destructor Documentation

◆ MoveGroupHelper()

MoveGroupHelper::MoveGroupHelper ( const std::string move_group = MOVE_GROUP)

Constructor. Sets up service clients.

Parameters
[in]move_groupName of the move group namespace.

Definition at line 74 of file services.cpp.

75  : nh_("/")
76  , goal_sub_(nh_.subscribe(move_group + "/goal", 10, &MoveGroupHelper::moveGroupGoalCallback, this))
77  , result_sub_(nh_.subscribe(move_group + "/result", 10, &MoveGroupHelper::moveGroupResultCallback, this))
78  , gpsc_(nh_.serviceClient<moveit_msgs::GetPlanningScene>(GET_SCENE, true))
79  , apsc_(nh_.serviceClient<moveit_msgs::ApplyPlanningScene>(APPLY_SCENE, true))
80  , co_(nh_.serviceClient<std_srvs::Empty>(CLEAR_OCTOMAP, true))
81  , eac_(nh_, EXECUTE, true)
82  , robot_(std::make_shared<ParamRobot>())
83 {
84  RBX_INFO("Waiting for %s to connect...", EXECUTE);
85  eac_.waitForServer();
86  RBX_INFO("%s connected!", EXECUTE);
87  RBX_INFO("Waiting for %s to connect...", GET_SCENE);
88  gpsc_.waitForExistence();
89  RBX_INFO("%s connected!", GET_SCENE);
90  RBX_INFO("Waiting for %s to connect...", APPLY_SCENE);
91  apsc_.waitForExistence();
92  RBX_INFO("%s connected!", APPLY_SCENE);
93  RBX_INFO("Waiting for %s to connect...", CLEAR_OCTOMAP);
94  co_.waitForExistence();
95  RBX_INFO("%s connected!", CLEAR_OCTOMAP);
96 }
static const std::string EXECUTE
Name of execute trajectory service.
Definition: services.h:131
ros::ServiceClient gpsc_
Get planning scene service.
Definition: services.h:114
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
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 moveGroupResultCallback(const moveit_msgs::MoveGroupActionResult &msg)
Callback function for a move group result.
Definition: services.cpp:213
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
static const std::string APPLY_SCENE
Name of apply scene service.
Definition: services.h:129
ros::ServiceClient apsc_
Apply planning scene service.
Definition: services.h:115
#define RBX_INFO(fmt,...)
Output a info logging message.
Definition: log.h:118

◆ ~MoveGroupHelper()

MoveGroupHelper::~MoveGroupHelper ( )

Destructor. Cleans up services.

Definition at line 98 of file services.cpp.

99 {
100  goal_sub_.shutdown();
101  result_sub_.shutdown();
102  gpsc_.shutdown();
103  apsc_.shutdown();
104  co_.shutdown();
105 }

Member Function Documentation

◆ clearOctomap()

bool MoveGroupHelper::clearOctomap ( )

Clears the octomap in the planning scene of the movegroup.

Returns
True on success, false on failure.

Definition at line 191 of file services.cpp.

192 {
193  std_srvs::EmptyRequest request;
194  std_srvs::EmptyResponse response;
195 
196  return co_.call(request, response);
197 }

◆ executeTrajectory()

bool MoveGroupHelper::executeTrajectory ( const robot_trajectory::RobotTrajectory path)

Executes a planned trajectory through move group.

Parameters
[in]pathPath to execute.
Returns
True on success, false on failure.

Definition at line 112 of file services.cpp.

113 {
114  if (!eac_.isServerConnected())
115  return false;
116 
117  moveit_msgs::ExecuteTrajectoryGoal goal;
118 
119  // Check if a Trajectory is time parameterized, with some goofiness for indigo.
120 #if ROBOWFLEX_AT_LEAST_KINETIC
121  double value = path.getWayPointDurationFromStart(path.getWayPointCount());
122 #else
123  double value = path.getWaypointDurationFromStart(path.getWayPointCount());
124 #endif
125 
126  if (value == 0)
127  {
128  RBX_ERROR("Trajectory is not parameterized and cannot be executed! did you use "
129  "Trajectory::computeTimeParameterization?");
130  return false;
131  }
132 
133  path.getRobotTrajectoryMsg(goal.trajectory);
134 
135  eac_.sendGoal(goal);
136  if (!eac_.waitForResult())
137  RBX_INFO("ExecuteTrajectory action returned early");
138 
139  return eac_.getState() == actionlib::SimpleClientGoalState::SUCCEEDED;
140 }
MOVEIT_DEPRECATED double getWaypointDurationFromStart(std::size_t index) const
double getWayPointDurationFromStart(std::size_t index) const
std::size_t getWayPointCount() const
void getRobotTrajectoryMsg(moveit_msgs::RobotTrajectory &trajectory) const
#define RBX_ERROR(fmt,...)
Output a error logging message.
Definition: log.h:102

◆ moveGroupGoalCallback()

void MoveGroupHelper::moveGroupGoalCallback ( const moveit_msgs::MoveGroupActionGoal &  msg)
private

Callback function for a move group goal.

Parameters
[in]msgGoal message.

Definition at line 199 of file services.cpp.

200 {
201  const std::string &id = msg.goal_id.id;
202  RBX_DEBUG("Intercepted request goal ID: `%s`", id);
203 
204  Action action;
205  action.scene.reset(new Scene(robot_));
206  pullScene(action.scene);
207  action.scene->useMessage(msg.goal.planning_options.planning_scene_diff);
208  action.request = msg.goal.request;
209 
210  requests_.emplace(id, action);
211 }
Wrapper class around the planning scene and collision geometry.
Definition: scene.h:48
bool pullScene(ScenePtr scene)
Pulls the current planning scene from move group.
Definition: services.cpp:158
std::map< std::string, Action > requests_
Move group requests.
Definition: services.h:123
#define RBX_DEBUG(fmt,...)
Output a debug logging message.
Definition: log.h:126

◆ moveGroupResultCallback()

void MoveGroupHelper::moveGroupResultCallback ( const moveit_msgs::MoveGroupActionResult &  msg)
private

Callback function for a move group result.

Parameters
[in]msgResult message.

Definition at line 213 of file services.cpp.

214 {
215  const std::string &id = msg.status.goal_id.id;
216 
217  auto request = requests_.find(id);
218  if (request == requests_.end())
219  {
220  RBX_WARN("Intercepted unknown request response ID: `%s`", id);
221  return;
222  }
223 
224  RBX_DEBUG("Intercepted request response ID: `%s`", id);
225 
226  Action &action = request->second;
227  action.id = id;
228  action.success = msg.result.error_code.val == moveit_msgs::MoveItErrorCodes::SUCCESS;
229  action.time = msg.result.planning_time;
230  action.trajectory = msg.result.planned_trajectory;
231 
232  if (callback_)
233  callback_(action);
234 
235  requests_.erase(request);
236 }
ResultCallback callback_
Callback function for move group results.
Definition: services.h:121
#define RBX_WARN(fmt,...)
Output a warning logging message.
Definition: log.h:110

◆ pullScene()

bool MoveGroupHelper::pullScene ( ScenePtr  scene)

Pulls the current planning scene from move group.

Parameters
[out]sceneScene to set to the current scene observed by move group.
Returns
True on success, false on failure.

Definition at line 158 of file services.cpp.

159 {
160  moveit_msgs::GetPlanningScene::Request request;
161  moveit_msgs::GetPlanningScene::Response response;
162  request.components.components = moveit_msgs::PlanningSceneComponents::SCENE_SETTINGS |
163  moveit_msgs::PlanningSceneComponents::ROBOT_STATE |
164  moveit_msgs::PlanningSceneComponents::ROBOT_STATE_ATTACHED_OBJECTS |
165  moveit_msgs::PlanningSceneComponents::WORLD_OBJECT_NAMES |
166  moveit_msgs::PlanningSceneComponents::WORLD_OBJECT_GEOMETRY |
167  moveit_msgs::PlanningSceneComponents::OCTOMAP |
168  moveit_msgs::PlanningSceneComponents::TRANSFORMS |
169  moveit_msgs::PlanningSceneComponents::ALLOWED_COLLISION_MATRIX |
170  moveit_msgs::PlanningSceneComponents::LINK_PADDING_AND_SCALING |
171  moveit_msgs::PlanningSceneComponents::OBJECT_COLORS;
172 
173  if (gpsc_.call(request, response))
174  {
175  scene->useMessage(response.scene);
176  return true;
177  }
178 
179  return false;
180 }
Functions for loading and animating scenes in Blender.

◆ pullState()

bool MoveGroupHelper::pullState ( RobotPtr  robot)

Pulls the current robot state from move group.

Parameters
[out]robotRobot whose state to set.
Returns
True on success, false on failure.

Definition at line 142 of file services.cpp.

143 {
144  moveit_msgs::GetPlanningScene::Request request;
145  moveit_msgs::GetPlanningScene::Response response;
146  request.components.components = moveit_msgs::PlanningSceneComponents::ROBOT_STATE |
147  moveit_msgs::PlanningSceneComponents::ROBOT_STATE_ATTACHED_OBJECTS;
148 
149  if (gpsc_.call(request, response))
150  {
151  robot->setState(response.scene.robot_state);
152  return true;
153  }
154 
155  return false;
156 }
Functions for loading and animating robots in Blender.

◆ pushScene()

bool MoveGroupHelper::pushScene ( const SceneConstPtr scene)

Pushes the current planning scene to move group.

Parameters
[in]sceneScene to use to set move group's current scene.
Returns
True on success, false on failure.

Definition at line 182 of file services.cpp.

183 {
184  moveit_msgs::ApplyPlanningScene::Request request;
185  moveit_msgs::ApplyPlanningScene::Response response;
186  request.scene = scene->getMessage();
187 
188  return apsc_.call(request, response);
189 }

◆ setResultCallback()

void MoveGroupHelper::setResultCallback ( const ResultCallback callback)

Sets a callback function that is called whenever a motion plan request is serviced by move group.

Parameters
[in]callbackCallback function to call upon move group requests.

Definition at line 107 of file services.cpp.

108 {
110 }
void callback(movegroup::MoveGroupHelper::Action &action)
Definition: tapedeck.cpp:20

Member Data Documentation

◆ APPLY_SCENE

const std::string MoveGroupHelper::APPLY_SCENE {"apply_planning_scene"}
staticprivate

Name of apply scene service.

Definition at line 129 of file services.h.

◆ apsc_

ros::ServiceClient robowflex::movegroup::MoveGroupHelper::apsc_
private

Apply planning scene service.

Definition at line 115 of file services.h.

◆ callback_

ResultCallback robowflex::movegroup::MoveGroupHelper::callback_
private

Callback function for move group results.

Definition at line 121 of file services.h.

◆ CLEAR_OCTOMAP

const std::string MoveGroupHelper::CLEAR_OCTOMAP {"clear_octomap"}
staticprivate

Name of clear octomap service.

Definition at line 130 of file services.h.

◆ co_

ros::ServiceClient robowflex::movegroup::MoveGroupHelper::co_
private

Clear octomap service.

Definition at line 116 of file services.h.

◆ eac_

actionlib::SimpleActionClient<moveit_msgs::ExecuteTrajectoryAction> robowflex::movegroup::MoveGroupHelper::eac_
private

Execute trajectory client.

Definition at line 118 of file services.h.

◆ EXECUTE

const std::string MoveGroupHelper::EXECUTE {"/execute_trajectory"}
staticprivate

Name of execute trajectory service.

Definition at line 131 of file services.h.

◆ GET_SCENE

const std::string MoveGroupHelper::GET_SCENE {"get_planning_scene"}
staticprivate

Name of get scene service.

Definition at line 128 of file services.h.

◆ goal_sub_

ros::Subscriber robowflex::movegroup::MoveGroupHelper::goal_sub_
private

Move group goal subscriber.

Definition at line 112 of file services.h.

◆ gpsc_

ros::ServiceClient robowflex::movegroup::MoveGroupHelper::gpsc_
private

Get planning scene service.

Definition at line 114 of file services.h.

◆ MOVE_GROUP

const std::string MoveGroupHelper::MOVE_GROUP {"/move_group"}
staticprivate

Name of move_group namespace.

MoveGroupHelper

Definition at line 127 of file services.h.

◆ nh_

ros::NodeHandle robowflex::movegroup::MoveGroupHelper::nh_
private

Node handle.

Definition at line 111 of file services.h.

◆ requests_

std::map<std::string, Action> robowflex::movegroup::MoveGroupHelper::requests_
private

Move group requests.

Definition at line 123 of file services.h.

◆ result_sub_

ros::Subscriber robowflex::movegroup::MoveGroupHelper::result_sub_
private

Move group result subscriber.

Definition at line 113 of file services.h.

◆ robot_

RobotPtr robowflex::movegroup::MoveGroupHelper::robot_
private

Robot on the parameter server used by move group.

Definition at line 125 of file services.h.


The documentation for this class was generated from the following files: