Skip to main content

VNH5019Controller Python Library

This library provides the Controller class to generate valid messages and communicate with the motor controller via either I2C or USB. Before any commands can be sent, the functions init_serial() or init_i2c() must be called. The constants CHANNEL_1, CHANNEL_2, and BOTH are passed to Controller.write_speed() and Controller.write_brake() to select the appropriate channel.

Installation

pip install VNH5019-Serial-Controller

Classes:

Controller

A class for writing to the VNH5019 Motor Controller via either I2C or USB.

Constants:

CHANNEL_1

CHANNEL_2

BOTH

Functions:

init_serial( port_name )

Initialize a serial port for communication with the motor controller.

port_name

Type: string

The name of the serial port to communicate over.

Returns

Type: None

init_i2c( pre_existing_bus=None )

Initialize the serial bus for communication.

pre_existing_bus

Type: SMBus

Default: None

A pre-existing I2C bus if it exists.

Returns

Type: None

Controller Methods

write_speed( channel, value )

Write a speed value between -100 (full reverse) to 100 (full forward) to one or both channels.

channel

Type: int

The channel whose speed we want to set. Must be one of CHANNEL_1, CHANNEL_2, or BOTH.

value

Type: int

The speed we want to set between -100 to 100.

Returns

Type: None

write_brake( channel, value )

Write a brake value between 0 (coast) to 100 (max brake) to one or both channels.

channel

Type: int

The channel whose speed we want to set. Must be one of CHANNEL_1, CHANNEL_2, or BOTH.

value

Type: int

The brake we want to set between 0 to 100.

Returns

Type: None

write_mixed_command( speed_val, turn_val )

Write a mixed command to the motor controller.

speed_val

Type: int

The speed we want to write between -100 (full reverse) to 100 (full forward).

turn_val

Type: int

The turn value we want to write between -100 (max left) to 100 (max right).

Returns

Type: None

stop()

Stop both motors by applying max brakes.

Returns

Type: None

set_active()

Put the motor controller into an active state.

Returns

Type: None

set_standby()

Put the motor controller into standby.

Returns

Type: None

Example

import VNH5019Controller
from time import sleep
from sys import argv

controller = VNH5019Controller.Controller()


def setup():
    print("Setting Up...")
    VNH5019Controller.init_serial(argv[1])
    sleep(5)
    controller.set_active()
    sleep(2)
    print("Ready!")


def loop():
    while True:
        # Drive Forward
        print("Forward")
        controller.write_speed(VNH5019Controller.BOTH, 100)
        sleep(1)
        controller.stop()
        sleep(1)

        # Drive Backward
        print("Backward")
        controller.write_speed(VNH5019Controller.BOTH, -100)
        sleep(1)
        controller.stop()
        sleep(1)

        # Turn Left Forward
        print("Forward Left")
        controller.write_mixed_command(100, -50)
        sleep(1)
        controller.stop()
        sleep(1)

        # Turn Right Forward
        print("Forward Right")
        controller.write_mixed_command(100, 50)
        sleep(1)
        controller.stop()
        sleep(1)

        # Turn Left Backward
        print("Backward Left")
        controller.write_mixed_command(-100, -50)
        sleep(1)
        controller.stop()
        sleep(1)

        # Turn Right Backward
        print("Backward Right")
        controller.write_mixed_command(-100, 50)
        sleep(1)
        controller.stop()
        sleep(1)

        # Enter Standby
        print("Entering Standby...")
        controller.set_standby()
        sleep(5)

        # Enter Active
        print("Entering Active...")
        controller.set_active()
        sleep(2)


def main():
    setup()
    loop()


if __name__ == '__main__':
    main()

Metadata

Release files for VNH5019-Serial-Controller 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for VNH5019-Serial-Controller 0.0.2
File Size Uploaded Provenance
VNH5019_Serial_Controller-0.0.2.tar.gz 4.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for VNH5019-Serial-Controller 0.0.2
File Interpreter ABI Platform
VNH5019_Serial_Controller-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.2 kB

Release files / VNH5019_Serial_Controller-0.0.2.tar.gz

Download URL VNH5019_Serial_Controller-0.0.2.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
511a093ae94666a6e09a97aa2552031a896d62ebd36d6df1737d21cb68ff085d
BLAKE2b-256 checksum
How to use checksums
5dfa3b2f64e619220a2e8599cc8eb1cc89572eda2b209be0c390aedfbc99a339
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.3

Release files / VNH5019_Serial_Controller-0.0.2-py3-none-any.whl

Download URL VNH5019_Serial_Controller-0.0.2-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1094a709ec7e449bfe2c57f005f18540d274a2a6019ff1fadea8b79dcf988abd
BLAKE2b-256 checksum
How to use checksums
3eaa6900ef562e4f5403c93090f782ba06a7bd72860a98e753dbe69ae7caf5d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.3

Security for VNH5019-Serial-Controller 0.0.2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page