Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <visualization_msgs/Marker.h>
00003 #include <geometry_msgs/PoseWithCovarianceStamped.h>
00004 #include <geometry_msgs/PoseStamped.h>
00005 #include <geometry_msgs/Pose.h>
00006 #include <geometry_msgs/Vector3.h>
00007 #include <cmath>
00008 #include <boost/lexical_cast.hpp>
00009
00010 visualization_msgs::Marker robot_line_strip;
00011 visualization_msgs::Marker human_line_strip;
00012 visualization_msgs::Marker text_view_facing;
00013
00014
00015 ros::Publisher robot_marker_pub;
00016 ros::Publisher human_marker_pub;
00017 ros::Publisher text_marker_pub;
00018
00019 ros::Time frame_time;
00020 bool task_done;
00021 double scav_distance = 0.0;
00022
00023 void robot_callback(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& msg) {
00024
00025 geometry_msgs::Point p;
00026 p.x = msg->pose.pose.position.x;
00027 p.y = msg->pose.pose.position.y;
00028 p.z = msg->pose.pose.position.z;
00029
00030 if (false == robot_line_strip.points.empty()) {
00031 double dis = pow((p.x-robot_line_strip.points.back().x), 2.0) +
00032 pow((p.y-robot_line_strip.points.back().y), 2.0);
00033 scav_distance += pow(dis, 0.5);
00034 }
00035 robot_line_strip.points.push_back(p);
00036
00037 text_view_facing.pose.position = p;
00038 text_view_facing.pose.position.y += 1.0;
00039 text_view_facing.text = boost::lexical_cast<std::string>(scav_distance);
00040
00041 text_marker_pub.publish(text_view_facing);
00042 robot_marker_pub.publish(robot_line_strip);
00043 }
00044
00045 void human_callback(const geometry_msgs::PoseStamped::ConstPtr& msg) {
00046
00047 ros::Duration d = ros::Time::now() - frame_time;
00048 frame_time = ros::Time::now();
00049 if (d.toSec() > 2) {
00050 human_line_strip.points.clear();
00051 }
00052
00053 geometry_msgs::Point p;
00054 p.x = msg->pose.position.x;
00055 p.y = msg->pose.position.y;
00056 p.z = msg->pose.position.z;
00057 human_line_strip.points.push_back(p);
00058
00059 human_marker_pub.publish(human_line_strip);
00060 }
00061
00062 int main( int argc, char** argv )
00063 {
00064 ros::init(argc, argv, "trajectory_drawing");
00065 ros::NodeHandle nh;
00066 frame_time = ros::Time::now();
00067 task_done = false;
00068
00069 robot_marker_pub = nh.advertise<visualization_msgs::Marker> ("scav_robot_marker", 10);
00070 human_marker_pub = nh.advertise<visualization_msgs::Marker> ("scav_human_marker", 10);
00071 text_marker_pub = nh.advertise<visualization_msgs::Marker> ("scav_text_marker" ,10);
00072
00073 ros::Subscriber robot_pos_sub = nh.subscribe("/amcl_pose", 100, robot_callback);
00074 ros::Subscriber human_pos_sub = nh.subscribe("/segbot_pcl_person_detector/human_poses", 100, human_callback);
00075
00076 robot_line_strip.header.frame_id = human_line_strip.header.frame_id = "level_mux/map";
00077 robot_line_strip.header.stamp = human_line_strip.header.stamp = ros::Time::now();
00078 robot_line_strip.ns = human_line_strip.ns = "trajectory_namespace";
00079 robot_line_strip.action = human_line_strip.action = visualization_msgs::Marker::ADD;
00080 robot_line_strip.pose.orientation.w = human_line_strip.pose.orientation.w = 1.0;
00081
00082 robot_line_strip.id = 1;
00083 human_line_strip.id = 2;
00084
00085 robot_line_strip.type = human_line_strip.type = visualization_msgs::Marker::LINE_STRIP;
00086
00087
00088 robot_line_strip.scale.x = human_line_strip.scale.x = 0.1;
00089
00090
00091
00092 robot_line_strip.color.a = human_line_strip.color.a = 1.0;
00093
00094 robot_line_strip.color.b = 1.0;
00095 human_line_strip.color.r = 1.0;
00096
00097
00098 geometry_msgs::Vector3 vec;
00099 vec.x = vec.y = vec.z = 1.0;
00100 text_view_facing.header.frame_id = "level_mux/map";
00101 text_view_facing.header.stamp = ros::Time::now();
00102 text_view_facing.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
00103 text_view_facing.ns = "trajectory_namespace";
00104 text_view_facing.id = 3;
00105 text_view_facing.scale = vec;
00106 text_view_facing.color.a = text_view_facing.color.r = 1.0;
00107 text_view_facing.color.b = 0.5;
00108 text_view_facing.pose.orientation.w = 1.0;
00109
00110 ros::Rate r(10);
00111
00112 while (task_done == false and ros::ok()) { ros::spinOnce(); }
00113 }
00114