42 #include <urdf_model/model.h> 44 #include <OgreSceneNode.h> 45 #include <OgreSceneManager.h> 46 #include <OgreEntity.h> 47 #include <OgreMaterialManager.h> 48 #include <OgreMaterial.h> 49 #include <OgreResourceGroupManager.h> 58 const std::string& name,
60 : scene_manager_(context->getSceneManager())
62 , visual_visible_(true)
63 , collision_visible_(false)
65 , doing_set_checkbox_(false)
66 , robot_loaded_(false)
67 , inChangedEnableAllLinks(false)
90 "Expand link details (sub properties) to see all info for all links.",
link_tree_,
94 "Expand joint details (sub properties) to see all info for all joints.",
151 M_NameToLink::iterator it =
links_.begin();
152 M_NameToLink::iterator end =
links_.end();
153 for (; it != end; ++it)
179 M_NameToLink::iterator it =
links_.begin();
180 M_NameToLink::iterator end =
links_.end();
181 for (; it != end; ++it)
196 M_NameToLink::iterator link_it =
links_.begin();
197 M_NameToLink::iterator link_end =
links_.end();
198 for (; link_it != link_end; ++link_it)
204 M_NameToJoint::iterator joint_it =
joints_.begin();
205 M_NameToJoint::iterator joint_end =
joints_.end();
206 for (; joint_it != joint_end; ++joint_it)
220 const urdf::LinkConstSharedPtr& link,
221 const std::string& parent_joint_name,
225 return new RobotLink(robot, link, parent_joint_name, visual, collision);
247 typedef std::map<std::string, urdf::LinkSharedPtr> M_NameToUrdfLink;
248 M_NameToUrdfLink::const_iterator link_it = urdf.links_.begin();
249 M_NameToUrdfLink::const_iterator link_end = urdf.links_.end();
250 for (; link_it != link_end; ++link_it)
252 const urdf::LinkConstSharedPtr& urdf_link = link_it->second;
253 std::string parent_joint_name;
255 if (urdf_link != urdf.getRoot() && urdf_link->parent_joint)
257 parent_joint_name = urdf_link->parent_joint->name;
262 if (urdf_link == urdf.getRoot())
267 links_[urdf_link->name] = link;
276 typedef std::map<std::string, urdf::JointSharedPtr> M_NameToUrdfJoint;
277 M_NameToUrdfJoint::const_iterator joint_it = urdf.joints_.begin();
278 M_NameToUrdfJoint::const_iterator joint_end = urdf.joints_.end();
279 for (; joint_it != joint_end; ++joint_it)
281 const urdf::JointConstSharedPtr& urdf_joint = joint_it->second;
284 joints_[urdf_joint->name] = joint;
308 M_NameToLink::iterator link_it =
links_.begin();
309 M_NameToLink::iterator link_end =
links_.end();
310 for (; link_it != link_end; ++link_it)
312 link_it->second->setParentProperty(
nullptr);
316 M_NameToJoint::iterator joint_it =
joints_.begin();
317 M_NameToJoint::iterator joint_end =
joints_.end();
318 for (; joint_it != joint_end; ++joint_it)
320 joint_it->second->setParentProperty(
nullptr);
327 M_NameToLink::iterator link_it =
links_.begin();
328 M_NameToLink::iterator link_end =
links_.end();
329 for (; link_it != link_end; ++link_it)
331 link_it->second->useDetailProperty(use_detail);
335 M_NameToJoint::iterator joint_it =
joints_.begin();
336 M_NameToJoint::iterator joint_end =
joints_.end();
337 for (; joint_it != joint_end; ++joint_it)
339 joint_it->second->useDetailProperty(use_detail);
347 M_NameToLink::iterator link_it =
links_.begin();
348 M_NameToLink::iterator link_end =
links_.end();
349 for (; link_it != link_end; ++link_it)
352 link_it->second->getLinkProperty()->expand();
354 link_it->second->getLinkProperty()->collapse();
357 M_NameToJoint::iterator joint_it =
joints_.begin();
358 M_NameToJoint::iterator joint_end =
joints_.end();
359 for (; joint_it != joint_end; ++joint_it)
362 joint_it->second->getJointProperty()->expand();
364 joint_it->second->getJointProperty()->collapse();
372 M_NameToLink::iterator link_it =
links_.begin();
373 M_NameToLink::iterator link_end =
links_.end();
374 for (; link_it != link_end; ++link_it)
376 link_it->second->hideSubProperties(hide);
379 M_NameToJoint::iterator joint_it =
joints_.begin();
380 M_NameToJoint::iterator joint_end =
joints_.end();
381 for (; joint_it != joint_end; ++joint_it)
383 joint_it->second->hideSubProperties(hide);
391 M_NameToLink::iterator link_it =
links_.begin();
392 M_NameToLink::iterator link_end =
links_.end();
393 for (; link_it != link_end; ++link_it)
395 link_it->second->expandDetails(expand);
403 M_NameToJoint::iterator joint_it =
joints_.begin();
404 M_NameToJoint::iterator joint_end =
joints_.end();
405 for (; joint_it != joint_end; ++joint_it)
407 joint_it->second->expandDetails(expand);
420 M_NameToLink::iterator link_it =
links_.begin();
421 M_NameToLink::iterator link_end =
links_.end();
422 for (; link_it != link_end; ++link_it)
424 if (link_it->second->hasGeometry())
426 link_it->second->getLinkProperty()->setValue(enable);
430 M_NameToJoint::iterator joint_it =
joints_.begin();
431 M_NameToJoint::iterator joint_end =
joints_.end();
432 for (; joint_it != joint_end; ++joint_it)
434 if (joint_it->second->hasDescendentLinksWithGeometry())
436 joint_it->second->getJointProperty()->setValue(enable);
461 std::map<LinkTreeStyle, std::string>::const_iterator style_it =
style_name_map_.begin();
462 std::map<LinkTreeStyle, std::string>::const_iterator style_end =
style_name_map_.end();
463 for (; style_it != style_end; ++style_it)
486 std::map<LinkTreeStyle, std::string>::const_iterator style_it =
style_name_map_.find(style);
519 M_NameToJoint::iterator joint_it =
joints_.begin();
520 M_NameToJoint::iterator joint_end =
joints_.end();
521 for (; joint_it != joint_end; ++joint_it)
523 joint_it->second->setParentProperty(
link_tree_);
524 joint_it->second->setJointPropertyDescription();
532 M_NameToLink::iterator link_it =
links_.begin();
533 M_NameToLink::iterator link_end =
links_.end();
534 for (; link_it != link_end; ++link_it)
536 link_it->second->setParentProperty(
link_tree_);
546 "A tree of all links in the robot. Uncheck a link to hide its geometry.");
554 "A tree of all joints and links in the robot. Uncheck a link to hide its geometry.");
570 "All links in the robot in alphabetic order. Uncheck a link to hide its geometry.");
593 std::vector<std::string>::const_iterator child_joint_it = link->
getChildJointNames().begin();
594 std::vector<std::string>::const_iterator child_joint_end = link->
getChildJointNames().end();
595 for (; child_joint_it != child_joint_end; ++child_joint_it)
624 M_NameToLink::iterator it =
links_.find(name);
627 ROS_WARN(
"Link [%s] does not exist", name.c_str());
636 M_NameToJoint::iterator it =
joints_.find(name);
639 ROS_WARN(
"Joint [%s] does not exist", name.c_str());
651 int links_with_geom_checked = 0;
652 int links_with_geom_unchecked = 0;
666 links_with_geom_checked += checked ? 1 : 0;
667 links_with_geom_unchecked += checked ? 0 : 1;
669 int links_with_geom = links_with_geom_checked + links_with_geom_unchecked;
672 std::vector<std::string>::const_iterator child_joint_it = link->
getChildJointNames().begin();
673 std::vector<std::string>::const_iterator child_joint_end = link->
getChildJointNames().end();
674 for (; child_joint_it != child_joint_end; ++child_joint_it)
679 int child_links_with_geom;
680 int child_links_with_geom_checked;
681 int child_links_with_geom_unchecked;
683 child_links_with_geom, child_links_with_geom_checked, child_links_with_geom_unchecked);
684 links_with_geom_checked += child_links_with_geom_checked;
685 links_with_geom_unchecked += child_links_with_geom_unchecked;
688 links_with_geom = links_with_geom_checked + links_with_geom_unchecked;
690 if (!links_with_geom)
702 M_NameToLink::iterator link_it =
links_.begin();
703 M_NameToLink::iterator link_end =
links_.end();
704 for (; link_it != link_end; ++link_it)
708 Ogre::Vector3 visual_position, collision_position;
709 Ogre::Quaternion visual_orientation, collision_orientation;
711 collision_position, collision_orientation))
717 if (visual_orientation.isNaN())
720 "visual orientation of %s contains NaNs. " 721 "Skipping render as long as the orientation is invalid.",
725 if (visual_position.isNaN())
729 "visual position of %s contains NaNs. Skipping render as long as the position is invalid.",
733 if (collision_orientation.isNaN())
736 "collision orientation of %s contains NaNs. " 737 "Skipping render as long as the orientation is invalid.",
741 if (collision_position.isNaN())
744 "collision position of %s contains NaNs. " 745 "Skipping render as long as the position is invalid.",
749 link->
setTransforms(visual_position, visual_orientation, collision_position, collision_orientation);
751 std::vector<std::string>::const_iterator joint_it = link->
getChildJointNames().begin();
752 std::vector<std::string>::const_iterator joint_end = link->
getChildJointNames().end();
753 for (; joint_it != joint_end; ++joint_it)
void updateVisibility()
Update the visibility of the link elements: visual mesh, collision mesh, trail, and axes...
virtual void update(const LinkUpdater &updater)
void setParentProperty(Property *new_parent)
Robot(Ogre::SceneNode *root_node, DisplayContext *context, const std::string &name, Property *parent_property)
void setEnableAllLinksCheckbox(QVariant val)
const Property * getJointProperty() const
void addLinkToLinkTree(LinkTreeStyle style, Property *parent, RobotLink *link)
void setJointPropertyDescription()
M_NameToJoint joints_
Map of name to joint info, stores all loaded joints.
void setRobotAlpha(float)
virtual void clear()
Clears all data loaded from a URDF.
virtual bool setValue(const QVariant &new_value)
Set the new value for this property. Returns true if the new value is different from the old value...
void useDetailProperty(bool use_detail)
A single element of a property tree, with a name, value, description, and possibly children...
void calculateJointCheckboxesRecursive(int &links_with_geom, int &links_with_geom_checked, int &links_with_geom_unchecked)
virtual void clearOptions()
Clear the list of options.
virtual void setName(const QString &name)
Set the name.
void changedLinkTreeStyle()
BoolProperty * expand_joint_details_
LinkFactory * link_factory_
factory for generating links and joints
virtual void setPosition(const Ogre::Vector3 &position)
virtual RobotLink * createLink(Robot *robot, const urdf::LinkConstSharedPtr &link, const std::string &parent_joint_name, bool visual, bool collision)
void setTransforms(const Ogre::Vector3 &parent_link_position, const Ogre::Quaternion &parent_link_orientation)
virtual const Ogre::Vector3 & getPosition()
virtual void setDescription(const QString &description)
Set the description.
RobotLink * getLink(const std::string &name)
bool isCollisionVisible()
Returns whether or not the collision representation is set to be visible To be visible this and isVis...
void calculateJointCheckboxes()
void setToErrorMaterial()
std::map< LinkTreeStyle, std::string > style_name_map_
static bool styleShowJoint(LinkTreeStyle style)
virtual void load(const urdf::ModelInterface &urdf, bool visual=true, bool collision=true)
Loads meshes/primitives from a robot description. Calls clear() before loading.
virtual void collapse()
Collapse (hide the children of) this Property.
bool visual_visible_
Should we show the visual representation?
virtual void setTransforms(const Ogre::Vector3 &visual_position, const Ogre::Quaternion &visual_orientation, const Ogre::Vector3 &collision_position, const Ogre::Quaternion &collision_orientation)
virtual void setScale(const Ogre::Vector3 &scale)
void setLinkFactory(LinkFactory *link_factory)
void changedExpandLinkDetails()
Pure-virtual base class for objects which give Display subclasses context in which to work...
const std::string & getChildLinkName() const
Ogre::SceneNode * root_visual_node_
Node all our visual nodes are children of.
void setCollisionVisible(bool visible)
Set whether the collision meshes/primitives of the robot should be visible.
void setLinkTreeStyle(LinkTreeStyle style)
const std::vector< std::string > & getChildJointNames() const
void show()
Show this Property in any PropertyTreeWidgets.
bool isVisible()
Returns whether anything is visible.
#define ROS_ERROR_THROTTLE(period,...)
void updateLinkVisibilities()
Call RobotLink::updateVisibility() on each link.
void changedExpandJointDetails()
BoolProperty * enable_all_links_
BoolProperty * expand_tree_
virtual bool getLinkTransforms(const std::string &link_name, Ogre::Vector3 &visual_position, Ogre::Quaternion &visual_orientation, Ogre::Vector3 &collision_position, Ogre::Quaternion &collision_orientation) const =0
void addJointToLinkTree(LinkTreeStyle style, Property *parent, RobotJoint *joint)
Property * getLinkProperty() const
void addOptionStd(const std::string &option, int value=0)
Contains any data we need from a joint in the robot.
virtual void setOrientation(const Ogre::Quaternion &orientation)
Ogre::SceneManager * scene_manager_
Contains any data we need from a link in the robot.
void setToNormalMaterial()
bool visible_
Should we show anything at all? (affects visual, collision, axes, and trails)
bool inChangedEnableAllLinks
BoolProperty * expand_link_details_
virtual void setRobotAlpha(float a)
const std::string & getName() const
Property specialized to provide getter for booleans.
static bool styleShowLink(LinkTreeStyle style)
void setVisualVisible(bool visible)
Set whether the visual meshes of the robot should be visible.
void changedHideSubProperties()
EnumProperty * link_tree_style_
Ogre::SceneNode * root_other_node_
virtual RobotJoint * createJoint(Robot *robot, const urdf::JointConstSharedPtr &joint)
void hide()
Hide this Property in any PropertyTreeWidgets.
virtual QVariant getValue() const
Return the value of this Property as a QVariant. If the value has never been set, an invalid QVariant...
bool collision_visible_
Should we show the collision representation?
Ogre::SceneNode * root_collision_node_
Node all our collision nodes are children of.
virtual void setVisible(bool visible)
Set the robot as a whole to be visible or not.
virtual bool getBool() const
virtual int getOptionInt()
Return the int value of the currently-chosen option, or 0 if the current option string does not have ...
virtual const Ogre::Quaternion & getOrientation()
M_NameToLink links_
Map of name to link info, stores all loaded links.
bool isVisualVisible()
Returns whether or not the visual representation is set to be visible To be visible this and isVisibl...
void changedEnableAllLinks()
static bool styleIsTree(LinkTreeStyle style)
void unparentLinkProperties()
RobotJoint * getJoint(const std::string &name)
void setParentProperty(Property *new_parent)