Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ add_library(vgoswec_chrono STATIC
src/active_pto.cpp
src/excitation_force_provider.cpp
src/impedance.cpp
src/rsda_pto_functor.cpp
)
target_include_directories(vgoswec_chrono PUBLIC src)
target_link_libraries(vgoswec_chrono
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,17 @@ cpp-vgoswec/
- **Project Chrono** ≥ 10.0 with `CH_USE_SIMD=OFF`
- **yaml-cpp** ≥ 0.7
- **Eigen3** ≥ 3.4
- **For SEA-Stack/HIL visualization parity**: `libseastack_app_lib.a` available in one of:
- `$HOME/SEA-Stack/build/lib/Release/`
- `$HOME/SEA-Stack/build/lib/`
- `$HOME/SEA-Stack/install/lib/`
- **For GUI/visualization** (optional — headless builds work without these):
- **VulkanSceneGraph (VSG)** ≥ 1.1 (`vsg::vsg` CMake target)
- **vsgXchange** ≥ 1.0 (asset loading for VSG; `vsgXchange::vsgXchange`)
- **vsgImGui** ≥ 0.3 (in-scene UI overlay; `vsgImGui::vsgImGui`)
- **Chrono VSG module** built alongside Chrono (`Chrono::Chrono_vsg`)
- **SEA-Stack GUI helper header** present at `$HOME/SEA-Stack/apps/seastack/gui/guihelper.h` (from the SEA-Stack source tree)
- **`libseastack_app_lib`** available in one of:
- `$HOME/SEA-Stack/build/lib/Release/`
- `$HOME/SEA-Stack/build/lib/`
- `$HOME/SEA-Stack/install/lib/`
When any of the above GUI components are absent CMake automatically falls back to a headless-only build that still compiles and produces CSV output.

## Build

Expand Down
108 changes: 62 additions & 46 deletions src/demo_vgoswec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "excitation_force_provider.h"
#include "impedance.h"
#include "pid_controller.h"
#include "rsda_pto_functor.h"

#include <seastack/adapters/chrono/helper.h>
#include <seastack/adapters/chrono/hydro_system.h>
Expand All @@ -19,9 +20,8 @@
#include <chrono/physics/ChBodyEasy.h>
#include <chrono/physics/ChLinkLock.h>
#include <chrono/physics/ChLinkMate.h>
#include <chrono/physics/ChLinkRSDA.h>
#include <chrono/physics/ChSystemNSC.h>
#include <chrono/physics/ChLinkMotorRotationTorque.h>
#include <chrono/functions/ChFunctionConst.h>

#include <cmath>
#include <filesystem>
Expand Down Expand Up @@ -161,39 +161,6 @@ struct Record {
double t, th, om, tau_pto, tau_exc, p;
};

static void RunHeadlessLoop(
ChSystemNSC& system,
seastack::chrono::HydroSystem& hydro_system,
const std::shared_ptr<ChBody>& flap_body,
const std::shared_ptr<ChLinkMotorRotationTorque>& motor,
const std::shared_ptr<seastack::pto::IPTOModel>& controller,
const std::shared_ptr<vgoswec::ExcitationForceProvider>& exc_provider,
double sim_duration,
double dt,
std::vector<Record>& records) {
while (system.GetChTime() <= sim_duration) {
const double t = system.GetChTime();

const auto rpy = flap_body->GetRot().GetCardanAnglesXYZ();
const double pitch_rad = rpy.y();
const double pitch_vel = flap_body->GetAngVelParent().y();

const double pto_tau = controller->ComputeForce(pitch_rad, pitch_vel, t);
motor->SetTorqueFunction(chrono_types::make_shared<ChFunctionConst>(pto_tau));

system.DoStepDynamics(dt);

const auto& per_comp = hydro_system.GetLastComponentForces();
if (!per_comp.empty()) {
exc_provider->Update(per_comp, system.GetChTime());
}
const double exc_tau = exc_provider->GetLatestExcitationTorque();

records.push_back(
{system.GetChTime(), pitch_rad, pitch_vel, pto_tau, exc_tau, -pto_tau * pitch_vel});
}
}

} // namespace

