Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <nav_msgs/Odometry.h>
00003
00004 #include <gtest/gtest.h>
00005 #include <iostream>
00006 #include <fstream>
00007
00008 #include <tf/tf.h>
00009
00010 nav_msgs::Odometry filtered_;
00011
00012 void filterCallback(const nav_msgs::OdometryConstPtr &msg)
00013 {
00014 filtered_ = *msg;
00015 }
00016
00017 TEST (BagTest, PoseCheck)
00018 {
00019 ros::NodeHandle nh;
00020 ros::NodeHandle nhLocal("~");
00021
00022 double finalX = 0;
00023 double finalY = 0;
00024 double finalZ = 0;
00025 double tolerance = 0;
00026 bool outputFinalPosition = false;
00027 std::string finalPositionFile;
00028
00029 nhLocal.getParam("final_x", finalX);
00030 nhLocal.getParam("final_y", finalY);
00031 nhLocal.getParam("final_z", finalZ);
00032 nhLocal.getParam("tolerance", tolerance);
00033 nhLocal.param("output_final_position", outputFinalPosition, false);
00034 nhLocal.param("output_location", finalPositionFile, std::string("test.txt"));
00035
00036 ros::Subscriber filteredSub = nh.subscribe("/odometry/filtered", 1, &filterCallback);
00037
00038 while(ros::ok())
00039 {
00040 ros::spinOnce();
00041 ros::Duration(0.0333333).sleep();
00042 }
00043
00044 if(outputFinalPosition)
00045 {
00046 try
00047 {
00048 std::ofstream posOut;
00049 posOut.open(finalPositionFile.c_str(), std::ofstream::app);
00050 posOut << filtered_.pose.pose.position.x << " " << filtered_.pose.pose.position.y << " " << filtered_.pose.pose.position.z << std::endl;
00051 posOut.close();
00052 }
00053 catch(...)
00054 {
00055 ROS_ERROR_STREAM("Unable to open output file.\n");
00056 }
00057 }
00058
00059 double xDiff = filtered_.pose.pose.position.x - finalX;
00060 double yDiff = filtered_.pose.pose.position.y - finalY;
00061 double zDiff = filtered_.pose.pose.position.z - finalZ;
00062
00063 EXPECT_LT(::sqrt(xDiff*xDiff + yDiff*yDiff + zDiff*zDiff), tolerance);
00064 }
00065
00066 int main(int argc, char **argv)
00067 {
00068 testing::InitGoogleTest(&argc, argv);
00069
00070 ros::init(argc, argv, "localization_node-bag-pose-tester");
00071 ros::Time::init();
00072
00073
00074 ros::Duration(2.0).sleep();
00075
00076 return RUN_ALL_TESTS();
00077 }
00078