Skip to content

Commit 3ae7098

Browse files
authored
Merge pull request #1211 from ignitionrobotics/arjo/fix/uniform_buoyancy
Fix buoyancy not being applied for one iteration
2 parents 525572f + 4d9c500 commit 3ae7098

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/systems/buoyancy/Buoyancy.cc

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,6 @@ void Buoyancy::PreUpdate(const ignition::gazebo::UpdateInfo &_info,
441441
{
442442
auto newPose = enableComponent<components::Inertial>(_ecm, _entity);
443443
newPose |= enableComponent<components::WorldPose>(_ecm, _entity);
444-
if (newPose)
445-
{
446-
// Skip entity if WorldPose and inertial are not yet ready
447-
return true;
448-
}
449444

450445
// World pose of the link.
451446
math::Pose3d linkWorldPose = worldPose(_entity, _ecm);
@@ -477,6 +472,13 @@ void Buoyancy::PreUpdate(const ignition::gazebo::UpdateInfo &_info,
477472
else if (this->dataPtr->buoyancyType
478473
== BuoyancyPrivate::BuoyancyType::GRADED_BUOYANCY)
479474
{
475+
if (newPose)
476+
{
477+
// Skip entity if WorldPose and inertial are not yet ready
478+
// TODO(arjo): Find a way of disabling gravity effects for
479+
// this first iteration.
480+
return true;
481+
}
480482
std::vector<Entity> collisions = _ecm.ChildrenByComponents(
481483
_entity, components::Collision());
482484
this->dataPtr->buoyancyForces.clear();
@@ -521,12 +523,13 @@ void Buoyancy::PreUpdate(const ignition::gazebo::UpdateInfo &_info,
521523
}
522524
}
523525
}
524-
}
525-
auto [force, torque] = this->dataPtr->ResolveForces(
526+
auto [force, torque] = this->dataPtr->ResolveForces(
526527
link.WorldInertialPose(_ecm).value());
527-
// Apply the wrench to the link. This wrench is applied in the
528-
// Physics System.
529-
link.AddWorldWrench(_ecm, force, torque);
528+
// Apply the wrench to the link. This wrench is applied in the
529+
// Physics System.
530+
link.AddWorldWrench(_ecm, force, torque);
531+
}
532+
530533
return true;
531534
});
532535
}

test/integration/buoyancy.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ TEST_F(BuoyancyTest, UniformWorldMovement)
5757
using namespace std::chrono_literals;
5858
server.SetUpdatePeriod(1ns);
5959

60-
std::size_t iterations = 1001;
60+
std::size_t iterations = 1000;
6161

6262
bool finished = false;
6363
test::Relay testSystem;

0 commit comments

Comments
 (0)