Robowflex  v0.1
Making MoveIt Easy
robowflex::Scene Class Reference

Wrapper class around the planning scene and collision geometry. More...

#include <scene.h>

+ Inheritance diagram for robowflex::Scene:

Classes

class  CollisionPluginLoader
 The actual plugin loader for collision plugins. Heavily inspired by code in moveit_ros/planning. More...
 

Public Member Functions

 Scene (const RobotConstPtr &robot)
 Constructor. More...
 
 Scene (const robot_model::RobotModelConstPtr &robot)
 Constructor. More...
 
 Scene (const Scene &scene)
 Copy Constructor. More...
 
void operator= (const Scene &scene)
 Assignment Copy Constructor. More...
 
ScenePtr deepCopy () const
 Deep Copy. More...
 
Getters and Setters
const planning_scene::PlanningScenePtr & getSceneConst () const
 Get a const reference to the planning scene. More...
 
planning_scene::PlanningScenePtr & getScene ()
 Get a reference to the planning scene. More...
 
moveit_msgs::PlanningScene getMessage () const
 Get the message that describes the current planning scene. More...
 
robot_state::RobotState & getCurrentState ()
 Get a reference to the current robot state in the planning scene. More...
 
const robot_state::RobotState & getCurrentStateConst () const
 Get a constant reference to the current robot state in the planning scene. More...
 
collision_detection::AllowedCollisionMatrixgetACM ()
 Get the current allowed collision matrix of the planning scene. More...
 
const collision_detection::AllowedCollisionMatrixgetACMConst () const
 Get the current allowed collision matrix of the planning scene. More...
 
void useMessage (const moveit_msgs::PlanningScene &msg, bool diff=false)
 Set the planning scene to be the same as a message. More...
 
Collision Object Management
void updateCollisionObject (const std::string &name, const GeometryConstPtr &geometry, const RobotPose &pose)
 Adds or updates collision object in the planning scene. If the geometry reference is the same, the collision object is updated. Otherwise, the old object named name is deleted and a new one is created. More...
 
bool hasObject (const std::string &name) const
 Returns true if the object name is in the scene. More...
 
std::vector< std::stringgetCollisionObjects () const
 Returns a list of all the names of collision objects in the scene. More...
 
GeometryPtr getObjectGeometry (const std::string &name) const
 Returns a representation of a collision object in the scene as a Geometry. If the object has multiple geometries, returns the first. More...
 
void removeCollisionObject (const std::string &name)
 Removes an object from the planning scene. More...
 
RobotPose getObjectPose (const std::string &name) const
 Get the current pose of a collision object. If the object has multiple geometries, returns the pose of the first. More...
 
RobotPose getObjectGraspPose (const std::string &name, const RobotPose &offset) const
 Get a pose in the global frame relative to a collision object for grasping. More...
 
bool moveAllObjectsGlobal (const RobotPose &transform)
 Move all objects according to a transform specified in world frame. More...
 
bool moveObjectGlobal (const std::string &name, const RobotPose &transform)
 Move all shapes in an object according to the given transform specified in world frame. More...
 
bool moveObjectLocal (const std::string &name, const RobotPose &transform)
 Move all shapes in an object according to the given transform specified in object frame. If the object has multiple shapes, the first one is considered the local frame. More...
 
RobotPose getFramePose (const std::string &id) const
 Get the pose of a particular frame in the scene. Example, use this to get the pose from /world to /base_link. More...
 
bool setCollisionDetector (const std::string &detector_name) const
 Attempts to set the collision detector plugin used by the scene to name. In MoveIt by default, 'Hybrid' is the only plugin defined. However, you can define your own libraries that contain classes that extend the collision_detection::CollisionPlugin class, and load them here as well. See http://moveit.ros.org/documentation/plugins/#collisionplugin for more details. More...
 
bool attachObjectToState (robot_state::RobotState &state, const std::string &name) const
 Attach the named collision object name to the default end-effector of the given robot state. Only works if there is one end-effector in the system. Uses all end-effector links as allowed touch links. More...
 
bool attachObjectToState (robot_state::RobotState &state, const std::string &name, const std::string &ee_link, const std::vector< std::string > &touch_links) const
 Attach the named collision object name to the link ee_link of the given robot state. More...
 
bool attachObject (const std::string &name)
 Helper function that attaches object to internal state and removes from scene. More...
 
bool attachObject (robot_state::RobotState &state, const std::string &name)
 Helper function that attaches object provided state and removes from scene. More...
 
bool attachObject (robot_state::RobotState &state, const std::string &name, const std::string &ee_link, const std::vector< std::string > &touch_links)
 Helper function that attaches object provided state and removes from scene. More...
 
