3 #include <dart/collision/CollisionObject.hpp>
4 #include <dart/constraint/ConstraintSolver.hpp>
6 #include <dart/gui/osg/osg.hpp>
27 const dart::collision::CollisionObject *object2)
const
29 return not
filter_->ignoresCollision(object1, object2);
37 : world_(dart::simulation::
World::create(name))
38 , filter_(
std::make_shared<dart::collision::CompositeCollisionFilter>())
41 world_->setGravity(Eigen::Vector3d(0, 0, -9.81));
43 auto *solver =
world_->getConstraintSolver();
45 auto &opt = solver->getCollisionOption();
48 collider_ = solver->getCollisionDetector();
57 auto world = std::make_shared<World>(
name_ + suffix);
60 world->addRobot(
robot.second->cloneRobot(
robot.first + suffix));
63 world->addStructure(structure.second->cloneStructure(structure.first + suffix));
86 info.
self->addShapeFramesOf(skeleton.get());
87 all_->addShapeFramesOf(skeleton.get());
91 info.
others->addShapeFramesOf(entry.second.self.get());
103 entry.second.others->removeShapeFramesOf(skeleton.get());
105 all_->removeShapeFramesOf(skeleton.get());
118 filter_->addCollisionFilter(
robot->getACM()->getFilter().get());
129 auto robot = it->second;
133 filter_->removeCollisionFilter(
robot->getACM()->getFilter().get());
168 structures_.emplace(structure->getName(), structure);
169 world_->addSkeleton(structure->getSkeleton());
171 filter_->addCollisionFilter(structure->getACM()->getFilter().get());
181 auto structure = it->second;
182 world_->removeSkeleton(structure->getSkeleton());
184 filter_->removeCollisionFilter(structure->getACM()->getFilter().get());
256 for (
unsigned int i = 0; i <
world_->getNumSkeletons(); ++i)
258 if (skeleton ==
world_->getSkeleton(i))
267 auto filter = std::make_shared<dart::collision::BodyNodeCollisionFilter>();
268 for (
unsigned int i = 0; i <
world_->getNumSkeletons(); ++i)
270 const auto &si =
world_->getSkeleton(i);
273 for (
unsigned int ii = 0; ii < si->getNumBodyNodes(); ++ii)
274 for (
unsigned int ij = ii + 1; ij < si->getNumBodyNodes(); ++ij)
275 filter->addBodyNodePairToBlackList(si->getBodyNode(ii), si->getBodyNode(ij));
278 for (
unsigned int j = i + 1; j <
world_->getNumSkeletons(); ++j)
280 const auto &sj =
world_->getSkeleton(j);
281 for (
unsigned int ii = 0; ii < si->getNumBodyNodes(); ++ii)
282 for (
unsigned int jj = 0; jj < sj->getNumBodyNodes(); ++jj)
283 filter->addBodyNodePairToBlackList(si->getBodyNode(ii), sj->getBodyNode(jj));
292 auto filter = std::make_shared<dart::collision::BodyNodeCollisionFilter>();
294 for (
const auto &[b1, b2] :
robot->getACM()->getDisabledPairs())
295 filter->addBodyNodePairToBlackList(
robot->getFrame(b1),
robot->getFrame(b2));
298 for (
const auto &[b1, b2] : structure->getACM()->getDisabledPairs())
299 filter->addBodyNodePairToBlackList(structure->getFrame(b1), structure->getFrame(b2));
306 dart::collision::CollisionOption option;
307 option.collisionFilter = (filter) ? filter :
filter_;
314 dart::collision::DistanceOption option;
316 option.distanceFilter = std::make_shared<DistanceCollisionWrapper>(
filter_);
318 dart::collision::DistanceResult result;
321 const auto &shape_node1 = result.shapeFrame1->asShapeNode();
322 const auto &shape_node2 = result.shapeFrame2->asShapeNode();
324 const auto &body_node1 = shape_node1->getBodyNodePtr();
325 const auto &body_node2 = shape_node2->getBodyNodePtr();
327 RBX_INFO(
"Distance B1:%s:%s -> B2:%s:%s = %d",
328 shape_node1->getName(), body_node1->getName(),
329 shape_node2->getName(), body_node2->getName(),
337 ::osg::ref_ptr<dart::gui::osg::RealTimeWorldNode> node =
new dart::gui::osg::RealTimeWorldNode(
world_);
339 auto viewer = dart::gui::osg::Viewer();
340 viewer.addWorldNode(node);
342 viewer.setUpViewInWindow(0, 0, 1080, 1080);
343 viewer.getCameraManipulator()->setHomePosition(
344 ::osg::Vec3(2.57, 3.14, 1.64), ::osg::Vec3(0.00, 0.00, 0.00), ::osg::Vec3(-0.24, -0.25, 0.94));
345 viewer.setCameraManipulator(viewer.getCameraManipulator());
352 world_->getSkeleton(i)->computeForwardKinematics();
359 auto skel =
world_->getSkeleton(i);
362 for (
auto *bn : skel->getBodyNodes())
394 if (filter_ ==
nullptr)
A const shared pointer wrapper for robowflex::Robot.
A shared pointer wrapper for robowflex::Robot.
DistanceCollisionWrapper(const std::shared_ptr< dart::collision::CollisionFilter > &filter)
Constructor.
std::shared_ptr< dart::collision::CollisionFilter > filter_
Wrapped collision filter.
bool needDistance(const dart::collision::CollisionObject *object1, const dart::collision::CollisionObject *object2) const override
A const shared pointer wrapper for robowflex::darts::Structure.
A shared pointer wrapper for robowflex::darts::Structure.
A shared pointer wrapper for robowflex::darts::World.
Wrapper for a dart::simulation::World, which contains a set of skeletons (i.e., Robots and Structures...
std::shared_ptr< dart::collision::CollisionGroup > getSelfCollisionGroup(const std::string &name) const
Get the self-collision group for a skeleton in this world.
double distanceToCollision() const
Gets the current signed distance to collision in the world.
dart::simulation::WorldPtr getSim()
Get the Dart world.
RobotPtr getRobot(const std::string &name)
Get a robot in the world.
WorldPtr clone(const std::string &suffix="") const
Clone this world.
void removeRobot(const std::string &name)
Remove a robot from the world.
void removeSkeletonCollider(const std::string &name, const dart::dynamics::SkeletonPtr &skeleton)
Remove a collision filter (ACM).
dart::simulation::WorldPtr world_
Underlying world.
std::shared_ptr< dart::collision::BodyNodeCollisionFilter > getDefaultFilter() const
Get a collision filter that is a copy of the default filter.
unsigned int getSkeletonIndex(const dart::dynamics::SkeletonPtr &skeleton) const
Get the index in the world of a skeleton.
std::map< std::string, RobotPtr > robots_
Robots in world.
std::shared_ptr< dart::collision::CollisionGroup > getOtherCollisionGroup(const std::string &name) const
Get the group for everything other than a given skeleton in this world.
std::shared_ptr< dart::collision::CompositeCollisionFilter > & getWorldCollisionFilter()
Get the current world collision filter (composite of all skeleton filters). This is more efficient th...
std::recursive_mutex mutex_
Internal lock.
const std::map< std::string, StructurePtr > & getStructures()
Get the set of structures in the world.
StructurePtr getStructure(const std::string &name)
Get a structure in the world.
World(const std::string &name="world")
Create an empty world.
void openOSGViewer()
Open the Open Scene Graph visualization for this world.
dart::collision::CollisionDetectorPtr collider_
Collision checker.
Eigen::Vector3d high_
Upper workspace bounds.
std::map< std::string, CollisionInfo > collision_
CollisionInfo getCollisionInfo(const std::string &name) const
Get the collision info (self and other collision groups) for a skeleton in this world.
std::pair< Eigen::Vector3d, Eigen::Vector3d > getWorkspaceBounds() const
Get the bounds on the workspace.
const Eigen::Vector3d & getWorkspaceHighConst() const
Get the upper bounds of the workspace.
void addSkeletonCollider(const std::string &name, const dart::dynamics::SkeletonPtr &skeleton)
Add a new collision filter (ACM) for a skeleton.
Eigen::Vector3d & getWorkspaceLow()
Get the lower bounds of the workspace.
std::shared_ptr< dart::collision::BodyNodeCollisionFilter > getAllValidFilter() const
Get a collision filter that allows collisions between all body nodes. Useful for constructing a custo...
RobotConstPtr getRobotConst(const std::string &name) const
Get a robot in the world.
void addRobot(RobotPtr robot)
Add a robot to the world.
const std::string name_
Name of world.
void addStructure(StructurePtr structure)
Add a structure to the world.
std::shared_ptr< dart::collision::CompositeCollisionFilter > filter_
const Eigen::Vector3d & getWorkspaceLowConst() const
Get the lower bounds of the workspace.
void lock()
Grab internal recursive lock for world.
Eigen::Vector3d low_
Lower workspace bounds.
std::map< std::string, StructurePtr > structures_
Structures in world.
StructureConstPtr getStructureConst(const std::string &name) const
Get a structure in the world.
const std::string & getName() const
Get the name of this world.
void clearIKModules()
Clear all IK modules created in skeletons in the world.
dart::collision::CollisionGroupPtr all_
All collision groups in world.
Eigen::Vector3d & getWorkspaceHigh()
Get the upper bounds of the workspace.
const dart::simulation::WorldPtr & getSimConst() const
Get the Dart world.
void unlock()
Unlock internal recursive world lock.
void removeStructure(const std::string &name)
Remove a structure from the world.
void forceUpdate()
Force forward kinematics to update.
bool inCollision(const std::shared_ptr< dart::collision::CollisionFilter > &filter=nullptr) const
Checks if world is currently in collision.
#define RBX_INFO(fmt,...)
Output a info logging message.
Functions for loading and animating robots in Blender.
DART-based robot modeling and planning.
Collision filter information.
std::shared_ptr< dart::collision::CollisionGroup > others
All other nodes in world.
std::shared_ptr< dart::collision::CollisionGroup > self