Go to the documentation of this file.00001 #include "gtest/gtest.h"
00002 #include "grizzly_motion/dead_reckoning.h"
00003
00004 #include "ros/console.h"
00005
00006 TEST(DeadReckoning, simple_straight)
00007 {
00008 ros::Time::init();
00009 ros::Time start = ros::Time::now();
00010 double wheel_radius = 0.2;
00011
00012 DeadReckoning dr(1.0, wheel_radius);
00013 nav_msgs::Odometry odom;
00014 sensor_msgs::JointState joints;
00015 grizzly_msgs::DrivePtr encoders(new grizzly_msgs::Drive);
00016 encoders->header.stamp = start;
00017 encoders->front_left = encoders->rear_left = 1.1;
00018 encoders->front_right = encoders->rear_right = 1.1;
00019 dr.next(encoders, &odom, &joints);
00020
00021
00022 for(int step = 0; step < 500; step++)
00023 {
00024 encoders->header.stamp += ros::Duration(0.02);
00025 EXPECT_TRUE(dr.next(encoders, &odom, &joints));
00026 }
00027
00028
00029 EXPECT_NEAR(10 * 1.1 * wheel_radius, odom.pose.pose.position.x, 0.005);
00030 EXPECT_NEAR(0.0, odom.pose.pose.position.y, 0.005);
00031 EXPECT_EQ(odom.header.stamp, encoders->header.stamp);
00032 }
00033
00034 TEST(DeadReckoning, curved_path)
00035 {
00036 ros::Time::init();
00037 ros::Time start = ros::Time::now();
00038 double wheel_radius = 0.1;
00039 double vehicle_width = 1.0;
00040
00041
00042
00043 double left_travel = 3.5*2 * M_PI / 4;
00044 double right_travel = 2.5*2 * M_PI / 4;
00045
00046 DeadReckoning dr(vehicle_width, wheel_radius);
00047 nav_msgs::Odometry odom;
00048 sensor_msgs::JointState joints;
00049 grizzly_msgs::DrivePtr encoders(new grizzly_msgs::Drive);
00050 encoders->header.stamp = start;
00051 encoders->front_left = encoders->rear_left = left_travel / wheel_radius / 10.0;
00052 encoders->front_right = encoders->rear_right = right_travel / wheel_radius / 10.0;
00053 dr.next(encoders, &odom, &joints);
00054
00055
00056 for(int step = 0; step < 500; step++)
00057 {
00058 encoders->header.stamp += ros::Duration(0.02);
00059 EXPECT_TRUE(dr.next(encoders, &odom, &joints));
00060 ROS_DEBUG_STREAM("ENC " << encoders->front_left << " " << encoders->front_right);
00061 ROS_DEBUG_STREAM("POSE " << odom.pose.pose.position.x << " " << odom.pose.pose.position.y);
00062 }
00063
00064
00065
00066 EXPECT_NEAR(3, odom.pose.pose.position.x, 0.05);
00067 EXPECT_NEAR(-3, odom.pose.pose.position.y, 0.05);
00068 EXPECT_EQ(odom.header.stamp, encoders->header.stamp);
00069 }
00070
00071 TEST(DeadReckoning, timeout)
00072 {
00073 ros::Time::init();
00074 ros::Time start = ros::Time::now();
00075
00076 nav_msgs::Odometry odom;
00077 sensor_msgs::JointState joints;
00078 grizzly_msgs::DrivePtr encoders(new grizzly_msgs::Drive);
00079 encoders->header.stamp = start;
00080
00081 DeadReckoning dr(1.0, 1.0);
00082 dr.next(encoders, &odom, &joints);
00083
00084
00085 encoders->header.stamp += ros::Duration(0.09);
00086 EXPECT_TRUE(dr.next(encoders, &odom, &joints));
00087
00088
00089 encoders->header.stamp += ros::Duration(0.11);
00090 EXPECT_FALSE(dr.next(encoders, &odom, &joints));
00091 }
00092
00093 int main(int argc, char **argv)
00094 {
00095 ::testing::InitGoogleTest(&argc, argv);
00096 return RUN_ALL_TESTS();
00097 }