icub-test
CartesianControlSimpleP2pMovementTest.cpp
1 /*
2  * iCub Robot Unit Tests (Robot Testing Framework)
3  *
4  * Copyright (C) 2015-2019 Istituto Italiano di Tecnologia (IIT)
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <string>
22 #include <robottestingframework/TestAssert.h>
23 #include <robottestingframework/dll/Plugin.h>
24 #include <yarp/os/Time.h>
25 #include <yarp/dev/CartesianControl.h>
26 #include <yarp/sig/Vector.h>
27 
28 #include "CartesianControlSimpleP2pMovementTest.h"
29 
30 using namespace std;
31 using namespace robottestingframework;
32 using namespace yarp::os;
33 using namespace yarp::dev;
34 using namespace yarp::sig;
35 
36 // prepare the plugin
37 ROBOTTESTINGFRAMEWORK_PREPARE_PLUGIN(CartesianControlSimpleP2pMovementTest)
38 
39 
40 /***********************************************************************************/
41 CartesianControlSimpleP2pMovementTest::CartesianControlSimpleP2pMovementTest() :
42  yarp::robottestingframework::TestCase("CartesianControlSimpleP2pMovementTest")
43 {
44 }
45 
46 
47 /***********************************************************************************/
48 CartesianControlSimpleP2pMovementTest::~CartesianControlSimpleP2pMovementTest()
49 {
50 }
51 
52 
53 /***********************************************************************************/
54 bool CartesianControlSimpleP2pMovementTest::setup(Property &property)
55 {
56  string robot=property.check("robot",Value("icubSim")).asString();
57  string arm=property.check("arm-type",Value("left")).asString();
58 
59  Property option;
60  option.put("device","cartesiancontrollerclient");
61  option.put("remote",("/"+robot+"/"+"cartesianController/"+arm+"_arm"));
62  option.put("local",("/"+getName()+"/"+arm+"_arm"));
63 
64  ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Opening Cartesian Controller Client for %s_arm",arm.c_str()));
65  ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(driver.open(option),"Unable to open the client!");
66  return true;
67 }
68 
69 
70 /***********************************************************************************/
71 void CartesianControlSimpleP2pMovementTest::tearDown()
72 {
73  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Closing Cartesian Controller Client");
74  ROBOTTESTINGFRAMEWORK_ASSERT_FAIL_IF_FALSE(driver.close(),"Unable to close the client!");
75 }
76 
77 
78 /***********************************************************************************/
79 void CartesianControlSimpleP2pMovementTest::run()
80 {
81  ICartesianControl *iarm;
82  ROBOTTESTINGFRAMEWORK_TEST_CHECK(driver.view(iarm),"Opening the view on the device!");
83 
84  bool done;
85 
86  Vector x,o;
87  double t0=Time::now();
88  while (Time::now()-t0<5.0)
89  {
90  done=iarm->getPose(x,o);
91  if (done)
92  break;
93  Time::delay(0.1);
94  }
95  ROBOTTESTINGFRAMEWORK_TEST_CHECK(done,"Initial pose retrieved!");
96 
97  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Setting up the context");
98  int context;
99  iarm->storeContext(&context);
100 
101  Vector dof;
102  iarm->getDOF(dof); dof=1.0;
103  iarm->setDOF(dof,dof);
104  iarm->setTrajTime(1.0);
105 
106  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Reaching for the target");
107  Vector xd(3,0.0); xd[0]=-0.4;
108  iarm->goToPositionSync(xd);
109 
110  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Waiting");
111  done=iarm->waitMotionDone(1.0,5.0);
112  ROBOTTESTINGFRAMEWORK_TEST_CHECK(done,"Target reached!");
113 
114  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Going back to starting pose");
115  iarm->setLimits(0,0.0,0.0);
116  iarm->setLimits(1,0.0,0.0);
117  iarm->setLimits(2,0.0,0.0);
118  iarm->goToPoseSync(x,o);
119 
120  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Waiting");
121  done=iarm->waitMotionDone(1.0,5.0);
122  ROBOTTESTINGFRAMEWORK_TEST_CHECK(done,"Starting pose reached!");
123 
124  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Cleaning up the context");
125  iarm->restoreContext(context);
126  iarm->deleteContext(context);
127 }
128 
This test verifies the point-to-point cartesian movement.