bool detachObject (const std::string &name)
 Helper function that detaches the object from the internal scene state. More...
 
bool detachObject (robot_state::RobotState &state, const std::string &name)
 Detach an object name from the robot state. More...
 
Checking Collisions
collision_detection::CollisionResult checkCollision (const robot_state::RobotState &state, const collision_detection::CollisionRequest &request={}) const
 Check if a robot state is in collision. More...
 
double distanceToCollision (const robot_state::RobotState &state) const
 Get the distance to collision for a robot state. More...
 
double distanceToObject (const robot_state::RobotState &state, const std::string &object) const
 Get the distance to collision to a specific object. More...
 
double distanceBetweenObjects (const std::string &one, const std::string &two) const
 Get the distance to collision between two collision objects in the scene. More...
 
double distanceACM (const robot_state::RobotState &state, const collision_detection::AllowedCollisionMatrix &acm) const
 Get the distance to collision using an ACM. More...
 
void clearACM (collision_detection::AllowedCollisionMatrix &acm) const
 Disables collision between all entries in the ACM (all robot links and objects in the scene) More...
 
moveit::core::GroupStateValidityCallbackFn getGSVCF (bool verbose) const
 Get the group state validity callback function that uses this scene. More...
 
IO
bool toYAMLFile (const std::string &file) const
 Serialize the current planning scene to a YAML file. More...
 
bool fromYAMLFile (const std::string &file)
 Load a planning scene from a YAML file. More...
 
bool fromOpenRAVEXMLFile (const std::string &file, std::string models_dir="")
 
- Public Member Functions inherited from robowflex::ID
 ID ()
 Constructor. More...
 
const std::stringgetID () const
 Get the unique ID for this object. More...
 
std::size_t getVersion () const
 Get the current version of this object. More...
 
Key getKey () const
 Get this ID as a Key. More...
 
bool operator== (const ID &b) const
 Compare with another ID object. More...
 
bool operator== (const Key &b) const
 Compare with an ID Key. More...
 

Private Member Functions

void fixCollisionObjectFrame (moveit_msgs::PlanningScene &msg)
 Corrects frame mismatches on loaded scenes by using the current root frame instead. More...
 

Private Attributes

CollisionPluginLoaderPtr loader_
 Plugin loader that sets collision detectors for the scene. More...
 
planning_scene::PlanningScenePtr scene_
 Underlying planning scene. More...
 

Additional Inherited Members

- Public Types inherited from robowflex::ID
using Key = std::pair< std::string, std::size_t >
 A snapshot of the state of an ID. Can be compared against another ID. More...
 
- Static Public Member Functions inherited from robowflex::ID
static Key getNullKey ()
 Get a null key for initialization. More...
 
- Protected Member Functions inherited from robowflex::ID
void incrementVersion ()
 Increment the version number of this object. More...
 

Detailed Description

Wrapper class around the planning scene and collision geometry.

The Scene class is a wrapper around MoveIt!'s planning_scene::PlanningScene, providing access to set and manipulate collision objects, attach and detach objects to the robot, and so on. There are also utilities to load and save planning scenes from YAML files (toYAMLFile() and fromYAMLFile()). Note that this class has its own robot state, separate from the one in the provided Robot. Information between this state and the Robot's scratch state are not synchronized, you must do this manually.

Definition at line 47 of file scene.h.

Constructor & Destructor Documentation

◆ Scene() [1/3]

Scene::Scene ( const RobotConstPtr robot)

Constructor.

Parameters
[in]robotRobot to construct planning scene for.

Definition at line 145 of file scene.cpp.

146  : loader_(new CollisionPluginLoader()), scene_(new planning_scene::PlanningScene(robot->getModelConst()))
147 {
148 }
planning_scene::PlanningScenePtr scene_
Underlying planning scene.
Definition: scene.h:351
CollisionPluginLoaderPtr loader_
Plugin loader that sets collision detectors for the scene.
Definition: scene.h:350
Functions for loading and animating robots in Blender.

◆ Scene() [2/3]

Scene::Scene ( const robot_model::RobotModelConstPtr &  robot)

Constructor.

Parameters
[in]robotRobot to construct planning scene for.

Definition at line 150 of file scene.cpp.

151  : loader_(new CollisionPluginLoader()), scene_(new planning_scene::PlanningScene(robot))
152 {
153 }

◆ Scene() [3/3]

Scene::Scene ( const Scene scene)

Copy Constructor.

Parameters
[in]sceneScene to copy.

Definition at line 155 of file scene.cpp.

