Skip to main content

Dynamic simulation environment for sailboats. With Sailboat Gym, you can explore and experiment with different control algorithms and strategies in a realistic virtual sailing environment.

Project description

Sailboat Gym ⛵

demo

Welcome to Sailboat Gym! This repository provides a dynamic simulation environment specifically designed for sailboats. With Sailboat Gym, you can explore and experiment with different control algorithms and strategies in a realistic virtual sailing environment.

Table of Contents

Installation (Docker Needed)

Pre-requirement: Please make sure you have Docker installed and running on your machine.

To install and set up Sailboat Gym, follow these steps:

  1. Clone the repository:

    git clone https://github.com/lucasmrdt/sailboat-gym.git
    cd sailboat-gym
    
  2. Install the required dependencies:

    pip install -r requirements.txt
    

Usage

To run a simple example in Sailboat Gym, use the following command:

python3 example.py

Alternatively, you can use the following code snippet in your Python script:

import gymnasium as gym
from gymnasium.wrappers.record_video import RecordVideo
import sailboat_gym

env = gym.make('SailboatLSAEnv-v0', renderer=sailboat_gym.CV2DRenderer())
env = RecordVideo(env, video_folder='./output/videos/')

env.reset(seed=10)

while True:
    act = env.action_space.sample()
    obs, reward, terminated, truncated, info = env.step(act)
    if truncated:
        break
    env.render()

env.close()

This example demonstrates how to create an instance of the SailboatLSAEnv environment and record a video of the simulation.

Environment

Description

The Sailboat Gym simulation is conducted using the Gazebo simulator and implemented through the usv_sim_lsa project, encapsulated inside a Docker. The Docker images/containers are handled automatically by the environment, so you don't have to worry about them.

The simulation incorporates various forces, such as hydrodynamic, hydrostatic, wind, wave, and thruster forces, using an enhanced version of the Free-Floating Plugin. Additionally, it incorporates lift and drag forces acting on the boat's rudder, keel, and/or sail through the Foil Dynamics Plugin. For more detailed information about the simulation, please consult the original paper.

Limitations

The current Docker version of the simulation does not include wave simulations. The calculation of waves relies on the UWSim Plugin, which heavily depends on OpenSceneGraph. By default, OpenSceneGraph requires creating a window and rendering the scene, making it challenging to run within a Docker container. Nevertheless, we are actively working on finding a solution to this issue.

Observation Space

sailing_schema

The sailboat's state is described by the following variables:

  • p_boat / $\mathbf{p}_{\text{boat}}$ (position of the boat in the world frame, 3D vector)
  • dt_p_boat / $\dot{\mathbf{p}}_{\text{boat}}$ (velocity of the boat in the world frame, 3D vector)
  • theta_boat / $\boldsymbol{\theta}_{\text{boat}}$ (orientation of the boat in the world frame - roll, pitch, and yaw)
  • dt_theta_boat / $\dot{\boldsymbol{\theta}}_{\text{boat}}$ (relative angular velocity of the boat)
  • theta_rudder / $\theta_{\text{rudder}}$ (relative orientation of the rudder)
  • dt_theta_rudder / $\dot{\theta}_{\text{rudder}}$ (relative angular velocity of the rudder)
  • theta_sail / $\theta_{\text{sail}}$ (relative orientation of the sail)
  • dt_theta_sail / $\dot{\theta}_{\text{sail}}$ (relative angular velocity of the sail)
  • wind / $\mathbf{wind}$ (wind velocity in the world frame - x and y components)

Action Space

The sailboat's action is described by the following variables:

  • theta_rudder / $\theta_{\text{rudder}}$ (relative orientation of the rudder)
  • theta_sail / $\theta_{\text{sail}}$ (relative orientation of the sail)

Reward Function

You are responsible for defining the reward function based on the specific task you aim to accomplish. The reward function takes the current state and the action taken by the agent as input and returns a scalar value. For example, the following reward function returns the negative distance between the boat and the goal:

goal = np.array([0, 0, 0])

def reward_fn(state, action):
    return -np.linalg.norm(state['p_boat'] - goal)

Rendering

Currently, Sailboat Gym provides 2D rendering of the simulation. The rendering is done using the CV2DRenderer class, which utilizes the OpenCV library to render the simulation based on the observation. It may be possible to implement 3D rendering using libraries such as Open3D, but this feature has not been implemented yet.

Documentation

For detailed information on the API, usage examples, and customization options, please refer to our documentation.

Contributing

We welcome contributions to Sailboat Gym. Please refer to our contributing guidelines for more information.

License

Sailboat Gym is released under the MIT License. You are free to use, modify, and distribute this software for both commercial and non-commercial purposes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sailboat-gym-1.0.1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sailboat_gym-1.0.1-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file sailboat-gym-1.0.1.tar.gz.

File metadata

  • Download URL: sailboat-gym-1.0.1.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for sailboat-gym-1.0.1.tar.gz
Algorithm Hash digest
SHA256 03ba1a05bfa22fd6de152b133c6f1099ee8baabeb8924e4a98e201aa7c713074
MD5 789c477689b77696a6d4d80000a61a6b
BLAKE2b-256 e27cdaf5df1317b498f399726690f72b9df88a563215c7071035d03abdc754e3

See more details on using hashes here.

File details

Details for the file sailboat_gym-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: sailboat_gym-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for sailboat_gym-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e4414927c773b048d1d7d373db02da3737b17242986c037ebe7db517f3db7076
MD5 6cea07b59ea03af18ab156755edfce48
BLAKE2b-256 92ecb22c93db505ef0c69162e0287040a878e72d375411a5b848ea0bdd69f17d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page