Skip to content

Commit c54c4f0

Browse files
epernodfredroyhugtalbot
authored
[Haptics.tests] Fix LCPForceFeedback blinking tests on ci (sofa-framework#5318)
* [Haptics.tests] Fix LCPForceFeedback blinking tests on ci * Update LCPForceFeedback_test.cpp * fix small typo --------- Co-authored-by: Frederick Roy <fredroy@users.noreply.github.com> Co-authored-by: Hugo <hugo.talbot@sofa-framework.org>
1 parent 5920708 commit c54c4f0

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

Sofa/Component/Haptics/tests/LCPForceFeedback_test.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ bool LCPForceFeedback_test::test_Collision()
273273
EXPECT_EQ(cons.size(), 84);
274274

275275
// check LCP computeForce method
276-
sofa::type::Vec3 position;
277-
sofa::type::Vec3 force;
278-
sofa::type::Vec3 trueForce;
276+
sofa::type::Vec3 position = sofa::type::Vec3(0, 0, 0);
277+
sofa::type::Vec3 force = sofa::type::Vec3(0, 0, 0);
278+
sofa::type::Vec3 trueForce = sofa::type::Vec3(0, 0, 0);
279279

280280
// check out of problem position
281281
m_LCPFFBack->computeForce(position[0], position[1], position[2], 0, 0, 0, 0, force[0], force[1], force[2]);
@@ -365,7 +365,8 @@ bool LCPForceFeedback_test::test_multiThread()
365365
haptic_thread = std::thread(HapticsThread, std::ref(this->m_terminate), this);
366366

367367
// run simulation for n steps
368-
for (int step = 0; step < 500; step++)
368+
int nbSimuSteps = 100;
369+
for (int step = 0; step < nbSimuSteps; step++)
369370
{
370371
sofa::simulation::node::animate(m_root.get());
371372

@@ -375,23 +376,23 @@ bool LCPForceFeedback_test::test_multiThread()
375376
m_currentPosition[1] = coords[0][1];
376377
m_currentPosition[2] = coords[0][2];
377378
mtxPosition.unlock();
378-
CTime::sleep(0.001);
379+
CTime::sleep(0.01); // wait more time between simulation step to let the LCP runs multiple loops
379380
}
380381

381382
// stop thread
382383
m_terminate = true;
383384
haptic_thread.join();
384385

385386
// get back info from haptic thread
386-
m_meanForceFFBack = m_meanForceFFBack / m_cptLoopContact;
387+
m_meanForceFFBack = m_meanForceFFBack / float(m_cptLoopContact);
387388

388-
EXPECT_GT(m_cptLoop, 500);
389-
EXPECT_GT(m_cptLoopContact, 400);
389+
EXPECT_GT(m_cptLoop, nbSimuSteps); // we assume the LCP runs faster than the current simulation speed
390+
EXPECT_GT(m_cptLoopContact, 0); // check that the simulation reached collision between instrument and floor
390391

391-
// make a simple test FFBack not equal to 0. Not possible to test exact value as CI have different thread speed
392-
EXPECT_NE(m_meanForceFFBack[0], 0.0);
393-
EXPECT_NE(m_meanForceFFBack[1], 0.0);
394-
EXPECT_NE(m_meanForceFFBack[2], 0.0);
392+
// make a simple test FFBack not equal to 0. Not possible to test exact value as CI have different thread speed
393+
EXPECT_NE(m_meanForceFFBack[0], 0.0);
394+
EXPECT_NE(m_meanForceFFBack[1], 0.0);
395+
EXPECT_NE(m_meanForceFFBack[2], 0.0);
395396

396397
return true;
397398
}

0 commit comments

Comments
 (0)