int main(int argc, char* argv[]) {
Expand Down Expand Up @@ -245,11 +212,10 @@ int main(int argc, char* argv[]) {
const ChVector3d hinge_pos(0.0, 0.0, cfg.hinge_z);
const ChQuaternion<> hinge_rot = QuatFromAngleX(CH_PI / 2.0);

auto motor = chrono_types::make_shared<ChLinkMotorRotationTorque>();
motor->Initialize(base_body, flap_body, ChFrame<>(hinge_pos, hinge_rot));
auto tau_fun = chrono_types::make_shared<ChFunctionConst>(0.0);
motor->SetTorqueFunction(tau_fun);
system.AddLink(motor);
// Revolute constraint: 5-DOF hinge, free rotation about world Y-axis
auto revolute = chrono_types::make_shared<ChLinkLockRevolute>();
revolute->Initialize(base_body, flap_body, ChFrame<>(hinge_pos, hinge_rot));
system.AddLink(revolute);

auto waves = BuildWaveField(cfg);
std::vector<std::shared_ptr<ChBody>> bodies{flap_body, base_body};
Expand All @@ -259,22 +225,72 @@ int main(int argc, char* argv[]) {
auto exc_provider = std::make_shared<vgoswec::ExcitationForceProvider>(0, 4);
auto controller = BuildController(cfg, args.controller_override, hydro_data, exc_provider);

// RSDA: applies PTO torque at every force-assembly sub-step via RsdaPtoFunctor.
// This replaces the per-outer-step ChLinkMotorRotationTorque + ChFunctionConst pattern.
auto rsda = chrono_types::make_shared<ChLinkRSDA>();
rsda->Initialize(base_body, flap_body, false,
ChFramed(hinge_pos, hinge_rot), ChFramed(hinge_pos, hinge_rot));
rsda->RegisterTorqueFunctor(std::make_shared<vgoswec::RsdaPtoFunctor>(controller));
system.AddLink(rsda);

std::vector<Record> records;
records.reserve(static_cast<size_t>(sim_duration / cfg.timestep) + 100);

if (args.visualization_on) {
const double dt = cfg.timestep;

#ifdef VGOSWEC_HAVE_SEASTACK_GUIHELPER
std::cout << "Visualization requested, but runtime GUI loop is not yet wired in this demo.\n"
<< "Falling back to headless simulation.\n";
// GUI path: CreateUI(true) -> real VSG renderer; CreateUI(false) -> headless no-op.
// A single loop driven by ui.IsRunning() works for both visual and headless runs.
auto pui = seastack::viz::CreateUI(args.visualization_on);
seastack::viz::UI& ui = *pui;
ui.Init(&system, "VGOSWEC-45");
ui.SetCamera(0, -3.0, 0.5, 0, 0, -0.5);
ui.SetWaveModel(waves);

while (system.GetChTime() <= sim_duration) {
if (!ui.IsRunning(dt)) break;
if (ui.simulationStarted) {
const double pitch_rad = rsda->GetAngle();
const double pitch_vel = rsda->GetVelocity();

system.DoStepDynamics(dt);

const auto& per_comp = hydro_system.GetLastComponentForces();
if (!per_comp.empty()) {
exc_provider->Update(per_comp, system.GetChTime());
}
const double exc_tau = exc_provider->GetLatestExcitationTorque();
const double pto_tau = rsda->GetTorque();

records.push_back(
{system.GetChTime(), pitch_rad, pitch_vel, pto_tau, exc_tau, -pto_tau * pitch_vel});
}
}
#else
if (args.visualization_on) {
std::cerr << "ERROR: Visualization requested but GUI support is not available in this build.\n"
<< "Rebuild with GUI support or use --no-viz.\n";
return 2;
#endif
}

RunHeadlessLoop(system, hydro_system, flap_body, motor, controller, exc_provider,
sim_duration, cfg.timestep, records);
// Headless loop
while (system.GetChTime() <= sim_duration) {
const double pitch_rad = rsda->GetAngle();
const double pitch_vel = rsda->GetVelocity();

system.DoStepDynamics(dt);

const auto& per_comp = hydro_system.GetLastComponentForces();
if (!per_comp.empty()) {
exc_provider->Update(per_comp, system.GetChTime());
}
const double exc_tau = exc_provider->GetLatestExcitationTorque();
const double pto_tau = rsda->GetTorque();

records.push_back(
{system.GetChTime(), pitch_rad, pitch_vel, pto_tau, exc_tau, -pto_tau * pitch_vel});
}
#endif

std::filesystem::create_directories("output");
std::ofstream csv("output/vgoswec_45_results.csv");
Expand Down