imarker_simple.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, PickNik Consulting
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of PickNik Consulting nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Dave Coleman
36  Desc: Use interactive markers in a C++ class
37 */
38 
39 #pragma once
40 
41 // ROS
42 #include <ros/ros.h>
43 
44 #include <geometry_msgs/PoseStamped.h>
45 
47 #include <visualization_msgs/InteractiveMarkerFeedback.h>
48 #include <visualization_msgs/InteractiveMarker.h>
50 #include <Eigen/Geometry>
51 
52 // C++
53 #include <string>
54 
56 {
57 using visualization_msgs::InteractiveMarkerControl;
58 using visualization_msgs::InteractiveMarkerFeedback;
59 
60 typedef std::function<void(const visualization_msgs::InteractiveMarkerFeedbackConstPtr&)> IMarkerCallback;
61 
62 namespace
63 {
64 geometry_msgs::Pose getIdentityPose()
65 {
66  geometry_msgs::Pose pose;
67  pose.orientation.w = 1.0;
68  return pose;
69 }
70 } // namespace
71 
72 class IMarkerSimple
73 {
74 public:
75  explicit IMarkerSimple(const std::string& name = "imarker", double scale = 0.2,
76  const geometry_msgs::Pose& initial_pose = getIdentityPose(),
77  const std::string& parent_frame = "world");
78 
79  geometry_msgs::Pose& getPose();
80 
81  void setPose(const Eigen::Isometry3d& pose);
82 
83  void setPose(const geometry_msgs::Pose& pose);
84 
85  void iMarkerCallback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr& feedback);
86 
87  void setIMarkerCallback(IMarkerCallback callback)
88  {
89  imarker_callback_ = callback;
90  }
91 
92 private:
94 
95  void make6DofMarker(const geometry_msgs::Pose& pose = getIdentityPose(), double scale = 0.2,
96  const std::string& parent_frame = "world");
97 
98  // --------------------------------------------------------
99 
100  // The short name of this class
101  std::string name_ = "imarker_simple";
102 
103  // A shared node handle
105 
106  geometry_msgs::Pose latest_pose_;
107 
108  // Interactive markers
109  std::shared_ptr<interactive_markers::InteractiveMarkerServer> imarker_server_;
110 
111  // Interactive markers
112  // interactive_markers::MenuHandler menu_handler_;
113  visualization_msgs::InteractiveMarker int_marker_;
114 
115  // Hook to parent class
117 }; // end class
118 
119 // Create std pointers for this class
120 typedef std::shared_ptr<IMarkerSimple> IMarkerSimplePtr;
121 typedef std::shared_ptr<const IMarkerSimple> IMarkerSimpleConstPtr;
122 
123 } // namespace rviz_visual_tools
rviz_visual_tools::IMarkerSimple::nh_
ros::NodeHandle nh_
Definition: imarker_simple.h:136
rviz_visual_tools::IMarkerSimple::imarker_callback_
IMarkerCallback imarker_callback_
Definition: imarker_simple.h:148
rviz_visual_tools::IMarkerSimple::latest_pose_
geometry_msgs::Pose latest_pose_
Definition: imarker_simple.h:138
ros.h
rviz_visual_tools::IMarkerSimple::setIMarkerCallback
void setIMarkerCallback(IMarkerCallback callback)
Definition: imarker_simple.h:119
menu_handler.h
rviz_visual_tools
Definition: imarker_simple.h:55
rviz_visual_tools::IMarkerSimple::iMarkerCallback
void iMarkerCallback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
Definition: imarker_simple.cpp:112
rviz_visual_tools::IMarkerSimple::getPose
geometry_msgs::Pose & getPose()
Definition: imarker_simple.cpp:94
rviz_visual_tools::IMarkerSimple::int_marker_
visualization_msgs::InteractiveMarker int_marker_
Definition: imarker_simple.h:145
rviz_visual_tools::IMarkerCallback
std::function< void(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &)> IMarkerCallback
Definition: imarker_simple.h:92
rviz_visual_tools::IMarkerSimple::setPose
void setPose(const Eigen::Isometry3d &pose)
Definition: imarker_simple.cpp:99
rviz_visual_tools::IMarkerSimpleConstPtr
std::shared_ptr< const IMarkerSimple > IMarkerSimpleConstPtr
Definition: imarker_simple.h:153
rviz_visual_tools::IMarkerSimple::sendUpdatedIMarkerPose
void sendUpdatedIMarkerPose()
Definition: imarker_simple.cpp:127
rviz_visual_tools::IMarkerSimple::imarker_server_
std::shared_ptr< interactive_markers::InteractiveMarkerServer > imarker_server_
Definition: imarker_simple.h:141
interactive_marker_server.h
rviz_visual_tools::IMarkerSimple::IMarkerSimple
IMarkerSimple(const std::string &name="imarker", double scale=0.2, const geometry_msgs::Pose &initial_pose=getIdentityPose(), const std::string &parent_frame="world")
Definition: imarker_simple.cpp:77
rviz_visual_tools::IMarkerSimplePtr
std::shared_ptr< IMarkerSimple > IMarkerSimplePtr
Definition: imarker_simple.h:152
rviz_visual_tools::IMarkerSimple::make6DofMarker
void make6DofMarker(const geometry_msgs::Pose &pose=getIdentityPose(), double scale=0.2, const std::string &parent_frame="world")
Definition: imarker_simple.cpp:133
rviz_visual_tools::IMarkerSimple::name_
std::string name_
Definition: imarker_simple.h:133
rviz_visual_tools::IMarkerSimple
Definition: imarker_simple.h:104
ros::NodeHandle


rviz_visual_tools
Author(s): Dave Coleman
autogenerated on Wed Mar 2 2022 01:03:26