Skip to main content

A library to make coding AUVs easier

Project description

ezauv

ezauv is a Python library to make AUVs, or autonomous underwater vehicles, easy. This library was created for BVR AUV, Beaver Country Day School's RoboSub team.

Why?

In the yearly RoboSub competition, teams build autonomous submarines. Much of the code of these submarine can be abstracted into a few basic concepts: tasks, like travelling a vector or circling a buoy; subtasks, like holding heading or depth; and sensors, such as IMUs and depth sensors. ezauv provides an easy interface for all of these pieces of code to simplify their creation. More importantly, ezauv solves the motors needed to travel a specific vector and rotation under the hood, regardless of the thrust vectors or locations of the motors and the sub's overall dimensions. This allows the code for one hardware surface to be ported to another with almost no change to the code. ezauv also allows for arbitrary polynomial pwm-to-thrust motor curves.

ezauv also provides interfaces for logging data to file, building the inertia tensor of your sub from a set of geometries, and some simple tasks and subtasks such as accelerating in a direction or using a PID on rotation.

Installation

  • Make sure pip is installed and working
  • Check your Python version; ezauv is built for Python 3.11, but will likely work on most versions >3
  • Run the following command with pip:
pip install ezauv

For developer information, read the wiki.

Example Program

This example creates a simulation with a square hovercraft, moves it forward, moves it backwards, and then spins it.

import numpy as np

from ezauv.auv import AUV
from ezauv.hardware import MotorController, Motor, SensorInterface
from ezauv.utils.inertia import InertiaBuilder, Cuboid
from ezauv.mission.tasks.main import AccelerateVector
from ezauv.mission.tasks.subtasks import HeadingPID, Simulate
from ezauv.mission import Path
from ezauv.simulation.core import Simulation
from ezauv import AccelerationState, TotalAccelerationState

motor_locations = [
    np.array([-1., 1., 0.]),    # motor 2
    np.array([-1., -1., 0.]),   # motor 3
    np.array([1., 1., 0.]),     # motor 4
    np.array([1., -1., 0.]),    # motor 5
]

motor_directions = [
    np.array([1., 1., 0.]),     # motor 2
    np.array([1., -1., 0.]),    # motor 3
    np.array([1., -1., 0.]),    # motor 4
    np.array([1., 1., 0.]),     # motor 5
]   # this debug motor configuration is the same as bvr auv's hovercraft


bounds = [[-0.9, 0.9]] * 4 # motors can't go outside of (-90%, 90%)...
deadzone = [[-0.1, 0.1]] * 4 # or inside (-10%, 10%), unless they equal 0 exactly

degrees = [
    -0.01,
    0.4,
    -0.4,
    1.4
]   # this defines our motor's pwm -> thrust curve as t = -0.01 + 0.4p - 0.4p^2 + 1.4p^3


sim = Simulation(motor_locations, motor_directions, bounds, deadzone, degrees)

sim_anchovy = AUV(
    motor_controller = MotorController(
        inertia = InertiaBuilder(
            Cuboid(
                mass=1,
                width=1,
                height=1,
                depth=0.1,
                center=np.array([0,0,0])
            )).moment_of_inertia(), # the moment of inertia helps with rotation

            motors = [
                Motor(
                    direction,
                    loc,
                    sim.set_motor(i),
                    lambda: 0,
                    Motor.Range(bounds[i][0], bounds[i][1]),
                    Motor.Range(deadzone[i][0], deadzone[i][1])
                    )
                for i, (loc, direction) in enumerate(zip(motor_locations, motor_directions))
                ],
            coefficients = degrees
        ),
        sensors = SensorInterface(sensors=[sim.imu(0.05)]),
        lock_to_yaw = False,
        clock = sim.clock(),
    )

sim_anchovy.register_subtask(Simulate(sim)) # gotta make sure it knows to simulate the sub

mission = Path(
    AccelerateVector(AccelerationState(Tx=1, local=False), 3),      # start by going right locally,
    AccelerateVector(AccelerationState(Tx=-1, local=False), 3),     # then slow down by going left locally,
    AccelerateVector(AccelerationState(Rz=-20, local=False), 5),    # then spin really fast,
    AccelerateVector(AccelerationState(Tx=-2, local=False), 5),    # then go left globally, while spinning
)

sim_anchovy.travel_path(mission)

sim.render() # this draws an animation using pygame; you can see it in videos/animation.mp4

Important Note

  • Currently, the library uses Gurobi. It installs a free license using gurobipy, but eventually it expires and either an academic or (very expensive) commerical license must be used. Eventually, this will be replaced with an open-source solver.

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

ezauv-0.1.9.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

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

ezauv-0.1.9-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file ezauv-0.1.9.tar.gz.

File metadata

  • Download URL: ezauv-0.1.9.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for ezauv-0.1.9.tar.gz
Algorithm Hash digest
SHA256 cb56dcfd4186e4eb03541b2212c73c5ed6152e5e3b1d249e124698b84f195fb5
MD5 555e587d11a5aa1494ce4850480dff72
BLAKE2b-256 c0f162be8ab3a73a3eda9f015b10bec58b672cf3b6b7d22a647aee36690a768c

See more details on using hashes here.

File details

Details for the file ezauv-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: ezauv-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for ezauv-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 a93cb4de9793f8edc18b998b2fbf11e1dbe7726ba0d4fa9f16310ed5e3eae19e
MD5 de4509c8cd66941c32fc98d467ed9115
BLAKE2b-256 eca42812effa98bcf54ac5f5739b7bd66c607da6b55adae5340f20a2138f9016

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