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