|
18 | 18 | namespace rviz |
19 | 19 | { |
20 | 20 |
|
21 | | - WrenchStampedDisplay::WrenchStampedDisplay() |
22 | | - { |
23 | | - force_color_property_ = |
24 | | - new rviz::ColorProperty( "Force Color", QColor( 204, 51, 51 ), |
| 21 | +WrenchStampedDisplay::WrenchStampedDisplay() |
| 22 | +{ |
| 23 | + force_color_property_ = |
| 24 | + new rviz::ColorProperty( "Force Color", QColor( 204, 51, 51 ), |
25 | 25 | "Color to draw the force arrows.", |
26 | 26 | this, SLOT( updateColorAndAlpha() )); |
27 | 27 |
|
28 | | - torque_color_property_ = |
29 | | - new rviz::ColorProperty( "Torque Color", QColor( 204, 204, 51), |
| 28 | + torque_color_property_ = |
| 29 | + new rviz::ColorProperty( "Torque Color", QColor( 204, 204, 51), |
30 | 30 | "Color to draw the torque arrows.", |
31 | 31 | this, SLOT( updateColorAndAlpha() )); |
32 | 32 |
|
33 | | - alpha_property_ = |
| 33 | + alpha_property_ = |
34 | 34 | new rviz::FloatProperty( "Alpha", 1.0, |
35 | 35 | "0 is fully transparent, 1.0 is fully opaque.", |
36 | 36 | this, SLOT( updateColorAndAlpha() )); |
37 | 37 |
|
38 | | - force_scale_property_ = |
| 38 | + force_scale_property_ = |
39 | 39 | new rviz::FloatProperty( "Force Arrow Scale", 2.0, |
40 | 40 | "force arrow scale", |
41 | 41 | this, SLOT( updateColorAndAlpha() )); |
42 | 42 |
|
43 | | - torque_scale_property_ = |
| 43 | + torque_scale_property_ = |
44 | 44 | new rviz::FloatProperty( "Torque Arrow Scale", 2.0, |
45 | 45 | "torque arrow scale", |
46 | | - this, SLOT( updateColorAndAlpha() )); |
| 46 | + this, SLOT( updateColorAndAlpha() )); |
47 | 47 |
|
48 | | - width_property_ = |
| 48 | + width_property_ = |
49 | 49 | new rviz::FloatProperty( "Arrow Width", 0.5, |
50 | 50 | "arrow width", |
51 | 51 | this, SLOT( updateColorAndAlpha() )); |
52 | 52 |
|
53 | 53 |
|
54 | | - history_length_property_ = |
55 | | - new rviz::IntProperty( "History Length", 1, |
| 54 | + history_length_property_ = |
| 55 | + new rviz::IntProperty( "History Length", 1, |
56 | 56 | "Number of prior measurements to display.", |
57 | 57 | this, SLOT( updateHistoryLength() )); |
58 | 58 |
|
59 | | - history_length_property_->setMin( 1 ); |
60 | | - history_length_property_->setMax( 100000 ); |
61 | | - } |
| 59 | + history_length_property_->setMin( 1 ); |
| 60 | + history_length_property_->setMax( 100000 ); |
| 61 | +} |
62 | 62 |
|
63 | | - void WrenchStampedDisplay::onInitialize() |
64 | | - { |
65 | | - MFDClass::onInitialize(); |
66 | | - updateHistoryLength( ); |
67 | | - } |
| 63 | +void WrenchStampedDisplay::onInitialize() |
| 64 | +{ |
| 65 | + MFDClass::onInitialize(); |
| 66 | + updateHistoryLength( ); |
| 67 | +} |
| 68 | + |
| 69 | +WrenchStampedDisplay::~WrenchStampedDisplay() |
| 70 | +{ |
| 71 | +} |
| 72 | + |
| 73 | +// Override rviz::Display's reset() function to add a call to clear(). |
| 74 | +void WrenchStampedDisplay::reset() |
| 75 | +{ |
| 76 | + MFDClass::reset(); |
| 77 | + visuals_.clear(); |
| 78 | +} |
68 | 79 |
|
69 | | - WrenchStampedDisplay::~WrenchStampedDisplay() |
| 80 | +void WrenchStampedDisplay::updateColorAndAlpha() |
| 81 | +{ |
| 82 | + float alpha = alpha_property_->getFloat(); |
| 83 | + float force_scale = force_scale_property_->getFloat(); |
| 84 | + float torque_scale = torque_scale_property_->getFloat(); |
| 85 | + float width = width_property_->getFloat(); |
| 86 | + Ogre::ColourValue force_color = force_color_property_->getOgreColor(); |
| 87 | + Ogre::ColourValue torque_color = torque_color_property_->getOgreColor(); |
| 88 | + |
| 89 | + for( size_t i = 0; i < visuals_.size(); i++ ) |
70 | 90 | { |
| 91 | + visuals_[i]->setForceColor( force_color.r, force_color.g, force_color.b, alpha ); |
| 92 | + visuals_[i]->setTorqueColor( torque_color.r, torque_color.g, torque_color.b, alpha ); |
| 93 | + visuals_[i]->setForceScale( force_scale ); |
| 94 | + visuals_[i]->setTorqueScale( torque_scale ); |
| 95 | + visuals_[i]->setWidth( width ); |
71 | 96 | } |
| 97 | +} |
| 98 | + |
| 99 | +// Set the number of past visuals to show. |
| 100 | +void WrenchStampedDisplay::updateHistoryLength() |
| 101 | +{ |
| 102 | + visuals_.rset_capacity(history_length_property_->getInt()); |
| 103 | +} |
72 | 104 |
|
73 | | - // Override rviz::Display's reset() function to add a call to clear(). |
74 | | - void WrenchStampedDisplay::reset() |
| 105 | +bool validateFloats( const geometry_msgs::WrenchStamped& msg ) |
| 106 | +{ |
| 107 | + return rviz::validateFloats(msg.wrench.force) && rviz::validateFloats(msg.wrench.torque) ; |
| 108 | +} |
| 109 | + |
| 110 | +// This is our callback to handle an incoming message. |
| 111 | +void WrenchStampedDisplay::processMessage( const geometry_msgs::WrenchStamped::ConstPtr& msg ) |
| 112 | +{ |
| 113 | + if( !validateFloats( *msg )) |
75 | 114 | { |
76 | | - MFDClass::reset(); |
77 | | - visuals_.clear(); |
| 115 | + setStatus( rviz::StatusProperty::Error, "Topic", "Message contained invalid floating point values (nans or infs)" ); |
| 116 | + return; |
78 | 117 | } |
79 | 118 |
|
80 | | - void WrenchStampedDisplay::updateColorAndAlpha() |
| 119 | + // Here we call the rviz::FrameManager to get the transform from the |
| 120 | + // fixed frame to the frame in the header of this Imu message. If |
| 121 | + // it fails, we can't do anything else so we return. |
| 122 | + Ogre::Quaternion orientation; |
| 123 | + Ogre::Vector3 position; |
| 124 | + if( !context_->getFrameManager()->getTransform( msg->header.frame_id, |
| 125 | + msg->header.stamp, |
| 126 | + position, orientation )) |
81 | 127 | { |
82 | | - float alpha = alpha_property_->getFloat(); |
83 | | - float force_scale = force_scale_property_->getFloat(); |
84 | | - float torque_scale = torque_scale_property_->getFloat(); |
85 | | - float width = width_property_->getFloat(); |
86 | | - Ogre::ColourValue force_color = force_color_property_->getOgreColor(); |
87 | | - Ogre::ColourValue torque_color = torque_color_property_->getOgreColor(); |
88 | | - |
89 | | - for( size_t i = 0; i < visuals_.size(); i++ ) |
90 | | - { |
91 | | - visuals_[i]->setForceColor( force_color.r, force_color.g, force_color.b, alpha ); |
92 | | - visuals_[i]->setTorqueColor( torque_color.r, torque_color.g, torque_color.b, alpha ); |
93 | | - visuals_[i]->setForceScale( force_scale ); |
94 | | - visuals_[i]->setTorqueScale( torque_scale ); |
95 | | - visuals_[i]->setWidth( width ); |
96 | | - } |
| 128 | + ROS_DEBUG( "Error transforming from frame '%s' to frame '%s'", |
| 129 | + msg->header.frame_id.c_str(), qPrintable( fixed_frame_ )); |
| 130 | + return; |
97 | 131 | } |
98 | 132 |
|
99 | | - // Set the number of past visuals to show. |
100 | | - void WrenchStampedDisplay::updateHistoryLength() |
| 133 | + if ( position.isNaN() ) |
101 | 134 | { |
102 | | - visuals_.rset_capacity(history_length_property_->getInt()); |
| 135 | + ROS_ERROR_THROTTLE(1.0, "Wrench position contains NaNs. Skipping render as long as the position is invalid"); |
| 136 | + return; |
103 | 137 | } |
104 | 138 |
|
105 | | - bool validateFloats( const geometry_msgs::WrenchStamped& msg ) |
| 139 | + // We are keeping a circular buffer of visual pointers. This gets |
| 140 | + // the next one, or creates and stores it if the buffer is not full |
| 141 | + boost::shared_ptr<WrenchStampedVisual> visual; |
| 142 | + if( visuals_.full() ) |
106 | 143 | { |
107 | | - return rviz::validateFloats(msg.wrench.force) && rviz::validateFloats(msg.wrench.torque) ; |
| 144 | + visual = visuals_.front(); |
108 | 145 | } |
109 | | - |
110 | | - // This is our callback to handle an incoming message. |
111 | | - void WrenchStampedDisplay::processMessage( const geometry_msgs::WrenchStamped::ConstPtr& msg ) |
| 146 | + else |
112 | 147 | { |
113 | | - if( !validateFloats( *msg )) |
114 | | - { |
115 | | - setStatus( rviz::StatusProperty::Error, "Topic", "Message contained invalid floating point values (nans or infs)" ); |
116 | | - return; |
117 | | - } |
118 | | - |
119 | | - // Here we call the rviz::FrameManager to get the transform from the |
120 | | - // fixed frame to the frame in the header of this Imu message. If |
121 | | - // it fails, we can't do anything else so we return. |
122 | | - Ogre::Quaternion orientation; |
123 | | - Ogre::Vector3 position; |
124 | | - if( !context_->getFrameManager()->getTransform( msg->header.frame_id, |
125 | | - msg->header.stamp, |
126 | | - position, orientation )) |
127 | | - { |
128 | | - ROS_DEBUG( "Error transforming from frame '%s' to frame '%s'", |
129 | | - msg->header.frame_id.c_str(), qPrintable( fixed_frame_ )); |
130 | | - return; |
131 | | - } |
132 | | - |
133 | | - if ( position.isNaN() ) |
134 | | - { |
135 | | - ROS_ERROR_THROTTLE(1.0, "Wrench position contains NaNs. Skipping render as long as the position is invalid"); |
136 | | - return; |
137 | | - } |
138 | | - |
139 | | - // We are keeping a circular buffer of visual pointers. This gets |
140 | | - // the next one, or creates and stores it if the buffer is not full |
141 | | - boost::shared_ptr<WrenchStampedVisual> visual; |
142 | | - if( visuals_.full() ) |
143 | | - { |
144 | | - visual = visuals_.front(); |
145 | | - } |
146 | | - else |
147 | | - { |
148 | | - visual.reset(new WrenchStampedVisual( context_->getSceneManager(), scene_node_ )); |
149 | | - } |
150 | | - |
151 | | - // Now set or update the contents of the chosen visual. |
152 | | - visual->setMessage( msg ); |
153 | | - visual->setFramePosition( position ); |
154 | | - visual->setFrameOrientation( orientation ); |
155 | | - float alpha = alpha_property_->getFloat(); |
156 | | - float force_scale = force_scale_property_->getFloat(); |
157 | | - float torque_scale = torque_scale_property_->getFloat(); |
158 | | - float width = width_property_->getFloat(); |
159 | | - Ogre::ColourValue force_color = force_color_property_->getOgreColor(); |
160 | | - Ogre::ColourValue torque_color = torque_color_property_->getOgreColor(); |
161 | | - visual->setForceColor( force_color.r, force_color.g, force_color.b, alpha ); |
162 | | - visual->setTorqueColor( torque_color.r, torque_color.g, torque_color.b, alpha ); |
163 | | - visual->setForceScale( force_scale ); |
164 | | - visual->setTorqueScale( torque_scale ); |
165 | | - visual->setWidth( width ); |
166 | | - |
167 | | - // And send it to the end of the circular buffer |
168 | | - visuals_.push_back(visual); |
| 148 | + visual.reset(new WrenchStampedVisual( context_->getSceneManager(), scene_node_ )); |
169 | 149 | } |
170 | 150 |
|
| 151 | + // Now set or update the contents of the chosen visual. |
| 152 | + visual->setWrench( msg->wrench ); |
| 153 | + visual->setFramePosition( position ); |
| 154 | + visual->setFrameOrientation( orientation ); |
| 155 | + float alpha = alpha_property_->getFloat(); |
| 156 | + float force_scale = force_scale_property_->getFloat(); |
| 157 | + float torque_scale = torque_scale_property_->getFloat(); |
| 158 | + float width = width_property_->getFloat(); |
| 159 | + Ogre::ColourValue force_color = force_color_property_->getOgreColor(); |
| 160 | + Ogre::ColourValue torque_color = torque_color_property_->getOgreColor(); |
| 161 | + visual->setForceColor( force_color.r, force_color.g, force_color.b, alpha ); |
| 162 | + visual->setTorqueColor( torque_color.r, torque_color.g, torque_color.b, alpha ); |
| 163 | + visual->setForceScale( force_scale ); |
| 164 | + visual->setTorqueScale( torque_scale ); |
| 165 | + visual->setWidth( width ); |
| 166 | + |
| 167 | + // And send it to the end of the circular buffer |
| 168 | + visuals_.push_back(visual); |
| 169 | +} |
| 170 | + |
171 | 171 | } // end namespace rviz |
172 | 172 |
|
173 | 173 | // Tell pluginlib about this class. It is important to do this in |
174 | 174 | // global scope, outside our package's namespace. |
175 | 175 | #include <pluginlib/class_list_macros.h> |
176 | 176 | PLUGINLIB_EXPORT_CLASS( rviz::WrenchStampedDisplay, rviz::Display ) |
177 | | - |
178 | | - |
179 | | - |
0 commit comments