Skip to content

Commit 2b551f8

Browse files
authored
mass property visualization (#714)
* Add mass properties to robot model display, robot, and robot link. Visual representation is based on gazebo, i.e. visualize mass as equivalent lead ball and inertia as box. * revert mock_view_picker * fix whitespace * fix whitespace * fix whitespace * add definition for M_PI on windows
1 parent 4a4da3e commit 2b551f8

File tree

6 files changed

+220
-15
lines changed

6 files changed

+220
-15
lines changed

rviz_default_plugins/include/rviz_default_plugins/displays/robot_model/robot_model_display.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ private Q_SLOTS:
107107
void updateAlpha();
108108
void updatePropertyVisibility();
109109
void updateRobotDescription();
110+
void updateMassVisible();
111+
void updateInertiaVisible();
110112

111113
void updateTopic() override;
112114

@@ -143,6 +145,10 @@ private Q_SLOTS:
143145
rviz_common::properties::FloatProperty * alpha_property_;
144146
rviz_common::properties::StringProperty * tf_prefix_property_;
145147

148+
rviz_common::properties::Property * mass_properties_;
149+
rviz_common::properties::Property * mass_enabled_property_;
150+
rviz_common::properties::Property * inertia_enabled_property_;
151+
146152
std::unique_ptr<rviz_default_plugins::transformation::TransformerGuard<
147153
rviz_default_plugins::transformation::TFFrameTransformer>> transformer_guard_;
148154
};

rviz_default_plugins/include/rviz_default_plugins/robot/robot.hpp

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,15 @@ class RVIZ_DEFAULT_PLUGINS_PUBLIC Robot : public QObject
110110
* @param urdf The robot description to read from
111111
* @param visual Whether or not to load the visual representation
112112
* @param collision Whether or not to load the collision representation
113+
* @param mass Whether or not to load the mass representation
114+
* @param inertia Whether or not to load the inertia representation
113115
*/
114-
virtual void load(const urdf::ModelInterface & urdf, bool visual = true, bool collision = true);
116+
virtual void load(
117+
const urdf::ModelInterface & urdf,
118+
bool visual = true,
119+
bool collision = true,
120+
bool mass = true,
121+
bool inertia = true);
115122

116123
/**
117124
* \brief Clears all data loaded from a URDF
@@ -138,6 +145,18 @@ class RVIZ_DEFAULT_PLUGINS_PUBLIC Robot : public QObject
138145
*/
139146
void setCollisionVisible(bool visible);
140147

148+
/**
149+
* \brief Set whether the mass of each part is visible
150+
* @param visible Whether the mass of each link is visible
151+
*/
152+
void setMassVisible(bool visible);
153+
154+
/**
155+
* \brief Set whether the inertia of each part is visible
156+
* @param visible Whether the inertia of each link is visible
157+
*/
158+
void setInertiaVisible(bool visible);
159+
141160
/**
142161
* \brief Returns whether anything is visible
143162
*/
@@ -153,6 +172,18 @@ class RVIZ_DEFAULT_PLUGINS_PUBLIC Robot : public QObject
153172
*/
154173
bool isCollisionVisible();
155174

175+
/**
176+
* \brief Returns whether or not mass of each link is visible.
177+
* To be visible this and isVisible() must both be true
178+
*/
179+
bool isMassVisible();
180+
181+
/**
182+
* \brief Returns whether or not inertia of each link is visible.
183+
* To be visible this and isVisible() must both be true
184+
*/
185+
bool isInertiaVisible();
186+
156187
void setAlpha(float a);
157188
float getAlpha() {return alpha_;}
158189

@@ -190,7 +221,9 @@ class RVIZ_DEFAULT_PLUGINS_PUBLIC Robot : public QObject
190221
const urdf::LinkConstSharedPtr & link,
191222
const std::string & parent_joint_name,
192223
bool visual,
193-
bool collision);
224+
bool collision,
225+
bool mass,
226+
bool inertia);
194227
virtual RobotJoint * createJoint(
195228
Robot * robot,
196229
const urdf::JointConstSharedPtr & joint);
@@ -280,6 +313,9 @@ private Q_SLOTS:
280313
bool visual_visible_; ///< Should we show the visual representation?
281314
bool collision_visible_; ///< Should we show the collision representation?
282315

316+
bool mass_visible_; ///< Should we show mass of each link?
317+
bool inertia_visible_; ///< Should we show inertia of each link?
318+
283319
rviz_common::DisplayContext * context_;
284320
rviz_common::properties::Property * link_tree_;
285321
rviz_common::properties::EnumProperty * link_tree_style_;
@@ -300,7 +336,12 @@ private Q_SLOTS:
300336
float alpha_;
301337

