Skip to content

Commit 6ac7f4e

Browse files
committed
no more crashes, still not working
1 parent ed104f1 commit 6ac7f4e

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

src/systems/buoyancy/Buoyancy.cc

+14-26
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,22 @@ void BuoyancyPrivate::GradedFluidDensity(
124124
auto prevLayerFluidDensity = this->fluidDensity;
125125
auto volsum = 0;
126126
auto centerOfBuoyancy = math::Vector3d{0,0,0};
127-
ignerr << __FILE__ << ": " << __LINE__ <<std::endl;
128127

129128
for(auto [height, currFluidDensity] : layers)
130129
{
131130
// Transform plane and slice the shape
132-
math::Planed plane{math::Vector3d{0,0,1}, height};
133-
math::Matrix4d matrix(_pose);
134-
auto waterPlane = plane.Transform(matrix.Inverse());
135-
auto vol = _shape.VolumeBelow(waterPlane);
136-
137-
ignerr << "Got position: " << _pose.Pos() << ", plane_normal: " << waterPlane.Normal()
138-
<< ", offset: " << waterPlane.Offset() << std::endl;
131+
math::Planed plane{math::Vector3d{0,0,1}, height - _pose.Pos().Z()};
132+
//math::Matrix4d matrix(_pose);
133+
//auto waterPlane = plane.Transform(matrix.Inverse());
134+
auto vol = _shape.VolumeBelow(plane);
135+
//ignerr << "Plane: " << waterPlane.Normal() << ".n = " << waterPlane.Offset() << " pose: "
136+
//<< _pose.Pos()<< " Rotation: "<< _pose.Rot().Euler() <<std::endl;
139137

140138
// Archimedes principal for this layer
141139
auto forceMag = - (vol - volsum) * _gravity * prevLayerFluidDensity;
142140

143141
// Calculate point from which force is applied
144-
auto cov = _shape.CenterOfVolumeBelow(waterPlane);
142+
auto cov = _shape.CenterOfVolumeBelow(plane);
145143

146144
if(!cov.has_value()) continue;
147145

@@ -159,11 +157,11 @@ void BuoyancyPrivate::GradedFluidDensity(
159157
prevLayerFluidDensity = currFluidDensity;
160158
volsum = vol;
161159
}
162-
ignerr << __FILE__ << ": " << __LINE__ <<std::endl;
163-
164160
// For the rest of the layers.
165161
auto vol = _shape.Volume();
166162

163+
ignerr << "Volume: " << vol << ", submerged" << volsum << std::endl;
164+
167165
// Archimedes principal for this layer
168166
auto forceMag = - (vol - volsum) * _gravity * prevLayerFluidDensity;
169167

@@ -185,10 +183,7 @@ std::pair<math::Vector3d, math::Vector3d> BuoyancyPrivate::resolveForces(
185183
const math::Pose3d &_pose)
186184
{
187185
auto force = math::Vector3d{0, 0, 0};
188-
ignerr << __FILE__ << ": " << __LINE__ <<std::endl;
189-
190186
auto torque = math::Vector3d{0, 0, 0};
191-
ignerr << __FILE__ << ": " << __LINE__ <<std::endl;
192187

193188
for(auto b: this->buoyancyForces)
194189
{
@@ -197,10 +192,7 @@ std::pair<math::Vector3d, math::Vector3d> BuoyancyPrivate::resolveForces(
197192
auto globalPoint = b.pose * localPoint;
198193
auto offset = globalPoint.Pos() - _pose.Pos();
199194
torque += force.Cross(offset);
200-
ignerr << __FILE__ << ": " << __LINE__ <<std::endl;
201-
202195
}
203-
ignerr << __FILE__ << ": " << __LINE__ <<std::endl;
204196

205197
return {force, torque};
206198
}
@@ -258,13 +250,11 @@ void Buoyancy::Configure(const Entity &_entity,
258250
auto depth = argument->Get<double>("above_depth");
259251
auto density = argument->Get<double>("density");
260252
this->dataPtr->layers[depth] = density;
261-
ignerr << "Added layer " << std::endl;
253+
igndbg << "Added layer at " << depth << std::endl;
262254
}
263255
argument = argument->GetNextElement();
264256
}
265257
}
266-
ignerr << "Finished parsing" << std::endl;
267-
268258
}
269259

270260
//////////////////////////////////////////////////
@@ -281,7 +271,6 @@ void Buoyancy::PreUpdate(const ignition::gazebo::UpdateInfo &_info,
281271
return;
282272
}
283273

284-
ignerr << "was here" << std::endl;
285274
// Compute the volume and center of volume for each new link
286275
_ecm.EachNew<components::Link, components::Inertial>(
287276
[&](const Entity &_entity,
@@ -297,6 +286,9 @@ void Buoyancy::PreUpdate(const ignition::gazebo::UpdateInfo &_info,
297286
return true;
298287
}
299288

289+
enableComponent<components::Inertial>(_ecm, _entity);
290+
enableComponent<components::WorldPose>(_ecm, _entity);
291+
300292
Link link(_entity);
301293

302294
std::vector<Entity> collisions = _ecm.ChildrenByComponents(
@@ -437,16 +429,13 @@ void Buoyancy::PreUpdate(const ignition::gazebo::UpdateInfo &_info,
437429
ignerr << "Invalid collision pointer. This shouldn't happen\n";
438430
continue;
439431
}
440-
ignerr << __FILE__ << ": " << __LINE__ <<std::endl;
441-
442432

443433
switch (coll->Data().Geom()->Type())
444434
{
445435
case sdf::GeometryType::BOX:
446436
//coll->Data().Geom()->BoxShape()->Shape().VolumeBelow();
447437
break;
448438
case sdf::GeometryType::SPHERE:
449-
ignerr << __FILE__ << ": " << __LINE__ <<std::endl;
450439
this->dataPtr->GradedFluidDensity<math::Sphered>(
451440
pose,
452441
coll->Data().Geom()->SphereShape()->Shape(),
@@ -462,12 +451,11 @@ void Buoyancy::PreUpdate(const ignition::gazebo::UpdateInfo &_info,
462451
}
463452
}
464453
}
465-
ignerr << __FILE__ << ": " << __LINE__ <<std::endl;
466-
467454
auto [force, torque]= this->dataPtr->resolveForces(
468455
link.WorldInertialPose(_ecm).value());
469456
// Apply the wrench to the link. This wrench is applied in the
470457
// Physics System.
458+
ignerr << "Force applied" << force << std::endl;
471459
link.AddWorldWrench(_ecm, force, torque);
472460
return true;
473461
});

0 commit comments

Comments
 (0)