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
00032 #include <tf/transform_listener.h>
00033 #include <geometry_msgs/PointStamped.h>
00034 #include <boost/bind.hpp>
00035 #include <boost/scoped_ptr.hpp>
00036
00037 #include "ros/ros.h"
00038
00039 #include <gtest/gtest.h>
00040
00041 using namespace tf;
00042
00043
00044 void getPose(tf::TransformListener* listener, double* x, double* y, double* th){
00045 geometry_msgs::TransformStamped geo_pose;
00046 tf::StampedTransform transform;
00047 try{
00048 listener->lookupTransform("/map", "/robot_0/base_link", ros::Time(0), transform);
00049
00050 transformStampedTFToMsg(transform, geo_pose);
00051
00052 *x = geo_pose.transform.translation.x;
00053 *y = geo_pose.transform.translation.y;
00054 *th = tf::getYaw(geo_pose.transform.rotation);
00055 }
00056 catch (tf::TransformException ex){
00057
00058 *x=0;
00059 *y=0;
00060 *th=0;
00061 }
00062
00063 }
00064
00065 TEST(dynamicPlanner, plannerFailure)
00066 {
00067 tf::TransformListener listener;
00068
00069 double goal_x = 20.413;
00070 double goal_y = 6.913;
00071
00072 ros::NodeHandle n;
00073 double x,y,th;
00074 double t = ros::Time::now().toSec();
00075 int atGoal = 0;
00076
00077 sleep(5.0);
00078
00079 while(ros::Time::now().toSec()-t < 180.0 && !atGoal){
00080 getPose(&listener,&x,&y,&th);
00081 ROS_INFO("x=%f y=%f",x,y);
00082 double dx = goal_x-x;
00083 double dy = goal_y-y;
00084 double dist = sqrt(dx*dx+dy*dy);
00085 atGoal = dist < 2.0;
00086 ros::Duration(2.0).sleep();
00087 }
00088
00089 EXPECT_EQ(1, atGoal);
00090 }
00091
00092 int main(int argc, char** argv)
00093 {
00094 testing::InitGoogleTest(&argc, argv);
00095
00096 ros::Time::setNow(ros::Time());
00097 ros::init(argc, argv, "test_dynamic_planner");
00098 ros::NodeHandle nh;
00099
00100 int ret = RUN_ALL_TESTS();
00101
00102 return ret;
00103 }
00104