Robowflex  v0.1
Making MoveIt Easy
visualization.h
Go to the documentation of this file.
1 /* Author: Zachary Kingston, Constantinos Chamzas */
2 
3 #ifndef ROBOWFLEX_IO_VISUALIZATION_
4 #define ROBOWFLEX_IO_VISUALIZATION_
5 
6 #include <moveit/planning_interface/planning_interface.h>
7 
10 #include <robowflex_library/tf.h>
11 #include <sensor_msgs/PointCloud2.h>
12 
13 namespace robowflex
14 {
15  /** \cond IGNORE */
18  ROBOWFLEX_CLASS_FORWARD(MotionRequestBuilder);
19  ROBOWFLEX_CLASS_FORWARD(Geometry);
20  ROBOWFLEX_CLASS_FORWARD(Trajectory);
21  /** \endcond */
22 
23  namespace IO
24  {
25  /** \cond IGNORE */
26  ROBOWFLEX_CLASS_FORWARD(RVIZHelper);
27  /** \endcond */
28 
29  /** \class robowflex::IO::RVIZHelperPtr
30  \brief A shared pointer wrapper for robowflex::IO::RVIZHelper. */
31 
32  /** \class robowflex::IO::RVIZHelperConstPtr
33  \brief A const shared pointer wrapper for robowflex::IO::RVIZHelper. */
34 
35  /** \brief RVIZ visualization helper. See \ref rviz for more information.
36  */
37  class RVIZHelper
38  {
39  public:
40  /** \brief Constructor. All parameters are placed under \a /name.
41  * This helper puts trajectories under /name/trajectory, scenes under /name/scene, and
42  * other markers under /name/markers. The robot description is placed under
43  * /name/robot_description.
44  * \param[in] robot Robot to model with this helper.
45  * \param[in] name Namespace to use.
46  */
47  RVIZHelper(const RobotConstPtr &robot, const std::string &name = "robowflex");
48 
49  /** \name Trajectories
50  * \{ */
51 
52  /** \brief Updates the trajectory being visualized.
53  * \param[in] response Planning response to visualize.
54  */
56 
57  /** \brief Updates the trajectory being visualized.
58  * \param[in] trajectory Trajectory to visualize.
59  */
61 
62  /** \brief Updates the trajectory being visualized.
63  * \param[in] trajectory Trajectory to visualize.
64  */
65  void updateTrajectory(const robot_trajectory::RobotTrajectoryPtr &trajectory);
66 
67  /** \brief Updates the trajectory being visualized.
68  * \param[in] traj RobotTrajectory to visualize.
69  * \param[in] start base_state to copy values for other joints.
70  */
71  void updateTrajectory(const moveit_msgs::RobotTrajectory &traj,
72  const moveit::core::RobotState &start);
73 
74  /** \brief Updates the trajectory being visualized to a list of trajectories.
75  * \param[in] trajectories Vector of MoveIt! robot trajectories to visualize.
76  */
78 
79  /** \brief Updates the trajectory being visualized to a list of trajectories.
80  * \param[in] responses Planning responses to visualize.
81  */
83 
84  /** \brief Updates the trajectory being visualized to a list of trajectories.
85  * \param[in] responses Vector of robowflex trajectories to visualize.
86  */
87  void updateTrajectories(const std::vector<TrajectoryPtr> &trajectories);
88 
89  /** \} */
90 
91  /** \name States
92  * \{ */
93 
94  /** \brief Visualizes a robot state.
95  * \param[in] state The state of the robot to be visualized.
96  */
97  void visualizeState(const robot_state::RobotStatePtr &state);
98 
99  /** \brief Visualizes a robot state.
100  * \param[in] state The state of the robot to be visualized.
101  */
102  void visualizeState(const std::vector<double> &state);
103 
104  /** \brief Visualize the current state of the robot.
105  */
106  void visualizeCurrentState();
107 
108  /** \} */
109 
110  /** \name Scenes
111  * \{ */
112 
113  /** \brief Removes the scene being visualized.
114  */
115  void removeScene();
116 
117  /** \brief Updates the scene being visualized.
118  * \param[in] scene Scene to visualize. If null, removes scene by publishing empty message.
119  */
120  void updateScene(const SceneConstPtr &scene);
121 
122  /** \brief Updates the pointcloud being visualized.
123  * \param[in] msg Pointcloud msg to visualize.
124  */
125  void updatePCD(const sensor_msgs::PointCloud2 &msg);
126 
127  /** \} */
128 
129  /** \name Markers
130  * \{ */
131 
132  /** \brief Add a marker message (under the name "name") to the scene.
133  * \param[in] marker A marker message.
134  * \param[in] name Name of marker.
135  */
136  void addMarker(const visualization_msgs::Marker &marker, const std::string &name = "");
137 
138  /** \brief Add a spherical marker (under the name "name") to the scene.
139  * \param[in] x The x coordinate of the sphere.
140  * \param[in] y The y coordinate of the sphere.
141  * \param[in] z The z coordinate of the sphere.
142  * \param[in] name Name of marker.
143  */
144  void addMarker(double x, double y, double z, const std::string &name = "");
145 
146  /** \brief Add a point (spherical) marker to the scene.
147  * \param[in] point The x,y,z coordinates as a vector
148  * \param[in] name Name of marker.
149  */
150  void addMarker(const Eigen::Vector3d &point, const std::string &name = "");
151 
152  /** \brief Add a transform marker to the managed list of markers.
153  * Displayed after an updateMarkers() call.
154  * \param[in] name Name of the marker.
155  * \param[in] base_frame Base frame of the pose of the marker.
156  * \param[in] pose Pose of the transform.
157  * \param[in] scale Scale factor that controls the size of the frame marker.
158  */
159  void addTransformMarker(const std::string &name, const std::string &base_frame,
160  const RobotPose &pose, double scale = 1);
161 
162  /** \brief Add a marker to the managed list of markers. Displayed after an updateMarkers() call.
163  * \param[in] name Name of the marker.
164  * \param[in] geometry Geometry of the marker to create.
165  * \param[in] base_frame Base frame of the pose of the marker.
166  * \param[in] pose Pose of the marker.
167  * \param[in] color Color of the marker.
168  */
169  void addGeometryMarker(const std::string &name, const GeometryConstPtr &geometry,
170  const std::string &base_frame, const RobotPose &pose,
171  const Eigen::Vector4d &color = color::WHITE);
172 
173  /** \brief Adds an arrow marker to the managed list of markers. Displayed after an updateMarkers()
174  * call.
175  * \param[in] name Name of the marker.
176  * \param[in] base_frame Base frame of the pose of the marker.
177  * \param[in] pose Pose of the marker.
178  * \param[in] color Color of the marker.
179  * \param[in] scale The scale of the marker.
180  */
181  void addArrowMarker(const std::string &name, const std::string &base_frame, const RobotPose &pose,
182  const Eigen::Vector4d &color, const Eigen::Vector3d &scale);
183 
184  /** \brief Adds a text marker to the managed list of markers. Displayed after updateMarkers().
185  * \param[in] name Name of the marker.
186  * \param[in] text The text to display.
187  * \param[in] base_frame Base frame of the pose of the marker.
188  * \param[in] pose Pose of the marker.
189  * \param[in] height The height of the text.
190  * \param[in] color Color of the marker.
191  */
192  void addTextMarker(const std::string &name, const std::string &text,
193  const std::string &base_frame, const RobotPose &pose, double height,
194  const Eigen::Vector4d &color = color::WHITE);
195 
196  /** \brief Add a set of lines as markers.
197  * \param[in] name Name of the marker.
198  * \param[in] points Pair-wise list of points to add as lines. (eg., 0-1, 2-3, ...)
199  * \param[in] colors List of colors for each point.
200  * \param[in] scale Scale of the marker.
201  */
202  void addLineMarker(const std::string &name, const std::vector<Eigen::Vector3d> &points,
203  const std::vector<Eigen::Vector4d> &colors, double scale);
204 
205  /** \brief Adds the current goal of the motion request builder as a
206  * set of markers in the marker array.
207  * \param[in] name Name of the marker(s).
208  * \param[in] request Request to add goal of as a marker.
209  */
210  void addGoalMarker(const std::string &name, const MotionRequestBuilder &request);
211 
212  /** \brief Adds the current goal of the motion plan request as a
213  * set of markers in the marker array.
214  * \param[in] name Name of the marker(s).
215  * \param[in] request Request to add goal of as a marker.
216  */
217  void addGoalMarker(const std::string &name, const moveit_msgs::MotionPlanRequest &request);
218 
219  /** \brief Removes all markers that were added through addMarker().
220  */
221  void removeAllMarkers();
222 
223  /** \brief Removes a marker that was added through addMarker().
224  * \param[in] name The name of the marker to remove.
225  */
226  void removeMarker(const std::string &name);
227 
228  /** \brief Displays the managed list of markers.
229  * Keeps track of whether markers have already been displayed and simply need an update, and
230  * removes markers removed by removeMarker().
231  */
232  void updateMarkers();
233 
234  /** \} */
235 
236  private:
237  /** \brief Fills a marker in with some common default information.
238  * \param[out] marker Marker to fill.
239  * \param[in] base_frame Base frame of the pose of the marker.
240  * \param[in] pose Pose of the marker.
241  * \param[in] color Color of the marker.
242  * \param[in] scale The scale of the marker.
243  */
244  void fillMarker(visualization_msgs::Marker &marker, const std::string &base_frame,
245  const RobotPose &pose, const Eigen::Vector4d &color,
246  const Eigen::Vector3d &scale) const;
247 
248  RobotConstPtr robot_; ///< Robot being visualized.
249  ros::NodeHandle nh_; ///< Handle for publishing.
250  ros::Publisher marker_pub_; ///< Marker publisher.
251  ros::Publisher trajectory_pub_; ///< Trajectory publisher.
252  ros::Publisher scene_pub_; ///< Scene publisher.
253  ros::Publisher pcd_pub_; ///< Pointcloud publisher.
254  ros::Publisher state_pub_; ///< State publisher.
255 
257  };
258  } // namespace IO
259 
260 } // namespace robowflex
261 
262 #endif
#define ROBOWFLEX_CLASS_FORWARD(C)
Macro that forward declares a class and defines two shared ptrs types:
Definition: class_forward.h:16
A const shared pointer wrapper for robowflex::Geometry.
RVIZ visualization helper. See Live Visualization with RViz for more information.
Definition: visualization.h:38
void addMarker(const visualization_msgs::Marker &marker, const std::string &name="")
Add a marker message (under the name "name") to the scene.
void removeMarker(const std::string &name)
Removes a marker that was added through addMarker().
void removeAllMarkers()
Removes all markers that were added through addMarker().
ros::Publisher marker_pub_
Marker publisher.
void addLineMarker(const std::string &name, const std::vector< Eigen::Vector3d > &points, const std::vector< Eigen::Vector4d > &colors, double scale)
Add a set of lines as markers.
std::multimap< std::string, visualization_msgs::Marker > markers_
Markers to publish.
ros::Publisher pcd_pub_
Pointcloud publisher.
void updateTrajectories(const std::vector< robot_trajectory::RobotTrajectoryPtr > &trajectories)
Updates the trajectory being visualized to a list of trajectories.
ros::Publisher scene_pub_
Scene publisher.
ros::Publisher trajectory_pub_
Trajectory publisher.
ros::NodeHandle nh_
Handle for publishing.
void visualizeState(const robot_state::RobotStatePtr &state)
Visualizes a robot state.
RobotConstPtr robot_
Robot being visualized.
void updateMarkers()
Displays the managed list of markers. Keeps track of whether markers have already been displayed and ...
void removeScene()
Removes the scene being visualized.
RVIZHelper(const RobotConstPtr &robot, const std::string &name="robowflex")
Constructor. All parameters are placed under /name. This helper puts trajectories under /name/traject...
void visualizeCurrentState()
Visualize the current state of the robot.
void addArrowMarker(const std::string &name, const std::string &base_frame, const RobotPose &pose, const Eigen::Vector4d &color, const Eigen::Vector3d &scale)
Adds an arrow marker to the managed list of markers. Displayed after an updateMarkers() call.
void fillMarker(visualization_msgs::Marker &marker, const std::string &base_frame, const RobotPose &pose, const Eigen::Vector4d &color, const Eigen::Vector3d &scale) const
Fills a marker in with some common default information.
ros::Publisher state_pub_
State publisher.
void updatePCD(const sensor_msgs::PointCloud2 &msg)
Updates the pointcloud being visualized.
void updateScene(const SceneConstPtr &scene)
Updates the scene being visualized.
void addGeometryMarker(const std::string &name, const GeometryConstPtr &geometry, const std::string &base_frame, const RobotPose &pose, const Eigen::Vector4d &color=color::WHITE)
Add a marker to the managed list of markers. Displayed after an updateMarkers() call.
void addGoalMarker(const std::string &name, const MotionRequestBuilder &request)
Adds the current goal of the motion request builder as a set of markers in the marker array.
void addTextMarker(const std::string &name, const std::string &text, const std::string &base_frame, const RobotPose &pose, double height, const Eigen::Vector4d &color=color::WHITE)
Adds a text marker to the managed list of markers. Displayed after updateMarkers().
void updateTrajectory(const planning_interface::MotionPlanResponse &response)
Updates the trajectory being visualized.
void addTransformMarker(const std::string &name, const std::string &base_frame, const RobotPose &pose, double scale=1)
Add a transform marker to the managed list of markers. Displayed after an updateMarkers() call.
A helper class to build motion planning requests for a robowflex::Planner.
Definition: builder.h:34
A const shared pointer wrapper for robowflex::Robot.
A const shared pointer wrapper for robowflex::Scene.
The Trajectory class is a wrapper around MoveIt!'s robot_trajectory::RobotTrajectory,...
Definition: trajectory.h:43
Functions for loading and animating robots in Blender.
static const Eigen::Vector4d WHITE
Definition: colormap.h:55
Main namespace. Contains all library classes and functions.
Definition: scene.cpp:25
std::decay< decltype(std::declval< moveit::core::Transforms >().getTransform("")) >::type RobotPose
A pose (point in SE(3)) used in various functions. Defined from what MoveIt! uses.
Definition: adapter.h:24
Functions for loading and animating scenes in Blender.
robot_trajectory::RobotTrajectory trajectory(rmodel,"right_arm")