Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <cortex_stream/cortex.h>
00003 #include <map>
00004 #include <visualization_msgs/Marker.h>
00005 #include <visualization_msgs/MarkerArray.h>
00006 #include <geometry_msgs/Pose.h>
00007 #include <geometry_msgs/Vector3.h>
00008
00009 #include <boost/lexical_cast.hpp>
00010 #include <cmath>
00011 #include <time.h>
00012 using namespace std;
00013 using namespace visualization_msgs;
00014
00015 visualization_msgs::MarkerArray markerArrayMsg;
00016
00017 void populate_marker_msg()
00018 {
00019
00020 Marker freespace;
00021 Marker nao;
00022 Marker box_obstacle_1;
00023 Marker box_obstacle_2;
00024
00025 geometry_msgs::Point p;
00026 p.x = -0.5; p.y = -0.75; p.z = 1.1;
00027 freespace.points.push_back(p);
00028 p.x = 4.5; p.y = -0.7; p.z = 0.8;
00029 freespace.points.push_back(p);
00030 p.x = 4.4; p.y = 3.3; p.z = 1.1;
00031 freespace.points.push_back(p);
00032 p.x = -0.45; p.y = 3.4; p.z = 1.0;
00033 freespace.points.push_back(p);
00034
00035 geometry_msgs::Point box_origin;
00036 double box_size_x = 0.4;
00037 double box_size_y = 0.2;
00038 double box_size_z = 0.2;
00039 double box_rotation = 1.0;
00040 static double offset_x = 0.0;
00041 static double offset_y = 0.0;
00042 box_origin.x = 2.5 + offset_x; box_origin.y = 0.5 + offset_y ; box_origin.z = box_size_z;
00043
00044
00045 offset_x += (rand()%100 - 50)/2000.0;
00046 offset_y += (rand()%100 - 50)/2000.0;
00047 box_obstacle_1.points.push_back(box_origin);
00048 p.x = box_origin.x + box_size_x; p.y = box_origin.y; p.z = box_origin.z - 0.03;
00049 box_obstacle_1.points.push_back(p);
00050 p.y += box_size_y; p.z += 0.02;
00051 box_obstacle_1.points.push_back(p);
00052 p.x -= box_size_x; p.z -= 0.01;
00053 box_obstacle_1.points.push_back(p);
00054
00055 static int drop_out_counter = 0;
00056 static bool drop_out = false;
00057 if( drop_out_counter % 50 == 0)
00058 {
00059 drop_out = !drop_out;
00060 }
00061
00062 box_origin.x = 2.0 + offset_y; box_origin.y = 1.0 + offset_x; box_origin.z = box_size_z;
00063 box_obstacle_2.points.push_back(box_origin);
00064 p.x = box_origin.x + box_size_x; p.y = box_origin.y; p.z = box_origin.z - 0.03;
00065 box_obstacle_2.points.push_back(p);
00066 p.y += box_size_y; p.z += 0.02;
00067 box_obstacle_2.points.push_back(p);
00068 p.x -= box_size_x; p.z -= 0.01;
00069 if(!drop_out)
00070 box_obstacle_2.points.push_back(p);
00071 drop_out_counter ++;
00072
00073
00074
00075
00076 markerArrayMsg.markers.clear();
00077 vector<string> object_names;
00078 markerArrayMsg.markers.push_back(freespace);
00079 object_names.push_back("map_free_space_boundings");
00080
00081 markerArrayMsg.markers.push_back(box_obstacle_1);
00082 object_names.push_back("box_obstacle_3");
00083 markerArrayMsg.markers.push_back(box_obstacle_2);
00084 object_names.push_back("box_obstacle_4");
00085
00086 int cnt = 0;
00087 double scale_fac = 0.1;
00088 for(MarkerArray::_markers_type::iterator it = markerArrayMsg.markers.begin(); it!=markerArrayMsg.markers.end(); ++it, ++cnt)
00089 {
00090 visualization_msgs::Marker & markerMsg = *it;
00091 markerMsg.type = visualization_msgs::Marker::SPHERE_LIST;
00092 markerMsg.header.frame_id = "/mocap";
00093 markerMsg.action = visualization_msgs::Marker::ADD;
00094
00095 markerMsg.id = cnt;
00096 markerMsg.ns = object_names[cnt];
00097 markerMsg.color.r = 1.0;
00098 markerMsg.color.g = 0.0;
00099 markerMsg.color.b = 0.0;
00100 markerMsg.color.a = 1.0;
00101 markerMsg.scale.x = scale_fac;
00102 markerMsg.scale.y = scale_fac;
00103 markerMsg.scale.z = scale_fac;
00104 geometry_msgs::Pose pose;
00105 pose.position.x = 0;
00106 pose.position.y = 0;
00107 pose.position.z = 0;
00108 }
00109
00110
00111 }
00112
00113 int main(int argc, char ** argv)
00114 {
00115
00116 ros::init(argc,argv,"cortex_fake_stream");
00117 ros::NodeHandle nh;
00118 ros::Rate r(20.0);
00119 srand ( time(NULL) );
00120
00121 ros::Publisher marker_pub = nh.advertise<visualization_msgs::MarkerArray>( "cortex_marker_array", 0 );
00122 while(ros::ok())
00123 {
00124 populate_marker_msg();
00125 r.sleep();
00126 ros::Time timestamp = ros::Time::now()-ros::Duration(0.1);
00127 int cnt = 0;
00128 for(MarkerArray::_markers_type::iterator it = markerArrayMsg.markers.begin(); it!=markerArrayMsg.markers.end(); ++it )
00129 {
00130 visualization_msgs::Marker & markerMsg = *it;
00131 markerMsg.header.stamp = timestamp;
00132 ++cnt;
00133 }
00134 ROS_INFO("Publishing %d markers",cnt);
00135 marker_pub.publish(markerArrayMsg);
00136 ros::spinOnce();
00137 }
00138 ROS_INFO("Exit peacefully");
00139 return 0;
00140 }