twist_stamped_display.cpp
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2015, JSK Lab
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/o2r other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
36 #include "twist_stamped_display.h"
37 
38 namespace jsk_rviz_plugins
39 {
41  {
42  linear_scale_property_ = new rviz::FloatProperty("linear scale", 1.0,
43  "linear velocity scale",
44  this, SLOT(updateLinearScale()));
45  angular_scale_property_ = new rviz::FloatProperty("angular scale", 1.0,
46  "angular velocity scale",
47  this, SLOT(updateAngularScale()));
48  linear_color_property_ = new rviz::ColorProperty("linear color", QColor(0, 255, 0),
49  "linear velocity color",
50  this, SLOT(updateLinearColor()));
51  angular_color_property_ = new rviz::ColorProperty("angular color", QColor(255, 0, 0),
52  "angular velocity color",
53  this, SLOT(updateAngularColor()));
56  }
57 
59  {
62  }
63 
65  {
78  Ogre::Vector3 zero_scale(0, 0, 0);
79  linear_arrow_->setScale(zero_scale);
80  x_rotate_arrow_->set(0, 0, 0, 0);
81  y_rotate_arrow_->set(0, 0, 0, 0);
82  z_rotate_arrow_->set(0, 0, 0, 0);
83  }
84 
86  {
88  }
89 
91  const geometry_msgs::TwistStamped::ConstPtr& msg)
92  {
93  // move scene_node_ to the frame pose
94  Ogre::Vector3 position;
95  Ogre::Quaternion orientation;
97  msg->header, position, orientation)) {
98  ROS_DEBUG("Error transforming from frame '%s' to frame '%s'",
99  msg->header.frame_id.c_str(), qPrintable(fixed_frame_));
100  return;
101  }
102  scene_node_->setPosition(position);
103  scene_node_->setOrientation(orientation);
104  // linear velocity
106  Ogre::Vector3 linear_direction(msg->twist.linear.x, msg->twist.linear.y, msg->twist.linear.z);
107  Ogre::Vector3 linear_scale(linear_scale_ * linear_direction.length(),
108  linear_scale_ * linear_direction.length(),
109  linear_scale_ * linear_direction.length());
110  linear_arrow_->setScale(linear_scale);
111  linear_arrow_->setDirection(linear_direction);
112 
113  // rotate velocity
116  Ogre::Vector3(0, 1, 0),
117  Ogre::Vector3(0, 0, 1),
118  Ogre::Vector3(1, 0, 0),
119  std::abs(msg->twist.angular.x),
120  msg->twist.angular.x > 0);
123  Ogre::Vector3(0, 0, 1),
124  Ogre::Vector3(1, 0, 0),
125  Ogre::Vector3(0, 1, 0),
126  std::abs(msg->twist.angular.y),
127  msg->twist.angular.y > 0);
130  Ogre::Vector3(1, 0, 0),
131  Ogre::Vector3(0, 1, 0),
132  Ogre::Vector3(0, 0, 1),
133  std::abs(msg->twist.angular.z),
134  msg->twist.angular.z > 0);
135  Ogre::ColourValue c = rviz::qtToOgre(angular_color_);
136  x_rotate_circle_->setColor(c.r, c.g, c.b, 1.0);
137  y_rotate_circle_->setColor(c.r, c.g, c.b, 1.0);
138  z_rotate_circle_->setColor(c.r, c.g, c.b, 1.0);
139  x_rotate_arrow_->setColor(c);
140  y_rotate_arrow_->setColor(c);
141  z_rotate_arrow_->setColor(c);
142  }
143 
145  BillboardLinePtr circle,
146  ArrowPtr arrow,
147  const Ogre::Vector3& ux,
148  const Ogre::Vector3& uy,
149  const Ogre::Vector3& uz,
150  const double r,
151  bool positive)
152  {
153  circle->clear();
154  if (r < 1.0e-9) { // too small to visualize it
155  arrow->set(0, 0, 0, 0);
156  return;
157  }
158  const double step = 10; // per 10 deg
159  const double start_theta = 20;
160  const double end_theta = 340;
161  circle->setMaxPointsPerLine((end_theta - start_theta) / step + 1); // +1?
162  circle->setLineWidth(r * angular_scale_ / 2 * 0.1);
163  for (double theta = start_theta; theta < end_theta; theta += step) {
164  double rad = theta / 180 * M_PI;
165  Ogre::Vector3 p = ux * cos(rad) * r * angular_scale_ + uy * sin(rad) * r * angular_scale_;
166  circle->addPoint(p);
167  }
168  // put arrow
169  if (positive) {
170  double end_rad = (end_theta - step) / 180 * M_PI;
171  Ogre::Vector3 endpoint = ux * cos(end_rad) * r * angular_scale_ + uy * sin(end_rad) * r * angular_scale_;
172  Ogre::Vector3 direction = ux * (- sin(end_rad)) + uy * cos(end_rad);
173  arrow->setPosition(endpoint);
174  arrow->setDirection(direction);
175  }
176  else {
177  double end_rad = (start_theta + step) / 180 * M_PI;
178  Ogre::Vector3 endpoint = ux * cos(end_rad) * r * angular_scale_ + uy * sin(end_rad) * r * angular_scale_;
179  Ogre::Vector3 direction = - ux * (- sin(end_rad)) - uy * cos(end_rad);
180  arrow->setPosition(endpoint);
181  arrow->setDirection(direction);
182  }
183  arrow->set(0, 0, r * angular_scale_ / 2, r * angular_scale_ / 2);
184  }
185 
187  // update methods
190  {
192  }
193 
195  {
197  }
198 
200  {
202  }
203 
205  {
207  }
208 }
209 
virtual QColor getColor() const
void setMin(float min)
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
DisplayContext * context_
virtual float getFloat() const
Ogre::SceneNode * scene_node_
Ogre::ColourValue qtToOgre(const QColor &c)
QString fixed_frame_
virtual void updateRotationVelocity(BillboardLinePtr circle, ArrowPtr arrow, const Ogre::Vector3 &ux, const Ogre::Vector3 &uy, const Ogre::Vector3 &uz, const double r, bool positive)
virtual void processMessage(const geometry_msgs::TwistStamped::ConstPtr &msg)
virtual FrameManager * getFrameManager() const =0
Ogre::SceneManager * scene_manager_
unsigned int step
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
#define ROS_DEBUG(...)


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Sat Mar 20 2021 03:03:18