cob_stretch_publisher.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: Tomas Lokaj (xlokaj03@stud.fit.vutbr.cz)
00011  * Supervised by: Michal Spanel (spanel@fit.vutbr.cz)
00012  * Date: 07/02/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 #include <ros/ros.h>
00028 #include <ros/publisher.h>
00029 #include <tf/tf.h>
00030 #include <tf/transform_listener.h>
00031 
00032 #include <math.h>
00033 #include <vector>
00034 
00035 #include <srs_ui_but/COBStretch.h>
00036 #include <srs_ui_but/topics_list.h>
00037 
00038 // Transform listener
00039 tf::TransformListener *tfListener;
00040 
00041 // Transformer
00042 tf::Transformer transformer;
00043 
00044 // Transformations
00045 tf::StampedTransform linkToBaseTf;
00046 
00047 srs_ui_but::COBStretch calculateStretch(std::vector<std::string> links)
00048 {
00049   ros::Time time_stamp = ros::Time().now();
00050 
00051   float radius = 0;
00052   float height = 0;
00053 
00054   for (std::vector<std::string>::iterator i = links.begin(); i != links.end(); i++)
00055   {
00056     try
00057     {
00058       tfListener->waitForTransform(*i, srs_ui_but::DEFAULT_COB_BASE_LINK, time_stamp, ros::Duration(0.2));
00059       tfListener->lookupTransform(*i, srs_ui_but::DEFAULT_COB_BASE_LINK, time_stamp, linkToBaseTf);
00060 
00061       transformer.setTransform(linkToBaseTf);
00062 
00063       // Transform link to camera
00064       tf::Stamped<btVector3> p;
00065       p.setX(0);
00066       p.setY(0);
00067       p.setZ(0);
00068       p.frame_id_ = *i;
00069       transformer.transformPoint(srs_ui_but::DEFAULT_COB_BASE_LINK, p, p);
00070 
00071       //std::cout << p.getX() << ", " << p.getY() << ", " << p.getZ() << ", " << std::endl;
00072 
00073       float r = pow(p.getX(), 2) + pow(p.getY(), 2);
00074       if (r > radius)
00075       {
00076         radius = r;
00077         height = p.getZ();
00078       }
00079     }
00080 
00081     catch (tf::TransformException& ex)
00082     {
00083       ROS_WARN("Transform ERROR:\n %s", ex.what());
00084     }
00085   }
00086 
00087   srs_ui_but::COBStretch cob_stretch;
00088   cob_stretch.radius = sqrt(radius);
00089   cob_stretch.height = height;
00090   cob_stretch.time_stamp = time_stamp;
00091 
00092   return cob_stretch;
00093 }
00094 
00095 int main(int argc, char **argv)
00096 {
00097   ros::init(argc, argv, "cob_stretch_publisher");
00098 
00099   ros::NodeHandle nh;
00100 
00101   tfListener = new tf::TransformListener();
00102 
00103   std::vector<std::string> links;
00104   links.push_back("arm_2_link");
00105   links.push_back("arm_3_link");
00106   links.push_back("arm_4_link  ");
00107   links.push_back("arm_5_link");
00108   links.push_back("arm_6_link");
00109   links.push_back("arm_7_link");
00110   links.push_back("sdh_finger_11_link");
00111   links.push_back("sdh_finger_12_link");
00112   links.push_back("sdh_finger_13_link");
00113   links.push_back("sdh_finger_21_link");
00114   links.push_back("sdh_finger_22_link");
00115   links.push_back("sdh_finger_23_link");
00116   links.push_back("sdh_grasp_link");
00117   links.push_back("sdh_palm_link");
00118   links.push_back("sdh_thumb_1_link");
00119   links.push_back("sdh_thumb_2_link");
00120   links.push_back("sdh_thumb_2_link");
00121   links.push_back("sdh_tip_link");
00122   links.push_back("tray_left_link");
00123   links.push_back("tray_right_link");
00124 
00125   ros::Publisher pub = nh.advertise<srs_ui_but::COBStretch> (srs_ui_but::COBStretch_TOPIC, 10);
00126 
00127   while (ros::ok())
00128   {
00129     srs_ui_but::COBStretch cob_stretch = calculateStretch(links);
00130     pub.publish(cob_stretch);
00131   }
00132   ros::spin();
00133 
00134   return 0;
00135 }


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