MultiRobotInfoVisual.h
Go to the documentation of this file.
1 #ifndef MULTI_ROBOT_INFO_VISUAL_HPP
2 #define MULTI_ROBOT_INFO_VISUAL_HPP
3 
4 #include <rviz/tool.h>
5 #include <ros/ros.h>
11 #include <OgreManualObject.h>
13 #include <map>
14 #include <memory>
15 #include <vector>
16 #include <boost/circular_buffer.hpp>
17 #include "TextVisual.h"
18 
19 #include <tuw_multi_robot_msgs/RobotInfo.h>
20 #include <tuw_multi_robot_msgs/Route.h>
21 #include <geometry_msgs/PoseWithCovariance.h>
22 #include <Eigen/Core>
23 #include <Eigen/Geometry>
24 
25 namespace tuw_multi_robot_rviz
26 {
27 
29 
30  public:
31 
32  using buf_type = boost::circular_buffer<geometry_msgs::PoseWithCovariance>;
33  RobotAttributes(size_t id,
34  std::string &rname,
35  double rad,
36  buf_type &pose,
37  Ogre::ColourValue color,
38  Ogre::SceneManager *_scene_manager,
39  Ogre::SceneNode *_parent_node);
40 
42 
43  std::string robot_name;
44  double robot_radius;
45  size_t robot_id;
46  double path_length_;
47  bool disabled;
48  bool path_stale;
49 
50  std::vector<std::unique_ptr<TextVisual>> route_visuals;
51 
53  void updateColor(Ogre::ColourValue &c)
54  {
55  color = c;
56  }
57 
59  void setDisabled()
60  {
61  disabled = true;
62  delete circle;
63  delete arrow;
64  circle = NULL;
65  arrow = NULL;
66  }
67 
68  void updatePose(const geometry_msgs::PoseWithCovariance &pose)
69  {
70  ros_poses.push_front(pose);
71  current_pos = Ogre::Vector3(pose.pose.position.x, pose.pose.position.y, pose.pose.position.z);
72  current_orient = Ogre::Quaternion(pose.pose.orientation.w, pose.pose.orientation.x, pose.pose.orientation.y, pose.pose.orientation.z);
73  }
74 
75  void updatePose(const buf_type &pose)
76  {
77  ros_poses = pose;
78 
79  if (pose.empty())
80  {
81  return;
82  }
83 
84  const auto current_pose = pose.front();
85  current_pos = Ogre::Vector3(current_pose.pose.position.x,
86  current_pose.pose.position.y,
87  current_pose.pose.position.z);
88 
89  current_orient = Ogre::Quaternion(current_pose.pose.orientation.w,
90  current_pose.pose.orientation.x,
91  current_pose.pose.orientation.y,
92  current_pose.pose.orientation.z);
93  }
94 
95  void setPoseBufferLength(size_t len)
96  {
97  ros_poses.resize(len);
98  }
99 
101  double getPathLength()
102  {
103  if (path_stale)
104  {
106  }
107  return path_length_;
108  }
109 
110  void render();
111 
112  private:
114  std::shared_ptr<tuw_multi_robot_msgs::Route> route;
116  std::size_t seg_id_current;
117 
119  Ogre::ColourValue color;
120  Ogre::Vector3 current_pos;
121  Ogre::Quaternion current_orient;
122  Ogre::SceneManager *scene_manager;
123  Ogre::SceneNode *frame_node;
124  Ogre::ManualObject* circle;
125  Ogre::ManualObject* arrow;
126  std::unique_ptr<TextVisual> text;
127 
129  void cbRoute(const ros::MessageEvent<const tuw_multi_robot_msgs::Route> &_event, int _topic);
130 
132  void updateCircle(bool first_time=false);
133 
135  void updateArrow(bool first_time=false);
136 
138  void updateText(bool first_time=false);
139 
141  void make_robot();
142 
144  void make_route();
145 
148  {
149  if (route == nullptr)
150  return;
151 
152  double min_dist = std::numeric_limits<double>::max();
153 
154  //Assumes sorted path!!
155  for (size_t i=seg_id_current; i < route->segments.size(); ++i)
156  {
157  const auto s = route->segments[i];
158  const auto position_s = s.start.position;
159  const auto position_e = s.end.position;
160  Eigen::Vector3f ps(position_s.x, position_s.y, position_s.z);
161  Eigen::Vector3f dvec (ps - Eigen::Vector3f(current_pos.x, current_pos.y, current_pos.z));
162  double dist = dvec.norm();
163  if (dist < min_dist)
164  {
165  min_dist = dist;
166  seg_id_current = i;
167  }
168  }
169 
170  double acc_len = 0;
171  for (size_t i=seg_id_current; i < route->segments.size(); ++i)
172  {
173  const auto s = route->segments[i];
174  auto position_s = s.start.position;
175  if (i==seg_id_current)
176  {
177  position_s.x = current_pos.x;
178  position_s.y = current_pos.y;
179  position_s.z = current_pos.z;
180  }
181  const auto position_e = s.end.position;
182  const double dist = pow(position_e.x - position_s.x, 2) + pow(position_e.y - position_s.y,2) + pow(position_e.z - position_s.z,2);
183  acc_len += sqrt(dist);
184  }
185  path_length_ = acc_len;
186  }
187  };
188 
190 {
191 
192 public:
193 
194  MultiRobotInfoVisual(Ogre::SceneManager *_scene_manager, Ogre::SceneNode *_parent_node);
195 
196  virtual ~MultiRobotInfoVisual();
197 
198  void setMessage(const tuw_multi_robot_msgs::RobotInfoConstPtr _msg);
199 
200  void setFramePosition( const Ogre::Vector3& _position);
201  void setFrameOrientation( const Ogre::Quaternion& orientation );
202 
203  // Set the scale of the visual, which is an user-editable
204  // parameter and therefore don't come from the RobotGoalsArrayStamped message.
205  void setScalePose( float scale );
206 
207  // Set the color of the visual's Pose, which is an user-editable
208  // parameter and therefore don't come from the RobotGoalsArrayStamped message.
209  void setColorPose( Ogre::ColourValue color );
210 
211  void disableRobot( const std::string &rName );
212 
213  void enableRobot( const std::string &rName );
214 
215  void resetDuration( const ros::Duration &ts);
216 
217  void resetKeepMeasurementsCount ( const unsigned int c );
218 
219  void doRender();
220 
221 
222 private:
223  using internal_map_type = std::pair<std::string, std::shared_ptr<RobotAttributes>>;
224  using map_type = std::map<std::string, std::shared_ptr<RobotAttributes>>;
225  using map_iterator = std::map<std::string, std::shared_ptr<RobotAttributes>>::iterator;
226  using recycle_map_type = std::map<std::string, ros::Time>;
227 
228  std::vector<std::string> recycle();
229 
230  // The object implementing the actual pose shape
231  //std::map<std::string, std::vector<Ogre::ManualObject*>> robot_renderings_map_;
233  //std::map<std::string, std::vector<std::unique_ptr<TextVisual>>> robot_route_renderings_map_;
234  std::set<std::string> disabled_robots_;
235 
238 
239  int default_size_ = {5};
240  int id_cnt = 0;
241  ros::Duration recycle_thresh_ = ros::Duration(5,0);
242  ros::Duration render_dur_thresh_ = ros::Duration(0.1);
244  // A SceneNode whose pose is set to match the coordinate frame of
245  // the Imu message header.
246  Ogre::SceneNode* frame_node_;
247 
248  // The SceneManager, kept here only so the destructor can ask it to
249  // destroy the ``frame_node_``.
250  Ogre::SceneManager* scene_manager_;
251 
252  // The pose Shape object's scale
253  float scale_pose_;
254 
255  // The pose Shape object's color
256  Ogre::ColourValue color_pose_ = Ogre::ColourValue(1,0,0,1);
257 
258  // The variance Shape object's color
259  Ogre::ColourValue color_variance_;
260 
261 };
262 
263 }
264 
265 #endif
#define NULL
std::map< std::string, std::shared_ptr< RobotAttributes > >::iterator map_iterator
std::unique_ptr< TextVisual > text
XmlRpcServer s
void updatePose(const geometry_msgs::PoseWithCovariance &pose)
std::shared_ptr< tuw_multi_robot_msgs::Route > route
std::vector< std::unique_ptr< TextVisual > > route_visuals
boost::circular_buffer< geometry_msgs::PoseWithCovariance > buf_type
void updateColor(Ogre::ColourValue &c)
std::map< std::string, ros::Time > recycle_map_type
RobotAttributes(size_t id, std::string &rname, double rad, buf_type &pose, Ogre::ColourValue color, Ogre::SceneManager *_scene_manager, Ogre::SceneNode *_parent_node)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
void updateCircle(bool first_time=false)
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
std::pair< std::string, std::shared_ptr< RobotAttributes > > internal_map_type
void cbRoute(const ros::MessageEvent< const tuw_multi_robot_msgs::Route > &_event, int _topic)
std::map< std::string, std::shared_ptr< RobotAttributes > > map_type


tuw_multi_robot_rviz
Author(s): Benjamin Binder
autogenerated on Mon Feb 28 2022 23:57:45