imarker_simple.cpp
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 via the external python node
37 */
38 
41 #include <string>
42 
43 namespace rviz_visual_tools
44 {
45 IMarkerSimple::IMarkerSimple(const std::string& name, double scale, const geometry_msgs::Pose& initial_pose,
46  const std::string& parent_frame)
47  : nh_("~"), latest_pose_(initial_pose)
48 {
49  // Create Marker Server
50  const std::string imarker_topic = nh_.getNamespace() + "/" + name;
51  imarker_server_.reset(new interactive_markers::InteractiveMarkerServer(imarker_topic, "", false));
52 
53  // ros::Duration(2.0).sleep();
54 
55  // Create imarker
56  make6DofMarker(latest_pose_, scale, parent_frame);
57 
58  // Send imarker to Rviz
59  imarker_server_->applyChanges();
60 }
61 
62 geometry_msgs::Pose& IMarkerSimple::getPose()
63 {
64  return latest_pose_;
65 }
66 
67 void IMarkerSimple::setPose(const Eigen::Isometry3d& pose)
68 {
69  geometry_msgs::Pose pose_msg;
71  setPose(pose_msg);
72 }
73 
74 void IMarkerSimple::setPose(const geometry_msgs::Pose& pose)
75 {
76  latest_pose_ = pose;
77  sendUpdatedIMarkerPose();
78 }
79 
80 void IMarkerSimple::iMarkerCallback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr& feedback)
81 {
82  // Ignore if not pose update
83  if (feedback->event_type != visualization_msgs::InteractiveMarkerFeedback::POSE_UPDATE)
84  {
85  return;
86  }
87 
88  latest_pose_ = feedback->pose;
89 
90  // Redirect to base class
91  if (imarker_callback_)
92  imarker_callback_(feedback);
93 }
94 
95 void IMarkerSimple::sendUpdatedIMarkerPose()
96 {
97  imarker_server_->setPose(int_marker_.name, latest_pose_);
98  imarker_server_->applyChanges();
99 }
100 
101 void IMarkerSimple::make6DofMarker(const geometry_msgs::Pose& pose, double scale, const std::string& parent_frame)
102 {
103  ROS_INFO_STREAM_NAMED(name_, "Making 6dof interactive marker named " << name_);
104 
105  int_marker_.header.frame_id = parent_frame;
106  int_marker_.pose = pose;
107  int_marker_.scale = scale;
108 
109  int_marker_.name = name_;
110 
111  // int_marker_.controls[0].interaction_mode = InteractiveMarkerControl::MENU;
112 
113  InteractiveMarkerControl control;
114  control.orientation.w = 0.7071;
115  control.orientation.x = 0.7071;
116  control.orientation.y = 0;
117  control.orientation.z = 0;
118  control.name = "rotate_x";
119  control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
120  int_marker_.controls.push_back(control);
121  control.name = "move_x";
122  control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
123  int_marker_.controls.push_back(control);
124 
125  control.orientation.w = 0.7071;
126  control.orientation.x = 0;
127  control.orientation.y = 0.7071;
128  control.orientation.z = 0;
129  control.name = "rotate_z";
130  control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
131  int_marker_.controls.push_back(control);
132  control.name = "move_z";
133  control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
134  int_marker_.controls.push_back(control);
135 
136  control.orientation.w = 0.7071;
137  control.orientation.x = 0;
138  control.orientation.y = 0;
139  control.orientation.z = 0.7071;
140  control.name = "rotate_y";
141  control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
142  int_marker_.controls.push_back(control);
143  control.name = "move_y";
144  control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
145  int_marker_.controls.push_back(control);
146 
147  imarker_server_->insert(int_marker_);
148  imarker_server_->setCallback(int_marker_.name, boost::bind(&IMarkerSimple::iMarkerCallback, this, _1));
149  // menu_handler_.apply(*imarker_server_, int_marker_.name);
150 }
151 
152 } // namespace rviz_visual_tools
rviz_visual_tools::RvizVisualTools::convertPoseSafe
static void convertPoseSafe(const Eigen::Isometry3d &pose, geometry_msgs::Pose &pose_msg)
Convert an Eigen pose to a geometry_msg pose - thread safe.
Definition: rviz_visual_tools.cpp:2575
rviz_visual_tools
Definition: imarker_simple.h:55
rviz_visual_tools.h
interactive_markers::InteractiveMarkerServer
make6DofMarker
void make6DofMarker(bool fixed)
imarker_simple.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
ROS_INFO_STREAM_NAMED
#define ROS_INFO_STREAM_NAMED(name, args)


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