Skip to main content

A library for controlling a Pololu VNH5019 Motor Controller Shield via USB Serial and I2C.

Project description

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()

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

VNH5019_Serial_Controller-0.0.2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

VNH5019_Serial_Controller-0.0.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file VNH5019_Serial_Controller-0.0.2.tar.gz.

File metadata

  • Download URL: VNH5019_Serial_Controller-0.0.2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for VNH5019_Serial_Controller-0.0.2.tar.gz
Algorithm Hash digest
SHA256 511a093ae94666a6e09a97aa2552031a896d62ebd36d6df1737d21cb68ff085d
MD5 24f2dc74a61ec37b8760c1cf4c546cca
BLAKE2b-256 5dfa3b2f64e619220a2e8599cc8eb1cc89572eda2b209be0c390aedfbc99a339

See more details on using hashes here.

File details

Details for the file VNH5019_Serial_Controller-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: VNH5019_Serial_Controller-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for VNH5019_Serial_Controller-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1094a709ec7e449bfe2c57f005f18540d274a2a6019ff1fadea8b79dcf988abd
MD5 0a902503087a12078f4ab798e4a48dd0
BLAKE2b-256 3eaa6900ef562e4f5403c93090f782ba06a7bd72860a98e753dbe69ae7caf5d6

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