/home/joel/ros_workspace/lar3/planning/trajectory_planner/src/mtt_target_generator.cpp

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <vector>
00003 #include <math.h>
00004 #include <visualization_msgs/Marker.h>
00005 #include <visualization_msgs/MarkerArray.h>
00006 #include <numeric>
00007 
00008 #include <pcl/ros/conversions.h>
00009 #include <pcl/point_cloud.h>
00010 #include <pcl/point_types.h>
00011 #include <interactive_markers/interactive_marker_server.h>
00012 #include <interactive_markers/menu_handler.h>
00013 #include <boost/lexical_cast.hpp>
00014 #include <boost/format.hpp>
00015 #include "std_msgs/String.h"
00016 #include <mtt/TargetList.h>
00017 
00018 //namepaces
00019 using namespace visualization_msgs;
00020 
00021 // Global Vars
00022 boost::shared_ptr<interactive_markers::InteractiveMarkerServer> server;
00023 ros::NodeHandle* p_n;
00024 ros::Publisher coor_pub;
00025 visualization_msgs::Marker marker;
00026 ros::Publisher line_pub;
00027 
00028 void processFeedback( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
00029 {
00030         std::ostringstream mouse_point_ss;
00031         if( feedback->mouse_point_valid )
00032         {
00033                 //mouse_point_ss << " at " << feedback->mouse_point.x
00034                         //<< ", " << feedback->mouse_point.y
00035                         //<< ", " << feedback->mouse_point.z
00036                         //<< " in frame " << feedback->header.frame_id;
00037         }
00038 
00039         switch ( feedback->event_type )
00040         {
00041                 case visualization_msgs::InteractiveMarkerFeedback::POSE_UPDATE:
00042                         
00043 
00044                         mtt::TargetList message;
00045                         message.header.stamp = ros::Time::now();
00046                         message.header.frame_id = "/world";
00047 
00048                         //set the mtt msg id field
00049                         message.id.push_back(0);
00050 
00051                         //set the mtt msg position field
00052                         pcl::PointCloud<pcl::PointXYZ> pc_in;
00053                         pcl::PointXYZ pt;
00054                         pt.x = feedback->pose.position.x;
00055                         pt.y = feedback->pose.position.y;
00056                         pt.z = 0;
00057                         pc_in.points.push_back(pt);
00058                         pcl::toROSMsg(pc_in, message.position);
00059 
00060 
00061                         //set the mtt msg velocity field
00062                         pcl::PointCloud<pcl::PointXYZ> pc_vel;
00063                         pt.x = 0;
00064                         pt.y = 0;
00065                         pt.z = 0;
00066                         pc_vel.points.push_back(pt);
00067                         pcl::toROSMsg(pc_vel, message.velocity);
00068 
00069                         //set the mtt msg obstacle_lines field
00070                         pcl::PointCloud<pcl::PointXYZ> pc_obs;
00071                         pt.x = feedback->pose.position.x +0;
00072                         pt.y = feedback->pose.position.y -1;
00073                         pt.z = 0;
00074                         pc_obs.points.push_back(pt);
00075 
00076                         pt.x = feedback->pose.position.x +0;
00077                         pt.y = feedback->pose.position.y +1;
00078                         pt.z = 0;
00079                         pc_obs.points.push_back(pt);
00080 
00081                         pt.x = feedback->pose.position.x +1;
00082                         pt.y = feedback->pose.position.y +1;
00083                         pt.z = 0;
00084                         pc_obs.points.push_back(pt);
00085 
00086                         sensor_msgs::PointCloud2 pc_msg;
00087                         pcl::toROSMsg(pc_obs, pc_msg);
00088 
00089                         message.obstacle_lines.push_back(pc_msg);       
00090                         
00091                         //publish the mtt msg   
00092                         coor_pub.publish(message);
00093 
00094 
00095                         //change the position of the line vis marker
00096                         geometry_msgs::Point p;
00097                         marker.header.frame_id = "/world";
00098                         marker.header.stamp = ros::Time::now();
00099                         marker.ns = "lines";
00100                         marker.id = 0;
00101                         marker.action = visualization_msgs::Marker::ADD;
00102                         marker.type = visualization_msgs::Marker::LINE_LIST;
00103                         marker.scale.x = 0.015;
00104                         marker.color.r = 0.7;
00105                         marker.color.g = 0.1;
00106                         marker.color.b = 0.1;
00107                         marker.color.a = 1.0;
00108                         marker.pose.position.x = feedback->pose.position.x;
00109                         marker.pose.position.y = feedback->pose.position.y;
00110                         marker.pose.position.z = 0;
00111 
00112                         p.x = 0;
00113                         p.y = -1;
00114                         p.z = 0;
00115                         marker.points.push_back(p);
00116                         p.x = 0;
00117                         p.y = 1;
00118                         p.z = 0;
00119                         marker.points.push_back(p);
00120                         marker.points.push_back(p);
00121                         p.x = 1;
00122                         p.y = 1;
00123                         p.z = 0;
00124                         marker.points.push_back(p);
00125 
00126 
00127                         line_pub.publish(marker);
00128 
00129         break;
00130 }
00131 
00132 server->applyChanges();
00133 }
00134 
00135 
00136 Marker makeBox( InteractiveMarker &msg )
00137 {
00138         Marker marker;
00139 
00140         marker.type = Marker::CUBE;
00141         marker.scale.x = msg.scale/7;
00142         marker.scale.y = msg.scale/7;
00143         marker.scale.z = msg.scale/7;
00144         marker.color.r = 0.7;
00145         marker.color.g = 0.1;
00146         marker.color.b = 0.1;
00147         marker.color.a = 0.8;
00148         return marker;
00149 }
00150 
00151 
00152 InteractiveMarkerControl& makeBoxControl( InteractiveMarker &msg )
00153 {
00154         InteractiveMarkerControl control;
00155         control.always_visible = true;
00156         control.markers.push_back( makeBox(msg) );
00157         msg.controls.push_back( control );
00158 
00159         return msg.controls.back();
00160 }
00161 
00162 
00163 void make6DofMarker( bool fixed )
00164 {
00165         InteractiveMarker int_marker;
00166         int_marker.header.frame_id = "/world";
00167         int_marker.pose.position.x = 5;
00168         int_marker.pose.position.y = 4;
00169         int_marker.pose.position.z = 0;
00170         int_marker.scale = 0.4;
00171         int_marker.name = "Control obstacle";
00172         int_marker.description = "Control the final \nposition of the obstacle";
00173 
00174         // insert a box
00175         makeBoxControl(int_marker);
00176         InteractiveMarkerControl control;
00177 
00178         control.orientation.w = 1;
00179         control.orientation.x = 1;
00180         control.orientation.y = 0;
00181         control.orientation.z = 0;
00182         control.name = "move_x";
00183         control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
00184         int_marker.controls.push_back(control);
00185 
00186         control.orientation.w = 1;
00187         control.orientation.x = 0;
00188         control.orientation.y = 0;
00189         control.orientation.z = 1;
00190         control.name = "move_y";
00191         control.interaction_mode = InteractiveMarkerControl::MOVE_AXIS;
00192         int_marker.controls.push_back(control);
00193 
00194         server->insert(int_marker);
00195         server->setCallback(int_marker.name, &processFeedback);
00196 }
00197 
00198 
00199 int main(int argc, char **argv)
00200 {
00201         ros::init(argc, argv, "mtt_target_generator");
00202         ros::NodeHandle n("~");
00203         ros::Rate loop_rate(10);
00204         p_n=&n;
00205 
00206         coor_pub = n.advertise<mtt::TargetList>("/mtt_targets", 1000);
00207 
00208         line_pub = n.advertise<visualization_msgs::Marker>( "/line_markers", 1 );
00209 
00210 
00211         server.reset( new interactive_markers::InteractiveMarkerServer("mtt_target_generator/im","",false) );
00212         make6DofMarker( true );
00213         server->applyChanges();
00214 
00215         while(ros::ok())
00216         {
00217                 loop_rate.sleep();
00218                 ros::spinOnce();
00219         }
00220 
00221         server.reset();
00222 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines


trajectory_planner
Author(s): joel
autogenerated on Thu Jul 26 2012 21:36:27