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 ⛵
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:
-
Clone the repository:
git clone https://github.com/lucasmrdt/sailboat-gym.git cd sailboat-gym
-
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 sail_gym
env = gym.make('SailboatLSAEnv-v0', renderer=sail_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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sailboat-gym-1.0.0.tar.gz.
File metadata
- Download URL: sailboat-gym-1.0.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50ce7d6b9502d44e45237c216f9d426873e9c65691b037c942cbb46da9d4930a
|
|
| MD5 |
8ed661511d7437d7a1b94b44a7553149
|
|
| BLAKE2b-256 |
072d6e2ae9395308918db912c99259c289fb5867d7b9a7b72b12fdf32d4ec10f
|
File details
Details for the file sailboat_gym-1.0.0-py3-none-any.whl.
File metadata
- Download URL: sailboat_gym-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58fa6a4602722f7c86ab49f8d28cf60921ec7cf228965fca39d33bcb4f8352dd
|
|
| MD5 |
7ea5a7480b7b913ce6bd207195ab614b
|
|
| BLAKE2b-256 |
25d7bd572ab12dbe52025e619f498050d91444e02f1c80a343282c0c6f9bc799
|