Skip to content

Commit 6e709d3

Browse files
author
Benjamin Délèze
authored
Merge pull request #6087 from cyberbotics/sync-master-faddc2077
Merge master into develop
2 parents 09dbed8 + 01b9c3d commit 6e709d3

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

docs/reference/changelog-r2023.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Released on ??
4040
- `Field.enableSFTracking` and `Field.disableSFTracking` which were failing ([#5640](https://github.com/cyberbotics/webots/pull/5640)).
4141
- `Motor.enableForceFeedback` where the `sampling_period` argument was missing ([#5797](https://github.com/cyberbotics/webots/pull/5797)).
4242
- `Motor.setAcceleration` was missing the device tag parameter ([#6036](https://github.com/cyberbotics/webots/pull/6036)).
43+
- `Lidar.getRangeImageArray` had a typo in its name ([#6080](https://github.com/cyberbotics/webots/issues/6080)).
4344
- Fixed crash resulting from requesting pose tracking of unsuitable nodes ([#5620](https://github.com/cyberbotics/webots/pull/5620)).
4445
- Fixed memory leaks, particularly when in no-rendering mode and spawning/deleting nodes ([#5639](https://github.com/cyberbotics/webots/pull/5639)).
4546
- Fixed crashes resulting from streaming pose, SF field values or contact points after deleting the tracked nodes ([#5638](https://github.com/cyberbotics/webots/pull/5638)).
@@ -69,6 +70,7 @@ Released on ??
6970
- Fixed unwanted altitude change when reaching a target waypoint in `mavic2pro_patrol.c` ([#5981](https://github.com/cyberbotics/webots/pull/5981)).
7071
- Fixed the extern controller connection to a target Webots instance when a snap one is running ([#6002](https://github.com/cyberbotics/webots/pull/6002)).
7172
- Fixed the double downloading of meshes ([#6034](https://github.com/cyberbotics/webots/pull/6034)).
73+
- Fixed generation of moment of inertia matrix based on bounding box ([#6048](https://github.com/cyberbotics/webots/pull/6048)).
7274
- Fixed the loading of remote mesh bounding objects ([#6047](https://github.com/cyberbotics/webots/pull/6047)).
7375

7476
## Webots R2023a

lib/controller/python/controller/lidar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def getNumberOfPoints(self) -> int:
7373
def getRangeImage(self) -> List[float]:
7474
return self.range_image[:self.horizontal_resolution * self.number_of_layers]
7575

76-
def defRangeImageArray(self) -> List[List[float]]:
76+
def getRangeImageArray(self) -> List[List[float]]:
7777
array = []
7878
for i in range(self.number_of_layers):
7979
array.append(self.getLayerRangeImage(i))

src/webots/nodes/WbSolid.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ using namespace WbSolidUtilities;
7878
using namespace std;
7979

8080
const double WbSolid::MASS_ZERO_THRESHOLD = 1e-10;
81+
const double REFERENCE_DENSITY = 1000.0;
8182

8283
QList<const WbSolid *> WbSolid::cSolids;
8384

@@ -989,7 +990,7 @@ void WbSolid::adjustOdeMass(bool mergeMass) {
989990
} else {
990991
const double fieldDensity = p->density();
991992
if (fieldDensity >= 0.0)
992-
dMassAdjust(mOdeMass, (currentMass * fieldDensity) / 1000.0);
993+
dMassAdjust(mOdeMass, (currentMass * fieldDensity) / REFERENCE_DENSITY);
993994
}
994995

995996
memcpy(mMassAroundCoM, mOdeMass, sizeof(dMass));
@@ -1414,7 +1415,7 @@ void WbSolid::setInertiaMatrixFromBoundingObject() {
14141415
dMassSetZero(&dmass);
14151416

14161417
// Adds the masses of all the primitives lying in the bounding object
1417-
WbSolidUtilities::addMass(&dmass, boundingObject(), 1000.0);
1418+
WbSolidUtilities::addMass(&dmass, boundingObject(), REFERENCE_DENSITY);
14181419
memcpy(mReferenceMass, &dmass, sizeof(dMass));
14191420

14201421
// Computes the inertia matrix around the center of mass of the bounding object
@@ -1424,18 +1425,25 @@ void WbSolid::setInertiaMatrixFromBoundingObject() {
14241425
const WbField *const parameter = findField("physics", true)->parameter();
14251426
WbPhysics *const p = parameter ? static_cast<WbPhysics *>(static_cast<WbSFNode *>(parameter->value())->value()) : physics();
14261427

1427-
const double s = 1.0 / absoluteScale().x();
1428+
const double s0 = absoluteScale().x();
1429+
const double s = 1.0 / s0;
14281430
double s3 = s * s;
14291431
double s5 = s3;
14301432
s3 *= s;
14311433

1432-
if (p->mass() < 0.0) {
1433-
double boundingObjectMass = mReferenceMass->mass;
1434-
boundingObjectMass *= 0.001 * p->density();
1434+
// Sets the actual total mass to mReferenceMass
1435+
double boundingObjectMass = mReferenceMass->mass;
1436+
if (p->mass() > 0.0)
1437+
boundingObjectMass = s0 * s0 * s0 * p->mass();
1438+
else {
1439+
boundingObjectMass *= p->density() / REFERENCE_DENSITY;
14351440
p->setMass(boundingObjectMass * s3, true);
14361441
p->parsingInfo(tr("'mass' set as bounding object's mass based on 'density'."));
14371442
}
14381443

1444+
// Adjust the total according to mass and density fields
1445+
dMassAdjust(mReferenceMass, boundingObjectMass);
1446+
14391447
p->setDensity(-1.0, true);
14401448

14411449
const double *const I = mReferenceMass->I;
@@ -1816,7 +1824,7 @@ void WbSolid::createOdeMass(bool reset) {
18161824
const WbPhysics *const p = physics();
18171825
const bool customMass = p->mode() == WbPhysics::CUSTOM_INERTIA_MATRIX;
18181826
// needed for average density and average damping
1819-
WbSolidUtilities::addMass(mReferenceMass, boundingObject(), 1000.0, !customMass);
1827+
WbSolidUtilities::addMass(mReferenceMass, boundingObject(), REFERENCE_DENSITY, !customMass);
18201828

18211829
// Checks whether there is a valid inertia matrix, and uses it if so
18221830
if (customMass)
@@ -1845,8 +1853,8 @@ void WbSolid::createOdeMass(bool reset) {
18451853
if (fieldMass > 0.0) {
18461854
const double s2 = s * s;
18471855
actualMass = s * s2 * fieldMass;
1848-
} else if (fieldDensity != 1000.0)
1849-
actualMass *= 0.001 * fieldDensity;
1856+
} else if (fieldDensity != REFERENCE_DENSITY)
1857+
actualMass *= fieldDensity / REFERENCE_DENSITY;
18501858

18511859
// Adjust the total according to mass and density fields
18521860
dMassAdjust(mOdeMass, actualMass);

0 commit comments

Comments
 (0)