$search
00001 /* 00002 * Copyright (c) 2008, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 #include "tf/transform_broadcaster.h" 00031 #include "ros/ros.h" 00032 00033 class testBroadcaster 00034 { 00035 public: 00036 //constructor 00037 testBroadcaster() : count(0), count1(0){}; 00038 //Clean up ros connections 00039 ~testBroadcaster() { } 00040 00041 //A pointer to the rosTFServer class 00042 tf::TransformBroadcaster broadcaster; 00043 00044 00045 // A function to call to send data periodically 00046 void test () { 00047 broadcaster.sendTransform(tf::StampedTransform(btTransform(tf::createIdentityQuaternion(), btVector3(1,2,3)), ros::Time().fromSec(1), "frame2", "frame1")); 00048 00049 if (count > 9000) 00050 { 00051 count = 0; 00052 std::cerr<<"Counter 0 rolledover at 9000"<< std::endl; 00053 } 00054 else 00055 count ++; 00056 //std::cerr<<count<<std::endl; 00057 }; 00058 00059 // A function to call to send data periodically 00060 void test_vector () { 00061 std::vector<tf::StampedTransform> vec; 00062 vec.push_back(tf::StampedTransform(btTransform(tf::createIdentityQuaternion(), btVector3(1,2,3)), ros::Time().fromSec(1), "vframe2", "vframe1")); 00063 vec.push_back(tf::StampedTransform(btTransform(tf::createIdentityQuaternion(), btVector3(1,2,3)), ros::Time().fromSec(1), "vframe1", "vframe0")); 00064 broadcaster.sendTransform(vec); 00065 00066 if (count1 > 9000) 00067 { 00068 count1 = 0; 00069 std::cerr<<"Counter 1 rolledover at 9000"<< std::endl; 00070 } 00071 else 00072 count1 ++; 00073 //std::cerr<<count1<<std::endl; 00074 }; 00075 private: 00076 int count; 00077 int count1; 00078 00079 }; 00080 00081 int main(int argc, char ** argv) 00082 { 00083 //Initialize ROS 00084 ros::init(argc, argv, "testBroadcaster", ros::init_options::AnonymousName); 00085 00086 //Construct/initialize the server 00087 testBroadcaster myTestBroadcaster; 00088 00089 ros::NodeHandle node; 00090 while(ros::ok())//Check if a Ctrl-C or other shutdown command has been recieved 00091 { 00092 //Send some data 00093 myTestBroadcaster.test(); 00094 myTestBroadcaster.test_vector(); 00095 usleep(1000); 00096 } 00097 00098 return 0; 00099 }; 00100