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 }
55 
56 namespace rviz
57 {
58 class Object;
59 class Axes;
60 }
61 
62 namespace tf
63 {
64 class TransformListener;
65 }
66 
67 namespace rviz
68 {
69 
70 class Property;
71 class EnumProperty;
72 class BoolProperty;
73 class Robot;
74 class RobotLink;
75 class RobotJoint;
76 class DisplayContext;
77 
84 class Robot : public QObject
85 {
86 Q_OBJECT
87 public:
88  Robot( Ogre::SceneNode* root_node, DisplayContext* context, const std::string& name, Property* parent_property );
89  virtual ~Robot();
90 
98  virtual void load( const urdf::ModelInterface &urdf, bool visual = true, bool collision = true );
99 
103  virtual void clear();
104 
105  virtual void update(const LinkUpdater& updater);
106 
111  virtual void setVisible( bool visible );
112 
117  void setVisualVisible( bool visible );
118 
123  void setCollisionVisible( bool visible );
124 
128  bool isVisible();
133  bool isVisualVisible();
138  bool isCollisionVisible();
139 
140  void setAlpha(float a);
141  float getAlpha() { return alpha_; }
142 
143  RobotLink* getRootLink() { return root_link_; }
144  RobotLink* getLink( const std::string& name );
145  RobotJoint* getJoint( const std::string& name );
146 
147  typedef std::map< std::string, RobotLink* > M_NameToLink;
148  typedef std::map< std::string, RobotJoint* > M_NameToJoint;
149  const M_NameToLink& getLinks() const { return links_; }
150  const M_NameToJoint& getJoints() const { return joints_; }
151 
152  const std::string& getName() { return name_; }
153 
154  Ogre::SceneNode* getVisualNode() { return root_visual_node_; }
155  Ogre::SceneNode* getCollisionNode() { return root_collision_node_; }
156  Ogre::SceneNode* getOtherNode() { return root_other_node_; }
157  Ogre::SceneManager* getSceneManager() { return scene_manager_; }
158  DisplayContext* getDisplayContext() { return context_; }
159 
160  virtual void setPosition( const Ogre::Vector3& position );
161  virtual void setOrientation( const Ogre::Quaternion& orientation );
162  virtual void setScale( const Ogre::Vector3& scale );
163  virtual const Ogre::Vector3& getPosition();
164  virtual const Ogre::Quaternion& getOrientation();
165 
168  {
169  public:
170  virtual RobotLink* createLink( Robot* robot,
171  const urdf::LinkConstSharedPtr& link,
172  const std::string& parent_joint_name,
173  bool visual,
174  bool collision);
175  virtual RobotJoint* createJoint( Robot* robot,
176  const urdf::JointConstSharedPtr& joint);
177  };
178 
188  void setLinkFactory(LinkFactory *link_factory);
189 
190 
192  STYLE_LINK_LIST, // list of all links sorted by link name
193  STYLE_DEFAULT = STYLE_LINK_LIST,
194  STYLE_JOINT_LIST, // list of joints sorted by joint name
195  STYLE_LINK_TREE, // tree of links
196  STYLE_JOINT_LINK_TREE // tree of joints with links
197  };
198 
200  void setLinkTreeStyle(LinkTreeStyle style);
201 
204  {
205  return link_tree_;
206  }
207 
208  // set joint checkboxes and All Links Enabled checkbox based on current link enables.
209  void calculateJointCheckboxes();
210 
211 private Q_SLOTS:
212  void changedLinkTreeStyle();
213  void changedExpandTree();
214  void changedHideSubProperties();
215  void changedEnableAllLinks();
216  void changedExpandLinkDetails();
217  void changedExpandJointDetails();
218 
219 protected:
221  void updateLinkVisibilities();
222 
225  void unparentLinkProperties();
226 
227  // place sub properties under detail (or not)
228  void useDetailProperty(bool use_detail);
229 
231  void addLinkToLinkTree(LinkTreeStyle style, Property *parent, RobotLink *link);
232  void addJointToLinkTree(LinkTreeStyle style, Property *parent, RobotJoint *joint);
233 
234  // set the value of the EnableAllLinks property without affecting child links/joints.
235  void setEnableAllLinksCheckbox(QVariant val);
236 
238  void initLinkTreeStyle();
239  static bool styleShowLink(LinkTreeStyle style);
240  static bool styleShowJoint(LinkTreeStyle style);
241  static bool styleIsTree(LinkTreeStyle style);
242 
243  Ogre::SceneManager* scene_manager_;
244 
245  M_NameToLink links_;
246  M_NameToJoint joints_;
248 
250 
251  Ogre::SceneNode* root_visual_node_;
252  Ogre::SceneNode* root_collision_node_;
253  Ogre::SceneNode* root_other_node_;
254 
255  bool visible_;
258 
266  std::map<LinkTreeStyle, std::string> style_name_map_;
267 
268  bool doing_set_checkbox_; // used only inside setEnableAllLinksCheckbox()
269  bool robot_loaded_; // true after robot model is loaded.
270 
271  // true inside changedEnableAllLinks(). Prevents calculateJointCheckboxes()
272  // from recalculating over and over.
274 
275  std::string name_;
276  float alpha_;
277 };
278 
279 } // namespace rviz
280 
281 #endif /* RVIZ_ROBOT_H_ */
std::map< std::string, RobotLink * > M_NameToLink
Definition: robot.h:147
float alpha_
Definition: robot.h:276
M_NameToJoint joints_
Map of name to joint info, stores all loaded joints.
Definition: robot.h:246
std::map< std::string, RobotJoint * > M_NameToJoint
Definition: robot.h:148
Ogre::SceneNode * getOtherNode()
Definition: robot.h:156
LinkTreeStyle
Definition: robot.h:191
std::string name_
Definition: robot.h:275
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:157
BoolProperty * expand_joint_details_
Definition: robot.h:264
LinkFactory * link_factory_
factory for generating links and joints
Definition: robot.h:249
const M_NameToLink & getLinks() const
Definition: robot.h:149
RobotLink * getRootLink()
Definition: robot.h:143
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
std::map< LinkTreeStyle, std::string > style_name_map_
Definition: robot.h:266
const std::string & getName()
Definition: robot.h:152
Ogre::SceneNode * getCollisionNode()
Definition: robot.h:155
bool visual_visible_
Should we show the visual representation?
Definition: robot.h:256
Pure-virtual base class for objects which give Display subclasses context in which to work...
RobotLink * root_link_
Definition: robot.h:247
Ogre::SceneNode * root_visual_node_
Node all our visual nodes are children of.
Definition: robot.h:251
TFSIMD_FORCE_INLINE Vector3()
BoolProperty * enable_all_links_
Definition: robot.h:265
BoolProperty * expand_tree_
Definition: robot.h:262
float getAlpha()
Definition: robot.h:141
Property * getLinkTreeProperty()
Definition: robot.h:203
Contains any data we need from a joint in the robot.
Definition: robot_joint.h:84
const M_NameToJoint & getJoints() const
Definition: robot.h:150
Ogre::SceneManager * scene_manager_
Definition: robot.h:243
Ogre::SceneNode * getVisualNode()
Definition: robot.h:154
bool visible_
Should we show anything at all? (affects visual, collision, axes, and trails)
Definition: robot.h:255
bool inChangedEnableAllLinks
Definition: robot.h:273
BoolProperty * expand_link_details_
Definition: robot.h:263
Property specialized to provide getter for booleans.
Definition: bool_property.h:38
bool robot_loaded_
Definition: robot.h:269
bool doing_set_checkbox_
Definition: robot.h:268
EnumProperty * link_tree_style_
Definition: robot.h:261
Ogre::SceneNode * root_other_node_
Definition: robot.h:253
Property * link_tree_
Definition: robot.h:260
DisplayContext * context_
Definition: robot.h:259
bool collision_visible_
Should we show the collision representation?
Definition: robot.h:257
Ogre::SceneNode * root_collision_node_
Node all our collision nodes are children of.
Definition: robot.h:252
M_NameToLink links_
Map of name to link info, stores all loaded links.
Definition: robot.h:245
Enum property.
Definition: enum_property.h:47
DisplayContext * getDisplayContext()
Definition: robot.h:158


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Wed Aug 28 2019 04:01:51