Skip to content

Commit

Permalink
Fix unitialized sliding friction when using asymmetric rolling fricti…
Browse files Browse the repository at this point in the history
…on. (#6618)

* Fix unitialized sliding friction when using asymmetric rolling friction.

Also update expected values in test to reflect the result of the change.

Previously mu2 was initialized when using asymmetric rolling friction, but ODE will use asymmetric sliding friction if we set `dContactAxisDep` (because `dContactAxisDep  == dContactMu2`), so we need to make sure `mu2` is set. The unitialized mu2 was resulting in the rolling_friction test failing under some circumstances.

* Update changelog.
  • Loading branch information
brettle authored Aug 11, 2024
1 parent 50ef671 commit 6b49409
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/reference/changelog-r2024.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ Released on December **th, 2023.
- Fixed invalid absolute sound file path resulted in crash ([#6593](https://github.com/cyberbotics/webots/pull/6593))
- Fixed Speaker relative sound file path not working with external controller ([#6605](https://github.com/cyberbotics/webots/pull/6605)).
- Fixed the bug that when the language is Python, getTargets() cannot correctly obtain the multi-target data detected by the radar ([#6606](https://github.com/cyberbotics/webots/pull/6606))
- Fixed unitialized sliding friction when using asymmetric rolling friction ([#6618](https://github.com/cyberbotics/webots/pull/6618)).
9 changes: 8 additions & 1 deletion src/webots/engine/WbSimulationCluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,15 @@ void WbSimulationCluster::fillSurfaceParameters(const WbContactProperties *cp, c
// handle rolling friction
if (rho[0] > 0 || rho[1] > 0 || rho[2] > 0) {
contact->surface.mode = contact->surface.mode | dContactRolling;
if (rho[1] > 0 || rho[2] > 0)
if (rho[1] > 0 || rho[2] > 0) {
// ODE will use asymmetric sliding friction if we set dContactAxisDep (because dContactAxisDep
// == dContactMu2), so we need to make sure mu2 is set. If it wasn't already set above, we
// want symmetric sliding friction which means setting mu2 = mu (like ODE would do if
// dContactMu2 was not set.)
if (!(contact->surface.mode & dContactMu2))
contact->surface.mu2 = contact->surface.mu;
contact->surface.mode = contact->surface.mode | dContactAxisDep;
}

contact->surface.rho = rho[0];
contact->surface.rho2 = rho[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,18 @@ int main(int argc, char **argv) {
// pre-registered velocities/positions after 200 timesteps (to ensure that if changes to the contact properties affect the
// rolling behavior it will be detected)
const double expected_positions[BALL_COUNT][3] = {
{-5.822856, -3.0, 0.498430}, {-14.564553, 0.0, 0.498392}, {-25.145860, 3.0, 1.942235},
{-16.0, -8.0, 1.498430}, {-14.0, -8.0, 1.498430}, {-12.0, -8.0, 1.498430},
{-5.822856, -27.511330, 0.498430}, {1.171054, -19.324655, 0.498430}, {1.171054, -13.936790, 0.498430}};
{-5.822856, -3.0, 0.498430}, {-14.564553, 0.0, 0.498392}, {-25.145860, 3.0, 1.942235},
{-16.0, -8.0, 1.498430}, {-14.0, -8.0, 1.498430}, {-12.0, -8.0, 1.498430},
{-5.822856, -27.511330, 0.498430}, {-5.822856, -19.314704, 0.498430}, {-5.822856, -13.936790, 0.498430}};
const double expected_velocities[BALL_COUNT][6] = {{5.957204, 0.0, 0.0, 0.0, 11.951927, 0.0},
{4.164077, 0.0, 0.000304, 0.0, 8.355176, 0.0},
{1.817242, 0.0, -0.368373, 0.0, 3.719816, 0.0},
{0.0, 0.0, 0.0, 0.0, 0.0, 25.0},
{0.0, 0.0, 0.0, 0.0, 0.0, 6.164800},
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
{5.957204, 3.686891, 0.0, -7.397003, 11.951927, -3.446233},
{7.029157, 0.0, 0.0, 0.0, 0.0, -4.455340},
{7.029157, 0.0, 0.0, 0.0, 0.0, -4.867729}};
{5.957204, 0.0, 0.0, 0.0, 11.951927, -4.639518},
{5.957204, 0.0, 0.0, 0.0, 11.951927, -4.867729}};

for (int i = 0; i < BALL_COUNT; ++i) {
sprintf(name, "BALL_%d", i + 1);
Expand Down

0 comments on commit 6b49409

Please sign in to comment.