APgenerator.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
27 #include <stdio.h>
28 #include <vector>
29 #include <math.h>
30 #include <visualization_msgs/Marker.h>
31 #include <visualization_msgs/MarkerArray.h>
32 #include <numeric>
33 #include <interactive_markers/interactive_marker_server.h>
34 #include <interactive_markers/menu_handler.h>
35 #include <boost/lexical_cast.hpp>
36 #include <boost/format.hpp>
37 #include "std_msgs/String.h"
38 #include <trajectory_planner/coordinates.h>
39 
40 //namepaces
41 using namespace visualization_msgs;
42 
43 // Global Vars
44 boost::shared_ptr<interactive_markers::InteractiveMarkerServer> server;
45 ros::NodeHandle* p_n;
46 ros::Publisher coor_pub;
47 trajectory_planner::coordinates message;
48 
49 
50 
51 void processFeedback( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
52 {
53  if( feedback->mouse_point_valid )
54  {
55  //mouse_point_ss << " at " << feedback->mouse_point.x
56  //<< ", " << feedback->mouse_point.y
57  //<< ", " << feedback->mouse_point.z
58  //<< " in frame " << feedback->header.frame_id;
59  }
60 
61  switch ( feedback->event_type )
62  {
63  case visualization_msgs::InteractiveMarkerFeedback::POSE_UPDATE:
64  message.x=feedback->pose.position.x; message.y=feedback->pose.position.y; message.theta=2.0*asin(feedback->pose.orientation.z);
65 
66  message.header.stamp = ros::Time::now();
67  message.header.frame_id = "/world";
68 
69  coor_pub.publish(message);
70 
71  break;
72  }
73 
74  server->applyChanges();
75 }
76 
77 
78 Marker makeBox( InteractiveMarker &msg )
79 {
80  Marker marker;
81 
82  marker.type = Marker::ARROW;
83  marker.scale.x = msg.scale;
84  marker.scale.y = msg.scale;
85  marker.scale.z = msg.scale;
86  marker.color.r = 0;
87  marker.color.g = 0.7;
88  marker.color.b = 0;
89  marker.color.a = 0.6;
90  return marker;
91 }
92 
93 
94 InteractiveMarkerControl& makeBoxControl( InteractiveMarker &msg )
95 {
96  InteractiveMarkerControl control;
97  control.always_visible = true;
98  control.markers.push_back( makeBox(msg) );
99  msg.controls.push_back( control );
100 
101  return msg.controls.back();
102 }
103 
104 
105 void make6DofMarker( bool fixed )
106 {
107  InteractiveMarker int_marker;
108  int_marker.header.frame_id = "/world";
109  int_marker.pose.position.x = 0;
110  int_marker.pose.position.y = 0;
111  int_marker.pose.position.z = 0;
112  int_marker.scale = 0.4;
113 
114  int_marker.name = "Control target";
115  int_marker.description = "Control the final \nposition of the robot";
116 
117  // insert a box
118  makeBoxControl(int_marker);
119  InteractiveMarkerControl control;
120 
121  control.orientation.w = 1;
122  control.orientation.x = 1;
123  control.orientation.y = 0;
124  control.orientation.z = 0;
125  control.name = "move_x";
126  control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
127  int_marker.controls.push_back(control);
128 
129  control.orientation.w = 1;
130  control.orientation.x = 0;
131  control.orientation.y = 0;
132  control.orientation.z = 1;
133  control.name = "move_y";
134  control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
135  int_marker.controls.push_back(control);
136 
137  control.orientation.w = 1;
138  control.orientation.x = 0;
139  control.orientation.y = 1;
140  control.orientation.z = 0;
141  control.interaction_mode = InteractiveMarkerControl::ROTATE_AXIS;
142  control.name = "rotate_z";
143  int_marker.controls.push_back(control);
144 
145  server->insert(int_marker);
146  server->setCallback(int_marker.name, &processFeedback);
147 }
148 
149 
150 int main(int argc, char **argv)
151 {
152  ros::init(argc, argv, "APgenerator");
153  ros::NodeHandle n("~");
154  ros::Rate loop_rate(10);
155  p_n=&n;
156 
157  coor_pub = n.advertise<trajectory_planner::coordinates>("/msg_coordinates", 1000);
158 
159 
160  server.reset( new interactive_markers::InteractiveMarkerServer("APgenerator/im","",false) );
161  make6DofMarker( true );
162  server->applyChanges();
163 
164  while(ros::ok())
165  {
166 
167 
168 
169  loop_rate.sleep();
170  ros::spinOnce();
171  }
172 
173  server.reset();
174 }
Marker makeBox(InteractiveMarker &msg)
Definition: APgenerator.cpp:78
void make6DofMarker(bool fixed)
InteractiveMarkerControl & makeBoxControl(InteractiveMarker &msg)
Definition: APgenerator.cpp:94
int main(int argc, char **argv)
void processFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
Definition: APgenerator.cpp:51
visualization_msgs::Marker marker
trajectory_planner::coordinates message
Definition: APgenerator.cpp:47
ros::NodeHandle * p_n
Definition: APgenerator.cpp:45
boost::shared_ptr< interactive_markers::InteractiveMarkerServer > server
Definition: APgenerator.cpp:44
ros::Publisher coor_pub
Definition: APgenerator.cpp:46


trajectory_planner
Author(s): Joel Pereira
autogenerated on Mon Mar 2 2015 01:32:54