test_ee_interface.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include "testUtils.h"
3 
4 #include <ros/ros.h>
5 #include <ros/console.h>
6 
7 #include <sensor_msgs/JointState.h>
8 
9 #include <end_effector/Parser.h>
11 #include <end_effector/Utils.h>
12 
13 namespace {
14 
15 class testEEInterface: public ::testing::Test {
16 
17 
18 protected:
19 
20  testEEInterface() {
21  }
22 
23  virtual ~testEEInterface() {
24  }
25 
26  virtual void SetUp() {
27 
28  ros::NodeHandle nh;
29 
30  ROSEE::Parser p ( nh );
31  p.init ( ROSEE::Utils::getPackagePath() + "/configs/urdf/test_ee.urdf",
32  ROSEE::Utils::getPackagePath() + "/configs/srdf/test_ee.srdf",
33  "ROSEE/actions/test_ee"
34  );
35  p.printEndEffectorFingerJointsMap();
36 
37  ee = std::make_shared<ROSEE::EEInterface>(p);
38  }
39 
40  virtual void TearDown() {
41  }
42 
44 };
45 
46 
47 TEST_F ( testEEInterface, checkFingers ) {
48 
49  std::vector<std::string> fingers;
50  fingers = ee->getFingers();
51 
52  EXPECT_FALSE (fingers.empty());
53 
54  ROS_INFO_STREAM ( "Fingers in EEInterface: " );
55  for ( auto& f : fingers ) {
56  ROS_INFO_STREAM ( f );
57  }
58 
59  EXPECT_TRUE ( ee->isFinger ( "finger_1" ) );
60 
61  EXPECT_FALSE ( ee->isFinger ( "finger_4" ) );
62 
63 
64 
65 }
66 
67 TEST_F ( testEEInterface, checkActuatedJointsNum ) {
68 
69  int joint_num = ee->getActuatedJointsNum();
70  EXPECT_EQ ( 6, joint_num );
71 
72  EXPECT_FALSE ( joint_num < 0 );
73 
74 }
75 
76 TEST_F ( testEEInterface, checkEEFingerJoints ) {
77 
78  int joint_num_finger1 = ee->getActuatedJointsNumInFinger("finger_1");
79 
80  int joint_num = ee->getActuatedJointsNum();
81 
82  EXPECT_TRUE ( joint_num >= joint_num_finger1 );
83 
84  int joint_num_counter = 0;
85  std::vector<std::string> fingers = ee->getFingers();
86 
87 
88 
89  for ( auto& f : fingers ) {
90  joint_num_counter += ee->getActuatedJointsNumInFinger(f);
91  }
92 
93  EXPECT_TRUE ( joint_num == joint_num_counter );
94 
95 }
96 
97 TEST_F ( testEEInterface, checkJointLimits) {
98 
99  Eigen::VectorXd upperLimits = ee->getUpperPositionLimits();
100  Eigen::VectorXd lowerLimits = ee->getLowerPositionLimits();
101 
102  ASSERT_EQ (upperLimits.size(), lowerLimits.size()); //stop if it fails here
103 
104  EXPECT_TRUE (upperLimits.size() > 0);
105 
106  for (int i=0; i<upperLimits.size(); i++) {
107 
108  EXPECT_GE (upperLimits(i), lowerLimits(i)); //greater or equal than
109  ROS_INFO_STREAM ( "Joint " << std::to_string(i) << " limits: " <<
110  upperLimits(i) << ", " << lowerLimits(i) );
111 
112  }
113 
114 }
115 
116 TEST_F ( testEEInterface, checkIdJoints ) {
117 
118  std::vector<std::string> actJoints = ee->getActuatedJoints();
119  // ASSERT_FALSE (actJoints.empty()); //a hand can have no actuated joints?
120 
121  // check if ids are unique
122  int id = -1;
123  int idPrevious = -1;
124  for ( auto& j : actJoints ) {
125  EXPECT_TRUE ( ee->getInternalIdForJoint (j, id) ); //return false if joint does not exist
126  EXPECT_NE ( id, idPrevious );
127  idPrevious = id;
128  }
129 
130 }
131 
132 } //namespace
133 
134 int main ( int argc, char **argv ) {
135 
136  if (argc < 2 ) {
137 
138  std::cout << "[TEST ERROR] Insert hand name as argument" << std::endl;
139  return -1;
140  }
141 
142  /* Run tests on an isolated roscore */
143  if(setenv("ROS_MASTER_URI", "http://localhost:11322", 1) == -1)
144  {
145  perror("setenv");
146  return 1;
147  }
148 
149  //run roscore
150  std::unique_ptr<ROSEE::TestUtils::Process> roscore;
151  roscore.reset(new ROSEE::TestUtils::Process({"roscore", "-p", "11322"}));
152 
153  if ( ROSEE::TestUtils::prepareROSForTests ( argc, argv, "testEEInterface" ) != 0 ) {
154 
155  std::cout << "[TEST ERROR] Prepare Funcion failed" << std::endl;
156  return -1;
157  }
158 
159  ::testing::InitGoogleTest ( &argc, argv );
160  return RUN_ALL_TESTS();
161 }
std::shared_ptr< EEInterface > Ptr
Definition: EEInterface.h:40
int main(int argc, char **argv)
#define EXPECT_FALSE(args)
#define EXPECT_EQ(a, b)
int prepareROSForTests(int argc, char **argv, std::string testName)
Function to be called in the main of each test, it runs roscore and fill parameter server with robot ...
Definition: testUtils.h:95
Class responsible for parsing the YAML file providing the URDF, SRDF, the EE-HAL library implementati...
Definition: Parser.h:46
#define ROS_INFO_STREAM(args)
static std::string getPackagePath()
Definition: Utils.h:87
#define EXPECT_TRUE(args)
TEST_F(TestRunner, threaded_test)


end-effector
Author(s): Luca Muratore , Davide Torielli , Liana Bertoni
autogenerated on Tue Apr 5 2022 02:57:53