159 {
160
161 int nJoints=0;
162 bool doneAll=false;
163 bool ret=false;
164
165 ROBOTTESTINGFRAMEWORK_TEST_REPORT("checking joints number");
166 iEncoders->getAxes(&nJoints);
167 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(m_NumJoints==nJoints, "expected number of joints is inconsistent");
168
169 ROBOTTESTINGFRAMEWORK_TEST_REPORT("Checking individual joints...");
170 for (int joint=0; joint<m_NumJoints; ++joint) {
171 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Checking joint %d", joint));
172 if (m_aRefAcc!=NULL) {
173 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPosition->setRefAcceleration(joint, m_aRefAcc[joint]),
174 Asserter::format("setting reference acceleration on joint %d", joint));
175 }
176
177 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPosition->setRefSpeed(joint, m_aRefVel[joint]),
178 Asserter::format("setting reference speed on joint %d", joint));
179
180
181 double timeStart=yarp::os::Time::now();
182 double timeNow=timeStart;
183 bool read=false;
184
185 ROBOTTESTINGFRAMEWORK_TEST_REPORT("Checking encoders");
186 while(timeNow<timeStart+m_aTimeout[joint] && !read) {
187
188 read=iEncoders->getEncoder(joint,m_aHome+joint);
189 yarp::os::Time::delay(0.1);
190 }
191 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(read, "getEncoder() returned true");
192
193 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPosition->positionMove(joint, m_aTargetVal[joint]),
194 Asserter::format("moving joint %d to %.2lf", joint, m_aTargetVal[joint]));
195
196 doneAll=false;
197 ret=iPosition->checkMotionDone(joint, &doneAll);
198 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(!doneAll&&ret, "checking checkMotionDone returns false after position move");
199
200 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Waiting timeout %.2lf", m_aTimeout[joint]));
201 bool reached=false;
202 while(timeNow<timeStart+m_aTimeout[joint] && !reached) {
203 double pos;
204 iEncoders->getEncoder(joint,&pos);
205 reached = yarp::robottestingframework::TestAsserter::isApproxEqual(pos, m_aTargetVal[joint], m_aMinErr[joint], m_aMaxErr[joint]);
206 timeNow=yarp::os::Time::now();
207 yarp::os::Time::delay(0.1);
208 }
209 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(reached, "reached position");
210 }
211
213 ROBOTTESTINGFRAMEWORK_TEST_REPORT("Checking multiple joints...");
214 if (m_aRefAcc!=NULL) {
215 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPosition->setRefAccelerations(m_aRefAcc),
216 "setting reference acceleration on all joints");
217 }
218 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPosition->setRefSpeeds(m_aRefVel),
219 "setting reference speed on all joints");
220
221 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPosition->positionMove(m_aHome),
222 "moving all joints to home");
223
224 doneAll=false;
225
226 ret=iPosition->checkMotionDone(&doneAll);
227 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(!doneAll&&ret, "checking checkMotionDone returns false after position move");
228
229
230 double timeStart=yarp::os::Time::now();
231 double timeNow=timeStart;
232
233 double timeout=m_aTimeout[0];
234 for(int j=0; j<m_NumJoints; j++)
235 {
236 if (timeout<m_aTimeout[j])
237 timeout=m_aTimeout[j];
238 }
239
240 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Waiting timeout %.2lf", timeout));
241 bool reached=false;
242 double *encoders;
243 encoders=new double [m_NumJoints];
244 while(timeNow<timeStart+timeout && !reached) {
245 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iEncoders->getEncoders(encoders), "getEncoders()");
246 reached = yarp::robottestingframework::TestAsserter::isApproxEqual(encoders, m_aHome, m_aMinErr, m_aMaxErr, m_NumJoints);
247 timeNow=yarp::os::Time::now();
248 yarp::os::Time::delay(0.1);
249 }
250
251 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(reached, "reached position");
252
253 if(reached) {
254
255
256
257
258 int times=10;
259 bool doneAll=false;
260 bool ret=false;
261
262 while(times>0 && !doneAll) {
263 ret=iPosition->checkMotionDone(&doneAll);
264 if (!doneAll)
265 yarp::os::Time::delay(0.1);
266 times--;
267 }
268
269 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(doneAll&&ret, "checking checkMotionDone returns true");
270 }
271
272
273 ROBOTTESTINGFRAMEWORK_TEST_REPORT("Now checking group interface");
274
275
276 int *jmap=new int [m_NumJoints];
277 double *swapped_refvel=new double [m_NumJoints];
278 double *swapped_target=new double [m_NumJoints];
279
280 for(int kk=0;kk<m_NumJoints;kk++)
281 {
282 swapped_refvel[kk]=m_aRefVel[m_NumJoints-kk-1];
283 swapped_target[kk]=m_aTargetVal[m_NumJoints-kk-1];
284 jmap[kk]=m_NumJoints-kk-1;
285 }
286
287 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPosition->setRefSpeeds(m_NumJoints, jmap, swapped_refvel),
288 "setting reference speed on all joints using group interface");
289
290 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPosition->positionMove(m_NumJoints, jmap, swapped_target),
291 "moving all joints to home using group interface");
292
293 ret=iPosition->checkMotionDone(m_NumJoints, jmap, &doneAll);
294 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(!doneAll&&ret, "checking checkMotionDone returns false after position move");
295
296 timeStart=yarp::os::Time::now();
297 timeNow=timeStart;
298
299 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Waiting timeout %.2lf", timeout));
300 reached=false;
301 while(timeNow<timeStart+timeout && !reached) {
302 iEncoders->getEncoders(encoders);
303 reached = yarp::robottestingframework::TestAsserter::isApproxEqual(encoders, m_aTargetVal, m_aMinErr, m_aMaxErr, m_NumJoints);
304 timeNow=yarp::os::Time::now();
305 yarp::os::Time::delay(0.1);
306 }
307 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(reached, "reached position");
308
309 if (reached) {
310 bool *done_vector=new bool [m_NumJoints];
311
312
313
314 int times=10;
315 bool doneAll=false;
316 bool ret=false;
317
318 while(times>0 && !doneAll) {
319 ret=iPosition->checkMotionDone(m_NumJoints, jmap, &doneAll);
320 if (!doneAll)
321 yarp::os::Time::delay(0.1);
322 times--;
323 }
324
325 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(doneAll&&ret, "checking checkMotionDone");
326 delete [] done_vector;
327 }
328
329
330 delete [] jmap;
331 delete [] swapped_refvel;
332 delete [] swapped_target;
333 delete [] encoders;
334}