117{
118 ICartesianControl *iarm;
119 ROBOTTESTINGFRAMEWORK_TEST_CHECK(drvCart.view(iarm),"Opening the view on the Cartesian device!");
120
121 IEncoders *ienc;
122 ROBOTTESTINGFRAMEWORK_TEST_CHECK(drvJoint.view(ienc),"Opening the view on the Joint device!");
123
124 bool done;
125
126 Vector x,o;
127 double t0=Time::now();
128 while (Time::now()-t0<5.0)
129 {
130 done=iarm->getPose(x,o);
131 if (done)
132 break;
133 Time::delay(0.1);
134 }
135 ROBOTTESTINGFRAMEWORK_TEST_CHECK(done,"Initial pose retrieved!");
136
137 ROBOTTESTINGFRAMEWORK_TEST_REPORT("Setting up the context");
138 int context;
139 iarm->storeContext(&context);
140
141 Vector dof;
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);
147
148 double tol;
149 iarm->getInTargetTol(&tol);
150
151 Vector pos2reach(3,0.0);
152 pos2reach[0]=-0.35;
153 pos2reach[1]=0.0;
154 pos2reach[2]=0.15;
155
156 Matrix dcm2reach=zeros(3,3);
157 dcm2reach(0,0)=dcm2reach(2,1)=dcm2reach(1,2)=-1.0;
158 Vector ori2reach=dcm2axis(dcm2reach);
159
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()));
162 Vector xh,oh,qh;
163 iarm->goToPoseSync(pos2reach,ori2reach);
164 iarm->getDesired(xh,oh,qh);
165
166 ROBOTTESTINGFRAMEWORK_TEST_REPORT("Waiting");
167 done=iarm->waitMotionDone(0.1,10.0);
168 iarm->stopControl();
169
170 Vector xf,of;
171 iarm->getPose(xf,of);
172
173 int nJoints;
174 ienc->getAxes(&nJoints);
175 Vector qf(nJoints);
176 ienc->getEncoders(qf.data());
177
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)));
189
190 ROBOTTESTINGFRAMEWORK_TEST_REPORT("Going back to starting pose");
191 iarm->goToPoseSync(x,o);
192
193 ROBOTTESTINGFRAMEWORK_TEST_REPORT("Waiting");
194 done=iarm->waitMotionDone(1.0,5.0);
195 ROBOTTESTINGFRAMEWORK_TEST_CHECK(done,"Starting pose reached!");
196
197 ROBOTTESTINGFRAMEWORK_TEST_REPORT("Cleaning up the context");
198 iarm->restoreContext(context);
199 iarm->deleteContext(context);
200}