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.2.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.2-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sailboat-gym-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 549ab15558eb6a6a9c564721d3f52e2b7cb08357dcc9221d59c2f495eae27f3c
MD5 a64a1b10d33c8c45bd16dbf0de214f86
BLAKE2b-256 b767fd18221c06210252849ec4c86dbcfebf4da0090a969227aae04f6dfa9301

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sailboat_gym-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0920d3f275c4bb17903a6e770ac89af423648582a0b4a42aed01be8d53a0e9a4
MD5 c215fc73de89c7d2201284539c866c61
BLAKE2b-256 e6f5aeeee32d58fc355f2dff8ddc999862c4ca2afe6d0d122c502890d7b9b841

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