Skip to content

Commit 09dbed8

Browse files
authored
Fix contact points warnings (#6081)
* Display more useful information in warning * Increase the number of allowed contact points in the salamander simulation * Fixed Sojourner climbing rocks and contact point warning
1 parent b5b7ab9 commit 09dbed8

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

projects/robots/nasa/worlds/sojourner.wbt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ WorldInfo {
1818
gravity 3.73
1919
basicTimeStep 16
2020
lineScale 0.2
21+
contactProperties ContactProperties {
22+
maxContactJoints 21
23+
}
2124
}
2225
Viewpoint {
2326
fieldOfView 0.895398
@@ -108,7 +111,7 @@ Rock10cm {
108111
}
109112
Rock10cm {
110113
translation 0.1779 -0.3873 -0.1161
111-
rotation 0 0 1 -1.8325953071795862
114+
rotation 0 0 -1 1.0472
112115
name "rock 10 cm(2)"
113116
color 0.9 0.4 0.3
114117
}

projects/samples/rendering/worlds/animated_skin.wbt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ WorldInfo {
4343
material2 "ping pong ball material"
4444
bounce 0.9
4545
}
46+
ContactProperties {
47+
material1 "body"
48+
maxContactJoints 26
49+
}
50+
ContactProperties {
51+
material1 "leg"
52+
maxContactJoints 17
53+
}
54+
ContactProperties {
55+
maxContactJoints 17
56+
}
4657
]
4758
}
4859
Viewpoint {

src/webots/engine/WbSimulationCluster.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,13 +475,20 @@ void WbSimulationCluster::handleCollisionIfSpace(void *data, dGeomID o1, dGeomID
475475
}
476476
}
477477

478-
void WbSimulationCluster::warnMoreContactPointsThanContactJoints() {
478+
void WbSimulationCluster::warnMoreContactPointsThanContactJoints(const QString &material1, const QString &material2, int max,
479+
int n) {
479480
static QMutex mutex;
480481
QMutexLocker<QMutex> lock(&mutex);
481482
static double lastWarningTime = -INFINITY;
482483
const double currentSimulationTime = WbSimulationState::instance()->time();
483484
if (currentSimulationTime > lastWarningTime + 1000.0) {
484-
WbLog::warning(QObject::tr("Contact joints will only be created for the deepest contact points."), false, WbLog::ODE);
485+
WbLog::warning(QObject::tr("Contact joints between materials '%1' and '%2' will only be created for the %3 deepest contact "
486+
"points instead of all the %4 contact points.")
487+
.arg(material1)
488+
.arg(material2)
489+
.arg(max)
490+
.arg(n),
491+
false, WbLog::ODE);
485492
lastWarningTime = currentSimulationTime;
486493
}
487494
}
@@ -656,7 +663,6 @@ void WbSimulationCluster::odeNearCallback(void *data, dGeomID o1, dGeomID o2) {
656663
n = n->parentNode();
657664
}
658665
}
659-
660666
const WbContactProperties *contactProperties = cl->findContactProperties(s1, s2);
661667
const int maxContactJoints = contactProperties ? contactProperties->maxContactJoints() : 10;
662668

@@ -679,7 +685,8 @@ void WbSimulationCluster::odeNearCallback(void *data, dGeomID o1, dGeomID o2) {
679685
return;
680686

681687
if (n > maxContactJoints) {
682-
WbSimulationCluster::warnMoreContactPointsThanContactJoints();
688+
WbSimulationCluster::warnMoreContactPointsThanContactJoints(s1->contactMaterial(), s2->contactMaterial(), maxContactJoints,
689+
n);
683690
std::nth_element(contact, contact + maxContactJoints, contact + n,
684691
[](const dContact &c1, const dContact &c2) { return (c1.geom.depth > c2.geom.depth); });
685692
n = maxContactJoints;

src/webots/engine/WbSimulationCluster.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class WbSimulationCluster {
7272
static void odeSensorRaysUpdate(int threadID);
7373
static const long long int WEBOTS_MAGIC_NUMBER;
7474
bool mSwapJointContactBuffer;
75-
static void warnMoreContactPointsThanContactJoints();
75+
static void warnMoreContactPointsThanContactJoints(const QString &material1, const QString &material2, int max, int n);
7676
};
7777

7878
#endif

0 commit comments

Comments
 (0)