test_composedAction.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include "testUtils.h"
3 
4 #include <ros/ros.h>
5 
11 
12 namespace {
13 
14 class testComposedAction: public ::testing::Test {
15 
16 
17 protected:
18 
19  testComposedAction() : grasp("grasp", true) {
20  }
21 
22  virtual ~testComposedAction() {
23  }
24 
25  virtual void SetUp() override {
26 
27  std::shared_ptr <ROSEE::ParserMoveIt> parserMoveIt = std::make_shared <ROSEE::ParserMoveIt> ();
28 
29  //if return false, models are not found and it is useless to continue the test
30  ASSERT_TRUE(parserMoveIt->init ("robot_description", false)) ;
31 
32  ROSEE::FindActions actionsFinder (parserMoveIt);
33 
34  std::string folderForActions = "ROSEE/actions/" + parserMoveIt->getHandName();
35 
36  trigMap = actionsFinder.findTrig(ROSEE::ActionPrimitive::Type::Trig, folderForActions + "/primitives/") ;
37 
38  if (trigMap.size() > 0){
39  for (auto trig : trigMap) {
40  std::shared_ptr <ROSEE::ActionPrimitive> pointer =
41  std::make_shared <ROSEE::ActionTrig> ( trig.second );
42  grasp.sumAction ( pointer );
43  }
44 
45  ROSEE::YamlWorker yamlWorker;
46  yamlWorker.createYamlFile (&grasp, folderForActions + "/generics/");
47 
48  //Parsing
49  graspParsed = yamlWorker.parseYamlComposed (folderForActions + "/generics/grasp.yaml");
50 
51  }
52  }
53 
54  virtual void TearDown() override{
55  }
56 
57  std::map < std::string , ROSEE::ActionTrig > trigMap;
59  ROSEE::ActionComposed graspParsed;
60 
61 
62 };
63 
64 TEST_F ( testComposedAction, checkNumberPrimitives ) {
65 
66  EXPECT_EQ ( grasp.numberOfInnerActions(), grasp.getInnerActionsNames().size() );
67 
68  EXPECT_EQ ( graspParsed.numberOfInnerActions(), graspParsed.getInnerActionsNames().size() );
69 
70 }
71 
72 TEST_F ( testComposedAction, checkEmitParse ) {
73 
74  if (trigMap.size() > 0) { //if empty, no grasp is defined in the setup so test without meaning
75 
76  EXPECT_EQ (grasp.getName(), graspParsed.getName() );
77  EXPECT_EQ (grasp.getType(), graspParsed.getType() );
78  EXPECT_EQ (grasp.isIndependent(), graspParsed.isIndependent() );
79  EXPECT_EQ (grasp.numberOfInnerActions(), graspParsed.numberOfInnerActions() );
80  EXPECT_EQ (grasp.getFingersInvolved(), graspParsed.getFingersInvolved() );
81 
82  for (auto joint: grasp.getJointPos() ) {
83 
84  //compare size of joint (number of dofs)
85  ASSERT_EQ (joint.second.size(), graspParsed.getJointPos().at(joint.first).size() );
86  //loop the eventually multiple joint pos (when dofs > 1)
87  for (int j = 0; j < joint.second.size(); ++j ){
88  EXPECT_DOUBLE_EQ ( joint.second.at(j), graspParsed.getJointPos().at(joint.first).at(j) );
89  }
90  }
91 
92  for (auto jointCount : grasp.getJointsInvolvedCount()) {
93 
94  EXPECT_EQ ( jointCount.second, graspParsed.getJointsInvolvedCount().at(jointCount.first) );
95 
96  }
97  }
98 }
99 
100 // if independent, at maximum only one primitive can influence each joint
101 TEST_F ( testComposedAction, checkIndependence ) {
102  if (grasp.isIndependent()) {
103  for (auto it : grasp.getJointsInvolvedCount() ) {
104  EXPECT_LE ( it.second, 1 );
105  }
106  }
107 }
108 
109 } //namespace
110 
111 int main ( int argc, char **argv ) {
112 
113  if (argc < 2 ){
114 
115  std::cout << "[TEST ERROR] Insert hand name as argument" << std::endl;
116  return -1;
117  }
118 
119  /* Run tests on an isolated roscore */
120  if(setenv("ROS_MASTER_URI", "http://localhost:11322", 1) == -1)
121  {
122  perror("setenv");
123  return 1;
124  }
125 
126  //run roscore
127  std::unique_ptr<ROSEE::TestUtils::Process> roscore;
128  roscore.reset(new ROSEE::TestUtils::Process({"roscore", "-p", "11322"}));
129 
130  if ( ROSEE::TestUtils::prepareROSForTests ( argc, argv, "testComposedAction" ) != 0 ) {
131 
132  std::cout << "[TEST ERROR] Prepare Funcion failed" << std::endl;
133  return -1;
134  }
135 
136 
137  ::testing::InitGoogleTest ( &argc, argv );
138  return RUN_ALL_TESTS();
139 }
ROSEE::YamlWorker
Definition: YamlWorker.h:47
ros.h
ROSEE::TestUtils::prepareROSForTests
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
ActionPrimitive.h
ROSEE::FindActions
Class to check which fingertips collide (for the pinch action at the moment)
Definition: FindActions.h:36
ActionComposed.h
ROSEE::TestUtils::Process
Definition: testUtils.h:22
ParserMoveIt.h
ROSEE::YamlWorker::createYamlFile
std::string createYamlFile(const std::map< std::set< std::string >, ActionPrimitive * > mapOfActions, const std::string actionName, std::string pathFolder)
Create/overwrite yaml file and emit info on it about each ActionPrimitive inside the given mapOfActio...
Definition: YamlWorker.cpp:39
ActionTrig.h
TEST_F
TEST_F(TestRunner, threaded_test)
ROSEE::YamlWorker::parseYamlComposed
ROSEE::ActionComposed parseYamlComposed(std::string fileWithPath)
Parse a composed Action.
Definition: YamlWorker.cpp:218
testUtils.h
main
int main(int argc, char **argv)
Definition: test_composedAction.cpp:111
EXPECT_EQ
#define EXPECT_EQ(a, b)
ROSEE::ActionComposed
A ActionComposed, which is formed by one or more Primitives (or even other composed)....
Definition: ActionComposed.h:44
FindActions.h


end-effector
Author(s): Luca Muratore , Davide Torielli , Liana Bertoni
autogenerated on Sat Dec 14 2024 03:49:26