JointDynamicsDataTest.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include "robodyn_controllers/JointDynamicsData.h"
00003 #include "robodyn_controllers/KdlTreeId.h"
00004 #include <ros/package.h>
00005 
00006 class JointDynamicsDataTest : public ::testing::Test
00007 {
00008 protected:
00009     virtual void SetUp()
00010     {
00011         std::string packagePath = ros::package::getPath("robodyn_controllers");
00012         id.loadFromFile(packagePath + "/test/urdf/SimpleTestRobot.xml");
00013         tree = id.getTree();
00014     }
00015 
00016     virtual void TearDown()
00017     {
00018     }
00019 
00020     KdlTreeId         id;
00021     KDL::Tree         tree;
00022     JointDynamicsData jd;
00023     JntDynData        data;
00024 };
00025 
00026 TEST_F(JointDynamicsDataTest, InitializeMapsTest)
00027 {
00028     // Initialize maps with blank tree
00029     KDL::Tree blankTree;
00030     jd.InitializeMaps(blankTree);
00031 
00032     EXPECT_FALSE(jd.extForceMap.empty()) ;
00033     EXPECT_FALSE(jd.segForceMap.empty()) ; // Empty trees still have root
00034     // segments
00035     EXPECT_TRUE(jd.jointDataMap.empty());
00036     EXPECT_TRUE(jd.jointTorqueCommandMap.empty());
00037     EXPECT_TRUE(jd.jointInertiaMap.empty());
00038 
00039     // Initialize maps with test tree
00040     jd.InitializeMaps(tree);
00041 
00042     ASSERT_FALSE(                   jd.segForceMap.empty());
00043     EXPECT_EQ (1,                   jd.segForceMap.count("link1"));
00044     EXPECT_EQ (1,                   jd.segForceMap.count("link4"));
00045     EXPECT_EQ (KDL::Wrench::Zero(), jd.segForceMap["link3"]);
00046 
00047     ASSERT_FALSE( jd.jointTorqueCommandMap.empty());
00048     EXPECT_EQ (1, jd.jointTorqueCommandMap.count("joint1"));
00049     EXPECT_EQ (0, jd.jointTorqueCommandMap["joint3"]);
00050     EXPECT_EQ (0, jd.jointTorqueCommandMap.count("link2"));
00051 }
00052 
00053 TEST_F(JointDynamicsDataTest, PopulateJointInfoTest)
00054 {
00055     jd.InitializeMaps(tree);
00056     KDL::Chain chain1, chain2;
00057     tree.getChain("link1", "link2", chain1);
00058     tree.getChain("link1", "link4", chain2);
00059 
00060     KDL::JntArray q1(chain1.getNrOfJoints());
00061     KDL::JntArray q1_dot(chain1.getNrOfJoints());
00062     KDL::JntArray q1_dotdot(chain1.getNrOfJoints());
00063     KDL::JntArray q2(chain2.getNrOfJoints());
00064     KDL::JntArray q2_dot(chain2.getNrOfJoints());
00065     KDL::JntArray q2_dotdot(chain2.getNrOfJoints());
00066 
00067     data.pos                  = 2.0;
00068     data.vel                  = 1.0;
00069     data.acc                  = 3.0;
00070     jd.jointDataMap["joint1"] = data;
00071     jd.jointDataMap["joint3"] = data;
00072 
00073     EXPECT_EQ(-1,  jd.PopulateJointInfo(chain2, q1, q1_dot, q1_dotdot));
00074     ASSERT_EQ(0,   jd.PopulateJointInfo(chain1, q1, q1_dot, q1_dotdot));
00075     EXPECT_EQ(2.0, q1(0) );
00076     EXPECT_EQ(1.0, q1_dot(0));
00077     EXPECT_EQ(3.0, q1_dotdot(0));
00078 
00079     ASSERT_EQ(0,   jd.PopulateJointInfo(chain2, q2, q2_dot, q2_dotdot));
00080     EXPECT_EQ(0.0, q2(0));
00081     EXPECT_EQ(1.0, q2_dot(1));
00082     EXPECT_EQ(0.0, q2_dotdot(0));
00083 
00084 }
00085 
00086 TEST_F(JointDynamicsDataTest, PopulateExtForceInfoTest)
00087 {
00088     jd.InitializeMaps(tree);
00089     KDL::Chain chain1, chain2;
00090     tree.getChain("link1", "link2", chain1);
00091     tree.getChain("link1", "link4", chain2);
00092 
00093     KDL::Wrenches f1(chain1.getNrOfSegments());
00094     KDL::Wrenches f2(chain2.getNrOfSegments());
00095 
00096     KDL::Vector force(1.0, 0.0, 0.0), torque(0.0, 2.0, 1.0);
00097     KDL::Wrench testW(force, torque);
00098     jd.extForceMap["link3"] = testW;
00099 
00100     EXPECT_EQ(-1, jd.PopulateExtForceInfo(chain1, f2));
00101     ASSERT_EQ(0,  jd.PopulateExtForceInfo(chain1, f1));
00102     EXPECT_EQ(KDL::Wrench::Zero(), f1[0]);
00103 
00104     ASSERT_EQ(0, jd.PopulateExtForceInfo(chain2, f2));
00105     EXPECT_EQ(testW, f2[0]);
00106     EXPECT_EQ(KDL::Wrench::Zero(), f2[1]);
00107 
00108 }
00109 
00110 TEST_F(JointDynamicsDataTest, StoreJointTorquesTest)
00111 {
00112     jd.InitializeMaps(tree);
00113     KDL::Chain chain1, chain2;
00114     tree.getChain("link1", "link2", chain1);
00115     tree.getChain("link1", "link4", chain2);
00116 
00117     KDL::JntArray tau1(chain1.getNrOfJoints());
00118     KDL::JntArray tau2(chain2.getNrOfJoints());
00119 
00120     tau1(0) = 2.0;
00121     tau2(0) = 1.0;
00122     tau2(1) = 3.0;
00123 
00124     EXPECT_EQ(-1, jd.StoreJointTorqueCommands(chain1, tau2));
00125     ASSERT_EQ(0,  jd.StoreJointTorqueCommands(chain1, tau1));
00126     ASSERT_EQ(0,  jd.StoreJointTorqueCommands(chain2, tau2));
00127 
00128     EXPECT_EQ(-2.0, jd.jointTorqueCommandMap["joint1"]);
00129     EXPECT_EQ(-1.0, jd.jointTorqueCommandMap["joint2"]);
00130     EXPECT_EQ(-3.0, jd.jointTorqueCommandMap["joint3"]);
00131 
00132 }
00133 
00134 TEST_F(JointDynamicsDataTest, StoreJointInertiaTest)
00135 {
00136     jd.InitializeMaps(tree);
00137     KDL::Chain chain1, chain2;
00138     tree.getChain("link1", "link2", chain1);
00139     tree.getChain("link1", "link4", chain2);
00140 
00141     KDL::JntArray Hv1(chain1.getNrOfJoints());
00142     KDL::JntArray Hv2(chain2.getNrOfJoints());
00143 
00144     Hv1(0) = 2.0;
00145     Hv2(0) = 1.0;
00146     Hv2(1) = 3.0;
00147 
00148     EXPECT_EQ(-1, jd.StoreJointInertia(chain2, Hv1));
00149     ASSERT_EQ(0,  jd.StoreJointInertia(chain1, Hv1));
00150     ASSERT_EQ(0,  jd.StoreJointInertia(chain2, Hv2));
00151 
00152     EXPECT_EQ(2.0, jd.jointInertiaMap["joint1"]);
00153     EXPECT_EQ(1.0, jd.jointInertiaMap["joint2"]);
00154     EXPECT_EQ(3.0, jd.jointInertiaMap["joint3"]);
00155 
00156 }
00157 
00158 TEST_F(JointDynamicsDataTest, StoreSegmentWrenchesTest)
00159 {
00160     jd.InitializeMaps(tree);
00161     KDL::Chain chain1, chain2;
00162     tree.getChain("link1", "link2", chain1);
00163     tree.getChain("link1", "link4", chain2);
00164 
00165     KDL::Wrenches f1(chain1.getNrOfSegments());
00166     KDL::Wrenches f2(chain2.getNrOfSegments());
00167 
00168     KDL::Vector force(1.0, 0.0, 0.0), torque(0.0, 2.0, 1.0);
00169     KDL::Wrench testW(force, torque);
00170 
00171     f1[0] = testW;
00172     f2[1] = testW;
00173 
00174     EXPECT_EQ(-1, jd.StoreSegmentWrenches(chain2, f1));
00175     ASSERT_EQ(0,  jd.StoreSegmentWrenches(chain1, f1));
00176     ASSERT_EQ(0,  jd.StoreSegmentWrenches(chain2, f2));
00177 
00178     EXPECT_EQ(testW,               jd.segForceMap["link2"]);
00179     EXPECT_EQ(KDL::Wrench::Zero(), jd.segForceMap["link3"]);
00180     EXPECT_EQ(testW,               jd.segForceMap["link4"]);
00181 
00182 }
00183 
00184 int main(int argc, char** argv)
00185 {
00186     ::testing::InitGoogleTest(&argc, argv);
00187     return RUN_ALL_TESTS();
00188 }


robodyn_controllers
Author(s):
autogenerated on Sat Jun 8 2019 20:20:53