155  : loader_(new CollisionPluginLoader()), scene_(other.getSceneConst())
156 {
157 }

Member Function Documentation

◆ attachObject() [1/3]

bool Scene::attachObject ( const std::string name)

Helper function that attaches object to internal state and removes from scene.

Parameters
[in]nameName of object to attach to robot and remove from scene.
Returns
True on success, false on failure.

Definition at line 403 of file scene.cpp.

404 {
405  return attachObject(getCurrentState(), name);
406 }
robot_state::RobotState & getCurrentState()
Get a reference to the current robot state in the planning scene.
Definition: scene.cpp:191
bool attachObject(const std::string &name)
Helper function that attaches object to internal state and removes from scene.
Definition: scene.cpp:403

◆ attachObject() [2/3]

bool Scene::attachObject ( robot_state::RobotState &  state,
const std::string name 
)

Helper function that attaches object provided state and removes from scene.

Parameters
[in]nameName of object to attach to robot and remove from scene.
Returns
True on success, false on failure.

Definition at line 408 of file scene.cpp.

409 {
410  if (attachObjectToState(state, name))
411  {
412  removeCollisionObject(name);
413  return true;
414  }
415 
416  return false;
417 }
void removeCollisionObject(const std::string &name)
Removes an object from the planning scene.
Definition: scene.cpp:265
bool attachObjectToState(robot_state::RobotState &state, const std::string &name) const
Attach the named collision object name to the default end-effector of the given robot state....
Definition: scene.cpp:354

◆ attachObject() [3/3]

bool Scene::attachObject ( robot_state::RobotState &  state,
const std::string name,
const std::string ee_link,
const std::vector< std::string > &  touch_links 
)

Helper function that attaches object provided state and removes from scene.

Parameters
[in]stateState of the robot to attach to.
[in]nameName of object to attach to.
[in]ee_linkLink to attach object to.
[in]touch_linksLinks the object is allowed to touch.
Returns
True on success, false on failure.

Definition at line 419 of file scene.cpp.

421 {
422  if (attachObjectToState(state, name, ee_link, touch_links))
423  {
424  removeCollisionObject(name);
425  return true;
426  }
427 
428  return false;
429 }

◆ attachObjectToState() [1/2]

bool Scene::attachObjectToState ( robot_state::RobotState &  state,
const std::string name 
) const

Attach the named collision object name to the default end-effector of the given robot state. Only works if there is one end-effector in the system. Uses all end-effector links as allowed touch links.

Parameters
[in]nameName of collision to attach.
[in]stateState of robot the object will be attached to
Returns
True on success, false on failure.

Definition at line 354 of file scene.cpp.

355 {
356  const auto &robot = state.getRobotModel();
357  const auto &ee = robot->getEndEffectors();
358 
359  // One end-effector
360  if (ee.size() == 1)
361  {
362  const auto &links = ee[0]->getLinkModelNames();
363  return attachObjectToState(state, name, links[0], links);
364  }
365 
366  return false;
367 }

◆ attachObjectToState() [2/2]

bool Scene::attachObjectToState ( robot_state::RobotState &  state,
const std::string name,
const std::string ee_link,
const std::vector< std::string > &  touch_links 
) const

Attach the named collision object name to the link ee_link of the given robot state.

Parameters
[in]stateState of the robot to attach.
[in]nameName of object to attach.
[in]ee_linkLink to attach object to.
[in]touch_linksLinks the object is allowed to touch.
Returns
True on success, false on failure.

Definition at line 369 of file scene.cpp.

371 {
372  const auto &world = scene_->getWorld();
373  if (!world->hasObject(name))
374  {
375  RBX_ERROR("World does not have object `%s`", name);
376  return false;
377  }
378 
379  const auto &obj = world->getObject(name);
380  if (!obj)
381  {
382  RBX_ERROR("Could not get object `%s`", name);
383  return false;
384  }
385 
386  const auto &tf = state.getGlobalLinkTransform(ee_link);
387 
388  RobotPoseVector poses;
389  for (const auto &pose : obj->shape_poses_)
390  poses.push_back(tf.inverse() * pose);
391 
392  std::set<std::string> touch_links_set(touch_links.begin(), touch_links.end());
393  auto *body = attachObjectHelper<moveit::core::AttachedBody>(state.getLinkModel(ee_link), //
394  name, //
395  obj->shapes_, //
396  poses, //
397  touch_links_set);
398  state.attachBody(body);
399 
400  return true;
401 }
T begin(T... args)
T end(T... args)
#define RBX_ERROR(fmt,...)
Output a error logging message.
Definition: log.h:102
T push_back(T... args)