302338
private:
303-
void createLinkProperties(const urdf::ModelInterface & urdf, bool visual, bool collision);
339+
void createLinkProperties(
340+
const urdf::ModelInterface & urdf,
341+
bool visual,
342+
bool collision,
343+
bool mass,
344+
bool inertia);
304345
void createJointProperties(const urdf::ModelInterface & urdf);
305346
void log_error(
306347
const RobotLink * link,

rviz_default_plugins/include/rviz_default_plugins/robot/robot_link.hpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ class RVIZ_DEFAULT_PLUGINS_PUBLIC RobotLink : public RobotElementBaseClass
112112
const urdf::LinkConstSharedPtr & link,
113113
const std::string & parent_joint_name,
114114
bool visual,
115-
bool collision);
115+
bool collision,
116+
bool mass,
117+
bool inertia);
116118
~RobotLink() override;
117119

118120
virtual void setRobotAlpha(float a);
@@ -188,6 +190,8 @@ private Q_SLOTS:
188190

189191
void createCollision(const urdf::LinkConstSharedPtr & link);
190192
void createVisual(const urdf::LinkConstSharedPtr & link);
193+
void createMass(const urdf::LinkConstSharedPtr & link);
194+
void createInertia(const urdf::LinkConstSharedPtr & link);
191195
void createSelection();
192196

193197
template<typename T>
@@ -243,10 +247,12 @@ private Q_SLOTS:
243247
std::vector<Ogre::Entity *> collision_meshes_; ///< The entities representing the
244248
///< collision mesh of this link (if they exist)
245249

246-
Ogre::SceneNode * visual_node_; ///< The scene node the visual meshes
247-
///< are attached to
248-
Ogre::SceneNode * collision_node_; ///< The scene node the collision meshes
249-
///< are attached to
250+
Ogre::SceneNode * visual_node_; ///< The scene node the visual meshes are attached to
251+
Ogre::SceneNode * collision_node_; ///< The scene node the collision meshes are attached to
252+
Ogre::SceneNode * mass_node_; ///< The scene node the visual meshes are attached to
253+
Ogre::SceneNode * inertia_node_; ///< The scene node the collision meshes are attached to
254+
rviz_rendering::Shape * mass_shape_; ///< The shape representing the mass
255+
rviz_rendering::Shape * inertia_shape_; ///< The shape representing the inertia
250256

251257
Ogre::RibbonTrail * trail_;
252258

rviz_default_plugins/src/rviz_default_plugins/displays/robot_model/robot_model_display.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ RobotModelDisplay::RobotModelDisplay()
9494
"Whether to display the collision representation of the robot.",
9595
this, SLOT(updateCollisionVisible()));
9696

97+
mass_properties_ = new Property("Mass Properties", QVariant(), "", this);
98+
mass_enabled_property_ = new Property(
99+
"Mass", false,
100+
"Whether to display the visual representation of the mass of each link.",
101+
mass_properties_, SLOT(updateMassVisible()), this);
102+
inertia_enabled_property_ = new Property(
103+
"Inertia", false,
104+
"Whether to display the visual representation of the inertia of each link.",
105+
mass_properties_, SLOT(updateInertiaVisible()), this);
106+
mass_properties_->collapse();
107+
97108
update_rate_property_ = new FloatProperty(
98109
"Update Interval", 0,
99110
"Interval at which to update the links, in seconds. "
@@ -202,6 +213,18 @@ void RobotModelDisplay::updateTfPrefix()
202213
context_->queueRender();
203214
}
204215

