imarker_simple_demo.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, PickNik LLC
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 LLC 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: Demonstrate how to use the imarker simple interface
37 */
38 
39 #ifndef RVIZ_VISUAL_TOOLS_IMARKER_SIMPLE_DEMO_H
40 #define RVIZ_VISUAL_TOOLS_IMARKER_SIMPLE_DEMO_H
41 
42 // ROS
43 #include <ros/ros.h>
46 
47 namespace rviz_visual_tools
48 {
50 {
51 public:
54  {
55  visual_tools_.reset(new rviz_visual_tools::RvizVisualTools("world", "/rviz_visual_tools"));
56  visual_tools_->loadMarkerPub();
57 
58  // Create a random initial pose
59  geometry_msgs::Pose init_pose;
60  visual_tools_->generateRandomPose(init_pose);
61 
62  // Create a 6DOF interactive marker
63  static const double SCALE = 0.2;
64  imarker_simple_.reset(new rviz_visual_tools::IMarkerSimple("imarker", SCALE, init_pose));
65 
66  // Add callback to this class
67  imarker_simple_->setIMarkerCallback(std::bind(&IMarkerSimpleDemo::processIMarkerPose, this, std::placeholders::_1));
68 
69  ROS_INFO_STREAM_NAMED(name_, "IMarkerSimpleDemo Ready.");
70  }
71 
72  void processIMarkerPose(const visualization_msgs::InteractiveMarkerFeedbackConstPtr& feedback)
73  {
74  // Show some spheres for fun
75  visual_tools_->publishSphere(feedback->pose, visual_tools_->getRandColor());
76  visual_tools_->trigger();
77  }
78 
79 private:
80  // --------------------------------------------------------
81 
82  // The short name of this class
83  std::string name_ = "imarker_simple_demo";
84 
85  // A shared node handle
87 
90 
91 }; // end class
92 
93 // Create std pointers for this class
94 typedef std::shared_ptr<IMarkerSimpleDemo> IMarkerSimpleDemoPtr;
95 typedef std::shared_ptr<const IMarkerSimpleDemo> IMarkerSimpleDemoConstPtr;
96 
97 } // namespace rviz_visual_tools
98 #endif // RVIZ_VISUAL_TOOLS_IMARKER_SIMPLE_DEMO_H
99 
100 int main(int argc, char** argv)
101 {
102  // Initialize ROS
103  ros::init(argc, argv, "imarker_simple_demo");
104  ROS_INFO_STREAM_NAMED("main", "Starting IMarkerSimpleDemo...");
105 
106  // Seed random number generator
107  // srand (time(NULL));
108 
109  // Allow the action server to recieve and send ros messages
111  spinner.start();
112 
113  // Initialize main class
115 
117 
118  // Shutdown
119  ROS_INFO_STREAM_NAMED("main", "Shutting down.");
120  ros::shutdown();
121 
122  return 0;
123 }
std::shared_ptr< IMarkerSimpleDemo > IMarkerSimpleDemoPtr
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
boost::shared_ptr< interactive_markers::InteractiveMarkerServer > server
#define ROS_INFO_STREAM_NAMED(name, args)
std::shared_ptr< const IMarkerSimpleDemo > IMarkerSimpleDemoConstPtr
void spinner()
std::shared_ptr< RvizVisualTools > RvizVisualToolsPtr
void processIMarkerPose(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
rviz_visual_tools::RvizVisualToolsPtr visual_tools_
int main(int argc, char **argv)
ROSCPP_DECL void shutdown()
rviz_visual_tools::IMarkerSimplePtr imarker_simple_
std::shared_ptr< IMarkerSimple > IMarkerSimplePtr
ROSCPP_DECL void waitForShutdown()


rviz_visual_tools
Author(s): Dave Coleman
autogenerated on Mon Feb 25 2019 03:54:12