Go to the documentation of this file.00001 #include <gtest/gtest.h>
00002 #include <boost/shared_ptr.hpp>
00003 #include <boost/make_shared.hpp>
00004 #include "robot_instance/RobotInstanceFactory.h"
00005 #include "robot_instance/CoeffMapLoader.h"
00006 #include "robodyn_mechanisms/JointCommandFactory.h"
00007 #include <ros/package.h>
00008
00009 using namespace std;
00010
00011 std::map<std::string, float> testFloats;
00012 std::map<std::string, int16_t> testInt16s;
00013 std::map<std::string, uint16_t> testUInt16s;
00014 std::map<std::string, int32_t> testInt32s;
00015 std::map<std::string, uint32_t> testUInt32s;
00016 std::map<std::string, float> testLiveCoeffs;
00017 ParamMap testParamMap;
00018 CoeffMapPtr motorCoeffMap;
00019 CoeffMapPtr brainstemCoeffMap;
00020 RobotInstancePtr instance;
00021
00022 float getFloat(std::string item)
00023 {
00024 return testFloats[item];
00025 }
00026
00027 void setFloat(std::string item, float value)
00028 {
00029 testFloats[item] = value;
00030 }
00031
00032 float getInt16(std::string item)
00033 {
00034 return testInt16s[item];
00035 }
00036
00037 float getUInt16(std::string item)
00038 {
00039 return testUInt16s[item];
00040 }
00041
00042 void setUInt16(std::string item, uint16_t value)
00043 {
00044 testUInt16s[item] = value;
00045 }
00046
00047 uint32_t getInt32(std::string item)
00048 {
00049 return testInt32s[item];
00050 }
00051
00052 uint32_t getUInt32(std::string item)
00053 {
00054 return testUInt32s[item];
00055 }
00056
00057 void setInt16(std::string item, int16_t value)
00058 {
00059 testInt16s[item] = value;
00060 }
00061
00062 float getMotorCoeff(std::string item)
00063 {
00064 return motorCoeffMap->operator[](item);
00065 }
00066
00067 bool hasBrainstemCoeff(std::string item)
00068 {
00069 if (brainstemCoeffMap->find(item) != brainstemCoeffMap->end())
00070 {
00071 return true;
00072 }
00073
00074 return false;
00075 }
00076
00077 float getBrainstemCoeff(std::string item)
00078 {
00079 return brainstemCoeffMap->operator[](item);
00080 }
00081
00082 bool hasLiveCoeff(std::string coeff)
00083 {
00084 return testLiveCoeffs.count(coeff) > 0;
00085 }
00086
00087 float getLiveCoeff(std::string coeff)
00088 {
00089 return testLiveCoeffs[coeff];
00090 }
00091
00092 void setLiveCoeff(std::string coeff, float value)
00093 {
00094 testLiveCoeffs[coeff] = value;
00095 }
00096
00097 bool hasParam(std::string paramName)
00098 {
00099 return (testParamMap.find(paramName) != testParamMap.end());
00100 }
00101
00102 bool getBoolParam(std::string paramName, bool& value)
00103 {
00104 value = boost::get<bool>(testParamMap[paramName]);
00105 return true;
00106 }
00107
00108 bool getStringParam(std::string paramName, std::string& value)
00109 {
00110 value = boost::get<std::string>(testParamMap[paramName]);
00111 return true;
00112 }
00113
00114 bool getDoubleParam(std::string paramName, double& value)
00115 {
00116 value = boost::get<double>(testParamMap[paramName]);
00117 return true;
00118 }
00119
00120 bool getIntParam(std::string paramName, int& value)
00121 {
00122 value = boost::get<int>(testParamMap[paramName]);
00123 return true;
00124 }
00125
00126 void setBoolParam(std::string paramName, bool value)
00127 {
00128 testParamMap[paramName] = value;
00129 }
00130
00131 void setStringParam(std::string paramName, std::string value)
00132 {
00133 testParamMap[paramName] = value;
00134 }
00135
00136 void setDoubleParam(std::string paramName, double value)
00137 {
00138 testParamMap[paramName] = value;
00139 }
00140
00141 void setIntParam(std::string paramName, int value)
00142 {
00143 testParamMap[paramName] = value;
00144 }
00145
00146 std::vector<std::string> getJointNames(std::string mechanism)
00147 {
00148 return instance->mechanismJointsMap[mechanism];
00149 }
00150
00151 std::vector<std::string> getAllJointNames(std::string mechanism)
00152 {
00153 return instance->mechanismAllJointsMap[mechanism];
00154 }
00155
00156 std::vector<std::string> getActuatorNames(std::string mechanism)
00157 {
00158 return instance->mechanismActuatorsMap[mechanism];
00159 }
00160
00161 std::string getCommandFile(std::string mechanism)
00162 {
00163 return instance->configurationSafetyBasePath + instance->APIMAP_PATH + instance->mechanismCommandMap[mechanism];
00164 }
00165
00166 class JointCommandFactoryTest : public ::testing::Test
00167 {
00168 protected:
00169 virtual void SetUp()
00170 {
00171 packagePath = ros::package::getPath("robot_instance");
00172 configPath = packagePath + "/test/config";
00173 configSafetyPath = packagePath + "/test/configSafety";
00174 fileName = "TestRobotInstance.xml";
00175 instance = RobotInstanceFactory::createRobotInstanceFromFile(configPath, configSafetyPath, fileName);
00176
00177 motorCoeffMap = boost::make_shared<CoeffMap>();
00178 brainstemCoeffMap = boost::make_shared<CoeffMap>();
00179 CoeffMapLoader::loadElements(instance, motorCoeffMap, brainstemCoeffMap);
00180
00181 testFloats.clear();
00182
00183 io.getFloat = getFloat;
00184 io.setFloat = setFloat;
00185 io.setUInt16 = setUInt16;
00186 io.getUInt16 = getUInt16;
00187 io.getInt16 = getInt16;
00188 io.setInt16 = setInt16;
00189 io.getInt32 = getInt32;
00190 io.getUInt32 = getUInt32;
00191 io.getMotorCoeff = getMotorCoeff;
00192 io.hasBrainstemCoeff = hasBrainstemCoeff;
00193 io.getBrainstemCoeff = getBrainstemCoeff;
00194 io.hasLiveCoeff = hasLiveCoeff;
00195 io.getLiveCoeff = getLiveCoeff;
00196 io.setLiveCoeff = setLiveCoeff;
00197 io.getJointNames = getJointNames;
00198 io.getAllJointNames = getAllJointNames;
00199 io.getActuatorNames = getActuatorNames;
00200 io.getCommandFile = getCommandFile;
00201 io.hasParam = hasParam;
00202 io.getBoolParam = getBoolParam;
00203 io.getIntParam = getIntParam;
00204 io.getDoubleParam = getDoubleParam;
00205 io.getStringParam = getStringParam;
00206 io.setBoolParam = setBoolParam;
00207 io.setIntParam = setIntParam;
00208 io.setDoubleParam = setDoubleParam;
00209 io.setStringParam = setStringParam;
00210
00211 ros::Time::init();
00212 }
00213
00214 virtual void TearDown()
00215 {
00216 }
00217
00218 string packagePath, configPath, configSafetyPath, fileName;
00219 JointCommandInterface::IoFunctions io;
00220 vector<JointCommandInterfacePtr> jointInterfacePtrs;
00221 };
00222
00223 TEST_F(JointCommandFactoryTest, generate)
00224 {
00225 for (unsigned int i = 0; i < instance->mechanisms.size(); ++i)
00226 {
00227 std::cout << "Loading mechanism: " << instance->mechanisms[i] << std::endl;
00228 jointInterfacePtrs.push_back(JointCommandFactory::generate(instance->mechanisms[i], io));
00229
00230 EXPECT_TRUE(jointInterfacePtrs[i].get());
00231 }
00232
00233 EXPECT_EQ(instance->mechanisms.size(), jointInterfacePtrs.size());
00234 }
00235
00236 int main(int argc, char** argv)
00237 {
00238 testing::InitGoogleTest(&argc, argv);
00239 return RUN_ALL_TESTS();
00240 }