216+
void RobotModelDisplay::updateMassVisible()
217+
{
218+
robot_->setMassVisible(mass_enabled_property_->getValue().toBool());
219+
context_->queueRender();
220+
}
221+
222+
void RobotModelDisplay::updateInertiaVisible()
223+
{
224+
robot_->setInertiaVisible(inertia_enabled_property_->getValue().toBool());
225+
context_->queueRender();
226+
}
227+
205228
void RobotModelDisplay::load_urdf()
206229
{
207230
if (!transformer_guard_->checkTransformer()) {

rviz_default_plugins/src/rviz_default_plugins/robot/robot.cpp

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Robot::Robot(
6969
visible_(true),
7070
visual_visible_(true),
7171
collision_visible_(false),
72+
mass_visible_(false),
73+
inertia_visible_(false),
7274
context_(context),
7375
doing_set_checkbox_(false),
7476
robot_loaded_(false),
@@ -83,6 +85,8 @@ Robot::Robot(
8385

8486
setVisualVisible(visual_visible_);
8587
setCollisionVisible(collision_visible_);
88+
setMassVisible(mass_visible_);
89+
setInertiaVisible(inertia_visible_);
8690
setAlpha(1.0f);
8791

8892
link_tree_ = new Property("Links", QVariant(), "", parent_property);
@@ -136,7 +140,12 @@ Robot::~Robot()
136140
delete link_factory_;
137141
}
138142

139-
void Robot::load(const urdf::ModelInterface & urdf, bool visual, bool collision)
143+
void Robot::load(
144+
const urdf::ModelInterface & urdf,
145+
bool visual,
146+
bool collision,
147+
bool mass,
148+
bool inertia)
140149
{
141150
link_tree_->hide(); // hide until loaded
142151
robot_loaded_ = false;
@@ -148,7 +157,7 @@ void Robot::load(const urdf::ModelInterface & urdf, bool visual, bool collision)
148157
root_link_ = nullptr;
149158

150159
// Properties are not added to display until changedLinkTreeStyle() is called (below).
151-
createLinkProperties(urdf, visual, collision);
160+
createLinkProperties(urdf, visual, collision, mass, inertia);
152161
createJointProperties(urdf);
153162

154163
// robot is now loaded
@@ -164,6 +173,8 @@ void Robot::load(const urdf::ModelInterface & urdf, bool visual, bool collision)
164173

165174
setVisualVisible(isVisualVisible() );
166175
setCollisionVisible(isCollisionVisible() );
176+
setMassVisible(isMassVisible());
177+
setInertiaVisible(isInertiaVisible());
167178
}
168179

169180
void Robot::clear()
@@ -279,6 +290,18 @@ void Robot::setCollisionVisible(bool visible)
279290
updateLinkVisibilities();
280291
}
281292

293+
void Robot::setMassVisible(bool visible)
294+
{
295+
mass_visible_ = visible;
296+
updateLinkVisibilities();
297+
}
298+
299+
void Robot::setInertiaVisible(bool visible)
300+
{
301+
inertia_visible_ = visible;
302+
updateLinkVisibilities();
303+
}
304+
282305
void Robot::updateLinkVisibilities()
283306
{
284307
for (auto & link_map_entry : links_) {
@@ -302,6 +325,16 @@ bool Robot::isCollisionVisible()
302325
return collision_visible_;
303326
}
304327

328+
bool Robot::isMassVisible()
329+
{
330+
return mass_visible_;
331+
}
332+
333+
bool Robot::isInertiaVisible()
334+
{
335+
return inertia_visible_;
336+
}
337+
305338
void Robot::setAlpha(float a)
306339
{
307340
alpha_ = a;
@@ -410,9 +443,11 @@ RobotLink * Robot::LinkFactory::createLink(
410443
const urdf::LinkConstSharedPtr & link,
411444
const std::string & parent_joint_name,
412445
bool visual,
413-
bool collision)
446+
bool collision,
447+
bool mass,
448+
bool inertia)
414449
{
415-
return new RobotLink(robot, link, parent_joint_name, visual, collision);
450+
return new RobotLink(robot, link, parent_joint_name, visual, collision, mass, inertia);
416451
}
417452

418453
RobotJoint * Robot::LinkFactory::createJoint(
@@ -422,7 +457,12 @@ RobotJoint * Robot::LinkFactory::createJoint(
422457
return new RobotJoint(robot, joint);
423458
}
424459

425-
void Robot::createLinkProperties(const urdf::ModelInterface & urdf, bool visual, bool collision)
460+
void Robot::createLinkProperties(
461+
const urdf::ModelInterface & urdf,
462+
bool visual,
463+
bool collision,
464+
bool mass,
465+
bool inertia)
426466
{
427467
for (const auto & link_entry : urdf.links_) {
428468
const urdf::LinkConstSharedPtr & urdf_link = link_entry.second;
@@ -433,7 +473,7 @@ void Robot::createLinkProperties(const urdf::ModelInterface & urdf, bool visual,
433473
}
434474

435475
RobotLink * link = link_factory_->createLink(
436-
this, urdf_link, parent_joint_name, visual, collision);
476+
this, urdf_link, parent_joint_name, visual, collision, mass, inertia);
437477

438478
if (urdf_link == urdf.getRoot()) {
439479
root_link_ = link;

0 commit comments

Comments
 (0)