wrench_display.cpp
Go to the documentation of this file.
1 #include <OgreSceneNode.h>
2 #include <OgreSceneManager.h>
3 
5 #include <rviz/frame_manager.h>
10 #include <rviz/validate_floats.h>
11 
12 #include <boost/foreach.hpp>
13 
14 #include "wrench_visual.h"
15 
16 #include "wrench_display.h"
17 
18 namespace rviz
19 {
21 {
23  new rviz::ColorProperty("Force Color", QColor(204, 51, 51), "Color to draw the force arrows.",
24  this, SLOT(updateProperties()));
25 
27  new rviz::ColorProperty("Torque Color", QColor(204, 204, 51), "Color to draw the torque arrows.",
28  this, SLOT(updateProperties()));
29 
30  alpha_property_ = new rviz::FloatProperty("Alpha", 1.0, "0 is fully transparent, 1.0 is fully opaque.",
31  this, SLOT(updateProperties()));
32 
33  force_scale_property_ = new rviz::FloatProperty("Force Arrow Scale", 2.0, "force arrow scale", this,
34  SLOT(updateProperties()));
35 
36  torque_scale_property_ = new rviz::FloatProperty("Torque Arrow Scale", 2.0, "torque arrow scale", this,
37  SLOT(updateProperties()));
38 
40  new rviz::FloatProperty("Arrow Width", 0.5, "arrow width", this, SLOT(updateProperties()));
41 
42 
44  new rviz::IntProperty("History Length", 1, "Number of prior measurements to display.", this,
45  SLOT(updateHistoryLength()));
46 
47  hide_small_values_property_ = new rviz::BoolProperty("Hide Small Values", true, "Hide small values",
48  this, SLOT(updateProperties()));
49 
52 }
53 
55 {
58 }
59 
61 {
62 }
63 
64 // Override rviz::Display's reset() function to add a call to clear().
66 {
68  visuals_.clear();
69 }
70 
72 {
73  float alpha = alpha_property_->getFloat();
74  float force_scale = force_scale_property_->getFloat();
75  float torque_scale = torque_scale_property_->getFloat();
76  float width = width_property_->getFloat();
77  bool hide_small_values = hide_small_values_property_->getBool();
78  Ogre::ColourValue force_color = force_color_property_->getOgreColor();
79  Ogre::ColourValue torque_color = torque_color_property_->getOgreColor();
80 
81  for (size_t i = 0; i < visuals_.size(); i++)
82  {
83  visuals_[i]->setForceColor(force_color.r, force_color.g, force_color.b, alpha);
84  visuals_[i]->setTorqueColor(torque_color.r, torque_color.g, torque_color.b, alpha);
85  visuals_[i]->setForceScale(force_scale);
86  visuals_[i]->setTorqueScale(torque_scale);
87  visuals_[i]->setWidth(width);
88  visuals_[i]->setHideSmallValues(hide_small_values);
89  }
90 }
91 
92 // Set the number of past visuals to show.
94 {
95  visuals_.rset_capacity(history_length_property_->getInt());
96 }
97 
98 
99 bool validateFloats(const geometry_msgs::WrenchStamped& msg)
100 {
101  return rviz::validateFloats(msg.wrench.force) && rviz::validateFloats(msg.wrench.torque);
102 }
103 
104 // This is our callback to handle an incoming message.
105 void WrenchStampedDisplay::processMessage(const geometry_msgs::WrenchStamped::ConstPtr& msg)
106 {
107  if (!validateFloats(*msg))
108  {
110  "Message contained invalid floating point values (nans or infs)");
111  return;
112  }
113 
114  // Here we call the rviz::FrameManager to get the transform from the
115  // fixed frame to the frame in the header of this Imu message. If
116  // it fails, we can't do anything else so we return.
117  Ogre::Quaternion orientation;
118  Ogre::Vector3 position;
119  if (!context_->getFrameManager()->getTransform(msg->header.frame_id, msg->header.stamp, position,
120  orientation))
121  {
122  ROS_DEBUG("Error transforming from frame '%s' to frame '%s'", msg->header.frame_id.c_str(),
123  qPrintable(fixed_frame_));
124  return;
125  }
126 
127  if (position.isNaN())
128  {
130  1.0, "Wrench position contains NaNs. Skipping render as long as the position is invalid");
131  return;
132  }
133 
134  // We are keeping a circular buffer of visual pointers. This gets
135  // the next one, or creates and stores it if the buffer is not full
137  if (visuals_.full())
138  {
139  visual = visuals_.front();
140  }
141  else
142  {
143  visual.reset(new WrenchVisual(context_->getSceneManager(), scene_node_));
144  }
145 
146  // Now set or update the contents of the chosen visual.
147  visual->setWrench(msg->wrench);
148  visual->setFramePosition(position);
149  visual->setFrameOrientation(orientation);
150  float alpha = alpha_property_->getFloat();
151  float force_scale = force_scale_property_->getFloat();
152  float torque_scale = torque_scale_property_->getFloat();
153  float width = width_property_->getFloat();
154  Ogre::ColourValue force_color = force_color_property_->getOgreColor();
155  Ogre::ColourValue torque_color = torque_color_property_->getOgreColor();
156  visual->setForceColor(force_color.r, force_color.g, force_color.b, alpha);
157  visual->setTorqueColor(torque_color.r, torque_color.g, torque_color.b, alpha);
158  visual->setForceScale(force_scale);
159  visual->setTorqueScale(torque_scale);
160  visual->setWidth(width);
161 
162  // And send it to the end of the circular buffer
163  visuals_.push_back(visual);
164 }
165 
166 } // end namespace rviz
167 
168 // Tell pluginlib about this class. It is important to do this in
169 // global scope, outside our package's namespace.
rviz::FloatProperty * force_scale_property_
boost::circular_buffer< boost::shared_ptr< WrenchVisual > > visuals_
rviz::ColorProperty * force_color_property_
void onInitialize() override
Override this function to do subclass-specific initialization.
DisplayContext * context_
This DisplayContext pointer is the main connection a Display has into the rest of rviz...
Definition: display.h:287
rviz::FloatProperty * alpha_property_
rviz::IntProperty * history_length_property_
void reset() override
Called to tell the display to clear its state.
Ogre::ColourValue getOgreColor() const
void setMin(int min)
rviz::FloatProperty * torque_scale_property_
Property specialized to enforce floating point max/min.
Property specialized to provide max/min enforcement for integers.
Definition: int_property.h:37
Ogre::SceneNode * scene_node_
The Ogre::SceneNode to hold all 3D scene elements shown by this Display.
Definition: display.h:295
void setMax(int max)
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
Definition: display.h:312
bool validateFloats(const sensor_msgs::CameraInfo &msg)
#define ROS_ERROR_THROTTLE(period,...)
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
rviz::FloatProperty * width_property_
virtual int getInt() const
Return the internal property value as an integer.
Definition: int_property.h:74
virtual Ogre::SceneManager * getSceneManager() const =0
Returns the Ogre::SceneManager used for the main RenderPanel.
Property specialized to provide getter for booleans.
Definition: bool_property.h:38
virtual float getFloat() const
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
Return the pose for a header, relative to the fixed frame, in Ogre classes.
rviz::BoolProperty * hide_small_values_property_
rviz::ColorProperty * torque_color_property_
void processMessage(const geometry_msgs::WrenchStamped::ConstPtr &msg) override
virtual bool getBool() const
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
Show status level and text. This is thread-safe.
Definition: display.cpp:175
#define ROS_DEBUG(...)


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