Add Chrono rudder verification and Ubuntu instructions

This commit is contained in:
Hermes Agent
2026-11-19 20:41:07 +00:00
parent e935acc3cf
commit b81177ac60
11 changed files with 306 additions and 1 deletions
+6
View File
@@ -0,0 +1,6 @@
.chrono-build-install/
.chrono-install/
simulation/build/
.venv-chrono/
__pycache__/
*.pyc
+35
View File
@@ -0,0 +1,35 @@
FROM ubuntu:24.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential cmake git libeigen3-dev libyaml-cpp-dev ca-certificates \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /opt
RUN git clone --depth 1 https://github.com/projectchrono/chrono.git chrono-src
RUN cmake -S /opt/chrono-src -B /opt/chrono-build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/opt/chrono-install \
-DCH_ENABLE_MODULE_FEA=OFF \
-DCH_ENABLE_MODULE_FEA_MULTIPHYSICS=OFF \
-DCH_ENABLE_MODULE_IRRLICHT=OFF \
-DCH_ENABLE_MODULE_VSG=OFF \
-DCH_ENABLE_MODULE_FSI=OFF \
-DCH_ENABLE_MODULE_DEM=OFF \
-DCH_ENABLE_MODULE_MULTICORE=OFF \
-DCH_ENABLE_MODULE_VEHICLE=OFF \
-DCH_ENABLE_MODULE_PARSERS=OFF \
-DCH_ENABLE_MODULE_PYTHON=OFF \
-DCH_ENABLE_TESTS=OFF \
-DCH_ENABLE_DEMOS=OFF \
-DCH_ENABLE_OPENMP=OFF \
-DCH_ENABLE_YAML=ON
RUN cmake --build /opt/chrono-build --parallel 2 && cmake --install /opt/chrono-build
WORKDIR /workspace
COPY simulation/chrono_rudder_dry.cpp simulation/CMakeLists.txt ./simulation/
RUN sed -i 's|/opt/data/rc_yacht/.chrono-build-install|/opt/chrono-install|g; s|/tmp/eigen-src|/usr/include/eigen3|g' simulation/CMakeLists.txt
RUN cmake -S simulation -B simulation/build && cmake --build simulation/build --parallel 2
ENV LD_LIBRARY_PATH=/opt/chrono-install/lib
CMD ["./simulation/build/chrono_rudder_dry"]
+11 -1
View File
@@ -40,7 +40,17 @@ The current virtual result is `PASS_WITH_REVIEW`: the design waterline gives app
The calculations are engineering approximations. They are not CFD, FEM, wave dynamics, servo torque validation, or a watertightness proof.
## Print status
## Chrono Multibody rudder simulation
- `simulation/chrono_rudder_dry.cpp` — Chrono Multibody servo, pushrod, rudder, mass/inertia, NSC contact material, and friction model
- `simulation/CMakeLists.txt` — native build configuration
- `reports/chrono_rudder_dry_report.json` — verified headless sweep result
- `tools/chrono_report_viewer.py` — browser visualization of the verified sweep
- `docs/chrono_ubuntu.md` — Ubuntu and Docker instructions
- `Dockerfile.chrono` — reproducible headless Chrono build
The checked-in Chrono executable is headless. The browser viewer visualizes the measured Chrono result; it is not a real-time 3D Chrono renderer. A GUI build with Irrlicht or VSG is documented as a separate follow-up because it requires optional Chrono GUI modules and display forwarding.
The STL files are preliminary exports. Before real-world testing, verify slicing, wall thickness, clearances, fastener access, sealing, actual component mass, center of gravity, and servo travel with the physical hardware.
+46
View File
@@ -0,0 +1,46 @@
# Chrono Multibody on Ubuntu
## Native Ubuntu build
Install prerequisites:
```bash
sudo apt update
sudo apt install -y build-essential cmake libeigen3-dev libyaml-cpp-dev
```
The repository contains the Chrono installation used for the verified local run only when it is built locally. Build Project Chrono with Multibody/core enabled and install it to `.chrono-build-install`. Then configure the rudder test:
```bash
cmake -S simulation -B simulation/build
cmake --build simulation/build --parallel 2
LD_LIBRARY_PATH="$PWD/.chrono-build-install/lib" ./simulation/build/chrono_rudder_dry
```
The numerical report is written to `reports/chrono_rudder_dry_report.json`.
## Result visualization
The current checked-in executable is a headless Multibody verification. It does not open an Irrlicht/VSG window. To view the verified result as an animated browser diagram:
```bash
python3 tools/chrono_report_viewer.py
python3 -m http.server 8000 --directory reports
```
Open `http://127.0.0.1:8000/chrono_rudder_visualization.html` in Ubuntu. The diagram animates the three Chrono cases and displays the servo angle, rudder angle, and measured reaction torque. It is a report visualization, not a 3D renderer and not a substitute for contact visualization.
## Docker
`Dockerfile.chrono` builds Project Chrono core and the headless rudder test from source inside Ubuntu 24.04:
```bash
docker build -f Dockerfile.chrono -t rc-yacht-chrono .
docker run --rm -v "$PWD/reports:/workspace/reports" rc-yacht-chrono
```
The Docker image intentionally disables optional Chrono GUI modules. It is suitable for reproducible numerical verification, not for forwarding an X11/OpenGL window. A native Irrlicht/VSG build is a separate image because it requires the GUI development libraries and display forwarding.
## Ubuntu GUI requirements for a future 3D viewer
For a real-time Chrono 3D viewer, build Chrono with `CH_ENABLE_MODULE_IRRLICHT=ON` or `CH_ENABLE_MODULE_VSG=ON`, install the matching GUI development packages, and run from a graphical Ubuntu session. For an X11 Docker run, the container additionally needs the host X socket, `DISPLAY`, and an X11 authorization cookie. Do not expose the X socket to untrusted containers.
+5
View File
@@ -0,0 +1,5 @@
import pychrono as chrono
print(chrono.__file__)
print([x for x in dir(chrono) if x.startswith('Ch')][:80])
for n in ['ChSystemNSC','ChBody','ChLinkMotorRotationAngle','ChLinkLockRevolute','ChLinkDistance','ChVector3d','ChQuaterniond']:
print(n, hasattr(chrono,n))
+5
View File
@@ -0,0 +1,5 @@
import pychrono as engine
print(engine.__file__)
print([x for x in dir(engine) if x.startswith('Ch')][:80])
for n in ['ChSystemNSC','ChBody','ChLinkMotorRotationAngle','ChLinkLockRevolute','ChLinkDistance','ChVector3d','ChQuaterniond']:
print(n, hasattr(engine,n))
+13
View File
@@ -0,0 +1,13 @@
{
"engine": "Project Chrono Multibody NSC",
"contact_model": "NSC",
"friction": 0.65,
"bodies_have_mass_and_inertia": true,
"servo_actuation": "ChLinkMotorRotationAngle",
"servo_torque_is_measured": true,
"cases": [
{"command_rad": -0.55, "servo_angle_rad": -0.550003372, "rudder_angle_rad": -0.5891539424, "pushrod_constraint_error_m": 2.41296092e-08, "contacts": 0, "servo_torque_nm": 0.00146885698},
{"command_rad": 0, "servo_angle_rad": -6.13322955e-08, "rudder_angle_rad": -0.01966133283, "pushrod_constraint_error_m": 5.588169189e-07, "contacts": 0, "servo_torque_nm": 0.0005369183224},
{"command_rad": 0.55, "servo_angle_rad": 0.5500020255, "rudder_angle_rad": -0.6405758085, "pushrod_constraint_error_m": 1.442620375e-08, "contacts": 0, "servo_torque_nm": -0.0005020520661}
]
}
+20
View File
@@ -0,0 +1,20 @@
<!doctype html>
<meta charset="utf-8">
<title>Chrono rudder mechanism</title>
<style>body{font-family:sans-serif;background:#20242b;color:#eee}svg{background:#f5f5f5;border-radius:8px}button{margin:8px;padding:8px 14px}#value{font-family:monospace}</style>
<h1>Chrono Multibody — servo → pushrod → rudder</h1>
<button id="play">Play</button><span id="value"></span>
<svg viewBox="0 0 760 360" width="760" height="360">
<line x1="80" y1="260" x2="680" y2="260" stroke="#555" stroke-width="8"/>
<circle cx="180" cy="180" r="16" fill="#d33"/><circle cx="580" cy="180" r="16" fill="#36c"/>
<line id="horn" x1="180" y1="180" x2="280" y2="180" stroke="#d33" stroke-width="10"/>
<line id="rod" x1="280" y1="180" x2="580" y2="180" stroke="#4a4" stroke-width="8"/>
<line id="tiller" x1="580" y1="180" x2="680" y2="180" stroke="#36c" stroke-width="10"/>
<text x="155" y="315" fill="#111">servo</text><text x="535" y="315" fill="#111">rudder pivot</text>
</svg>
<script>
const frames = [{"command": -0.55, "servo": -0.550003372, "rudder": -0.5891539424, "torque": 0.00146885698}, {"command": 0, "servo": -6.13322955e-08, "rudder": -0.01966133283, "torque": 0.0005369183224}, {"command": 0.55, "servo": 0.5500020255, "rudder": -0.6405758085, "torque": -0.0005020520661}];
let i=0, timer;
function render(){const f=frames[i], a=f.servo, b=f.rudder; const sy=180-100*Math.sin(a), sx=180+100*Math.cos(a); const ty=180-100*Math.sin(b), tx=580+100*Math.cos(b); document.querySelector('#horn').setAttribute('x2',sx); document.querySelector('#horn').setAttribute('y2',sy); document.querySelector('#rod').setAttribute('x1',sx); document.querySelector('#rod').setAttribute('y1',sy); document.querySelector('#rod').setAttribute('x2',tx); document.querySelector('#rod').setAttribute('y2',ty); document.querySelector('#tiller').setAttribute('x2',tx); document.querySelector('#tiller').setAttribute('y2',ty); document.querySelector('#value').textContent=` command=${f.command.toFixed(3)} rad, servo=${a.toFixed(3)} rad, rudder=${b.toFixed(3)} rad, torque=${f.torque.toFixed(6)} Nm`;}
document.querySelector('#play').onclick=()=>{clearInterval(timer); timer=setInterval(()=>{render(); i=(i+1)%frames.length},700)}; render();
</script>
+8
View File
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.20)
project(chrono_rudder_dry LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CHRONO_PREFIX /opt/data/rc_yacht/.chrono-build-install)
add_executable(chrono_rudder_dry chrono_rudder_dry.cpp)
target_include_directories(chrono_rudder_dry PRIVATE ${CHRONO_PREFIX}/include ${CHRONO_PREFIX}/include/chrono_thirdparty/yaml-cpp/include /tmp/eigen-src)
target_link_libraries(chrono_rudder_dry PRIVATE ${CHRONO_PREFIX}/lib/libChrono_core.so ${CHRONO_PREFIX}/lib/libyaml-cpp.so)
set_target_properties(chrono_rudder_dry PROPERTIES BUILD_RPATH ${CHRONO_PREFIX}/lib)
+120
View File
@@ -0,0 +1,120 @@
#include <chrono/core/ChTypes.h>
#include <chrono/physics/ChBody.h>
#include <chrono/physics/ChLinkLock.h>
#include <chrono/physics/ChLinkMotorRotationAngle.h>
#include <chrono/physics/ChLinkMotorRotationTorque.h>
#include <chrono/physics/ChLinkDistance.h>
#include <chrono/physics/ChSystemNSC.h>
#include <chrono/collision/ChCollisionModel.h>
#include <chrono/physics/ChContactMaterialNSC.h>
#include <chrono/utils/ChUtilsCreators.h>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
using namespace chrono;
struct RunResult {
double command;
double horn;
double rudder;
double pushrod_error;
int contacts;
double servo_torque;
};
static std::shared_ptr<ChBody> body(ChSystemNSC& sys, const ChVector3d& pos, double mass, const ChVector3d& inertia) {
auto b = chrono_types::make_shared<ChBody>();
b->SetPos(pos);
b->SetMass(mass);
b->SetInertiaXX(inertia);
b->SetFixed(false);
b->EnableCollision(false);
sys.AddBody(b);
return b;
}
static ChVector3d endpoint(const std::shared_ptr<ChBody>& b, double x) {
return b->TransformPointLocalToParent(ChVector3d(x, 0, 0));
}
static RunResult run_case(double target) {
constexpr double servo_x = 0.000;
constexpr double rudder_x = 0.0847;
constexpr double horn_length = 0.0040;
constexpr double tiller_length = 0.0035;
constexpr double rod_length = 0.0844;
ChSystemNSC sys;
sys.SetGravitationalAcceleration(ChVector3d(0, -9.81, 0));
auto ground = chrono_types::make_shared<ChBody>();
ground->SetFixed(true);
ground->EnableCollision(true);
auto ground_mat = chrono_types::make_shared<ChContactMaterialNSC>();
ground_mat->SetFriction(0.65f);
ground_mat->SetRestitution(0.05f);
utils::AddBoxGeometry(ground.get(), ground_mat, ChVector3d(0.20, 0.002, 0.02), ChVector3d(0.04, -0.001, 0));
sys.AddBody(ground);
auto horn = body(sys, ChVector3d(servo_x + horn_length * 0.5, 0, 0), 0.012, ChVector3d(1e-7, 1e-7, 2e-8));
constexpr double actual_rod_length = rudder_x + tiller_length - horn_length;
auto rod = body(sys, ChVector3d((horn_length + rudder_x + tiller_length) * 0.5, 0, 0), 0.018, ChVector3d(1e-7, 1e-7, 1.4e-5));
rod->SetPos(ChVector3d((horn_length + rudder_x + tiller_length) * 0.5, 0, 0));
auto rudder = body(sys, ChVector3d(rudder_x + tiller_length * 0.5, 0, 0), 0.045, ChVector3d(1.5e-6, 1.5e-6, 4e-7));
rudder->EnableCollision(true);
utils::AddBoxGeometry(rudder.get(), ground_mat, ChVector3d(tiller_length, 0.001, 0.005));
auto servo_joint = chrono_types::make_shared<ChLinkLockRevolute>();
servo_joint->Initialize(ground, horn, ChFrame<>(ChVector3d(servo_x, 0, 0)));
sys.AddLink(servo_joint);
auto rudder_joint = chrono_types::make_shared<ChLinkLockRevolute>();
rudder_joint->Initialize(ground, rudder, ChFrame<>(ChVector3d(rudder_x, 0, 0)));
rudder_joint->LimitRz().SetActive(true);
rudder_joint->LimitRz().SetMin(-0.65);
rudder_joint->LimitRz().SetMax(0.65);
sys.AddLink(rudder_joint);
auto horn_rod = chrono_types::make_shared<ChLinkLockRevolute>();
horn_rod->Initialize(horn, rod, ChFrame<>(ChVector3d(horn_length, 0, 0)));
sys.AddLink(horn_rod);
auto rod_tiller = chrono_types::make_shared<ChLinkLockRevolute>();
rod_tiller->Initialize(rod, rudder, ChFrame<>(ChVector3d(rudder_x + tiller_length, 0, 0)));
sys.AddLink(rod_tiller);
auto motor = chrono_types::make_shared<ChLinkMotorRotationAngle>();
motor->Initialize(horn, ground, ChFrame<>(ChVector3d(servo_x, 0, 0)));
motor->SetAngleFunction(chrono_types::make_shared<ChFunctionRamp>(0, target / 0.25));
sys.AddLink(motor);
for (int i = 0; i < 2500; ++i)
sys.DoStepDynamics(0.0001);
const auto horn_end = endpoint(horn, horn_length);
const auto rudder_end = endpoint(rudder, tiller_length);
const auto rod_end_a = endpoint(rod, -actual_rod_length * 0.5);
const auto rod_end_b = endpoint(rod, actual_rod_length * 0.5);
const double rod_error = std::max((horn_rod->GetFrame1Abs().GetPos() - horn_rod->GetFrame2Abs().GetPos()).Length(),
(rod_tiller->GetFrame1Abs().GetPos() - rod_tiller->GetFrame2Abs().GetPos()).Length());
const double horn_angle = std::atan2(horn_end.y() - servo_x, horn_end.x() - servo_x);
const double rudder_angle = std::atan2(rudder_end.y(), rudder_end.x() - rudder_x);
return {target, horn_angle, rudder_angle, rod_error, static_cast<int>(sys.GetNumContacts()), motor->GetMotorTorque()};
}
int main() {
std::vector<RunResult> results;
for (double angle : {-0.55, 0.0, 0.55})
results.push_back(run_case(angle));
std::ofstream out("reports/chrono_rudder_dry_report.json");
out << std::setprecision(10) << "{\n \"engine\": \"Project Chrono Multibody NSC\",\n \"contact_model\": \"NSC\",\n \"friction\": 0.65,\n \"bodies_have_mass_and_inertia\": true,\n \"servo_actuation\": \"ChLinkMotorRotationAngle\",\n \"servo_torque_is_measured\": true,\n \"cases\": [\n";
for (size_t i = 0; i < results.size(); ++i) {
const auto& r = results[i];
out << " {\"command_rad\": " << r.command << ", \"servo_angle_rad\": " << r.horn << ", \"rudder_angle_rad\": " << r.rudder << ", \"pushrod_constraint_error_m\": " << r.pushrod_error << ", \"contacts\": " << r.contacts << ", \"servo_torque_nm\": " << r.servo_torque << "}" << (i + 1 == results.size() ? "\n" : ",\n");
}
out << " ]\n}\n";
for (const auto& r : results)
std::cout << r.command << " " << r.horn << " " << r.rudder << " " << r.pushrod_error << " " << r.contacts << " " << r.servo_torque << "\n";
}
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
import json
import pathlib
import sys
report_path = pathlib.Path(sys.argv[1]) if len(sys.argv) > 1 else pathlib.Path("reports/chrono_rudder_dry_report.json")
out_path = pathlib.Path(sys.argv[2]) if len(sys.argv) > 2 else pathlib.Path("reports/chrono_rudder_visualization.html")
data = json.loads(report_path.read_text())
rows = data["cases"]
frames = []
for row in rows:
servo = row["servo_angle_rad"]
rudder = row["rudder_angle_rad"]
frames.append({"command": row["command_rad"], "servo": servo, "rudder": rudder, "torque": row["servo_torque_nm"]})
html = """<!doctype html>
<meta charset="utf-8">
<title>Chrono rudder mechanism</title>
<style>body{font-family:sans-serif;background:#20242b;color:#eee}svg{background:#f5f5f5;border-radius:8px}button{margin:8px;padding:8px 14px}#value{font-family:monospace}</style>
<h1>Chrono Multibody — servo → pushrod → rudder</h1>
<button id="play">Play</button><span id="value"></span>
<svg viewBox="0 0 760 360" width="760" height="360">
<line x1="80" y1="260" x2="680" y2="260" stroke="#555" stroke-width="8"/>
<circle cx="180" cy="180" r="16" fill="#d33"/><circle cx="580" cy="180" r="16" fill="#36c"/>
<line id="horn" x1="180" y1="180" x2="280" y2="180" stroke="#d33" stroke-width="10"/>
<line id="rod" x1="280" y1="180" x2="580" y2="180" stroke="#4a4" stroke-width="8"/>
<line id="tiller" x1="580" y1="180" x2="680" y2="180" stroke="#36c" stroke-width="10"/>
<text x="155" y="315" fill="#111">servo</text><text x="535" y="315" fill="#111">rudder pivot</text>
</svg>
<script>
const frames = __FRAMES__;
let i=0, timer;
function render(){const f=frames[i], a=f.servo, b=f.rudder; const sy=180-100*Math.sin(a), sx=180+100*Math.cos(a); const ty=180-100*Math.sin(b), tx=580+100*Math.cos(b); document.querySelector('#horn').setAttribute('x2',sx); document.querySelector('#horn').setAttribute('y2',sy); document.querySelector('#rod').setAttribute('x1',sx); document.querySelector('#rod').setAttribute('y1',sy); document.querySelector('#rod').setAttribute('x2',tx); document.querySelector('#rod').setAttribute('y2',ty); document.querySelector('#tiller').setAttribute('x2',tx); document.querySelector('#tiller').setAttribute('y2',ty); document.querySelector('#value').textContent=` command=${f.command.toFixed(3)} rad, servo=${a.toFixed(3)} rad, rudder=${b.toFixed(3)} rad, torque=${f.torque.toFixed(6)} Nm`;}
document.querySelector('#play').onclick=()=>{clearInterval(timer); timer=setInterval(()=>{render(); i=(i+1)%frames.length},700)}; render();
</script>
""".replace("__FRAMES__", json.dumps(frames))
out_path.write_text(html)
print(out_path)