gym-sailing: A sailing environment for OpenAI Gym / Gymnasium
This is a Gymnasium (OpenAI Gym) environment designed to train reinforcement learning (RL) agents to control a sailboat. The environment simulates the dynamics of a sailboat and allows the agent to learn tacking behavior to reach a target point.
Environments
| Environment | Description |
|---|---|
| Sailboat-v0 | The main environment with a continuous action space. |
| SailboatDiscrete-v0 | A variation of the environment with a discrete action space. |
| Motorboat-v0 | An easy test environment with a motorboat instead of a sailboat. |
Installation
You can install the latest release using pip:
pip install gym-sailing
Alternatively, if you prefer, you can clone the repository and install it locally.
Usage
Basic Usage
Bare minimum code to run the environment:
import gymnasium as gym
import gym_sailing
env = gym.make("Sailboat-v0", render_mode="human")
observation, info = env.reset(seed=42)
for _ in range(1000):
action = env.action_space.sample() # this is where you would insert your policy
observation, reward, terminated, truncated, info = env.step(action)
if terminated or truncated:
observation, info = env.reset()
env.close()
Training an RL Agent
To train an RL agent using stable-baselines3:
from stable_baselines3 import PPO
import gymnasium as gym
import gym_sailing
env = gym.make("Sailboat-v0")
model = PPO('MlpPolicy', env, verbose=1)
# Train the agent
model.learn(total_timesteps=1_000_000)
# Test the trained model
observation, info = env.reset()
for _ in range(1000):
action, _ = model.predict(observation)
observation, reward, terminated, truncated, info = env.step(action)
env.close()
Environment Details
Observation Space
The observation space includes:
- Boat Speed: The current speed of the boat.
- Boat Heading: The angle of the boat relative to the wind, ranging from -$\pi$ to $\pi$.
- Heading Rate: The rate of change of the boat's heading.
- Course to Target: The angle between the boat's heading and the target, ranging from -$\pi$ to $\pi$.
- Distance to Target: The normalized distance between the boat and the target.
Action Space
The action space consists of:
- Rudder Angle: The angle of the rudder, ranging from -1 to 1 for Sailboat-v0 and Motorboat-v0, and {-1, 0, 1} for SailboatDiscrete-v0.
Reward
The default reward function includes:
- Alive Penalty: A penalty for each time step to encourage the agent to reach the target quickly.
- Target Reward: A reward for reaching the target.
- Course Penalty: A penalty for leaving the course area.
- Progress Reward: A reward for making progress towards the target, using the L8 norm, to encourage the agent to move upwind.
Episode End
- The environment is terminated if the boat reaches the target or leaves the course area.
- The environment is truncated after 3000 steps.
Benchmarks
Benchmarks using stable-baselines3 with default hyperparameters. Good policies that tack only once tend to achieve ~390 total reward for the sailboat environment. PPO seems to perform better, but SAC is also a good option, that even converging faster.
Contributing
Contributions are welcome. Please fork the repository and submit a pull request with your changes. For any questions or suggestions, feel free to open an issue.
Future Work
Here are some features I'd like to add in the future:
- Add currents of different intensities and directions.
- Add wind shifts.
- Add wind gusts and lulls.
- Make the polar diagram more accurate, using the data from this paper: R. Binns, F. W. Bethwaite, and N. R. Saunders, “Development of A More Realistic Sailing Simulator,” High Performance Yacht Design Conference. RINA, pp. 243–250, Dec. 04, 2002. doi: 10.3940/rina.ya.2002.29.
Inspiration
This project was inspired by this fork: https://github.com/openai/gym/compare/master...JonAsbury:gym:Sailing-Simulator-Env
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for gym-sailing 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gym_sailing-0.2.1.tar.gz | 923.6 kB | Without provenance | Details for gym_sailing-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gym_sailing-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for gym_sailing-0.2.1-py3-none-any.whl |
Total release size: 946.7 kB
Release files / gym_sailing-0.2.1.tar.gz
| Download URL | gym_sailing-0.2.1.tar.gz |
|---|---|
| Size | 923.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
67938c3e3df52580351b79fcf82c6131f2b078c6d14d50bfaa63e8ccd58fe568
|
|
BLAKE2b-256 checksum How to use checksums |
c7572527aac22527e0d0823ac9a5c4be22d9a52f5ded5671fb3ef50ba2565c79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.4
|
Release files / gym_sailing-0.2.1-py3-none-any.whl
| Download URL | gym_sailing-0.2.1-py3-none-any.whl |
|---|---|
| Size | 23.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4f49dc4180c54c7fc92837ae6fd5e1e15b32867a0cee3f0a47054891dc5cb397
|
|
BLAKE2b-256 checksum How to use checksums |
deb6b50efc6670694a41580f1bf04416d22f86ae71b4c8e103492659c4e544e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.4
|
Security for gym-sailing 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.