◆ checkCollision()

collision_detection::CollisionResult Scene::checkCollision ( const robot_state::RobotState &  state,
const collision_detection::CollisionRequest request = {} 
) const

Check if a robot state is in collision.

Parameters
[in]stateState to check for collision.
[in]requestOptional request parameters for collision checking.
Returns
The collision result.

Definition at line 466 of file scene.cpp.

468 {
470  scene_->checkCollision(request, result, state);
471 
472  return result;
473 }

◆ clearACM()

void Scene::clearACM ( collision_detection::AllowedCollisionMatrix acm) const

Disables collision between all entries in the ACM (all robot links and objects in the scene)

Parameters
[in,out]acmACM to clear.

Definition at line 496 of file scene.cpp.

497 {
498  const auto &links = getCurrentStateConst().getRobotModel()->getLinkModelNames();
499  const auto &objs = getCollisionObjects();
500 
501  // No self-collision distances
502  for (unsigned int i = 0; i < links.size(); ++i)
503  for (unsigned int j = i + 1; j < links.size(); ++j)
504  acm.setEntry(links[i], links[j], true);
505 
506  // No obstacle collisions
507  for (unsigned int i = 0; i < objs.size(); ++i)
508  for (unsigned int j = i + 1; j < objs.size(); ++j)
509  acm.setEntry(objs[i], objs[j], true);
510 
511  // Ignore all other objects
512  for (const auto &link : links)
513  for (const auto &obj : objs)
514  acm.setEntry(link, obj, true);
515 }
void setEntry(const std::string &name1, const std::string &name2, bool allowed)
std::vector< std::string > getCollisionObjects() const
Returns a list of all the names of collision objects in the scene.
Definition: scene.cpp:247
const robot_state::RobotState & getCurrentStateConst() const
Get a constant reference to the current robot state in the planning scene.
Definition: scene.cpp:197

◆ deepCopy()

ScenePtr Scene::deepCopy ( ) const

Deep Copy.

Returns
The deep copied planning scene.

Definition at line 165 of file scene.cpp.

166 {
167  auto scene = std::make_shared<Scene>(scene_->getRobotModel());
168  scene->useMessage(getMessage());
169 
170  return scene;
171 }
moveit_msgs::PlanningScene getMessage() const
Get the message that describes the current planning scene.
Definition: scene.cpp:184
Functions for loading and animating scenes in Blender.

◆ detachObject() [1/2]

bool Scene::detachObject ( const std::string name)

Helper function that detaches the object from the internal scene state.

Parameters
[in]nameName of collision to detach.
Returns
True on success, false on failure.

Definition at line 437 of file scene.cpp.

438 {
439  return detachObject(getCurrentState(), name);
440 }
bool detachObject(const std::string &name)
Helper function that detaches the object from the internal scene state.
Definition: scene.cpp:437

◆ detachObject() [2/2]

bool Scene::detachObject ( robot_state::RobotState &  state,
const std::string name 
)

Detach an object name from the robot state.

Parameters
[in]stateState to detatch the object from.
[in]nameName of collision to detach.
Returns
True on success, false on failure.

Definition at line 442 of file scene.cpp.

443 {
445 
446  const auto &world = scene_->getWorldNonConst();
447  const auto &body = state.getAttachedBody(name);
448 
449  if (!body)
450  {
451  RBX_ERROR("Robot does not have attached object `%s`", name);
452  return false;
453  }
454 
455  world->addToObject(name, body->getShapes(), body->getGlobalCollisionBodyTransforms());
456 
457  if (not state.clearAttachedBody(name))
458  {
459  RBX_ERROR("Could not detach object `%s`", name);
460  return false;
461  }
462 
463  return true;
464 }
void incrementVersion()
Increment the version number of this object.
Definition: id.cpp:42

◆ distanceACM()

double Scene::distanceACM ( const robot_state::RobotState &  state,
const collision_detection::AllowedCollisionMatrix acm 
) const

Get the distance to collision using an ACM.

Parameters
[in]stateState of the robot.
[in]oneacm ACM to use for distance check.
Returns
The distance between all colliding entries in ACM. On error, returns NaN.

Definition at line 480 of file scene.cpp.

482 {
485 
486  req.acm = &acm;
487 
488 #if ROBOWFLEX_MOVEIT_VERSION >= ROBOWFLEX_MOVEIT_VERSION_COMPUTE(1, 1, 0)
489  scene_->getCollisionEnv()->distanceRobot(req, res, state);
490 #else
491  scene_->getCollisionWorld()->distanceRobot(req, res, *scene_->getCollisionRobot(), state);
492 #endif
493  return res.minimum_distance.distance;
494 }
const AllowedCollisionMatrix * acm
DistanceResultsData minimum_distance

