robot.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef RVIZ_ROBOT_H_
31 #define RVIZ_ROBOT_H_
32 
33 #include "link_updater.h"
34 
35 #include <string>
36 #include <map>
37 
39 #include <OgreQuaternion.h>
40 #include <OgreAny.h>
41 
42 #include <urdf/model.h> // can be replaced later by urdf_model/types.h
43 
44 #include <OgrePrerequisites.h>
45 
46 namespace Ogre
47 {
48 class Any;
49 }
50 
51 namespace rviz
52 {
53 class Object;
54 class Axes;
55 } // namespace rviz
56 
57 namespace tf
58 {
59 class TransformListener;
60 }
61 
62 namespace rviz
63 {
64 class Property;
65 class EnumProperty;
66 class BoolProperty;
67 class Robot;
68 class RobotLink;
69 class RobotJoint;
70 class DisplayContext;
71 
79 class Robot : public QObject
80 {
81  Q_OBJECT
82 public:
83  Robot(Ogre::SceneNode* root_node,
84  DisplayContext* context,
85  const std::string& name,
86  Property* parent_property);
87  ~Robot() override;
88 
96  virtual void load(const urdf::ModelInterface& urdf, bool visual = true, bool collision = true);
97 
101  virtual void clear();
102 
103  virtual void update(const LinkUpdater& updater);
104 
109  virtual void setVisible(bool visible);
110 
115  void setVisualVisible(bool visible);
116 
121  void setCollisionVisible(bool visible);
122 
126  bool isVisible();
131  bool isVisualVisible();
136  bool isCollisionVisible();
137 
138  void setAlpha(float a);
139  float getAlpha()
140  {
141  return alpha_;
142  }
143 
145  {
146  return root_link_;
147  }
148  RobotLink* getLink(const std::string& name);
149  RobotJoint* getJoint(const std::string& name);
150 
151  typedef std::map<std::string, RobotLink*> M_NameToLink;
152  typedef std::map<std::string, RobotJoint*> M_NameToJoint;
153  const M_NameToLink& getLinks() const
154  {
155  return links_;
156  }
157  const M_NameToJoint& getJoints() const
158  {
159  return joints_;
160  }
161 
162  const std::string& getName()
163  {
164  return name_;
165  }
166 
167  Ogre::SceneNode* getVisualNode()
168  {
169  return root_visual_node_;
170  }
171  Ogre::SceneNode* getCollisionNode()
172  {
173  return root_collision_node_;
174  }
175  Ogre::SceneNode* getOtherNode()
176  {
177  return root_other_node_;
178  }
179  Ogre::SceneManager* getSceneManager()
180  {
181  return scene_manager_;
182  }
184  {
185  return context_;
186  }
187 
188  virtual void setPosition(const Ogre::Vector3& position);
189  virtual void setOrientation(const Ogre::Quaternion& orientation);
190  virtual void setScale(const Ogre::Vector3& scale);
191  virtual const Ogre::Vector3& getPosition();
192  virtual const Ogre::Quaternion& getOrientation();
193 
196  {
197  public:
198  virtual ~LinkFactory() = default;
199 
200  virtual RobotLink* createLink(Robot* robot,
201  const urdf::LinkConstSharedPtr& link,
202  const std::string& parent_joint_name,
203  bool visual,
204  bool collision);
205  virtual RobotJoint* createJoint(Robot* robot, const urdf::JointConstSharedPtr& joint);
206  };
207 
217  void setLinkFactory(LinkFactory* link_factory);
218 
219 
221  {
222  STYLE_LINK_LIST, // list of all links sorted by link name
224  STYLE_JOINT_LIST, // list of joints sorted by joint name
225  STYLE_LINK_TREE, // tree of links
226  STYLE_JOINT_LINK_TREE // tree of joints with links
227  };
228 
230  void setLinkTreeStyle(LinkTreeStyle style);
231 
234  {
235  return link_tree_;
236  }
237 
238  // set joint checkboxes and All Links Enabled checkbox based on current link enables.
240 
241 private Q_SLOTS:
242  void changedLinkTreeStyle();
243  void changedExpandTree();
245  void changedEnableAllLinks();
248 
249 protected:
251  void updateLinkVisibilities();
252 
255  void unparentLinkProperties();
256 
257  // place sub properties under detail (or not)
258  void useDetailProperty(bool use_detail);
259 
261  void addLinkToLinkTree(LinkTreeStyle style, Property* parent, RobotLink* link);
262  void addJointToLinkTree(LinkTreeStyle style, Property* parent, RobotJoint* joint);
263 
264  // set the value of the EnableAllLinks property without affecting child links/joints.
265  void setEnableAllLinksCheckbox(const QVariant& val);
266 
268  void initLinkTreeStyle();
269  static bool styleShowLink(LinkTreeStyle style);
270  static bool styleShowJoint(LinkTreeStyle style);
271  static bool styleIsTree(LinkTreeStyle style);
272 
273  Ogre::SceneManager* scene_manager_;
274 
278 
280 
281  Ogre::SceneNode* root_visual_node_;
282  Ogre::SceneNode* root_collision_node_;
283  Ogre::SceneNode* root_other_node_;
284 
285  bool visible_;
288 
296  std::map<LinkTreeStyle, std::string> style_name_map_;
297 
298  bool doing_set_checkbox_; // used only inside setEnableAllLinksCheckbox()
299  bool robot_loaded_; // true after robot model is loaded.
300 
301  // true inside changedEnableAllLinks(). Prevents calculateJointCheckboxes()
302  // from recalculating over and over.
304 
305  std::string name_;
306  float alpha_;
307 };
308 
309 } // namespace rviz
310 
311 #endif /* RVIZ_ROBOT_H_ */
rviz::Robot::M_NameToLink
std::map< std::string, RobotLink * > M_NameToLink
Definition: robot.h:151
rviz::Robot::setCollisionVisible
void setCollisionVisible(bool visible)
Set whether the collision meshes/primitives of the robot should be visible.
Definition: robot.cpp:143
rviz::Robot::expand_link_details_
BoolProperty * expand_link_details_
Definition: robot.h:293
rviz::Robot::links_
M_NameToLink links_
Map of name to link info, stores all loaded links.
Definition: robot.h:275
Ogre
Definition: axes_display.h:35
rviz::Robot::LinkTreeStyle
LinkTreeStyle
Definition: robot.h:220
rviz::Robot::STYLE_JOINT_LINK_TREE
@ STYLE_JOINT_LINK_TREE
Definition: robot.h:226
rviz::Robot::visual_visible_
bool visual_visible_
Should we show the visual representation?
Definition: robot.h:286
rviz::Robot::LinkFactory::~LinkFactory
virtual ~LinkFactory()=default
rviz::Robot::changedExpandLinkDetails
void changedExpandLinkDetails()
Definition: robot.cpp:387
rviz::Robot::getLinkTreeProperty
Property * getLinkTreeProperty()
Definition: robot.h:233
rviz::Robot::root_other_node_
Ogre::SceneNode * root_other_node_
Definition: robot.h:283
rviz::Robot::setScale
virtual void setScale(const Ogre::Vector3 &scale)
Definition: robot.cpp:780
rviz::Robot::~Robot
~Robot() override
Definition: robot.cpp:100
rviz::Robot::link_tree_
Property * link_tree_
Definition: robot.h:290
rviz::Robot::expand_joint_details_
BoolProperty * expand_joint_details_
Definition: robot.h:294
rviz::Robot::getVisualNode
Ogre::SceneNode * getVisualNode()
Definition: robot.h:167
rviz::BoolProperty
Property specialized to provide getter for booleans.
Definition: bool_property.h:38
rviz::Robot::isCollisionVisible
bool isCollisionVisible()
Returns whether or not the collision representation is set to be visible To be visible this and isVis...
Definition: robot.cpp:170
rviz::Robot::changedHideSubProperties
void changedHideSubProperties()
Definition: robot.cpp:368
rviz::Robot::doing_set_checkbox_
bool doing_set_checkbox_
Definition: robot.h:298
rviz::Robot::STYLE_LINK_LIST
@ STYLE_LINK_LIST
Definition: robot.h:222
rviz::Robot::getAlpha
float getAlpha()
Definition: robot.h:139
rviz::Robot::name_
std::string name_
Definition: robot.h:305
rviz::Robot::link_factory_
LinkFactory * link_factory_
factory for generating links and joints
Definition: robot.h:279
rviz::EnumProperty
Enum property.
Definition: enum_property.h:46
rviz::Robot::getPosition
virtual const Ogre::Vector3 & getPosition()
Definition: robot.cpp:786
rviz::Robot::visible_
bool visible_
Should we show anything at all? (affects visual, collision, axes, and trails)
Definition: robot.h:285
rviz::Robot::inChangedEnableAllLinks
bool inChangedEnableAllLinks
Definition: robot.h:303
rviz::Property
A single element of a property tree, with a name, value, description, and possibly children.
Definition: property.h:100
rviz::Robot::STYLE_JOINT_LIST
@ STYLE_JOINT_LIST
Definition: robot.h:224
rviz::Robot::getOrientation
virtual const Ogre::Quaternion & getOrientation()
Definition: robot.cpp:791
rviz::Robot::styleIsTree
static bool styleIsTree(LinkTreeStyle style)
Definition: robot.cpp:479
rviz::Robot::robot_loaded_
bool robot_loaded_
Definition: robot.h:299
rviz::Robot::setVisualVisible
void setVisualVisible(bool visible)
Set whether the visual meshes of the robot should be visible.
Definition: robot.cpp:137
rviz::LinkUpdater
Definition: link_updater.h:40
rviz::Robot::LinkFactory::createJoint
virtual RobotJoint * createJoint(Robot *robot, const urdf::JointConstSharedPtr &joint)
Definition: robot.cpp:228
rviz::Robot::getName
const std::string & getName()
Definition: robot.h:162
rviz::Robot::getCollisionNode
Ogre::SceneNode * getCollisionNode()
Definition: robot.h:171
rviz::Robot::link_tree_style_
EnumProperty * link_tree_style_
Definition: robot.h:291
rviz
Definition: add_display_dialog.cpp:54
rviz::Robot::initLinkTreeStyle
void initLinkTreeStyle()
Definition: robot.cpp:452
rviz::Robot::expand_tree_
BoolProperty * expand_tree_
Definition: robot.h:292
model.h
rviz::Robot::getJoints
const M_NameToJoint & getJoints() const
Definition: robot.h:157
rviz::Robot::alpha_
float alpha_
Definition: robot.h:306
rviz::Robot::addJointToLinkTree
void addJointToLinkTree(LinkTreeStyle style, Property *parent, RobotJoint *joint)
Definition: robot.cpp:606
rviz::Robot::setOrientation
virtual void setOrientation(const Ogre::Quaternion &orientation)
Definition: robot.cpp:774
rviz::Robot::joints_
M_NameToJoint joints_
Map of name to joint info, stores all loaded joints.
Definition: robot.h:276
ogre_vector.h
rviz::RobotJoint
Contains any data we need from a joint in the robot.
Definition: robot_joint.h:79
rviz::Robot::addLinkToLinkTree
void addLinkToLinkTree(LinkTreeStyle style, Property *parent, RobotLink *link)
Definition: robot.cpp:585
rviz::Robot::setLinkTreeStyle
void setLinkTreeStyle(LinkTreeStyle style)
Definition: robot.cpp:484
rviz::Robot::root_collision_node_
Ogre::SceneNode * root_collision_node_
Node all our collision nodes are children of.
Definition: robot.h:282
rviz::Robot::setEnableAllLinksCheckbox
void setEnableAllLinksCheckbox(const QVariant &val)
Definition: robot.cpp:443
rviz::DisplayContext
Pure-virtual base class for objects which give Display subclasses context in which to work.
Definition: display_context.h:81
Robot
rviz::Robot::setAlpha
void setAlpha(float a)
Definition: robot.cpp:175
rviz::Robot::LinkFactory
Definition: robot.h:195
rviz::Robot::root_visual_node_
Ogre::SceneNode * root_visual_node_
Node all our visual nodes are children of.
Definition: robot.h:281
rviz::Robot::isVisualVisible
bool isVisualVisible()
Returns whether or not the visual representation is set to be visible To be visible this and isVisibl...
Definition: robot.cpp:165
rviz::Robot::changedExpandJointDetails
void changedExpandJointDetails()
Definition: robot.cpp:399
rviz::Robot::updateLinkVisibilities
void updateLinkVisibilities()
Call RobotLink::updateVisibility() on each link.
Definition: robot.cpp:149
rviz::Robot::calculateJointCheckboxes
void calculateJointCheckboxes()
Definition: robot.cpp:646
rviz::Robot::getOtherNode
Ogre::SceneNode * getOtherNode()
Definition: robot.h:175
rviz::Robot::STYLE_LINK_TREE
@ STYLE_LINK_TREE
Definition: robot.h:225
rviz::Robot::update
virtual void update(const LinkUpdater &updater)
Definition: robot.cpp:699
rviz::Robot::getSceneManager
Ogre::SceneManager * getSceneManager()
Definition: robot.h:179
rviz::Robot::useDetailProperty
void useDetailProperty(bool use_detail)
Definition: robot.cpp:324
rviz::Robot::STYLE_DEFAULT
@ STYLE_DEFAULT
Definition: robot.h:223
rviz::Robot::styleShowJoint
static bool styleShowJoint(LinkTreeStyle style)
Definition: robot.cpp:474
rviz::Robot::collision_visible_
bool collision_visible_
Should we show the collision representation?
Definition: robot.h:287
urdf
rviz::Robot::setPosition
virtual void setPosition(const Ogre::Vector3 &position)
Definition: robot.cpp:768
rviz::Robot::getLinks
const M_NameToLink & getLinks() const
Definition: robot.h:153
rviz::Robot::scene_manager_
Ogre::SceneManager * scene_manager_
Definition: robot.h:273
rviz::Robot::changedEnableAllLinks
void changedEnableAllLinks()
Definition: robot.cpp:411
rviz::Robot::setVisible
virtual void setVisible(bool visible)
Set the robot as a whole to be visible or not.
Definition: robot.cpp:120
rviz::Robot::isVisible
bool isVisible()
Returns whether anything is visible.
Definition: robot.cpp:160
rviz::Robot::unparentLinkProperties
void unparentLinkProperties()
Definition: robot.cpp:305
rviz::Robot::changedExpandTree
void changedExpandTree()
Definition: robot.cpp:343
tf
rviz::Robot::getRootLink
RobotLink * getRootLink()
Definition: robot.h:144
rviz::Robot::getLink
RobotLink * getLink(const std::string &name)
Definition: robot.cpp:622
rviz::Robot::enable_all_links_
BoolProperty * enable_all_links_
Definition: robot.h:295
rviz::Robot::getJoint
RobotJoint * getJoint(const std::string &name)
Definition: robot.cpp:634
rviz::Robot
Definition: robot.h:79
rviz::Robot::M_NameToJoint
std::map< std::string, RobotJoint * > M_NameToJoint
Definition: robot.h:152
rviz::Robot::styleShowLink
static bool styleShowLink(LinkTreeStyle style)
Definition: robot.cpp:469
rviz::Robot::style_name_map_
std::map< LinkTreeStyle, std::string > style_name_map_
Definition: robot.h:296
rviz::Robot::Robot
Robot(Ogre::SceneNode *root_node, DisplayContext *context, const std::string &name, Property *parent_property)
Definition: robot.cpp:56
rviz::Robot::load
virtual void load(const urdf::ModelInterface &urdf, bool visual=true, bool collision=true)
Loads meshes/primitives from a robot description. Calls clear() before loading.
Definition: robot.cpp:233
rviz::Robot::getDisplayContext
DisplayContext * getDisplayContext()
Definition: robot.h:183
rviz::Robot::context_
DisplayContext * context_
Definition: robot.h:289
rviz::Robot::LinkFactory::createLink
virtual RobotLink * createLink(Robot *robot, const urdf::LinkConstSharedPtr &link, const std::string &parent_joint_name, bool visual, bool collision)
Definition: robot.cpp:219
rviz::Robot::changedLinkTreeStyle
void changedLinkTreeStyle()
Definition: robot.cpp:494
rviz::Robot::setLinkFactory
void setLinkFactory(LinkFactory *link_factory)
Definition: robot.cpp:111
rviz::Robot::root_link_
RobotLink * root_link_
Definition: robot.h:277
rviz::Robot::clear
virtual void clear()
Clears all data loaded from a URDF.
Definition: robot.cpp:189


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Aug 2 2024 08:43:10