RosMsgFkMonitorTest.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include "robodyn_controllers/KdlTreeFk.h"
00003 #include "robodyn_controllers/RosMsgFkMonitor.h"
00004 #include "robodyn_utilities/RosMsgConverter.h"
00005 #include <ros/package.h>
00006 
00007 class RosMsgFkMonitorTest : public ::testing::Test
00008 {
00009 protected:
00010     virtual void SetUp()
00011     {
00012         std::string packagePath = ros::package::getPath("robodyn_controllers");
00013         rmt.loadFromFile(packagePath + "/test/urdf/SimpleTestRobot.xml");
00014         ros::Time::init();
00015     }
00016 
00017     virtual void TearDown()
00018     {
00019     }
00020 
00021     RosMsgFkMonitor rmt;
00022 };
00023 
00024 TEST_F(RosMsgFkMonitorTest, getNodeFramesTest)
00025 {
00026     r2_msgs::StringArray     nodes;
00027     std::map<std::string, KDL::FrameVel> nodeFrameResult;
00028 
00029     EXPECT_FALSE(rmt.getNodeFrames(nodes, nodeFrameResult )) << "getNodeFrames should return false when sent an empty node list";
00030     EXPECT_EQ(0, nodeFrameResult.size()) << "nodeFrameResult should be empty";
00031 
00032 
00033     nodes.data.push_back("joint1");
00034     EXPECT_TRUE(rmt.getNodeFrames(nodes, nodeFrameResult)) << "getNodeFrames should return true when asked to get a node in its tree";
00035     EXPECT_EQ(1,                         nodeFrameResult.size()) << "nodeFrameResult should have 1 value in it";
00036     EXPECT_EQ("joint1",                  nodeFrameResult.begin()->first) << "nodeFrameResult's first element is joint1";
00037 
00038     nodes.data.push_back("joint2");
00039     nodes.data.push_back("joint3");
00040     EXPECT_TRUE(rmt.getNodeFrames(nodes, nodeFrameResult)) << "getNodeFrames should return true when asked for a list of nodes in tree";
00041     EXPECT_EQ(3,                         nodeFrameResult.size()) << "nodeFrameResult should have 3 values in it";
00042     EXPECT_EQ("joint1",                  nodeFrameResult.begin()->first) << "nodeFrameResult's first element is joint1";
00043     EXPECT_EQ("joint3",                  nodeFrameResult.rbegin()->first) << "nodeFrameResut's last element is joint3";
00044 
00045     nodes.data.push_back("joint4");
00046     EXPECT_FALSE(rmt.getNodeFrames(nodes, nodeFrameResult)) << "getNodeFrames should return false when asked to retreive a node not in the tree";
00047     EXPECT_EQ(3,                          nodeFrameResult.size()) << "nodeFrameResult should still be populated with valid nodes in tree";
00048 
00049 
00050 }
00051 
00052 TEST_F(RosMsgFkMonitorTest, getPoseStateTest)
00053 {
00054     sensor_msgs::JointState actualState;
00055     r2_msgs::PoseState poseState;
00056 
00057     actualState.name.push_back("joint0");
00058     actualState.name.push_back("joint1");
00059     actualState.name.push_back("joint2");
00060     actualState.name.push_back("joint3");
00061 
00062     actualState.position.push_back(5.0);
00063     actualState.position.push_back(5.0);
00064     actualState.position.push_back(5.0);
00065     actualState.position.push_back(5.0);
00066 
00067     actualState.velocity.push_back(5.0);
00068     actualState.velocity.push_back(5.0);
00069     actualState.velocity.push_back(5.0);
00070     actualState.velocity.push_back(5.0);
00071 
00072     actualState.effort.push_back(5.0);
00073     actualState.effort.push_back(5.0);
00074     actualState.effort.push_back(5.0);
00075     actualState.effort.push_back(5.0);
00076 
00077     std::vector<std::string> jointNames;
00078     rmt.getJointNames(jointNames);
00079     KDL::JntArrayVel joints;
00080 
00081     try
00082     {
00083         RosMsgConverter::JointStateToJntArrayVel(actualState, jointNames, joints);
00084     }
00085     catch (std::exception& e)
00086     {
00087         NasaCommonLogging::Logger::log("gov.nasa.controllers.RosMsgFkMonitorTest", log4cpp::Priority::ERROR, e.what());
00088     }
00089 
00090     EXPECT_TRUE(rmt.getPoseState(actualState, poseState));
00091     EXPECT_EQ(4, poseState.positions.size()) << "we should have 4 position messages, one for each joint";
00092     EXPECT_EQ(4, poseState.velocities.size()) << "we should have 4 twist velocity messages, one for each joint velocity";
00093     EXPECT_EQ(4, poseState.accelerations.size()) << "we should have 4 twist messages, one for each joint acceleration";
00094 //    geometry_msgs::Pose pose = poseState.positions[0];
00095 //    geometry_msgs::Twist vel = poseState.velocities[0];
00096 //    geometry_msgs::Twist acc = poseState.accelerations[0];
00097 
00098 }
00099 
00100 
00101 
00102 int main(int argc, char** argv)
00103 {
00104     ::testing::InitGoogleTest(&argc, argv);
00105     return RUN_ALL_TESTS();
00106 }
00107 
00108 


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