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/dev/IEncoders.h>
27 #include <yarp/sig/Matrix.h>
28 #include <yarp/math/Math.h>
30 #include "CartesianControlReachingToleranceTest.h"
33 using namespace robottestingframework;
34 using namespace yarp::os;
35 using namespace yarp::dev;
36 using namespace yarp::sig;
37 using namespace yarp::math;
44 CartesianControlReachingToleranceTest::CartesianControlReachingToleranceTest() :
45 yarp::robottestingframework::TestCase(
"CartesianControlReachingToleranceTest")
51 CartesianControlReachingToleranceTest::~CartesianControlReachingToleranceTest()
57 bool CartesianControlReachingToleranceTest::setup(Property &property)
59 string robot=
property.check(
"robot",Value(
"icubSim")).asString();
60 string arm=
property.check(
"arm-type",Value(
"left")).asString();
63 optCart.put(
"device",
"cartesiancontrollerclient");
64 optCart.put(
"remote",(
"/"+robot+
"/"+
"cartesianController/"+arm+
"_arm"));
65 optCart.put(
"local",(
"/"+getName()+
"/cartesian/"+arm+
"_arm"));
68 optJoint.put(
"device",
"remote_controlboard");
69 optJoint.put(
"remote",(
"/"+robot+
"/"+arm+
"_arm"));
70 optJoint.put(
"local",(
"/"+getName()+
"/joint/"+arm+
"_arm"));
72 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format(
"Opening Cartesian Controller Client for %s_arm",arm.c_str()));
73 ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(drvCart.open(optCart),
"Unable to open the client!");
75 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format(
"Opening Joint Controller Client for %s_arm",arm.c_str()));
76 ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(drvJoint.open(optJoint),
"Unable to open the client!");
82 void CartesianControlReachingToleranceTest::tearDown()
84 ROBOTTESTINGFRAMEWORK_TEST_REPORT(
"Closing Cartesian Controller Client");
85 ROBOTTESTINGFRAMEWORK_ASSERT_FAIL_IF_FALSE(drvCart.close(),
"Unable to close the client!");
87 ROBOTTESTINGFRAMEWORK_TEST_REPORT(
"Closing Joint Controller Client");
88 ROBOTTESTINGFRAMEWORK_ASSERT_FAIL_IF_FALSE(drvJoint.close(),
"Unable to close the client!");
93 double CartesianControlReachingToleranceTest::compute_error(
const Vector &xh,
const Vector &oh,
94 const Vector &x,
const Vector &o)
105 Matrix Des=axis2dcm(oh);
106 Vector ax=dcm2axis(Des*SE3inv(H));
116 void CartesianControlReachingToleranceTest::run()
118 ICartesianControl *iarm;
119 ROBOTTESTINGFRAMEWORK_TEST_CHECK(drvCart.view(iarm),
"Opening the view on the Cartesian device!");
122 ROBOTTESTINGFRAMEWORK_TEST_CHECK(drvJoint.view(ienc),
"Opening the view on the Joint device!");
127 double t0=Time::now();
128 while (Time::now()-t0<5.0)
130 done=iarm->getPose(x,o);
135 ROBOTTESTINGFRAMEWORK_TEST_CHECK(done,
"Initial pose retrieved!");
137 ROBOTTESTINGFRAMEWORK_TEST_REPORT(
"Setting up the context");
139 iarm->storeContext(&context);
142 iarm->getDOF(dof); dof=1.0;
143 dof[0]=dof[1]=dof[2]=0.0;
144 iarm->setDOF(dof,dof);
145 iarm->setTrajTime(1.0);
146 iarm->setInTargetTol(0.02);
149 iarm->getInTargetTol(&tol);
151 Vector pos2reach(3,0.0);
156 Matrix dcm2reach=zeros(3,3);
157 dcm2reach(0,0)=dcm2reach(2,1)=dcm2reach(1,2)=-1.0;
158 Vector ori2reach=dcm2axis(dcm2reach);
160 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format(
"Reaching for the target: (%s, %s)",
161 pos2reach.toString(3,3).c_str(),ori2reach.toString(3,3).c_str()));
163 iarm->goToPoseSync(pos2reach,ori2reach);
164 iarm->getDesired(xh,oh,qh);
166 ROBOTTESTINGFRAMEWORK_TEST_REPORT(
"Waiting");
167 done=iarm->waitMotionDone(0.1,10.0);
171 iarm->getPose(xf,of);
174 ienc->getAxes(&nJoints);
176 ienc->getEncoders(qf.data());
178 ROBOTTESTINGFRAMEWORK_TEST_CHECK(done,
"Target reached!");
179 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format(
"Reaching tolerance: %g",tol));
180 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format(
"Solved pose: (%s, %s)",
181 xh.toString(3,3).c_str(),oh.toString(3,3).c_str()));
182 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format(
"Reached pose: (%s, %s)",
183 xf.toString(3,3).c_str(),of.toString(3,3).c_str()));
184 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format(
"Solved joints qh: (%s)",
185 qh.subVector(3,dof.length()-1).toString(3,3).c_str()));
186 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format(
"Reached joints qf: (%s)",
187 qf.subVector(0,6).toString(3,3).c_str()));
188 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format(
"Error: %g",compute_error(xh,oh,xf,of)));
190 ROBOTTESTINGFRAMEWORK_TEST_REPORT(
"Going back to starting pose");
191 iarm->goToPoseSync(x,o);
193 ROBOTTESTINGFRAMEWORK_TEST_REPORT(
"Waiting");
194 done=iarm->waitMotionDone(1.0,5.0);
195 ROBOTTESTINGFRAMEWORK_TEST_CHECK(done,
"Starting pose reached!");
197 ROBOTTESTINGFRAMEWORK_TEST_REPORT(
"Cleaning up the context");
198 iarm->restoreContext(context);
199 iarm->deleteContext(context);
This test verifies the point-to-point cartesian movement.