00001
00004
00005
00006
00007
00008 #include <cost_map_ros/cost_map_ros.hpp>
00009 #include <gtest/gtest.h>
00010 #include <iostream>
00011 #include <string>
00012
00013 #include "../../../../include/cost_map_demos/from_ros_costmaps.hpp"
00014
00015
00016
00017
00018
00019 TEST(Costmap2DROS, full_window) {
00020 std::cout << std::endl;
00021 ROS_INFO("***********************************************************");
00022 ROS_INFO(" Copy Full Window");
00023 ROS_INFO("***********************************************************");
00024
00025
00026 std::string layer_name = "obstacle_costs";
00027 cost_map_demos::ROSCostmapServer ros_costmap_5x5("five_by_five", "base_link_5x5", cost_map::Position(0.0, 0.0), 5.0, 5.0);
00028 cost_map::CostMap cost_map_5x5, cost_map_4x4;
00029 cost_map::fromCostmap2DROS(*(ros_costmap_5x5.getROSCostmap()), layer_name, cost_map_5x5);
00030
00031 ASSERT_EQ(cost_map_5x5.getFrameId(), ros_costmap_5x5.getROSCostmap()->getGlobalFrameID());
00032 ASSERT_EQ(cost_map_5x5.getLength().x(),
00033 ros_costmap_5x5.getROSCostmap()->getCostmap()->getSizeInCellsX()*ros_costmap_5x5.getROSCostmap()->getCostmap()->getResolution()
00034 );
00035 ASSERT_EQ(cost_map_5x5.getLength().y(),
00036 ros_costmap_5x5.getROSCostmap()->getCostmap()->getSizeInCellsY()*ros_costmap_5x5.getROSCostmap()->getCostmap()->getResolution()
00037 );
00038 ASSERT_EQ(cost_map_5x5.getSize()[0], ros_costmap_5x5.getROSCostmap()->getCostmap()->getSizeInCellsX());
00039 ASSERT_EQ(cost_map_5x5.getSize()[1], ros_costmap_5x5.getROSCostmap()->getCostmap()->getSizeInCellsY());
00040 cost_map::Length position = cost_map_5x5.getPosition() - 0.5 * cost_map_5x5.getLength().matrix();
00041 ASSERT_EQ(position.x(), ros_costmap_5x5.getROSCostmap()->getCostmap()->getOriginX());
00042 ASSERT_EQ(position.y(), ros_costmap_5x5.getROSCostmap()->getCostmap()->getOriginY());
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 ASSERT_EQ(cost_map_5x5.at(layer_name, cost_map::Index(1,9)), ros_costmap_5x5.getROSCostmap()->getCostmap()->getCost(8,0));
00058 std::cout << std::endl;
00059 }
00060
00061 TEST(Costmap2DROS, cost_map_centres) {
00062 std::cout << std::endl;
00063 ROS_INFO("***********************************************************");
00064 ROS_INFO(" Check Subwindow Centres");
00065 ROS_INFO("***********************************************************");
00066 ROS_INFO("Subwindows are centred as closely as possible to the robot");
00067 ROS_INFO("pose, though not exactly. They still need to align with");
00068 ROS_INFO("the underlying ros costmap so that they don't introduce a");
00069 ROS_INFO("new kind of error. As a result, the centre is shifted from");
00070 ROS_INFO("the robot pose to the nearest appropriate point which aligns");
00071 ROS_INFO("the new cost map exactly on top of the original ros costmap.");
00072 std::cout << std::endl;
00073 std::string layer_name = "obstacle_costs";
00074 cost_map_demos::ROSCostmapServer ros_costmap_5x5_3x3_offset("five_by_five_three_by_three_offset", "base_link_5x5_3x3_offset", cost_map::Position(-6.0, 0.0), 5.0, 5.0);
00075 cost_map_demos::ROSCostmapServer ros_costmap_5x5_3x3_centre("five_by_five_three_by_three_centre", "base_link_5x5_3x3_centre", cost_map::Position(-6.0, -6.0), 5.0, 5.0);
00076 cost_map_demos::ROSCostmapServer ros_costmap_5x5_2_5x2_5_offset("five_by_five_twohalf_by_twohalf_offset", "base_link_5x5_2_5x2_5_offset", cost_map::Position(-12.0, 0.0), 5.0, 5.0);
00077 cost_map::CostMap cost_map_5x5_3x3_offset, cost_map_5x5_3x3_centre, cost_map_5x5_2_5x2_5_offset;
00078 cost_map::Length geometry_3x3(3.0, 3.0);
00079 cost_map::fromCostmap2DROSAtRobotPose(*(ros_costmap_5x5_3x3_offset.getROSCostmap()), geometry_3x3, layer_name, cost_map_5x5_3x3_offset);
00080 cost_map::fromCostmap2DROSAtRobotPose(*(ros_costmap_5x5_3x3_centre.getROSCostmap()), geometry_3x3, layer_name, cost_map_5x5_3x3_centre);
00081 cost_map::Length geometry_2_5x2_5(2.5, 2.5);
00082 cost_map::fromCostmap2DROSAtRobotPose(*(ros_costmap_5x5_2_5x2_5_offset.getROSCostmap()), geometry_2_5x2_5, layer_name, cost_map_5x5_2_5x2_5_offset);
00083 ROS_INFO_STREAM(" cost_map_5x5_3x3_offset : " << cost_map_5x5_3x3_offset.getPosition().transpose());
00084 ROS_INFO_STREAM(" cost_map_5x5_3x3_offset : " << cost_map_5x5_3x3_centre.getPosition().transpose());
00085 ROS_INFO_STREAM(" cost_map_5x5_3x3_offset : " << cost_map_5x5_2_5x2_5_offset.getPosition().transpose());
00086 ASSERT_EQ(-3.5, cost_map_5x5_3x3_offset.getPosition().x());
00087 ASSERT_EQ(2.5, cost_map_5x5_3x3_offset.getPosition().y());
00088 ASSERT_EQ(-3.5, cost_map_5x5_3x3_centre.getPosition().x());
00089 ASSERT_EQ(-3.5, cost_map_5x5_3x3_centre.getPosition().y());
00090 ASSERT_EQ(-9.75, cost_map_5x5_2_5x2_5_offset.getPosition().x());
00091 ASSERT_EQ(2.25, cost_map_5x5_2_5x2_5_offset.getPosition().y());
00092 std::cout << std::endl;
00093 }
00094
00095
00096
00097
00098
00099 int main(int argc, char **argv) {
00100
00101 ros::init(argc, argv, "test_from_ros_costmaps");
00102
00103 cost_map_demos::TransformBroadcaster broadcaster;
00104 cost_map_demos::broadcastCostmap2DROSTestSuiteTransforms(broadcaster);
00105
00106 testing::InitGoogleTest(&argc,argv);
00107 int result = RUN_ALL_TESTS();
00108 broadcaster.shutdown();
00109 return result;
00110 }
00111
00112