◆ distanceBetweenObjects()

double Scene::distanceBetweenObjects ( const std::string one,
const std::string two 
) const

Get the distance to collision between two collision objects in the scene.

Parameters
[in]oneOne of the objects to check.
[in]twoThe other object to check.
Returns
The distance between the objects. On error, returns NaN.

Definition at line 535 of file scene.cpp.

536 {
537  if (one == two) // Early terminate if they are the same
538  return 0.;
539 
540  if (not hasObject(one))
541  {
542  RBX_ERROR("World does not have object `%s`", one);
544  }
545 
546  if (not hasObject(two))
547  {
548  RBX_ERROR("World does not have object `%s`", two);
550  }
551 
552  robot_state::RobotState copy = getCurrentStateConst();
553  attachObjectToState(copy, one);
554 
556  clearACM(acm);
557  acm.setEntry(one, one, true);
558  acm.setEntry(one, two, false);
559 
560  return distanceACM(copy, acm);
561 }
void clearACM(collision_detection::AllowedCollisionMatrix &acm) const
Disables collision between all entries in the ACM (all robot links and objects in the scene)
Definition: scene.cpp:496
double distanceACM(const robot_state::RobotState &state, const collision_detection::AllowedCollisionMatrix &acm) const
Get the distance to collision using an ACM.
Definition: scene.cpp:480
bool hasObject(const std::string &name) const
Returns true if the object name is in the scene.
Definition: scene.cpp:431
T copy(T... args)
T quiet_NaN(T... args)

◆ distanceToCollision()

double Scene::distanceToCollision ( const robot_state::RobotState &  state) const

Get the distance to collision for a robot state.

Parameters
[in]stateState to get distance to collision for.
Returns
The distance of the state to collision.

Definition at line 475 of file scene.cpp.

476 {
477  return scene_->distanceToCollision(state);
478 }

◆ distanceToObject()

double Scene::distanceToObject ( const robot_state::RobotState &  state,
const std::string object 
) const

Get the distance to collision to a specific object.

Parameters
[in]stateState of the robot.
[in]objectObject to check against.
Returns
The distance to collision to the object. On error, returns NaN.

Definition at line 517 of file scene.cpp.

518 {
519  if (not hasObject(object))
520  {
521  RBX_ERROR("World does not have object `%s`", object);
523  }
524 
526  clearACM(acm);
527 
528  // Enable collision to the object of interest
529  for (const auto &link : getCurrentStateConst().getRobotModel()->getLinkModelNames())
530  acm.setEntry(link, object, false);
531 
532  return distanceACM(state, acm);
533 }

◆ fixCollisionObjectFrame()

void Scene::fixCollisionObjectFrame ( moveit_msgs::PlanningScene &  msg)
private

Corrects frame mismatches on loaded scenes by using the current root frame instead.

Parameters
[in,out]msgMessage to correct frame names for.

Definition at line 223 of file scene.cpp.

224 {
225  for (auto &co : msg.world.collision_objects)
226  if (co.header.frame_id.empty() or not scene_->knowsFrameTransform(co.header.frame_id))
227  co.header.frame_id = scene_->getRobotModel()->getRootLinkName();
228 }

◆ fromOpenRAVEXMLFile()

bool Scene::fromOpenRAVEXMLFile ( const std::string file,
std::string  models_dir = "" 
)

Definition at line 611 of file scene.cpp.

612 {
613  if (models_dir.empty())
614  models_dir = IO::resolveParent(file);
615 
616  moveit_msgs::PlanningScene msg;
617  if (!openrave::fromXMLFile(msg, file, models_dir))
618  return false;
619 
620  scene_->usePlanningSceneMsg(msg);
621  return true;
622 }
T empty(T... args)
std::string resolveParent(const std::string &path)
Resolves package:// URLs to get the directory this path is in.
bool fromXMLFile(moveit_msgs::PlanningScene &planning_scene, const std::string &file, const std::string &model_dir)
Loads a planning_scene from an OpenRAVE Environment XML.
Definition: openrave.cpp:208

◆ fromYAMLFile()

bool Scene::fromYAMLFile ( const std::string file)

Load a planning scene from a YAML file.

Parameters
[in]fileFile to load planning scene from.
Returns
True on success, false on failure.

Definition at line 589 of file scene.cpp.

