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
00029
00030 #include <tf/tf.h>
00031
00032 #include <ros/time.h>
00033 #include <ros/assert.h>
00034
00035 #include <boost/lexical_cast.hpp>
00036
00037 using namespace tf;
00038
00039 int main(int argc, char** argv)
00040 {
00041 uint32_t num_levels = 10;
00042 if (argc > 1)
00043 {
00044 num_levels = boost::lexical_cast<uint32_t>(argv[1]);
00045 }
00046
00047 tf::Transformer bc;
00048 StampedTransform t;
00049 t.stamp_ = ros::Time(1);
00050 t.frame_id_ = "root";
00051 t.child_frame_id_ = "0";
00052 t.setIdentity();
00053 t.setOrigin(tf::Vector3(1,0,0));
00054 bc.setTransform(t, "me");
00055 t.stamp_ = ros::Time(2);
00056 bc.setTransform(t, "me");
00057
00058 for (uint32_t i = 1; i < num_levels/2; ++i)
00059 {
00060 for (uint32_t j = 1; j < 3; ++j)
00061 {
00062 std::stringstream parent_ss;
00063 parent_ss << (i - 1);
00064 std::stringstream child_ss;
00065 child_ss << i;
00066
00067 t.stamp_ = ros::Time(j);
00068 t.frame_id_ = parent_ss.str();
00069 t.child_frame_id_ = child_ss.str();
00070 bc.setTransform(t, "me");
00071 }
00072 }
00073
00074 t.frame_id_ = "root";
00075 std::stringstream ss;
00076 ss << num_levels/2;
00077 t.stamp_ = ros::Time(1);
00078 t.child_frame_id_ = ss.str();
00079 bc.setTransform(t, "me");
00080 t.stamp_ = ros::Time(2);
00081 bc.setTransform(t, "me");
00082
00083 for (uint32_t i = num_levels/2 + 1; i < num_levels; ++i)
00084 {
00085 for (uint32_t j = 1; j < 3; ++j)
00086 {
00087 std::stringstream parent_ss;
00088 parent_ss << (i - 1);
00089 std::stringstream child_ss;
00090 child_ss << i;
00091
00092 t.stamp_ = ros::Time(j);
00093 t.frame_id_ = parent_ss.str();
00094 t.child_frame_id_ = child_ss.str();
00095 bc.setTransform(t, "me");
00096 }
00097 }
00098
00099
00100
00101 std::string v_frame0 = boost::lexical_cast<std::string>(num_levels - 1);
00102 std::string v_frame1 = boost::lexical_cast<std::string>(num_levels/2 - 1);
00103 ROS_INFO("%s to %s", v_frame0.c_str(), v_frame1.c_str());
00104 StampedTransform out_t;
00105
00106 const uint32_t count = 1000000;
00107 ROS_INFO("Doing %d %d-level tests", count, num_levels);
00108
00109 #if 01
00110 {
00111 ros::WallTime start = ros::WallTime::now();
00112 for (uint32_t i = 0; i < count; ++i)
00113 {
00114 bc.lookupTransform(v_frame1, v_frame0, ros::Time(0), out_t);
00115 }
00116 ros::WallTime end = ros::WallTime::now();
00117 ros::WallDuration dur = end - start;
00118
00119 ROS_INFO("lookupTransform at Time(0) took %.3fs for an average of %.3f us", dur.toSec(), dur.toSec() * 1.0e6 / (double)count);
00120 }
00121 #endif
00122
00123 #if 01
00124 {
00125 ros::WallTime start = ros::WallTime::now();
00126 for (uint32_t i = 0; i < count; ++i)
00127 {
00128 bc.lookupTransform(v_frame1, v_frame0, ros::Time(1), out_t);
00129 }
00130 ros::WallTime end = ros::WallTime::now();
00131 ros::WallDuration dur = end - start;
00132
00133 ROS_INFO("lookupTransform at Time(1) took %.3fs for an average of %.3f us", dur.toSec(), dur.toSec() * 1.0e6 / (double)count);
00134 }
00135 #endif
00136
00137 #if 01
00138 {
00139 ros::WallTime start = ros::WallTime::now();
00140 for (uint32_t i = 0; i < count; ++i)
00141 {
00142 bc.lookupTransform(v_frame1, v_frame0, ros::Time(1.5), out_t);
00143 }
00144 ros::WallTime end = ros::WallTime::now();
00145 ros::WallDuration dur = end - start;
00146
00147 ROS_INFO("lookupTransform at Time(1.5) took %.3fs for an average of %.3f us", dur.toSec(), dur.toSec() * 1.0e6 / (double)count);
00148 }
00149 #endif
00150
00151 #if 01
00152 {
00153 ros::WallTime start = ros::WallTime::now();
00154 for (uint32_t i = 0; i < count; ++i)
00155 {
00156 bc.lookupTransform(v_frame1, v_frame0, ros::Time(2), out_t);
00157 }
00158 ros::WallTime end = ros::WallTime::now();
00159 ros::WallDuration dur = end - start;
00160
00161 ROS_INFO("lookupTransform at Time(2) took %.3fs for an average of %.3f us", dur.toSec(), dur.toSec() * 1.0e6 / (double)count);
00162 }
00163 #endif
00164
00165 #if 01
00166 {
00167 ros::WallTime start = ros::WallTime::now();
00168 for (uint32_t i = 0; i < count; ++i)
00169 {
00170 bc.canTransform(v_frame1, v_frame0, ros::Time(0));
00171 }
00172 ros::WallTime end = ros::WallTime::now();
00173 ros::WallDuration dur = end - start;
00174
00175 ROS_INFO("canTransform at Time(0) took %.3fs for an average of %.3f us", dur.toSec(), dur.toSec() * 1.0e6 / (double)count);
00176 }
00177 #endif
00178
00179 #if 01
00180 {
00181 ros::WallTime start = ros::WallTime::now();
00182 for (uint32_t i = 0; i < count; ++i)
00183 {
00184 bc.canTransform(v_frame1, v_frame0, ros::Time(1));
00185 }
00186 ros::WallTime end = ros::WallTime::now();
00187 ros::WallDuration dur = end - start;
00188
00189 ROS_INFO("canTransform at Time(1) took %.3fs for an average of %.3f us", dur.toSec(), dur.toSec() * 1.0e6 / (double)count);
00190 }
00191 #endif
00192
00193 #if 01
00194 {
00195 ros::WallTime start = ros::WallTime::now();
00196 for (uint32_t i = 0; i < count; ++i)
00197 {
00198 bc.canTransform(v_frame1, v_frame0, ros::Time(1.5));
00199 }
00200 ros::WallTime end = ros::WallTime::now();
00201 ros::WallDuration dur = end - start;
00202
00203 ROS_INFO("canTransform at Time(1.5) took %.3fs for an average of %.3f us", dur.toSec(), dur.toSec() * 1.0e6 / (double)count);
00204 }
00205 #endif
00206
00207 #if 01
00208 {
00209 ros::WallTime start = ros::WallTime::now();
00210 for (uint32_t i = 0; i < count; ++i)
00211 {
00212 bc.canTransform(v_frame1, v_frame0, ros::Time(2));
00213 }
00214 ros::WallTime end = ros::WallTime::now();
00215 ros::WallDuration dur = end - start;
00216
00217 ROS_INFO("canTransform at Time(2) took %.3fs for an average of %.3f us", dur.toSec(), dur.toSec() * 1.0e6 / (double)count);
00218 }
00219 #endif
00220 }