If <composite flatinertia="true">, set mjCBody.explicit_inertial so that an <inertial> element is added in mj_saveLastXML. Bug found by the WriteReadCompare test.

PiperOrigin-RevId: 450702639
Change-Id: I978dfb6713d68ce8327f2e8eea1fc31f43a38b5e
This commit is contained in:
Alessio Quaglino
2022-05-24 09:38:06 -07:00
committed by Copybara-Service
parent dbf6c74f8f
commit 43e3b3a3f9
4 changed files with 15 additions and 6 deletions
+5 -5
View File
@@ -332,17 +332,17 @@ static constexpr int kFieldSize = 500;
// The maximum spacing between a normalised floating point number x and an
// adjacent normalised number is 2 epsilon |x|; a factor 10 is added accounting
// for losses during non-idempotent operations such as vector normalizations.
mjtNum Compare(mjtNum val1, mjtNum val2) {
mjtNum error;
template<typename T = mjtNum> T Compare(T val1, T val2) {
T error;
if (mju_abs(val1) <= 1 || mju_abs(val2) <= 1) {
// Asbolute precision for small numbers
error = mju_abs(val1-val2);
} else {
// Relative precision for larger numbers
mjtNum magnitude = mju_max(mju_abs(val1), mju_abs(val2));
T magnitude = mju_max(mju_abs(val1), mju_abs(val2));
error = mju_abs(val1/magnitude - val2/magnitude) / magnitude;
}
return error < 2*10*std::numeric_limits<double>::epsilon() ? 0 : error;
return error < 2*10*std::numeric_limits<T>::epsilon() ? 0 : error;
}
mjtNum CompareModel(const mjModel* m1, const mjModel* m2, char (&field)[kFieldSize]) {
@@ -388,7 +388,7 @@ mjtNum CompareModel(const mjModel* m1, const mjModel* m2, char (&field)[kFieldSi
TEST_F(XMLWriterTest, WriteReadCompare) {
FullFloatPrecision increase_precision;
// Loop over all xml files in data
std::vector<std::string> paths = {GetModelPath("humanoid"), GetModelPath("humanoid100")};
std::vector<std::string> paths = {GetModelPath("humanoid"), GetModelPath("flag")};
std::string ext(".xml");
for (auto const& path : paths) {
for (auto &p : std::filesystem::recursive_directory_iterator(path)) {