590 {
591  moveit_msgs::PlanningScene msg;
592  if (!IO::fromYAMLFile(msg, file))
593  return false;
594 
596 
597  // Add robot_state if loaded scene does not contain one.
598  if (msg.robot_state.joint_state.position.empty())
599  moveit::core::robotStateToRobotStateMsg(scene_->getCurrentState(), msg.robot_state);
600 
601  auto acm(getACM());
602  useMessage(msg);
603 
604  // Update ACM only if anything specified.
605  if (msg.allowed_collision_matrix.entry_names.empty())
606  getACM() = acm;
607 
608  return true;
609 }
void useMessage(const moveit_msgs::PlanningScene &msg, bool diff=false)
Set the planning scene to be the same as a message.
Definition: scene.cpp:213
void fixCollisionObjectFrame(moveit_msgs::PlanningScene &msg)
Corrects frame mismatches on loaded scenes by using the current root frame instead.
Definition: scene.cpp:223
collision_detection::AllowedCollisionMatrix & getACM()
Get the current allowed collision matrix of the planning scene.
Definition: scene.cpp:202
void robotStateToRobotStateMsg(const RobotState &state, moveit_msgs::RobotState &robot_state, bool copy_attached_bodies=true)
bool fromYAMLFile(moveit_msgs::PlanningScene &msg, const std::string &file)
Loads a planning scene from a YAML file.
Definition: yaml.cpp:1914

◆ getACM()

Get the current allowed collision matrix of the planning scene.

Returns
The allowed collision matrix.

Definition at line 202 of file scene.cpp.

203 {
205  return scene_->getAllowedCollisionMatrixNonConst();
206 }

◆ getACMConst()

const collision_detection::AllowedCollisionMatrix & Scene::getACMConst ( ) const

Get the current allowed collision matrix of the planning scene.

Returns
The allowed collision matrix.

Definition at line 208 of file scene.cpp.

209 {
210  return scene_->getAllowedCollisionMatrix();
211 }

◆ getCollisionObjects()

std::vector< std::string > Scene::getCollisionObjects ( ) const

Returns a list of all the names of collision objects in the scene.

Returns
A list of all the collision objects in the scene.

Definition at line 247 of file scene.cpp.

248 {
249  const auto &world = scene_->getWorld();
250  return world->getObjectIds();
251 }

◆ getCurrentState()

robot_state::RobotState & Scene::getCurrentState ( )

Get a reference to the current robot state in the planning scene.

Returns
The planning scene robot.

Definition at line 191 of file scene.cpp.

192 {
194  return scene_->getCurrentStateNonConst();
195 }

◆ getCurrentStateConst()

const robot_state::RobotState & Scene::getCurrentStateConst ( ) const

Get a constant reference to the current robot state in the planning scene.

Returns
The planning scene robot.

Definition at line 197 of file scene.cpp.

198 {
199  return scene_->getCurrentState();
200 }

◆ getFramePose()

RobotPose Scene::getFramePose ( const std::string id) const

Get the pose of a particular frame in the scene. Example, use this to get the pose from /world to /base_link.

Parameters
[in]idThe ID of the frame to look for.
Returns
Pose of the object, Identity if frame is not present.

Definition at line 333 of file scene.cpp.

334 {
335  if (not scene_->knowsFrameTransform(id))
336  RBX_WARN("Frame %s in not present in the scene!", id);
337 
338  return scene_->getFrameTransform(id);
339 }
#define RBX_WARN(fmt,...)
Output a warning logging message.
Definition: log.h:110

◆ getGSVCF()

moveit::core::GroupStateValidityCallbackFn Scene::getGSVCF ( bool  verbose) const

Get the group state validity callback function that uses this scene.

Parameters
[in]verboseIf true, will have verbose collision output.
Returns
The group state validity function. This function will return true if there is no collision, and false otherwise.

Definition at line 563 of file scene.cpp.

564 {
565  return [this, verbose](robot_state::RobotState *state, //
566  const moveit::core::JointModelGroup *jmg, //
567  const double *values) //
568  {
569  state->setJointGroupPositions(jmg, values);
570  state->updateCollisionBodyTransforms();
571 
573  request.verbose = verbose;
574 
575  auto result = this->checkCollision(*state, request);
576  return not result.collision;
577  };
578 }
collision_detection::CollisionResult checkCollision(const robot_state::RobotState &state, const collision_detection::CollisionRequest &request={}) const
Check if a robot state is in collision.
Definition: scene.cpp:466

◆ getMessage()

moveit_msgs::PlanningScene Scene::getMessage ( ) const

Get the message that describes the current planning scene.

Returns
The planning scene message.

Definition at line 184 of file scene.cpp.

185 {
186  moveit_msgs::PlanningScene msg;
187  scene_->getPlanningSceneMsg(msg);
188  return msg;
189 }

