228 {
229
230 int nJoints=0;
231 bool doneAll=false;
232 bool ret=false;
233
234
235
236
237
238
239
240
241
242
243
244
245
246 ROBOTTESTINGFRAMEWORK_TEST_REPORT("setting velocity refs for all joints...");
247
248 if(refAcc.size() != 0)
249 {
250 ROBOTTESTINGFRAMEWORK_TEST_REPORT("setting acceleration refs for all joints...");
251 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iVelocity->setRefAccelerations(numJoints, jList, refAcc.data()),
252 Asserter::format("setting reference acceleration on joints"));
253 }
254
255 ROBOTTESTINGFRAMEWORK_TEST_REPORT("setting velocity refs for all joints...");
256 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPosition->setRefSpeeds(numJoints, jList, refVel.data()),
257 Asserter::format("setting reference speed on joints"));
258
259
260
261
262 ROBOTTESTINGFRAMEWORK_TEST_REPORT("all joints are going to home...");
263 for (int i=0; i<numJoints; ++i)
264 {
265
266
267
268 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format(" joint %d is going to home", jList[i]));
269
270 setAndCheckControlMode(jList[i], VOCAB_CM_POSITION);
271
272 ROBOTTESTINGFRAMEWORK_ASSERT_FAIL_IF_FALSE(jPosMotion->goToSingle(jList[i], homePos[i]),
273 Asserter::format(("go to target pos for j %d"),jList[i]));
274 }
275
276 yarp::os::Time::delay(5);
277
278 ROBOTTESTINGFRAMEWORK_TEST_REPORT("Checking individual joints...");
279
280 const double res_th = 0.01;
281
282 for (int i=0; i<numJoints; ++i)
283 {
284
285 double rec_targetPos=200.0;
286
287
288
289 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Checking PosReference joint %d with resolution threshold %.3f", jList[i], res_th));
290
291 setAndCheckControlMode(jList[i], VOCAB_CM_POSITION);
292
293 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(jPosMotion->goToSingle(jList[i], targetPos[i]),
294 Asserter::format(("go to target pos for j %d"),jList[i]));
295
296 yarp::os::Time::delay(0.5);
297
298 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPosition->getTargetPosition(jList[i], &rec_targetPos),
299 Asserter::format(("getting target pos for j %d"),jList[i]));
300
301 bool res = yarp::robottestingframework::TestAsserter::isApproxEqual(targetPos[i], rec_targetPos, res_th, res_th);
302 ROBOTTESTINGFRAMEWORK_TEST_CHECK(res, Asserter::format(
303 ("IPositionControl: getting target pos for j %d: setval =%.2f received %.2f"),
304 jList[i], targetPos[i],rec_targetPos));
305
306
307
308
309
310
311 yarp::os::Time::delay(3);
312
313
314 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Checking pwm reference joint %d", jList[i]));
315
316
317 setAndCheckControlMode(jList[i], VOCAB_CM_PWM);
318
319 double output = 2;
320 double rec_output = 0;
321 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPWM->setRefDutyCycle(jList[i], output),
322 Asserter::format(("set ref output for j %d"),jList[i]));
323yarp::os::Time::delay(0.5);
324
325 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPWM->getRefDutyCycle(jList[i], &rec_output),
326 Asserter::format(("get ref output for j %d"),jList[i]));
327
328 ROBOTTESTINGFRAMEWORK_TEST_CHECK((output == rec_output),
329 Asserter::format(("getting target output for j %d: setval =%.2f received %.2f"),jList[i], output,rec_output));
330
331 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPosition->positionMove(jList[i], homePos[i]),
332 Asserter::format(("go to home for j %d"),jList[i]));
333yarp::os::Time::delay(0.5);
334 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPosition->getTargetPosition(jList[i], &rec_targetPos),
335 Asserter::format(("getting target pos for j %d"),jList[i]));
336
337
338
339 res = yarp::robottestingframework::TestAsserter::isApproxEqual(homePos[i], rec_targetPos, res_th, res_th);
340 ROBOTTESTINGFRAMEWORK_TEST_CHECK(!res,
341 Asserter::format(("joint %d discards PosotinMove command while it is in opnLoop mode. Set=%.2f rec=%.2f"),jList[i], homePos[i], rec_targetPos));
342
343
344
345 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Checking directPos reference joint %d", jList[i]));
346
347 setAndCheckControlMode(jList[i], VOCAB_CM_POSITION_DIRECT);
348
349 double curr_pos=targetPos[i];
350 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iEncoders->getEncoder(jList[i], &curr_pos),
351 Asserter::format(("get encoders for j %d"),jList[i]));
352
353 double delta = 0.1;
354 double new_directPos = curr_pos+delta;
355 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPosDirect->setPosition(jList[i], new_directPos),
356 Asserter::format(("Direct:setPosition for j %d"),jList[i]));
357yarp::os::Time::delay(0.5);
358
359 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPosDirect->getRefPosition(jList[i], &rec_targetPos),
360 Asserter::format(("getting target pos for j %d"),jList[i]));
361
362 res = yarp::robottestingframework::TestAsserter::isApproxEqual(new_directPos, rec_targetPos, res_th, res_th);
363 ROBOTTESTINGFRAMEWORK_TEST_CHECK(res,
364 Asserter::format(("iDirect: getting target direct pos for j %d: setval =%.2f received %.2f"),jList[i], new_directPos,rec_targetPos));
365
366
367 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iPosition->getTargetPosition(jList[i], &rec_targetPos),
368 Asserter::format(("getting target pos for j %d"),jList[i]));
369
370 res = yarp::robottestingframework::TestAsserter::isApproxEqual(targetPos[i], rec_targetPos, res_th, res_th);
371 ROBOTTESTINGFRAMEWORK_TEST_CHECK(res, Asserter::format(
372 ("IPositionControl: getting target pos for j %d: setval =%.2f received %.2f"),
373 jList[i], targetPos[i],rec_targetPos));
374
375
376
377 ROBOTTESTINGFRAMEWORK_TEST_REPORT(Asserter::format("Checking velocity reference joint %d", jList[i]));
378
379 setAndCheckControlMode(jList[i], VOCAB_CM_VELOCITY);
380
381 double vel= 0.5;
382 double rec_vel;
383 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iVelocity->velocityMove(jList[i], vel),
384 Asserter::format(("IVelocity:velocityMove for j %d"),jList[i]));
385
386yarp::os::Time::delay(0.5);
387 ROBOTTESTINGFRAMEWORK_TEST_FAIL_IF_FALSE(iVelocity->getRefVelocity(jList[i], &rec_vel),
388 Asserter::format(("IVelocity:getting target velocity for j %d"),jList[i]));
389 res = yarp::robottestingframework::TestAsserter::isApproxEqual(vel, rec_vel, res_th, res_th);
390 ROBOTTESTINGFRAMEWORK_TEST_CHECK(res,
391 Asserter::format(("iVelocity: getting target vel for j %d: setval =%.2f received %.2f"),jList[i], vel,rec_vel));
392 }
393
394}