From c52dbba68b56fd406d600b55b51947e4094669ec Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Wed, 24 Jul 2024 08:23:14 -0400 Subject: [PATCH 1/5] Deprecate use of added mass via hydrodynamics I believe we should deprecate this option as it has instabilities. The `fluid_added_mass` approach is superior. We should update our tutorials as well. Signed-off-by: Arjo Chakravarty --- src/systems/hydrodynamics/Hydrodynamics.cc | 17 ++++++++++++++++- src/systems/hydrodynamics/Hydrodynamics.hh | 19 +++++++++++-------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/systems/hydrodynamics/Hydrodynamics.cc b/src/systems/hydrodynamics/Hydrodynamics.cc index 171ca8f021..cc2352b2fe 100644 --- a/src/systems/hydrodynamics/Hydrodynamics.cc +++ b/src/systems/hydrodynamics/Hydrodynamics.cc @@ -340,7 +340,11 @@ void Hydrodynamics::Configure( << "\thttps://github.com/gazebosim/gz-sim/pull/1888" << std::endl; } + // Added mass according to Fossen's equations (p 37) + // Note: Adding added mass here is deprecated and will be removed in + // Gazebo J as this formulation has instabilities. + bool added_mass_specified = false; this->dataPtr->Ma = Eigen::MatrixXd::Zero(6, 6); for(auto i = 0; i < 6; i++) { @@ -350,12 +354,23 @@ void Hydrodynamics::Configure( prefix += "Dot"; prefix += snameConventionVel[j]; this->dataPtr->Ma(i, j) = SdfParamDouble(_sdf, prefix, 0); + if (std::abs(this->dataPtr->Ma(i, j)) > 1e-6) + { + added_mass_specified = true; + } } } _sdf->Get("disable_coriolis", this->dataPtr->disableCoriolis, false); _sdf->Get("disable_added_mass", this->dataPtr->disableAddedMass, false); - + if (!this->dataPtr->disableAddedMass || added_mass_specified) + { + gzerr << "The use of added mass through this plugin is deprecated and will" + << "be removed in Gazebo J* as this formulation has instabilities." + << " We recommend using the SDF `` tag based method" + << "[http://sdformat.org/spec?ver=1.11&elem=link#inertial_fluid_added_mass]" + << std::endl; + } // Create model object, to access convenient functions auto model = gz::sim::Model(_entity); diff --git a/src/systems/hydrodynamics/Hydrodynamics.hh b/src/systems/hydrodynamics/Hydrodynamics.hh index 1ada82b467..42d960a0ce 100644 --- a/src/systems/hydrodynamics/Hydrodynamics.hh +++ b/src/systems/hydrodynamics/Hydrodynamics.hh @@ -46,12 +46,12 @@ namespace systems /// quadratic drag and coriolis force. /// /// ### Diagonal terms: - /// * - Added mass in x direction [kg] - /// * - Added mass in y direction [kg] - /// * - Added mass in z direction [kg] - /// * - Added mass in roll direction [kgm^2] - /// * - Added mass in pitch direction [kgm^2] - /// * - Added mass in yaw direction [kgm^2] + /// * - (Deprecated) Added mass in x direction [kg] + /// * - (Deprecated) Added mass in y direction [kg] + /// * - (Deprecated) Added mass in z direction [kg] + /// * - (Deprecated) Added mass in roll direction [kgm^2] + /// * - (Deprecated) Added mass in pitch direction [kgm^2] + /// * - (Deprecated) Added mass in yaw direction [kgm^2] /// * - Quadratic damping, 2nd order, x component [kg/m] /// * - Linear damping, 1st order, x component [kg] /// * - Quadratic damping, 2nd order, y component [kg/m] @@ -70,10 +70,13 @@ namespace systems /// non-diagonal sides. We use the SNAMe convention of naming search terms. /// (x, y, z) correspond to the respective axis. (k, m, n) correspond to /// roll, pitch and yaw. Similarly U, V, W represent velocity vectors in - /// X, Y and Z axis while P, Q, R representangular velocity in roll, pitch + /// X, Y and Z axis while P, Q, R represent angular velocity in roll, pitch /// and yaw axis respectively. /// * Added Mass: <{x|y|z|k|m|n}Dot{U|V|W|P|Q|R}> e.g. - /// Units are either kg or kgm^2 depending on the choice of terms. + /// (Deprecated) Units are either kg or kgm^2 depending on the + /// choice of terms. You should use the sdf method based spec + // for `fluid_added_mass`: + /// http://sdformat.org/spec?ver=1.11&elem=link#inertial_fluid_added_mass /// * Quadratic Damping With abs term (this is probably what you want): /// <{x|y|z|k|m|n}{U|V|W|P|Q|R}abs{U|V|W|P|Q|R}> /// e.g. From a2e38940c0a30834cbdbeba98502b838765a65fa Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Thu, 25 Jul 2024 12:47:31 -0400 Subject: [PATCH 2/5] Address feedback Signed-off-by: Arjo Chakravarty --- src/systems/hydrodynamics/Hydrodynamics.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/systems/hydrodynamics/Hydrodynamics.cc b/src/systems/hydrodynamics/Hydrodynamics.cc index cc2352b2fe..0525654fe8 100644 --- a/src/systems/hydrodynamics/Hydrodynamics.cc +++ b/src/systems/hydrodynamics/Hydrodynamics.cc @@ -344,7 +344,7 @@ void Hydrodynamics::Configure( // Added mass according to Fossen's equations (p 37) // Note: Adding added mass here is deprecated and will be removed in // Gazebo J as this formulation has instabilities. - bool added_mass_specified = false; + bool addedMassSpecified = false; this->dataPtr->Ma = Eigen::MatrixXd::Zero(6, 6); for(auto i = 0; i < 6; i++) { @@ -354,21 +354,19 @@ void Hydrodynamics::Configure( prefix += "Dot"; prefix += snameConventionVel[j]; this->dataPtr->Ma(i, j) = SdfParamDouble(_sdf, prefix, 0); - if (std::abs(this->dataPtr->Ma(i, j)) > 1e-6) - { - added_mass_specified = true; - } + addedMassSpecified = addedMassSpecified && (std::abs(this->dataPtr->Ma(i, j)) > 1e-6) } } _sdf->Get("disable_coriolis", this->dataPtr->disableCoriolis, false); _sdf->Get("disable_added_mass", this->dataPtr->disableAddedMass, false); - if (!this->dataPtr->disableAddedMass || added_mass_specified) + if (!this->dataPtr->disableAddedMass || addedMassSpecified) { gzerr << "The use of added mass through this plugin is deprecated and will" << "be removed in Gazebo J* as this formulation has instabilities." << " We recommend using the SDF `` tag based method" << "[http://sdformat.org/spec?ver=1.11&elem=link#inertial_fluid_added_mass]" + << "To get rid of this warning we recommend setting ` to true." << std::endl; } // Create model object, to access convenient functions From a2f5572157da4d0df2f335b51137b20bfd3f1a8b Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Wed, 7 Aug 2024 12:01:25 +0800 Subject: [PATCH 3/5] Style Signed-off-by: Arjo Chakravarty --- src/systems/hydrodynamics/Hydrodynamics.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/systems/hydrodynamics/Hydrodynamics.cc b/src/systems/hydrodynamics/Hydrodynamics.cc index 0525654fe8..860db286bd 100644 --- a/src/systems/hydrodynamics/Hydrodynamics.cc +++ b/src/systems/hydrodynamics/Hydrodynamics.cc @@ -365,8 +365,10 @@ void Hydrodynamics::Configure( gzerr << "The use of added mass through this plugin is deprecated and will" << "be removed in Gazebo J* as this formulation has instabilities." << " We recommend using the SDF `` tag based method" - << "[http://sdformat.org/spec?ver=1.11&elem=link#inertial_fluid_added_mass]" - << "To get rid of this warning we recommend setting ` to true." + << "[http://sdformat.org/spec?ver=1.11&elem=link" + << "#inertial_fluid_added_mass]" + << "To get rid of this warning we recommend setting" + << "` to true." << std::endl; } // Create model object, to access convenient functions From 9b238e17a18ba5ed69d092a7bc5a07f444388d90 Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Wed, 7 Aug 2024 12:26:25 +0800 Subject: [PATCH 4/5] Style Signed-off-by: Arjo Chakravarty --- src/systems/hydrodynamics/Hydrodynamics.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/systems/hydrodynamics/Hydrodynamics.cc b/src/systems/hydrodynamics/Hydrodynamics.cc index 860db286bd..805d24cb3a 100644 --- a/src/systems/hydrodynamics/Hydrodynamics.cc +++ b/src/systems/hydrodynamics/Hydrodynamics.cc @@ -354,7 +354,7 @@ void Hydrodynamics::Configure( prefix += "Dot"; prefix += snameConventionVel[j]; this->dataPtr->Ma(i, j) = SdfParamDouble(_sdf, prefix, 0); - addedMassSpecified = addedMassSpecified && (std::abs(this->dataPtr->Ma(i, j)) > 1e-6) + addedMassSpecified &= (std::abs(this->dataPtr->Ma(i, j)) > 1e-6); } } From da9dc71bfdb334611eae45db05d6ea0a7cf4adab Mon Sep 17 00:00:00 2001 From: Arjo Chakravarty Date: Thu, 8 Aug 2024 08:42:33 +0800 Subject: [PATCH 5/5] Address feedback Signed-off-by: Arjo Chakravarty --- src/systems/hydrodynamics/Hydrodynamics.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/systems/hydrodynamics/Hydrodynamics.cc b/src/systems/hydrodynamics/Hydrodynamics.cc index 805d24cb3a..c3cd80e9c1 100644 --- a/src/systems/hydrodynamics/Hydrodynamics.cc +++ b/src/systems/hydrodynamics/Hydrodynamics.cc @@ -354,7 +354,8 @@ void Hydrodynamics::Configure( prefix += "Dot"; prefix += snameConventionVel[j]; this->dataPtr->Ma(i, j) = SdfParamDouble(_sdf, prefix, 0); - addedMassSpecified &= (std::abs(this->dataPtr->Ma(i, j)) > 1e-6); + addedMassSpecified = (std::abs(this->dataPtr->Ma(i, j)) > 1e-6) + && addedMassSpecified; } }