◆ getObjectGeometry()

GeometryPtr Scene::getObjectGeometry ( const std::string name) const

Returns a representation of a collision object in the scene as a Geometry. If the object has multiple geometries, returns the first.

Parameters
[in]nameName of the object to extract.
Returns
A representation of the collision object as a Geometry.

Definition at line 253 of file scene.cpp.

254 {
255  const auto &world = scene_->getWorld();
256 
257  const auto &obj = world->getObject(name);
258  if (obj)
259  return std::make_shared<Geometry>(*obj->shapes_[0]);
260 
261  RBX_WARN("Object %s does not exist in scene!", name);
262  return nullptr;
263 }

◆ getObjectGraspPose()

RobotPose Scene::getObjectGraspPose ( const std::string name,
const RobotPose offset 
) const

Get a pose in the global frame relative to a collision object for grasping.

Parameters
[in]nameName of object to get pose for.
[in]offsetThe offset of the grasp in the object's frame.
Returns
Pose of the grasp offset from the object.

Definition at line 286 of file scene.cpp.

287 {
288  if (not hasObject(name))
289  throw Exception(1, log::format("Object `%1%` not in scene!", name));
290 
291  return getObjectPose(name) * offset;
292 }
Exception that contains a message and an error code.
Definition: util.h:15
RobotPose getObjectPose(const std::string &name) const
Get the current pose of a collision object. If the object has multiple geometries,...
Definition: scene.cpp:270
std::string format(const std::string &fmt, Args &&... args)
Recursion base case, return string form of formatted arguments.
Definition: log.h:60

◆ getObjectPose()

RobotPose Scene::getObjectPose ( const std::string name) const

Get the current pose of a collision object. If the object has multiple geometries, returns the pose of the first.

Parameters
[in]nameName of object to get pose for.
Returns
Pose of the object.

Definition at line 270 of file scene.cpp.

271 {
272  const auto &world = scene_->getWorldNonConst();
273  const auto &obj = world->getObject(name);
274  if (obj)
275  {
276 #if ROBOWFLEX_MOVEIT_VERSION >= ROBOWFLEX_MOVEIT_VERSION_COMPUTE(1, 1, 6)
277  return obj->pose_ * obj->shape_poses_[0];
278 #else
279  return obj->shape_poses_[0];
280 #endif
281  }
282 
283  return RobotPose::Identity();
284 }

◆ getScene()

planning_scene::PlanningScenePtr & Scene::getScene ( )

Get a reference to the planning scene.

Returns
The planning scene.

Definition at line 178 of file scene.cpp.

179 {
181  return scene_;
182 }

◆ getSceneConst()

const planning_scene::PlanningScenePtr & Scene::getSceneConst ( ) const

Get a const reference to the planning scene.

Returns
The planning scene.

Definition at line 173 of file scene.cpp.

174 {
175  return scene_;
176 }

◆ hasObject()

bool Scene::hasObject ( const std::string name) const

Returns true if the object name is in the scene.

Parameters
[in]nameName of the object to look for.
Returns
True if object is in scene, false otherwise.

Definition at line 431 of file scene.cpp.

432 {
433  const auto &world = scene_->getWorld();
434  return world->hasObject(name);
435 }

◆ moveAllObjectsGlobal()

bool Scene::moveAllObjectsGlobal ( const RobotPose transform)

Move all objects according to a transform specified in world frame.

Parameters
[in]transformThe transform to move objects in world frame.
Returns
True on success.

Definition at line 294 of file scene.cpp.

295 {
296  bool r = true;
297  for (const auto &obj : getCollisionObjects())
298  {
299  r &= moveObjectGlobal(obj, transform);
300  if (not r)
301  return r;
302  }
303 
304  return r;
305 }
bool moveObjectGlobal(const std::string &name, const RobotPose &transform)
Move all shapes in an object according to the given transform specified in world frame.
Definition: scene.cpp:307

◆ moveObjectGlobal()

bool Scene::moveObjectGlobal ( const std::string name,
const RobotPose transform 
)

Move all shapes in an object according to the given transform specified in world frame.

Parameters
[in]nameName of the object to move.
[in]transformThe transform to move the object in world frame.
Returns
True on success.

Definition at line 307 of file scene.cpp.

308 {
310 
311  bool success = false;
312 #if ROBOWFLEX_AT_LEAST_KINETIC
313  const auto &world = scene_->getWorldNonConst();
314  success = world->moveObject(name, transform);
315 #endif
316  if (not success)
317  RBX_ERROR("Failed to move object %s", name);
318 
319  return success;
320 }

