icub-test
GazeControlSimpleLookTest.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 <robottestingframework/dll/Plugin.h>
22 #include <robottestingframework/TestAssert.h>
23 #include <yarp/os/Time.h>
24 #include <yarp/dev/GazeControl.h>
25 #include <yarp/sig/Vector.h>
26 
27 #include "GazeControlSimpleLookTest.h"
28 
29 using namespace std;
30 using namespace robottestingframework;
31 using namespace yarp::os;
32 using namespace yarp::dev;
33 using namespace yarp::sig;
34 
35 // prepare the plugin
36 ROBOTTESTINGFRAMEWORK_PREPARE_PLUGIN(GazeControlSimpleLookTest)
37 
38 
39 /***********************************************************************************/
40 GazeControlSimpleLookTest::GazeControlSimpleLookTest() :
41  yarp::robottestingframework::TestCase("GazeControlSimpleLookTest")
42 {
43 }
44 
45 
46 /***********************************************************************************/
47 GazeControlSimpleLookTest::~GazeControlSimpleLookTest()
48 {
49 }
50 
51 
52 /***********************************************************************************/
53 bool GazeControlSimpleLookTest::setup(Property &property)
54 {
55  Property option;
56  option.put("device","gazecontrollerclient");
57  option.put("remote","/iKinGazeCtrl");
58  option.put("local",("/"+getName()+"/gaze"));
59 
60  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Opening Gaze Controller Client");
61  ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(driver.open(option),"Unable to open the client!");
62  return true;
63 }
64 
65 
66 /***********************************************************************************/
67 void GazeControlSimpleLookTest::tearDown()
68 {
69  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Closing Gaze Controller Client");
70  ROBOTTESTINGFRAMEWORK_ASSERT_FAIL_IF_FALSE(driver.close(),"Unable to close the client!");
71 }
72 
73 
74 /***********************************************************************************/
75 void GazeControlSimpleLookTest::run()
76 {
77  IGazeControl *igaze;
78  ROBOTTESTINGFRAMEWORK_TEST_CHECK(driver.view(igaze),"Opening the view on the device!");
79 
80  bool done;
81 
82  Vector fp;
83  double t0=Time::now();
84  while (Time::now()-t0<5.0)
85  {
86  done=igaze->getFixationPoint(fp);
87  if (done)
88  break;
89  Time::delay(0.1);
90  }
91  ROBOTTESTINGFRAMEWORK_TEST_CHECK(done,"Initial fixation-point retrieved!");
92 
93  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Setting up the context");
94  int context;
95  igaze->storeContext(&context);
96 
97  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Looking at the target");
98  Vector fpd(3,0.0); fp[0]=-0.4;
99  igaze->lookAtFixationPoint(fpd);
100 
101  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Waiting");
102  igaze->waitMotionDone(1.0,5.0);
103 
104  igaze->checkMotionDone(&done);
105  ROBOTTESTINGFRAMEWORK_TEST_CHECK(done,"Target reached!");
106 
107  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Going back");
108  igaze->lookAtFixationPoint(fp);
109 
110  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Waiting");
111  igaze->waitMotionDone(1.0,5.0);
112 
113  igaze->checkMotionDone(&done);
114  ROBOTTESTINGFRAMEWORK_TEST_CHECK(done,"Done!");
115 
116  ROBOTTESTINGFRAMEWORK_TEST_REPORT("Cleaning up the context");
117  igaze->restoreContext(context);
118  igaze->deleteContext(context);
119 }
120 
This test verifies the simple gaze movements.