Skip to content

RISE-Maritime/sail_wing_fmu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sail Wing FMU

A Functional Mock-up Unit (FMU) implementation for a rigid wing sail, compatible with FMI 3.0 standard. This FMU models the aerodynamic behavior and actuator dynamics of a sail wing and is designed to be integrated into a larger sail wing control system.

Features

  • FMI 3.0 Compliant: Co-simulation FMU with standard FMI interface
  • Aerodynamic Modeling: 2D rigid wing model with bilinear interpolated Cx/Cy coefficients
  • Actuator Dynamics: Rate-limited boom and flap control with position limits
  • Cross-Platform: Supports Linux and Windows (x86_64)
  • Rust Implementation: Using fmu_from_struct macro for automatic FMU generation
  • Comprehensive Testing: Unit tests and visualization tools for force and coefficient analysis

Model Parameters, Inputs, and Outputs

Parameters

  • wing_length_m (m): Wing span length
  • wing_chord_m (m): Wing chord length
  • boom_speed_deg_per_s (deg/s): Maximum boom rotation rate
  • flap_speed_deg_per_s (deg/s): Maximum flap deflection rate

Inputs

  • apparent_wind_speed_ms (m/s): Wind speed relative to the wing
  • apparent_wind_angle_rad (rad): Wind direction relative to the wing
  • boom_angle_order_rad (rad): Commanded boom angle
  • flap_angle_order_rad (rad): Commanded flap deflection angle

Outputs

  • boom_angle_rad (rad): Actual boom angle
  • flap_angle_rad (rad): Actual flap deflection angle
  • force_x_N (N): Aerodynamic force in X direction (body frame)
  • force_y_N (N): Aerodynamic force in Y direction (body frame)
  • force_z_N (N): Aerodynamic force in Z direction (body frame, always 0)

Building

Standard Build

cargo build --release

FMU Generation

Generate cross-compiled FMU for Linux and Windows:

./build_fmu.sh

Output: dist/SailWing.fmu

Testing

# Run all tests
cargo test

# Run specific test
cargo test test_sail_wing_do_step

# Generate aerodynamic coefficient plots (Cx/Cy vs. angle of attack)
cargo test test_aero_database_raw_plots -- --nocapture

# Generate force analysis plots (Forces vs. boom angle for different flap angles)
cargo test test_force_analysis_plots -- --nocapture

Test plots are saved to tests/output/:

  • raw_cx_coefficient_plot.png: Cx coefficients vs. angle of attack
  • raw_cy_coefficient_plot.png: Cy coefficients vs. angle of attack
  • force_fx_analysis.png: X-forces vs. boom angle
  • force_fy_analysis.png: Y-forces vs. boom angle

Python Simulation

A simple Python test script is available for testing the generated FMU:

# Run simple simulation test (requires fmpy)
python tests/simple_simulation.py

Model Physics

Aerodynamic Database

The aerodynamic coefficients are hardcoded in src/aerodatabase.rs with data for:

  • Flap angles: 0°, 10°, 20°, 30°
  • Angle of attack: 0° to 360° (varying resolution)
  • Coefficients: Cx (chord-aligned) and Cy (perpendicular to chord)

The database uses bilinear interpolation for intermediate values with proper wrapping at 360°/0°.

Coordinate Systems

  • Wing coordinates: X along chord, Y perpendicular to chord
  • Body coordinates: X forward, Y starboard
  • Forces are transformed from wing to body frame using the boom angle

Actuator Dynamics

  • Boom: Unlimited rotation (wraps at 360°), rate-limited by boom_speed_deg_per_s
  • Flap: Limited to ±30° (max defined in aerodynamic database), rate-limited by flap_speed_deg_per_s
  • Both actuators use simple rate limiting with position clamping

Project Structure

.
├── src/
│   ├── lib.rs              # Main FMU struct and physics implementation
│   └── aerodatabase.rs     # Aerodynamic coefficient database and interpolation
├── tests/
│   ├── integration_tests.rs    # Comprehensive test suite
│   └── simple_simulation.py    # Python FMU validation script
├── build_fmu.sh            # Cross-compilation script for FMU generation
├── Cargo.toml              # Rust dependencies and build configuration
└── README.md               # This file

Dependencies

Runtime

  • fmu_from_struct: FMU macro generation for Rust structs
  • serde, serde_json: Serialization support (for future config file support)

Development

  • more-asserts: Enhanced test assertions
  • plotters: Plot generation for analysis and visualization
  • cross: Cross-compilation for Linux and Windows targets

License

See LICENSE.txt for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages