Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "footprint_marker.h"
00029
00030 #include <tf/tf.h>
00031 #include <tf/transform_listener.h>
00032 #include <tf/message_filter.h>
00033 #include <message_filters/subscriber.h>
00034
00035
00036 namespace srs_ui_but
00037 {
00038
00039 const double DEFAULT_LIFETIME = 5.0;
00040 const double DEFAULT_Z_POSITION = 0.11;
00041
00042 const std::string POLYGON_TOPIC = "polygon_in";
00043 const std::string MARKER_TOPIC = "marker_out";
00044
00045
00046 FootprintMarker::FootprintMarker()
00047 {
00048
00049 nh_ = ros::NodeHandle("~");
00050
00051
00052
00053 nh_.param("marker_lifetime", lifetime_, DEFAULT_LIFETIME);
00054 nh_.param("z_pos", z_pos_, DEFAULT_Z_POSITION);
00055
00056
00057 ros::NodeHandle nh;
00058 marker_pub_ = nh.advertise<visualization_msgs::Marker>(MARKER_TOPIC, 10);
00059
00060
00061 polygon_sub_ = nh.subscribe<geometry_msgs::PolygonStamped>(POLYGON_TOPIC, 10, &FootprintMarker::polygonCallback, this);
00062
00063
00064
00065 marker_.header.frame_id = "/base_link";
00066 marker_.header.stamp = ros::Time::now();
00067 marker_.ns = "cob_footprint_marker";
00068 marker_.id = 0;
00069 marker_.type = visualization_msgs::Marker::LINE_LIST;
00070
00071 marker_.action = visualization_msgs::Marker::ADD;
00072 marker_.lifetime = ros::Duration(lifetime_);
00073 marker_.pose.orientation.x = 0;
00074 marker_.pose.orientation.y = 0;
00075 marker_.pose.orientation.z = 0;
00076 marker_.pose.orientation.w = 1;
00077 marker_.pose.position.x = 0;
00078 marker_.pose.position.y = 0;
00079 marker_.pose.position.z = z_pos_;
00080 marker_.scale.x = 0.01;
00081 marker_.color.r = 1.0;
00082 marker_.color.g = 1.0;
00083 marker_.color.b = 0.0;
00084 marker_.color.a = 1.0;
00085
00086
00087 geometry_msgs::Point v;
00088 v.x = v.y = v.z = 0;
00089 marker_.points.push_back(v);
00090 marker_.points.push_back(v);
00091
00092 ROS_INFO("Footprint marker publisher initialized.");
00093 }
00094
00095
00096 FootprintMarker::~FootprintMarker()
00097 {
00098 }
00099
00100 void FootprintMarker::polygonCallback(const geometry_msgs::PolygonStampedConstPtr& polygon)
00101 {
00102 marker_.header.stamp = ros::Time::now();
00103 marker_.header.frame_id = polygon->header.frame_id;
00104 marker_.points.clear();
00105
00106
00107 for( std::size_t i = 0; i < polygon->polygon.points.size(); ++i )
00108 {
00109 std::size_t i2 = (i + 1) % polygon->polygon.points.size();
00110
00111 geometry_msgs::Point v1, v2;
00112 v1.x = polygon->polygon.points[i].x;
00113 v1.y = polygon->polygon.points[i].y;
00114 v1.z = polygon->polygon.points[i].z;
00115 v2.x = polygon->polygon.points[i2].x;
00116 v2.y = polygon->polygon.points[i2].y;
00117 v2.z = polygon->polygon.points[i2].z;
00118
00119 marker_.points.push_back(v1);
00120 marker_.points.push_back(v2);
00121 }
00122
00123 ROS_INFO_ONCE("First footprint polygon received, publishing the marker...");
00124
00125 marker_pub_.publish(marker_);
00126 }
00127
00128
00129 }
00130