BeamPublisher.hpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, LABUST, UNIZG-FER
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the LABUST nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *  Author: Gyula Nagy
00034  *  Created: 14.11.2013.
00035  *********************************************************************/
00036 #ifndef BEAMPUBLISHER_HPP_
00037 #define BEAMPUBLISHER_HPP_
00038 #include <labust/navigation/NavQuestMessages.hpp>
00039 #include <labust/tools/conversions.hpp>
00040 
00041 #include <geometry_msgs/TwistStamped.h>
00042 #include <std_msgs/Float32MultiArray.h>
00043 #include <ros/ros.h>
00044 
00045 namespace labust
00046 {
00047         namespace navigation
00048         {
00052                 template<std::size_t N>
00053                 struct BeamPublisher
00054                 {
00055                         typedef boost::shared_ptr<BeamPublisher<N> > Ptr;
00056                         BeamPublisher(ros::NodeHandle nh, const std::string& topic)
00057                         {
00058                                 pub = nh.advertise<std_msgs::Float32MultiArray>(topic,1);
00059                         }
00060 
00061                         void operator()(const float vec[N], int quality=50)
00062                         {
00063                                 std_msgs::Float32MultiArrayPtr array(
00064                                                 new std_msgs::Float32MultiArray());
00065                                 //Condition speed mm/s -> m/s
00066                                 float cond_vec[N];
00067                                 for (int i=0; i<3;++i) cond_vec[i]=vec[i]/1000;
00068                                 array->data.assign(&cond_vec[0],&cond_vec[N]);
00069                                 //array->data.push_back(quality);
00070                                 pub.publish(array);
00071                         }
00072 
00073                         ros::Publisher pub;
00074                 };
00075 
00079                 struct TwistPublisher
00080                 {
00081                         typedef boost::shared_ptr<TwistPublisher> Ptr;
00082                         TwistPublisher(ros::NodeHandle nh, const std::string& topic,
00083                                         const std::string& frame_id):
00084                                                 frame_id(frame_id)
00085                         {
00086                                 pub = nh.advertise<geometry_msgs::TwistStamped>(topic,1);
00087                         }
00088 
00089                         void operator()(const float vec[3])
00090                         {
00091                                 geometry_msgs::TwistStamped::Ptr twist(
00092                                                 new geometry_msgs::TwistStamped());
00093                                 twist->header.stamp=ros::Time();
00094                                 twist->header.frame_id=frame_id;
00095                                 //Condition speed mm/s -> m/s
00096                                 float cond_vec[3];
00097                                 for (int i=0; i<3;++i) cond_vec[i]=vec[i]/1000;
00098                                 labust::tools::vectorToPoint(cond_vec,twist->twist.linear);
00099                                 pub.publish(twist);
00100                         }
00101 
00102                         std::string frame_id;
00103                         ros::Publisher pub;
00104                 };
00105         }
00106 }
00107 
00108 //BEAMPUBLISHER_HPP_
00109 #endif


navquest_dvl
Author(s): Gyula Nagy
autogenerated on Thu Jul 10 2014 10:34:00