Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latent Data on ROS 2 #157

Merged
merged 35 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ab5960b
update spring to match at-sea polytropic process
andermi Jun 26, 2023
605c60d
can now specify spring params per batch
andermi Jun 27, 2023
36c4eb9
tune spring to match atsea
andermi Jul 6, 2023
b831d13
ros2 service for incwave height; issues so replace LinearIncidentWave…
andermi Jul 12, 2023
36c6b45
use parent folder for FreeSurfaceHydrodynamics includes
andermi Aug 9, 2023
d47aedf
add matrix_mode: False option to sim params yaml to allow vectorized …
andermi Aug 9, 2023
b79cd37
Merge branch 'andermi/fix_fshydro_includes' into andermi/atsea_spring
andermi Aug 9, 2023
353b83d
Merge branch 'andermi/add_vectorized_batch_mode' into andermi/atsea_s…
andermi Aug 9, 2023
51a58f4
Merge branch 'andermi/atsea_spring' into andermi/incoming_wave_service
andermi Aug 22, 2023
c3bfe60
added latent data and tweaked incwaveheight
andermi Aug 24, 2023
8fdfc12
can specify incwaveheight points in sdf
andermi Aug 24, 2023
f20743d
added spring and pto (still need a couple pto losses)
andermi Aug 25, 2023
39e063a
linters
andermi Aug 29, 2023
563f41e
Merge branch 'andermi/incoming_wave_service' into andermi/latent_data
andermi Aug 29, 2023
9c47ee0
linters
andermi Aug 29, 2023
2d88d78
Merge branch 'main' into andermi/incoming_wave_service
andermi Aug 31, 2023
54bd6ed
Merge branch 'andermi/incoming_wave_service' into andermi/latent_data
andermi Aug 31, 2023
5251ce3
add ehpto force
andermi Sep 1, 2023
85af088
added forces from piston friction and wavebodyinteraction
andermi Sep 5, 2023
fd00588
Debug flag for WaveBodyInteractions plugin (#160)
andermi Sep 6, 2023
b959789
Merge branch 'main' into andermi/latent_data
andermi Sep 7, 2023
a4300d3
temporarily checkout andermi/latent_data in mbari_wec_utils for CI
andermi Sep 7, 2023
f85f14b
linters
andermi Sep 7, 2023
dadcc18
add gas mass and eff_v/m; comment units; use buoy_utils/constants.h i…
andermi Sep 10, 2023
2f0f097
fix last push
andermi Sep 10, 2023
cfd1e1a
fix latent_data pub
andermi Sep 10, 2023
1acea31
Added Shaft Mechanical Power to Latent Data
hamilton8415 Sep 13, 2023
721ce7e
Added additional loss terms to electrohydraulic latent data
hamilton8415 Sep 13, 2023
0f24cce
Resolved signs with supplied hydraulic power
hamilton8415 Sep 13, 2023
64a5198
Fixed bug in relief valve loss computation
hamilton8415 Sep 13, 2023
4cfbdb4
Adjusted fields
hamilton8415 Sep 14, 2023
da31486
Fixed formating for linters
hamilton8415 Sep 14, 2023
71ab5da
Merge pull request #162 from osrf/hamilton8415/latent_data
hamilton8415 Sep 15, 2023
b41eeca
Merge branch 'main' into andermi/latent_data
andermi Sep 19, 2023
fbe8a5d
Add wave body total power to latent data (#165)
andermi Sep 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build-and-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ cp -r $GITHUB_WORKSPACE $COLCON_WS_SRC
wget https://raw.githubusercontent.com/osrf/mbari_wec/main/mbari_wec_all.yaml
vcs import --skip-existing < mbari_wec_all.yaml

cd mbari_wec_utils
git checkout andermi/latent_data
cd ..

rosdep init
rosdep update
rosdep install --from-paths ./ -i -y -r --rosdistro $ROS_DISTRO
Expand Down
3 changes: 2 additions & 1 deletion buoy_description/models/mbari_wec/model.sdf.em
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ if not ignore_piston_mean_pos:
<P0>@(print(f'{P0_l:.00f}', end=''))</P0>
</plugin>

<plugin filename="WaveBodyInteractions" name="buoy_gazebo::WaveBodyInteractions">
<plugin filename="WaveBodyInteractions" name="buoy_gazebo::WaveBodyInteractions">
<LinkName>Buoy</LinkName>
<debug>false</debug>
<WaterplaneOrigin_x>0</WaterplaneOrigin_x> <!-- Waterplane origin relative to link origin -->
<WaterplaneOrigin_y>0</WaterplaneOrigin_y>
<WaterplaneOrigin_z>2.46</WaterplaneOrigin_z>
Expand Down
11 changes: 3 additions & 8 deletions buoy_description/models/mbari_wec_ros/model.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,10 @@
<namespace>/</namespace>
<node_name>inc_wave_service</node_name>
<points use_buoy_origin="true">
<xy>-1.0 -1.0</xy>
<xy>0.0 -1.0</xy>
<xy>1.0 -1.0</xy>
<xy>-1.0 0.0</xy>
<xy>0.0 0.0</xy>
<xy>1.0 0.0</xy>
<xy>-1.0 1.0</xy>
<xy>0.0 1.0</xy>
<xy>1.0 1.0</xy>
<!-- may add multiple xy tags -->
<!-- <xy>-1.0 0.0</xy> -->
<!-- <xy>1.0 0.0</xy> -->
</points>
</plugin>

Expand Down
1 change: 1 addition & 0 deletions buoy_gazebo/src/ElectroHydraulicPTO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ gz_add_plugin(ElectroHydraulicPTO
ElectroHydraulicPTO.cpp
INCLUDE_DIRS
..
../LatentData
EXTRA_ROS_PKGS
simple_interp
)
63 changes: 0 additions & 63 deletions buoy_gazebo/src/ElectroHydraulicPTO/ElectroHydraulicLoss.hpp

This file was deleted.

68 changes: 47 additions & 21 deletions buoy_gazebo/src/ElectroHydraulicPTO/ElectroHydraulicPTO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "ElectroHydraulicPTO.hpp"

#include <eigen3/unsupported/Eigen/NonLinearOptimization>

#include <gz/msgs/double.pb.h>
Expand Down Expand Up @@ -40,12 +42,12 @@
#include <gz/plugin/Register.hh>
#include <gz/transport/Node.hh>

#include "ElectroHydraulicPTO.hpp"
#include "ElectroHydraulicSoln.hpp"
#include "ElectroHydraulicState.hpp"
#include "ElectroHydraulicLoss.hpp"
#include "BatteryState.hpp"

#include <LatentData/LatentData.hpp>


namespace buoy_gazebo
{
Expand Down Expand Up @@ -262,16 +264,15 @@ void ElectroHydraulicPTO::PreUpdate(
pto_state = buoy_gazebo::ElectroHydraulicState(pto_state_comp->Data());
}

buoy_gazebo::ElectroHydraulicLoss pto_loss;
buoy_gazebo::LatentData latent_data;
if (_ecm.EntityHasComponentType(
this->dataPtr->PrismaticJointEntity,
buoy_gazebo::components::ElectroHydraulicLoss().TypeId()))
this->dataPtr->model.Entity(),
buoy_gazebo::components::LatentData().TypeId()))
{
auto pto_loss_comp =
_ecm.Component<buoy_gazebo::components::ElectroHydraulicLoss>(
this->dataPtr->PrismaticJointEntity);
auto latent_data_comp =
_ecm.Component<buoy_gazebo::components::LatentData>(this->dataPtr->model.Entity());

pto_loss = buoy_gazebo::ElectroHydraulicLoss(pto_loss_comp->Data());
latent_data = buoy_gazebo::LatentData(latent_data_comp->Data());
}

if (pto_state.scale_command) {
Expand Down Expand Up @@ -346,7 +347,7 @@ void ElectroHydraulicPTO::PreUpdate(
if (i_try > 0) {
std::stringstream warning;
warning << "Warning: Reduced piston to achieve convergence" << std::endl;
igndbg << warning.str();
gzdbg << warning.str();
}

if (solver_info != 1) {
Expand All @@ -355,13 +356,16 @@ void ElectroHydraulicPTO::PreUpdate(
warning << "Warning: Numericals solver in ElectroHydraulicPTO did not converge" << std::endl;
warning << "solver info: [" << solver_info << "]" << std::endl;
warning << "=================================" << std::endl;
igndbg << warning.str();
gzdbg << warning.str();
}

// Solve Electrical
const double N = this->dataPtr->x[0U];
double deltaP = this->dataPtr->x[1U];
double VBus = this->dataPtr->x[2U];
const double eff_m = this->dataPtr->functor.hyd_eff_m.eval(fabs(N));
const double eff_v = this->dataPtr->functor.hyd_eff_v.eval(fabs(deltaP));

VBus = std::min(VBus, this->dataPtr->MaxTargetVoltage);
double BusPower = this->dataPtr->functor.BusPower;

Expand Down Expand Up @@ -404,12 +408,35 @@ void ElectroHydraulicPTO::PreUpdate(
pto_state.target_a = this->dataPtr->functor.I_Wind.I;


pto_loss.hydraulic_motor_loss += 1.0;
pto_loss.relief_valve_loss += 2.0;
pto_loss.motor_drive_i2r_loss += 3.0;
pto_loss.motor_drive_switching_loss += 4.0;
pto_loss.motor_drive_friction_loss += 5.0;
pto_loss.battery_i2r_loss = I_Batt * I_Batt * this->dataPtr->Ri;
double piston_force = -deltaP * this->dataPtr->PistonArea * buoy_utils::NEWTONS_PER_LB;

latent_data.electro_hydraulic.valid = true;
latent_data.electro_hydraulic.rpm = N;
latent_data.electro_hydraulic.upper_hydraulic_pressure =
pto_state.upper_hyd_press * buoy_utils::PASCAL_PER_PSI;
latent_data.electro_hydraulic.lower_hydraulic_pressure =
pto_state.lower_hyd_press * buoy_utils::PASCAL_PER_PSI;
latent_data.electro_hydraulic.force = piston_force;
latent_data.electro_hydraulic.supplied_hydraulic_power =
-deltaP * this->dataPtr->functor.Q / buoy_utils::INLB_PER_NM;
latent_data.electro_hydraulic.hydraulic_motor_loss =
this->dataPtr->functor.HydraulicMotorLoss;
latent_data.electro_hydraulic.relief_valve_loss =
this->dataPtr->functor.ReliefValveLoss;
latent_data.electro_hydraulic.shaft_mech_power =
this->dataPtr->functor.ShaftMechPower;
latent_data.electro_hydraulic.motor_drive_i2r_loss =
this->dataPtr->functor.I2RLoss;
latent_data.electro_hydraulic.motor_drive_switching_loss =
this->dataPtr->functor.SwitchingLoss;
latent_data.electro_hydraulic.motor_drive_friction_loss =
this->dataPtr->functor.FrictionLoss;
latent_data.electro_hydraulic.load_dump_power =
I_Load * VBus;
latent_data.electro_hydraulic.battery_i2r_loss =
I_Batt * I_Batt * this->dataPtr->Ri;
latent_data.electro_hydraulic.battery_storage_power =
I_Batt * VBus - latent_data.electro_hydraulic.battery_i2r_loss;

_ecm.SetComponentData<buoy_gazebo::components::BatteryState>(
this->dataPtr->PrismaticJointEntity,
Expand All @@ -421,9 +448,9 @@ void ElectroHydraulicPTO::PreUpdate(

auto stampMsg = gz::sim::convert<gz::msgs::Time>(_info.simTime);

_ecm.SetComponentData<buoy_gazebo::components::ElectroHydraulicLoss>(
this->dataPtr->PrismaticJointEntity,
pto_loss);
_ecm.SetComponentData<buoy_gazebo::components::LatentData>(
this->dataPtr->model.Entity(),
latent_data);

gz::msgs::Double pistonvel;
pistonvel.mutable_header()->mutable_stamp()->CopyFrom(stampMsg);
Expand All @@ -437,7 +464,6 @@ void ElectroHydraulicPTO::PreUpdate(
// Apply force if not in Velocity Mode, in which case a joint velocity is applied elsewhere
// (likely by a test Fixture)
if (!this->dataPtr->VelMode) {
double piston_force = -deltaP * this->dataPtr->PistonArea * buoy_utils::NEWTONS_PER_LB;
// Create new component for this entitiy in ECM (if it doesn't already exist)
auto forceComp = _ecm.Component<gz::sim::components::JointForceCmd>(
this->dataPtr->PrismaticJointEntity);
Expand Down
29 changes: 20 additions & 9 deletions buoy_gazebo/src/ElectroHydraulicPTO/ElectroHydraulicSoln.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ struct ElectroHydraulicSoln : Functor<double>
mutable double BusPower;
double Q;

mutable double ShaftMechPower;
mutable double FrictionLoss;
mutable double SwitchingLoss;
mutable double I2RLoss;
mutable double ReliefValveLoss;
mutable double HydraulicMotorLoss;

private:
static const std::vector<double> Peff; // psi
static const std::vector<double> Neff; // rpm
Expand Down Expand Up @@ -170,28 +177,32 @@ struct ElectroHydraulicSoln : Functor<double>
const double T_applied =
1.375 * this->I_Wind.TorqueConstantInLbPerAmp * WindCurr;

double ShaftMechPower = T_applied * buoy_utils::NM_PER_INLB *
ShaftMechPower = -T_applied * buoy_utils::NM_PER_INLB *
x[0U] * buoy_utils::RPM_TO_RAD_PER_SEC;
BusPower = -ShaftMechPower - (
MotorDriveFrictionLoss(x[0U]) +
MotorDriveSwitchingLoss(x[2U]) +
MotorDriveISquaredRLoss(WindCurr));
FrictionLoss = MotorDriveFrictionLoss(x[0U]);
SwitchingLoss = MotorDriveSwitchingLoss(x[2U]);
I2RLoss = MotorDriveISquaredRLoss(WindCurr);
BusPower = ShaftMechPower - (FrictionLoss + SwitchingLoss + I2RLoss);
double Q_Relief = 0;
if (x[1U] < -PressReliefSetPoint) { // Pressure relief is a one wave valve,
// relieves when lower pressure is higher
// than upper (resisting extension)
Q_Relief = (x[1U] + PressReliefSetPoint) * ReliefValveFlowPerPSI *
buoy_utils::CubicInchesPerGallon / buoy_utils::SecondsPerMinute;
}
// Q_Relief = 0;
ReliefValveLoss = Q_Relief * x[1U] / buoy_utils::INLB_PER_NM; // Result is Watts

double Q_Motor = this->Q - Q_Relief;
double Q = x[0U] * this->HydMotorDisp / buoy_utils::SecondsPerMinute;
double Q_Leak = (1.0 - eff_v) * std::max(fabs(Q_Motor), fabs(Q)) * sgn(x[1]);
double Q_Ideal = x[0U] * this->HydMotorDisp / buoy_utils::SecondsPerMinute;
double Q_Leak = (1.0 - eff_v) * std::max(fabs(Q_Motor), fabs(Q_Ideal)) * sgn(x[1]);

double T_Fluid = x[1U] * this->HydMotorDisp / (2.0 * M_PI);
double T_Friction = -(1.0 - eff_m) * std::max(fabs(T_applied), fabs(T_Fluid)) * sgn(x[0]);

fvec[0U] = Q_Motor - Q_Leak - Q;
HydraulicMotorLoss = Q_Leak * x[1U] / buoy_utils::INLB_PER_NM - // Result is Watts
T_Friction * x[0U] * 2.0 * M_PI / (buoy_utils::INLB_PER_NM * buoy_utils::SecondsPerMinute);

fvec[0U] = Q_Motor - Q_Leak - Q_Ideal;
fvec[1U] = T_applied + T_Friction + T_Fluid;
fvec[2U] = BusPower - (x[2U] - VBattEMF) * x[2U] / this->Ri;

Expand Down
2 changes: 2 additions & 0 deletions buoy_gazebo/src/LatentData/IncWaveHeight/IncWaveHeight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ void IncWaveHeight::PreUpdate(
latent_data = buoy_gazebo::LatentData(latent_data_comp->Data());
}

latent_data.inc_wave_heights.valid = this->dataPtr->inc_wave_valid_;

double SimTime = std::chrono::duration<double>(this->dataPtr->current_time_).count();
auto sec_nsec = gz::math::durationToSecNsec(this->dataPtr->current_time_);
// all fixed points from SDF computed at SimTime (relative_time = 0.0)
Expand Down
Loading
Loading