00001 #include <iostream> 00002 #include <gtest/gtest.h> 00003 #include <boost/shared_ptr.hpp> 00004 #include <boost/make_shared.hpp> 00005 #include "robot_instance/StringUtilities.h" 00006 #include "robot_instance/RobotInstanceFactory.h" 00007 #include "robot_instance/CoeffMapLoader.h" 00008 #include <ros/package.h> 00009 00010 using namespace std; 00011 00012 class CoeffMapLoaderTest : public ::testing::Test 00013 { 00014 protected: 00015 virtual void SetUp() 00016 { 00017 packagePath = ros::package::getPath("robot_instance"); 00018 configPath = packagePath + "/test/config"; 00019 configSafetyPath = packagePath + "/test/configSafety"; 00020 fileName = "TestRobotInstance.xml"; 00021 instance = RobotInstanceFactory::createRobotInstanceFromFile(configPath, configSafetyPath, fileName); 00022 00023 motorCoeffMap = boost::make_shared<CoeffMap>(); 00024 brainstemCoeffMap = boost::make_shared<CoeffMap>(); 00025 } 00026 00027 virtual void TearDown() 00028 { 00029 } 00030 00031 string packagePath, configPath, configSafetyPath, fileName; 00032 RobotInstancePtr instance; 00033 CoeffMapPtr motorCoeffMap; 00034 CoeffMapPtr brainstemCoeffMap; 00035 }; 00036 00037 TEST_F(CoeffMapLoaderTest, LoadElements) 00038 { 00039 CoeffMapLoader::loadElements(instance, motorCoeffMap, brainstemCoeffMap); 00040 00041 EXPECT_EQ(1222, motorCoeffMap->size()); 00042 EXPECT_EQ(144, brainstemCoeffMap->size()); 00043 00044 // Normal assertions to check good data 00045 // std::vector<std::string> names; 00046 // for(CoeffMap::iterator it = motorCoeffMap->begin(); it != motorCoeffMap->end(); ++it) 00047 // { 00048 // //cout << it->first << " " << it->second << endl; 00049 // names.push_back(it->first); 00050 // } 00051 // EXPECT_EQ(1093, names.size()); // (TestSafety==14 * 9) = 126 00052 // (TestClass==45 * 5) = 225 00053 // (TestThumbClass==75 * 1) = 75 00054 // (TestPrimaryFingerClass==75 * 1) = 75 00055 // (TestSecondaryFingersClass==53 * 1) = 53 00056 // (TestRightWristClass==89 * 1) = 89 00057 // (TestCalibration==50 * 9) = 450 + 00058 // ==== 00059 // 1093 00060 00061 // Breakdown by mechanism 00062 // /r2/left_leg/joint0 00063 // TestClass == 42 00064 // TestCalibration == 48 00065 // TestSafety == 14 00066 // === + 00067 // 104 00068 // 00069 // /r2/left_leg/joint1 00070 // TestClass == 42 00071 // TestCalibration == 48 00072 // TestSafety == 14 00073 // === + 00074 // 104 00075 // 00076 // /r2/right_leg/gripper/joint0 00077 // TestClass == 42 00078 // TestCalibration == 48 00079 // TestSafety == 14 00080 // === + 00081 // 104 00082 // 00083 // /r2/left_arm/joint0 00084 // TestClass == 42 00085 // TestCalibration == 48 00086 // TestSafety == 14 00087 // === + 00088 // 104 00089 // 00090 // /r2/left_arm/joint1 00091 // TestClass == 42 00092 // TestCalibration == 48 00093 // TestSafety == 14 00094 // === + 00095 // 104 00096 // 00097 // /r2/right_arm/hand/thumb 00098 // TestThumbClass == 75 00099 // TestCalibration == 48 00100 // TestSafety == 14 00101 // === + 00102 // 137 00103 // 00104 // /r2/right_arm/hand/index 00105 // TestPrimaryFingerClass == 75 00106 // TestCalibration == 48 00107 // TestSafety == 14 00108 // === + 00109 // 137 00110 // 00111 // /r2/right_arm/hand/ringlittle 00112 // TestSecondaryFingersClass == 53 00113 // TestCalibration == 48 00114 // TestSafety == 14 00115 // === + 00116 // 115 00117 // 00118 // /r2/right_arm/wrist 00119 // TestRightWristClass == 89 00120 // TestCalibration == 48 00121 // TestSafety == 14 00122 // === + 00123 // 151 00124 00125 // sort(names.begin(), names.end()); // The underlying map can be in any order; sort to make sure 00126 00127 // EXPECT_STREQ("/r2/left_arm/joint0/APS1_BiasComp_Offset", names[0].c_str()); 00128 // EXPECT_FLOAT_EQ(0, motorCoeffMap->operator[](names[0])); 00129 00130 // EXPECT_STREQ("/r2/left_arm/joint0/APS1_C_COS_OFFSET", names[1].c_str()); 00131 // EXPECT_FLOAT_EQ(2064.822523, motorCoeffMap->operator[](names[1])); 00132 00133 // // skip the middle... 00134 00135 // commented out because Dustin said so 00136 // EXPECT_STREQ("/r2/right_leg/gripper/joint0/YawGain", names[1058].c_str()); 00137 // EXPECT_FLOAT_EQ(1, motorCoeffMap->operator[](names[1058])); 00138 00139 // EXPECT_STREQ("/r2/right_leg/gripper/joint0/YawOffset", names[1059].c_str()); 00140 // EXPECT_FLOAT_EQ(0, motorCoeffMap->operator[](names[1059])); 00141 00142 // // Example for how to generate location of coeff on associated Robonet node 00143 // std::string coeffName = "/r2/left_leg/joint0/Velocity_Limit"; 00144 // std::string mechanism = StringUtilities::getRoboDynEverythingButJoint(coeffName); //! @todo should use method for getting everything but element... 00145 // std::string node = instance->mechanismNodeMap[mechanism]; 00146 // std::string element = StringUtilities::getRoboDynJoint(coeffName); 00147 // EXPECT_STREQ("/left_leg/node0/Velocity_Limit", StringUtilities::makeFullyQualifiedRobonetElement(node, element).c_str()); 00148 } 00149 00150 int main(int argc, char** argv) 00151 { 00152 testing::InitGoogleTest(&argc, argv); 00153 return RUN_ALL_TESTS(); 00154 }