NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
trajectory_visual.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 #ifndef MOBILITY_PLANNER_QP_TRAJ_OPT_ROS_SRC_TRAJECTORY_VISUAL_H_
20 #define MOBILITY_PLANNER_QP_TRAJ_OPT_ROS_SRC_TRAJECTORY_VISUAL_H_
21 
23 #include <traj_opt_basic/types.h>
24 #include <traj_opt_msgs/Trajectory.h>
25 
26 #include <string>
27 #include <vector>
28 
29 namespace Ogre {
30 class Vector3;
31 class Quaternion;
32 }
33 
34 namespace rviz {
35 class Arrow;
36 class Line;
37 class Shape;
38 class Object;
39 }
40 
41 namespace traj_opt {
42 
43 // BEGIN_TUTORIAL
44 // Declare the visual class for this display.
45 //
46 // Each instance of TrajectoryVisual represents the visualization of a single
47 // traj_opt_msgs::Trajectory message. Currently it just shows an arrow with
48 // the direction and magnitude of the acceleration vector, but could
49 // easily be expanded to include more of the message data.
50 
51 enum Style { Mike, Sikang, CJ, SE3 };
52 
54  public:
55  // Constructor. Creates the visual stuff and puts it into the
56  // scene, but in an unconfigured state.
57  TrajectoryVisual(Ogre::SceneManager* scene_manager,
58  Ogre::SceneNode* parent_node);
59 
60  // Destructor. Removes the visual stuff from the scene.
61  virtual ~TrajectoryVisual();
62 
63  void draw();
64  // Configure the visual to show the data in the message.
65  void setMessage(const traj_opt_msgs::Trajectory::ConstPtr& msg);
66 
67  // Set the pose of the coordinate frame the message refers to.
68  // These could be done inside setMessage(), but that would require
69  // calls to FrameManager and error handling inside setMessage(),
70  // which doesn't seem as clean. This way TrajectoryVisual is only
71  // responsible for visualization.
72  void setFramePosition(const Ogre::Vector3& position);
73  void setFrameOrientation(const Ogre::Quaternion& orientation);
74 
75  // Set the color and alpha of the visual, which are user-editable
76  // parameters and therefore don't come from the Trajectory message.
77  void setColor(float r, float g, float b, float a);
78  void setColorV(float r, float g, float b, float a);
79  void setColorA(float r, float g, float b, float a);
80  void setScale(float thickness);
81  void setCurve();
82  void setStyle(int style);
83 
84  void resetTrajPoints(int traj_points, int tangent_points, bool use_v,
85  bool use_a);
86 
87  private:
88  traj_opt::Mat3 matFromVecD(const traj_opt::VecD& vec);
89  Ogre::Vector3 vecFromVecD(const traj_opt::VecD& vec);
90  // Tangent velocity vectors
91  std::vector<boost::shared_ptr<rviz::Object> > vel_arrows_;
92  std::vector<boost::shared_ptr<rviz::Object> > acc_arrows_;
93  // Lines making up the actual trajectory
94  std::vector<boost::shared_ptr<rviz::Object> > trajectory_lines_;
95  std::vector<boost::shared_ptr<rviz::Shape> > trajectory_balls_;
96 
97  double thickness_{0.1};
98  int num_traj_points_{50};
99  int num_vel_points_{50};
100  bool vel_on_{true};
101  bool acc_on_{false};
102 
103  // Style style_{Style::Sikang}; // default to working style
104  Style style_{Style::Mike}; // default to better style
105 
106  static void setShapeFromPosePair(const Ogre::Vector3& p0,
107  const Ogre::Vector3& p1, double scale,
108  rviz::Shape* shape);
109  static void setShapeFromPosePair(const Ogre::Vector3& p0,
110  const Ogre::Vector3& p1, double scale,
111  rviz::Arrow* shape);
112 
113  boost::shared_ptr<traj_opt::Trajectory> traj_;
114 
115  // A SceneNode whose pose is set to match the coordinate frame of
116  // the Trajectory message header.
117  Ogre::SceneNode* frame_node_;
118 
119  // The SceneManager, kept here only so the destructor can ask it to
120  // destroy the ``frame_node_``.
121  Ogre::SceneManager* scene_manager_;
122 };
123 // END_TUTORIAL
124 
125 } // namespace traj_opt
126 
127 #endif // MOBILITY_PLANNER_QP_TRAJ_OPT_ROS_SRC_TRAJECTORY_VISUAL_H_
traj_opt::SE3
@ SE3
Definition: trajectory_visual.h:51
traj_opt::CJ
@ CJ
Definition: trajectory_visual.h:51
trajectory.h
Ogre
Definition: trajectory_display.h:28
traj_opt::TrajectoryVisual
Definition: trajectory_visual.h:53
types.h
traj_opt::TrajectoryVisual::draw
void draw()
Definition: trajectory_visual.cpp:95
traj_opt::TrajectoryVisual::setStyle
void setStyle(int style)
Definition: trajectory_visual.cpp:78
traj_opt::TrajectoryVisual::TrajectoryVisual
TrajectoryVisual(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node)
Definition: trajectory_visual.cpp:51
traj_opt::TrajectoryVisual::setCurve
void setCurve()
Definition: trajectory_visual.cpp:157
traj_opt::TrajectoryVisual::resetTrajPoints
void resetTrajPoints(int traj_points, int tangent_points, bool use_v, bool use_a)
Definition: trajectory_visual.cpp:87
traj_opt::TrajectoryVisual::setFramePosition
void setFramePosition(const Ogre::Vector3 &position)
Definition: trajectory_visual.cpp:304
traj_opt::TrajectoryVisual::setColorA
void setColorA(float r, float g, float b, float a)
Definition: trajectory_visual.cpp:322
traj_opt::Sikang
@ Sikang
Definition: trajectory_visual.h:51
traj_opt::TrajectoryVisual::setColorV
void setColorV(float r, float g, float b, float a)
Definition: trajectory_visual.cpp:319
traj_opt::TrajectoryVisual::setMessage
void setMessage(const traj_opt_msgs::Trajectory::ConstPtr &msg)
Definition: trajectory_visual.cpp:296
traj_opt::Style
Style
Definition: trajectory_visual.h:51
rviz
Definition: trajectory_display.h:32
traj_opt::TrajectoryVisual::setScale
void setScale(float thickness)
Definition: trajectory_visual.cpp:325
traj_opt::TrajectoryVisual::~TrajectoryVisual
virtual ~TrajectoryVisual()
Definition: trajectory_visual.cpp:74
traj_opt
Definition: msg_traj.h:27
traj_opt::TrajectoryVisual::setColor
void setColor(float r, float g, float b, float a)
Definition: trajectory_visual.cpp:314
traj_opt::Mike
@ Mike
Definition: trajectory_visual.h:51
traj_opt::TrajectoryVisual::setFrameOrientation
void setFrameOrientation(const Ogre::Quaternion &orientation)
Definition: trajectory_visual.cpp:308
traj_opt::Mat3
Eigen::Matrix< decimal_t, 3, 3 > Mat3
Definition: types.h:42
traj_opt::VecD
Eigen::Matrix< decimal_t, Eigen::Dynamic, 1 > VecD
Definition: types.h:49