◆ moveObjectLocal()

bool Scene::moveObjectLocal ( const std::string name,
const RobotPose transform 
)

Move all shapes in an object according to the given transform specified in object frame. If the object has multiple shapes, the first one is considered the local frame.

Parameters
[in]nameName of the object to move.
[in]transformThe transform to move the object in object frame.
Returns
True on success.

Definition at line 322 of file scene.cpp.

323 {
325 
326  const auto pose = getObjectPose(name);
327  const auto global_tf = pose * transform * pose.inverse();
328 
329  bool success = moveObjectGlobal(name, global_tf);
330  return success;
331 }
T transform(T... args)

◆ operator=()

void Scene::operator= ( const Scene scene)

Assignment Copy Constructor.

Parameters
[in]sceneScene to copy.

Definition at line 159 of file scene.cpp.

160 {
162  scene_ = other.getSceneConst();
163 }

◆ removeCollisionObject()

void Scene::removeCollisionObject ( const std::string name)

Removes an object from the planning scene.

Parameters
[in]nameName of object to remove.

Definition at line 265 of file scene.cpp.

266 {
267  scene_->getWorldNonConst()->removeObject(name);
268 }

◆ setCollisionDetector()

bool Scene::setCollisionDetector ( const std::string detector_name) const

Attempts to set the collision detector plugin used by the scene to name. In MoveIt by default, 'Hybrid' is the only plugin defined. However, you can define your own libraries that contain classes that extend the collision_detection::CollisionPlugin class, and load them here as well. See http://moveit.ros.org/documentation/plugins/#collisionplugin for more details.

Parameters
[in]detector_nameName of the collision detection plugin.
Returns
True if sucessful, false otherwise.

Definition at line 341 of file scene.cpp.

342 {
343  bool success = true;
344  if (not loader_->activate(detector_name, scene_, true))
345  {
346  success = false;
347  RBX_WARN("Was not able to load collision detector plugin '%s'", detector_name);
348  }
349 
350  RBX_INFO("Using collision detector: %s", scene_->getActiveCollisionDetectorName());
351  return success;
352 }
#define RBX_INFO(fmt,...)
Output a info logging message.
Definition: log.h:118

◆ toYAMLFile()

bool Scene::toYAMLFile ( const std::string file) const

Serialize the current planning scene to a YAML file.

Parameters
[in]fileFile to serialize planning scene to.
Returns
True on success, false on failure.

Definition at line 580 of file scene.cpp.

581 {
582  moveit_msgs::PlanningScene msg;
583  scene_->getPlanningSceneMsg(msg);
584 
585  YAML::Node node = IO::toNode(msg);
586  return IO::YAMLToFile(node, file);
587 }
bool YAMLToFile(const YAML::Node &node, const std::string &file)
Write the contents of a YAML node out to a potentially new file.
YAML::Node toNode(const geometry_msgs::Pose &msg)
Converts a pose message to YAML.
Definition: yaml.cpp:1874

◆ updateCollisionObject()

void Scene::updateCollisionObject ( const std::string name,
const GeometryConstPtr geometry,
const RobotPose pose 
)

Adds or updates collision object in the planning scene. If the geometry reference is the same, the collision object is updated. Otherwise, the old object named name is deleted and a new one is created.

Parameters
[in]nameName of object to add or update.
[in]geometryGeometry of object.
[in]posePose of object.

Definition at line 230 of file scene.cpp.

232 {
234 
235  const auto &world = scene_->getWorldNonConst();
236  if (world->hasObject(name))
237  {
238  if (!world->moveShapeInObject(name, geometry->getShape(), pose))
239  world->removeObject(name);
240  else
241  return;
242  }
243 
244  world->addToObject(name, geometry->getShape(), pose);
245 }

◆ useMessage()

void Scene::useMessage ( const moveit_msgs::PlanningScene &  msg,
bool  diff = false 
)

Set the planning scene to be the same as a message.

Parameters
[in]msgMessage to use to set planning scene.
[in]diffIf true, uses the message as a diff.

Definition at line 213 of file scene.cpp.

214 {
216 
217  if (!diff)
218  scene_->setPlanningSceneMsg(msg);
219  else
220  scene_->setPlanningSceneDiffMsg(msg);
221 }

Member Data Documentation

◆ loader_

CollisionPluginLoaderPtr robowflex::Scene::loader_
private

Plugin loader that sets collision detectors for the scene.

Definition at line 350 of file scene.h.

◆ scene_

planning_scene::PlanningScenePtr robowflex::Scene::scene_
private

Underlying planning scene.

Definition at line 351 of file scene.h.


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