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 
38 #include <OgreVector3.h>
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 namespace Ogre
45 {
46 class SceneManager;
47 class Entity;
48 class SceneNode;
49 class Vector3;
50 class Quaternion;
51 class Any;
52 class RibbonTrail;
53 class SceneNode;
54 } // namespace Ogre
55 
56 namespace rviz
57 {
58 class Object;
59 class Axes;
60 } // namespace rviz
61 
62 namespace tf
63 {
64 class TransformListener;
65 }
66 
67 namespace rviz
68 {
69 class Property;
70 class EnumProperty;
71 class BoolProperty;
72 class Robot;
73 class RobotLink;
74 class RobotJoint;
75 class DisplayContext;
76 
84 class Robot : public QObject
85 {
86  Q_OBJECT
87 public:
88  Robot(Ogre::SceneNode* root_node,
89  DisplayContext* context,
90  const std::string& name,
91  Property* parent_property);
92  ~Robot() override;
93 
101  virtual void load(const urdf::ModelInterface& urdf, bool visual = true, bool collision = true);
102 
106  virtual void clear();
107 
108  virtual void update(const LinkUpdater& updater);
109 
114  virtual void setVisible(bool visible);
115 
120  void setVisualVisible(bool visible);
121 
126  void setCollisionVisible(bool visible);
127 
131  bool isVisible();
136  bool isVisualVisible();
141  bool isCollisionVisible();
142 
143  void setAlpha(float a);
144  float getAlpha()
145  {
146  return alpha_;
147  }
148 
150  {
151  return root_link_;
152  }
153  RobotLink* getLink(const std::string& name);
154  RobotJoint* getJoint(const std::string& name);
155 
156  typedef std::map<std::string, RobotLink*> M_NameToLink;
157  typedef std::map<std::string, RobotJoint*> M_NameToJoint;
158  const M_NameToLink& getLinks() const
159  {
160  return links_;
161  }
162  const M_NameToJoint& getJoints() const
163  {
164  return joints_;
165  }
166 
167  const std::string& getName()
168  {
169  return name_;
170  }
171 
172  Ogre::SceneNode* getVisualNode()
173  {
174  return root_visual_node_;
175  }
176  Ogre::SceneNode* getCollisionNode()
177  {
178  return root_collision_node_;
179  }
180  Ogre::SceneNode* getOtherNode()
181  {
182  return root_other_node_;
183  }
184  Ogre::SceneManager* getSceneManager()
185  {
186  return scene_manager_;
187  }
189  {
190  return context_;
191  }
192 
193  virtual void setPosition(const Ogre::Vector3& position);
194  virtual void setOrientation(const Ogre::Quaternion& orientation);
195  virtual void setScale(const Ogre::Vector3& scale);
196  virtual const Ogre::Vector3& getPosition();
197  virtual const Ogre::Quaternion& getOrientation();
198 
201  {
202  public:
203  virtual ~LinkFactory() = default;
204 
205  virtual RobotLink* createLink(Robot* robot,
206  const urdf::LinkConstSharedPtr& link,
207  const std::string& parent_joint_name,
208  bool visual,
209  bool collision);
210  virtual RobotJoint* createJoint(Robot* robot, const urdf::JointConstSharedPtr& joint);
211  };
212 
222  void setLinkFactory(LinkFactory* link_factory);
223 
224 
226  {
227  STYLE_LINK_LIST, // list of all links sorted by link name
228  STYLE_DEFAULT = STYLE_LINK_LIST,
229  STYLE_JOINT_LIST, // list of joints sorted by joint name
230  STYLE_LINK_TREE, // tree of links
231  STYLE_JOINT_LINK_TREE // tree of joints with links
232  };
233 
235  void setLinkTreeStyle(LinkTreeStyle style);
236 
239  {
240  return link_tree_;
241  }
242 
243  // set joint checkboxes and All Links Enabled checkbox based on current link enables.
244  void calculateJointCheckboxes();
245 
246 private Q_SLOTS:
247  void changedLinkTreeStyle();
248  void changedExpandTree();
249  void changedHideSubProperties();
250  void changedEnableAllLinks();
251  void changedExpandLinkDetails();
252  void changedExpandJointDetails();
253 
254 protected:
256  void updateLinkVisibilities();
257 
260  void unparentLinkProperties();
261 
262  // place sub properties under detail (or not)
263  void useDetailProperty(bool use_detail);
264 
266  void addLinkToLinkTree(LinkTreeStyle style, Property* parent, RobotLink* link);
267  void addJointToLinkTree(LinkTreeStyle style, Property* parent, RobotJoint* joint);
268 
269  // set the value of the EnableAllLinks property without affecting child links/joints.
270  void setEnableAllLinksCheckbox(QVariant val);
271 
273  void initLinkTreeStyle();
274  static bool styleShowLink(LinkTreeStyle style);
275  static bool styleShowJoint(LinkTreeStyle style);
276  static bool styleIsTree(LinkTreeStyle style);
277 
278  Ogre::SceneManager* scene_manager_;
279 
280  M_NameToLink links_;
281  M_NameToJoint joints_;
283 
285 
286  Ogre::SceneNode* root_visual_node_;
287  Ogre::SceneNode* root_collision_node_;
288  Ogre::SceneNode* root_other_node_;
289 
290  bool visible_;
293 
301  std::map<LinkTreeStyle, std::string> style_name_map_;
302 
303  bool doing_set_checkbox_; // used only inside setEnableAllLinksCheckbox()
304  bool robot_loaded_; // true after robot model is loaded.
305 
306  // true inside changedEnableAllLinks(). Prevents calculateJointCheckboxes()
307  // from recalculating over and over.
309 
310  std::string name_;
311  float alpha_;
312 };
313 
314 } // namespace rviz
315 
316 #endif /* RVIZ_ROBOT_H_ */
float alpha_
Definition: robot.h:311
M_NameToJoint joints_
Map of name to joint info, stores all loaded joints.
Definition: robot.h:281
const M_NameToLink & getLinks() const
Definition: robot.h:158
Ogre::SceneNode * getOtherNode()
Definition: robot.h:180
std::map< std::string, RobotJoint * > M_NameToJoint
Definition: robot.h:157
LinkTreeStyle
Definition: robot.h:225
std::string name_
Definition: robot.h:310
const M_NameToJoint & getJoints() const
Definition: robot.h:162
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
Ogre::SceneManager * getSceneManager()
Definition: robot.h:184
BoolProperty * expand_joint_details_
Definition: robot.h:299
LinkFactory * link_factory_
factory for generating links and joints
Definition: robot.h:284
RobotLink * getRootLink()
Definition: robot.h:149
void setVisible(PanelDockWidget *widget, bool visible)
Definition: display.cpp:293
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
std::map< LinkTreeStyle, std::string > style_name_map_
Definition: robot.h:301
const std::string & getName()
Definition: robot.h:167
Ogre::SceneNode * getCollisionNode()
Definition: robot.h:176
bool visual_visible_
Should we show the visual representation?
Definition: robot.h:291
Pure-virtual base class for objects which give Display subclasses context in which to work...
RobotLink * root_link_
Definition: robot.h:282
Ogre::SceneNode * root_visual_node_
Node all our visual nodes are children of.
Definition: robot.h:286
BoolProperty * enable_all_links_
Definition: robot.h:300
BoolProperty * expand_tree_
Definition: robot.h:297
float getAlpha()
Definition: robot.h:144
Property * getLinkTreeProperty()
Definition: robot.h:238
Contains any data we need from a joint in the robot.
Definition: robot_joint.h:84
Ogre::SceneManager * scene_manager_
Definition: robot.h:278
Ogre::SceneNode * getVisualNode()
Definition: robot.h:172
bool visible_
Should we show anything at all? (affects visual, collision, axes, and trails)
Definition: robot.h:290
bool inChangedEnableAllLinks
Definition: robot.h:308
std::map< std::string, RobotLink * > M_NameToLink
Definition: robot.h:156
BoolProperty * expand_link_details_
Definition: robot.h:298
Property specialized to provide getter for booleans.
Definition: bool_property.h:38
bool robot_loaded_
Definition: robot.h:304
bool doing_set_checkbox_
Definition: robot.h:303
EnumProperty * link_tree_style_
Definition: robot.h:296
Ogre::SceneNode * root_other_node_
Definition: robot.h:288
bool isVisible(PanelDockWidget *widget)
Definition: display.cpp:297
Property * link_tree_
Definition: robot.h:295
DisplayContext * context_
Definition: robot.h:294
bool collision_visible_
Should we show the collision representation?
Definition: robot.h:292
Ogre::SceneNode * root_collision_node_
Node all our collision nodes are children of.
Definition: robot.h:287
M_NameToLink links_
Map of name to link info, stores all loaded links.
Definition: robot.h:280
Enum property.
Definition: enum_property.h:46
DisplayContext * getDisplayContext()
Definition: robot.h:188


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:25