@@ -124,24 +124,22 @@ void BuoyancyPrivate::GradedFluidDensity(
124
124
auto prevLayerFluidDensity = this ->fluidDensity ;
125
125
auto volsum = 0 ;
126
126
auto centerOfBuoyancy = math::Vector3d{0 ,0 ,0 };
127
- ignerr << __FILE__ << " : " << __LINE__ <<std::endl;
128
127
129
128
for (auto [height, currFluidDensity] : layers)
130
129
{
131
130
// 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;
139
137
140
138
// Archimedes principal for this layer
141
139
auto forceMag = - (vol - volsum) * _gravity * prevLayerFluidDensity;
142
140
143
141
// Calculate point from which force is applied
144
- auto cov = _shape.CenterOfVolumeBelow (waterPlane );
142
+ auto cov = _shape.CenterOfVolumeBelow (plane );
145
143
146
144
if (!cov.has_value ()) continue ;
147
145
@@ -159,11 +157,11 @@ void BuoyancyPrivate::GradedFluidDensity(
159
157
prevLayerFluidDensity = currFluidDensity;
160
158
volsum = vol;
161
159
}
162
- ignerr << __FILE__ << " : " << __LINE__ <<std::endl;
163
-
164
160
// For the rest of the layers.
165
161
auto vol = _shape.Volume ();
166
162
163
+ ignerr << " Volume: " << vol << " , submerged" << volsum << std::endl;
164
+
167
165
// Archimedes principal for this layer
168
166
auto forceMag = - (vol - volsum) * _gravity * prevLayerFluidDensity;
169
167
@@ -185,10 +183,7 @@ std::pair<math::Vector3d, math::Vector3d> BuoyancyPrivate::resolveForces(
185
183
const math::Pose3d &_pose)
186
184
{
187
185
auto force = math::Vector3d{0 , 0 , 0 };
188
- ignerr << __FILE__ << " : " << __LINE__ <<std::endl;
189
-
190
186
auto torque = math::Vector3d{0 , 0 , 0 };
191
- ignerr << __FILE__ << " : " << __LINE__ <<std::endl;
192
187
193
188
for (auto b: this ->buoyancyForces )
194
189
{
@@ -197,10 +192,7 @@ std::pair<math::Vector3d, math::Vector3d> BuoyancyPrivate::resolveForces(
197
192
auto globalPoint = b.pose * localPoint;
198
193
auto offset = globalPoint.Pos () - _pose.Pos ();
199
194
torque += force.Cross (offset);
200
- ignerr << __FILE__ << " : " << __LINE__ <<std::endl;
201
-
202
195
}
203
- ignerr << __FILE__ << " : " << __LINE__ <<std::endl;
204
196
205
197
return {force, torque};
206
198
}
@@ -258,13 +250,11 @@ void Buoyancy::Configure(const Entity &_entity,
258
250
auto depth = argument->Get <double >(" above_depth" );
259
251
auto density = argument->Get <double >(" density" );
260
252
this ->dataPtr ->layers [depth] = density;
261
- ignerr << " Added layer " << std::endl;
253
+ igndbg << " Added layer at " << depth << std::endl;
262
254
}
263
255
argument = argument->GetNextElement ();
264
256
}
265
257
}
266
- ignerr << " Finished parsing" << std::endl;
267
-
268
258
}
269
259
270
260
// ////////////////////////////////////////////////
@@ -281,7 +271,6 @@ void Buoyancy::PreUpdate(const ignition::gazebo::UpdateInfo &_info,
281
271
return ;
282
272
}
283
273
284
- ignerr << " was here" << std::endl;
285
274
// Compute the volume and center of volume for each new link
286
275
_ecm.EachNew <components::Link, components::Inertial>(
287
276
[&](const Entity &_entity,
@@ -297,6 +286,9 @@ void Buoyancy::PreUpdate(const ignition::gazebo::UpdateInfo &_info,
297
286
return true ;
298
287
}
299
288
289
+ enableComponent<components::Inertial>(_ecm, _entity);
290
+ enableComponent<components::WorldPose>(_ecm, _entity);
291
+
300
292
Link link (_entity);
301
293
302
294
std::vector<Entity> collisions = _ecm.ChildrenByComponents (
@@ -437,16 +429,13 @@ void Buoyancy::PreUpdate(const ignition::gazebo::UpdateInfo &_info,
437
429
ignerr << " Invalid collision pointer. This shouldn't happen\n " ;
438
430
continue ;
439
431
}
440
- ignerr << __FILE__ << " : " << __LINE__ <<std::endl;
441
-
442
432
443
433
switch (coll->Data ().Geom ()->Type ())
444
434
{
445
435
case sdf::GeometryType::BOX:
446
436
// coll->Data().Geom()->BoxShape()->Shape().VolumeBelow();
447
437
break ;
448
438
case sdf::GeometryType::SPHERE:
449
- ignerr << __FILE__ << " : " << __LINE__ <<std::endl;
450
439
this ->dataPtr ->GradedFluidDensity <math::Sphered>(
451
440
pose,
452
441
coll->Data ().Geom ()->SphereShape ()->Shape (),
@@ -462,12 +451,11 @@ void Buoyancy::PreUpdate(const ignition::gazebo::UpdateInfo &_info,
462
451
}
463
452
}
464
453
}
465
- ignerr << __FILE__ << " : " << __LINE__ <<std::endl;
466
-
467
454
auto [force, torque]= this ->dataPtr ->resolveForces (
468
455
link .WorldInertialPose (_ecm).value ());
469
456
// Apply the wrench to the link. This wrench is applied in the
470
457
// Physics System.
458
+ ignerr << " Force applied" << force << std::endl;
471
459
link .AddWorldWrench (_ecm, force, torque);
472
460
return true ;
473
461
});
0 commit comments