Read the latest Real Python tutorials
Project description
Pydrodynamics
Pydrodynamics (Python Hydrodynamics) is a simple Python package for simulating 6DOF rigid body dynamics with a focus on Remotely Operated Vehicles (ROVs) or Autonomous Underwater Vehicles (AUVs) using thrusters.
The reason behind this package is to provide a simple but powerful way to calculate the motion of an underwater vehicle when subjected to both thruster (control) forces and environmental forces (like buoyancy and drag).
It was built to support the development of a custom underwater vehicle simulator for the RoboSub competition, with Reinforcement Learning (RL) used for both the control system and mission planning.
Overview of Classes
vehicle.py: The main class that represents the vehicle. It ties the other classes together and is the main interface for the user to simulate the vehicle's motion.thrusters.py: Based on PWMs given, calculates the total forces and moments generated by the thrusters on the vehicle. It uses a CSV file to look up thrust values based on PWM and voltage.environment.py: This class calculates the forces acting on the vehicle due to the external environment, such as buoyancy, gravity, drag, added mass, and Coriolis forces.dynamics.py: Given the external forces acting on the vehicle, this class calculates the next state of the vehicle using the equations of motion formulated by Fossen.params.py: Imports the vehicle configuration from the provided YAML file and provides utility functions to access deeply nested parameters.utils.py: Contains type definitions and shared functions such as calculating the rotation matrix to convert from body to world, unpacking the state object, etc.
Getting Started
Install the package using pip:
pip install pydrodynamics
Create a new Python file and import the necessary classes:
from pydrodynamics import Vehicle, State
# Provide the path to the vehicle configuration file
path_to_vehicle_config = "path/to/vehicle_config.yaml"
# Optional: Define the initial state of the vehicle
optional_initial_state = State(
position=Position(0, 0, 0),
orientation=Orientation(0, 0, 0),
linear_velocity=LinearVelocity(0, 0, 0),
angular_velocity=AngularVelocity(0, 0, 0),
voltage=16.8,
)
# Create a new Vehicle object
auv = Vehicle(path_to_vehicle_config)
In the main loop, call the step function and pass delta time (time passed) with thruster PWM values to obtain the next state of the vehicle:
# Call the step function to simulate the vehicle's motion at every time step
thruster_pwm = [1900, 1601, 1601, 1100, 1900, 1601, 1601, 1100]
next_state = auv.step(dt, thruster_pwm)
Make sure to provide a valid path to the vehicle configuration file. The configuration file should be in YAML format and contain the following information:
name: 'New Vehicle'
env:
gravity: 9.81
density: 1000
physical:
mass: 0.0
# Total fluid volume occupied by the vehicle, used for buoyant force
volume: 0.0
# Center of mass from origin coordinate
com:
x: 0.0
y: 0.0
z: 0.0
# Center of buoyancy from origin coordinate
cob:
x: 0.0
y: 0.0
z: 0.0
# Inertia matrix, assuming off diagonal elements are 0
inertia:
x: 0.0
y: 0.0
z: 0.0
# Projected area of the vehicle in x, y, z directions
projected_area:
x: 0.0
y: 0.0
z: 0.0
# Drag coefficients
drag:
x:
# Drag coefficient in x direction when subjected to surge velocity in x axis (u)
u: 0.0
v: 0.0
w: 0.0
p: 0.0
q: 0.0
r: 0.0
y:
...
z:
...
k:
...
m:
...
n:
...
# Added mass coefficients (unused for now)
added_mass:
x:
u: 0.0
v: 0.0
w: 0.0
p: 0.0
q: 0.0
r: 0.0
y:
...
z:
...
k:
...
m:
...
n:
...
# Will be changing soon to accomodate for simulation of voltage drop and draining battery
electrical:
voltage: 0.0
capacity: 0.0
thrusters:
# Path to the thruster data file, containing thrust at each voltage and PWM
data: 'thruster_data.csv'
# List of thrusters on board
list:
- name: thruster1
# Position of the thruster relative to the center of mass (COM)
pos:
x: 0.0
y: 0.0
z: 0.0
# Direction of the thruster, will be normalized later
dir:
x: 0.0
y: 0.0
z: 0.0
Building the Package
To build the package for local development, you can use the following command:
python -m pip install -e .
Future Work
- Implement added mass and coriolis forces
- Simulate draining battery and voltage drop
References
This work is mostly based on the work done by Thor I. Fossen in his model for marine vehicles.
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 pydrodynamics-1.0.0.tar.gz.
File metadata
- Download URL: pydrodynamics-1.0.0.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3ac6ff939db61cf51158337d764c767cdc2be2684f3ac9a009c574d4dc2a2f2
|
|
| MD5 |
1053f19161dba667e4e606609e06eccb
|
|
| BLAKE2b-256 |
295199be447df6fab8fadf7e74b35aaee8be59e6b7be9dfff9c44db15030f35c
|
File details
Details for the file pydrodynamics-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pydrodynamics-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8a6ade19d1015d1ee26ca88207b316760213dc5d4d22953df0f6936bb57086e
|
|
| MD5 |
8963933c9295ef93288bcc570347e786
|
|
| BLAKE2b-256 |
f8e7a2223676cf8467fe60c51b4c33ee2a5720e13e0ef39b05b5fc0048151e5a
|