mtt_target_generator.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 
34 #include <pcl/conversions.h>
35 #include <pcl/point_cloud.h>
36 #include <pcl/point_types.h>
37 #include <interactive_markers/interactive_marker_server.h>
38 #include <interactive_markers/menu_handler.h>
39 #include <boost/lexical_cast.hpp>
40 #include <boost/format.hpp>
41 #include "std_msgs/String.h"
42 #include <mtt/TargetListPC.h>
43 #include <pcl_conversions/pcl_conversions.h>
44 
45 //namepaces
46 using namespace visualization_msgs;
47 
48 // Global Vars
49 boost::shared_ptr<interactive_markers::InteractiveMarkerServer> server;
50 ros::NodeHandle* p_n;
51 ros::Publisher coor_pub;
52 visualization_msgs::Marker marker;
53 ros::Publisher line_pub;
54 
55 void processFeedback( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
56 {
57  std::ostringstream mouse_point_ss;
58  if( feedback->mouse_point_valid )
59  {
60  //mouse_point_ss << " at " << feedback->mouse_point.x
61  //<< ", " << feedback->mouse_point.y
62  //<< ", " << feedback->mouse_point.z
63  //<< " in frame " << feedback->header.frame_id;
64  }
65 
66  switch ( feedback->event_type )
67  {
68  case visualization_msgs::InteractiveMarkerFeedback::POSE_UPDATE:
69 
70 
71  mtt::TargetListPC message;
72  message.header.stamp = ros::Time::now();
73  message.header.frame_id = "/world";
74 
75  //set the mtt msg id field
76  message.id.push_back(0);
77 
78  //set the mtt msg position field
79  pcl::PointCloud<pcl::PointXYZ> pc_in;
80  pcl::PointXYZ pt;
81  pt.x = feedback->pose.position.x;
82  pt.y = feedback->pose.position.y;
83  pt.z = 0;
84  pc_in.points.push_back(pt);
85  pcl::toROSMsg(pc_in, message.position);
86 
87 
88  //set the mtt msg velocity field
89  pcl::PointCloud<pcl::PointXYZ> pc_vel;
90  pt.x = 0;
91  pt.y = 0;
92  pt.z = 0;
93  pc_vel.points.push_back(pt);
94  pcl::toROSMsg(pc_vel, message.velocity);
95 
96  //set the mtt msg obstacle_lines field
97  pcl::PointCloud<pcl::PointXYZ> pc_obs;
98  pt.x = feedback->pose.position.x +0;
99  pt.y = feedback->pose.position.y -1;
100  pt.z = 0;
101  pc_obs.points.push_back(pt);
102 
103  pt.x = feedback->pose.position.x +0;
104  pt.y = feedback->pose.position.y +1;
105  pt.z = 0;
106  pc_obs.points.push_back(pt);
107 
108  pt.x = feedback->pose.position.x +1;
109  pt.y = feedback->pose.position.y +1;
110  pt.z = 0;
111  pc_obs.points.push_back(pt);
112 
113  sensor_msgs::PointCloud2 pc_msg;
114  pcl::toROSMsg(pc_obs, pc_msg);
115 
116  message.obstacle_lines.push_back(pc_msg);
117 
118  //publish the mtt msg
119  coor_pub.publish(message);
120 
121 
122  //change the position of the line vis marker
123  geometry_msgs::Point p;
124  marker.header.frame_id = "/world";
125  marker.header.stamp = ros::Time::now();
126  marker.ns = "lines";
127  marker.id = 0;
128  marker.action = visualization_msgs::Marker::ADD;
129  marker.type = visualization_msgs::Marker::LINE_LIST;
130  marker.scale.x = 0.015;
131  marker.color.r = 0.7;
132  marker.color.g = 0.1;
133  marker.color.b = 0.1;
134  marker.color.a = 1.0;
135  marker.pose.position.x = feedback->pose.position.x;
136  marker.pose.position.y = feedback->pose.position.y;
137  marker.pose.position.z = 0;
138 
139  p.x = 0;
140  p.y = -1;
141  p.z = 0;
142  marker.points.push_back(p);
143  p.x = 0;
144  p.y = 1;
145  p.z = 0;
146  marker.points.push_back(p);
147  marker.points.push_back(p);
148  p.x = 1;
149  p.y = 1;
150  p.z = 0;
151  marker.points.push_back(p);
152 
153 
154  line_pub.publish(marker);
155 
156  break;
157 }
158 
159 server->applyChanges();
160 }
161 
162 
163 Marker makeBox( InteractiveMarker &msg )
164 {
165  Marker marker;
166 
167  marker.type = Marker::CUBE;
168  marker.scale.x = msg.scale/7;
169  marker.scale.y = msg.scale/7;
170  marker.scale.z = msg.scale/7;
171  marker.color.r = 0.7;
172  marker.color.g = 0.1;
173  marker.color.b = 0.1;
174  marker.color.a = 0.8;
175  return marker;
176 }
177 
178 
179 InteractiveMarkerControl& makeBoxControl( InteractiveMarker &msg )
180 {
181  InteractiveMarkerControl control;
182  control.always_visible = true;
183  control.markers.push_back( makeBox(msg) );
184  msg.controls.push_back( control );
185 
186  return msg.controls.back();
187 }
188 
189 
190 void make6DofMarker( bool fixed )
191 {
192  InteractiveMarker int_marker;
193  int_marker.header.frame_id = "/world";
194  int_marker.pose.position.x = 5;
195  int_marker.pose.position.y = 4;
196  int_marker.pose.position.z = 0;
197  int_marker.scale = 0.4;
198  int_marker.name = "Control obstacle";
199  int_marker.description = "Control the final \nposition of the obstacle";
200 
201  // insert a box
202  makeBoxControl(int_marker);
203  InteractiveMarkerControl control;
204 
205  control.orientation.w = 1;
206  control.orientation.x = 1;
207  control.orientation.y = 0;
208  control.orientation.z = 0;
209  control.name = "move_x";
210  control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
211  int_marker.controls.push_back(control);
212 
213  control.orientation.w = 1;
214  control.orientation.x = 0;
215  control.orientation.y = 0;
216  control.orientation.z = 1;
217  control.name = "move_y";
218  control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
219  int_marker.controls.push_back(control);
220 
221  server->insert(int_marker);
222  server->setCallback(int_marker.name, &processFeedback);
223 }
224 
225 
226 int main(int argc, char **argv)
227 {
228  ros::init(argc, argv, "mtt_target_generator");
229  ros::NodeHandle n("~");
230  ros::Rate loop_rate(10);
231  p_n=&n;
232 
233  coor_pub = n.advertise<mtt::TargetListPC>("/mtt_targets", 1000);
234 
235  line_pub = n.advertise<visualization_msgs::Marker>( "/line_markers", 1 );
236 
237 
238  server.reset( new interactive_markers::InteractiveMarkerServer("mtt_target_generator/im","",false) );
239  make6DofMarker( true );
240  server->applyChanges();
241 
242  while(ros::ok())
243  {
244  loop_rate.sleep();
245  ros::spinOnce();
246  }
247 
248  server.reset();
249 }
ros::Publisher line_pub
void make6DofMarker(bool fixed)
Marker makeBox(InteractiveMarker &msg)
InteractiveMarkerControl & makeBoxControl(InteractiveMarker &msg)
void processFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
int main(int argc, char **argv)
ros::Publisher coor_pub
visualization_msgs::Marker marker
trajectory_planner::coordinates message
Definition: APgenerator.cpp:47
ros::NodeHandle * p_n
boost::shared_ptr< interactive_markers::InteractiveMarkerServer > server


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