footprint_marker.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * \file
00003  *
00004  * $Id:$
00005  *
00006  * Copyright (C) Brno University of Technology
00007  *
00008  * This file is part of software developed by dcgm-robotics@FIT group.
00009  *
00010  * Author: Michal Spanel (spanel@fit.vutbr.cz)
00011  * Supervised by: Michal Spanel (spanel@fit.vutbr.cz)
00012  * Date: 10/12/2012
00013  * 
00014  * This file is free software: you can redistribute it and/or modify
00015  * it under the terms of the GNU Lesser General Public License as published by
00016  * the Free Software Foundation, either version 3 of the License, or
00017  * (at your option) any later version.
00018  * 
00019  * This file is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public License
00025  * along with this file.  If not, see <http://www.gnu.org/licenses/>.
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     // a handle for this node, initialize node
00049     nh_ = ros::NodeHandle("~");
00050 
00051     // read parameters from parameter server
00052 //    nh_.param("marker_frame", base_frame_, std::string("/base_link"));
00053     nh_.param("marker_lifetime", lifetime_, DEFAULT_LIFETIME);
00054     nh_.param("z_pos", z_pos_, DEFAULT_Z_POSITION);
00055 
00056     // Create the publisher
00057     ros::NodeHandle nh;
00058     marker_pub_ = nh.advertise<visualization_msgs::Marker>(MARKER_TOPIC, 10);
00059 
00060     // Subscribe to the polygon topic
00061     polygon_sub_ = nh.subscribe<geometry_msgs::PolygonStamped>(POLYGON_TOPIC, 10, &FootprintMarker::polygonCallback, this);
00062 
00063     // Create the marker template
00064     // Message template
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 //    marker_.type = visualization_msgs::Marker::LINE_STRIP;
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     // Create the disc like geometry for the markers
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     // Line list...
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 


srs_ui_but
Author(s): Vit Stancl (stancl@fit.vutbr.cz), Michal Spanel (spanel@fit.vutbr.cz), Tomas Lokaj
autogenerated on Mon Oct 6 2014 08:49:30