Skip to main content

🐍 | motorgo-python | 🐍

Python API for controlling PiHat-compatible MotorGo boards from the Raspberry Pi.


Introduction

motorgo-python provides a Python API to control a MotorGo when it is mounted to a Raspberry Pi as a PiHat. It enables you to control the motor channels and stream the enocder and IMU data from the MotorGo. This package also includes a motorgo command line utility (CLI) that lets you configure settings on the MotorGo and perform basic operations without the need for code.

Please follow our setup guide at (our docs)[https://docs.motorgo.net].

Supported Boards

Currently, motorgo-python only supports the Plink. Support for the Axis is on the way!

Installation

You can install motorgo-python using pip.

pip install motorgo-python

If you are using Python 3.12 or greater, you may need to use the --break-system-packages argument. motorgo-python cannot be installed in a virtual env as it needs access to

Next, you need to configure the MotorGo to be used in PiHat mode, which can be done using the included CLI. Attach the MotorGo to the 40-pin Pi header and run the command:

motorgo flash

Usage

Below is an example program that demonstrates how to use the pyplink package to control motor channels on the MotorGo Plink board.

This example, and others, can be found in the examples/ directory of this repository.

# spin_motors.py
# Before running this script, ensure that the MotorGo Plink is
# connected to the Raspberry Pi and that it has been flashed with the
# MotorGo firmware.

import time

from motorgo import BrakeMode, ControlMode, Plink


def main():
    # Create a Plink object, the main interface to the MotorGo board
    plink = Plink()

    # The first thing to set up for a Plink is the power supply voltage.
    # This is the voltage you are providing to the Plink on the barrel jack.
    # If this is the battery, make sure this is the charged voltage.
    plink.power_supply_voltage = 9.0

    # The Plink object has 4 MotorChannel objects, corresponding to the 4 motor channels
    # on the board
    # You can access them directly: plink.channel1
    # Or you can save references as local variables for convenience:
    left_motor = plink.channel1
    right_motor = plink.channel2

    # Next, you need to set the motor voltage limit.
    # This is the maximum voltage your motor channels will output to protect the motors.
    # The voltage limit is 0 by default, which means the motors will not move if this is not set.
    left_motor.motor_voltage_limit = 6.0
    right_motor.motor_voltage_limit = 6.0
    plink.channel3.motor_voltage_limit = 6.0
    plink.channel4.motor_voltage_limit = 6.0

    # Finally, connect to the MotorGo board and psuh the configuration
    plink.connect()

    # You can configure how you want to control the motor channels.
    # Power mode: Set the power of the motor in the range [-1, 1]
    #            This directly corresponds to setting a voltage to the motor
    #
    # Velocity mode: Set the velocity of the motor in rad/s
    #              This mode requires setting the velocity PID gains
    #              It also requires an encoder to be connected to the motor
    left_motor.control_mode = ControlMode.POWER
    right_motor.control_mode = ControlMode.VELOCITY
    plink.channel3.control_mode = ControlMode.POWER
    plink.channel4.control_mode = ControlMode.POWER

    # If you are using ControlMode.VELOCITY, you must set the velocity PID gains
    right_motor.set_velocity_pid_gains(4.5, 0.1, 0.0)

    while True:

        # Set motor powers
        # Set the power command in the range [-1, 1]
        left_motor.power_command = 0.5

        # Set the velocity command in rad/s
        right_motor.velocity_command = 1.2

        # Set the power command in the range [-1, 1]
        plink.channel3.power_command = 0.25
        plink.channel4.power_command = -0.25

        # You can read the position and velocity of the motor channels from the encoders
        print("----")
        print(
            f"Channel 1 position: {plink.channel1.position}, velocity: {plink.channel1.velocity}"
        )
        print(
            f"Channel 2 position: {plink.channel2.position}, velocity: {plink.channel2.velocity}"
        )
        print(
            f"Channel 3 position: {plink.channel3.position}, velocity: {plink.channel3.velocity}"
        )
        print(
            f"Channel 4 position: {plink.channel4.position}, velocity: {plink.channel4.velocity}"
        )
        print("----")

        time.sleep(0.01)


if __name__ == "__main__":
    main()

Metadata

Release files for motorgo-python 0.1.0

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

Source distribution (sdist)

Source distribution for motorgo-python 0.1.0
File Size Uploaded Provenance Actions
motorgo_python-0.1.0.tar.gz 17.4 kB Without provenance Details for motorgo_python-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for motorgo-python 0.1.0
File Interpreter ABI Platform Actions
motorgo_python-0.1.0-py3-none-any.whl Python 3 none any Details for motorgo_python-0.1.0-py3-none-any.whl

Total release size: 37.9 kB

Release files / motorgo_python-0.1.0.tar.gz

Download URL motorgo_python-0.1.0.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e39057aeef7c4cb49a7df59db807ad9c0d022ff13972f0ec4e68c7eb9505687d
BLAKE2b-256 checksum
How to use checksums
d27b861279d108388055f1aa9aa764a17ca6b5dbfae8be2ecf7d00f404e47c7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / motorgo_python-0.1.0-py3-none-any.whl

Download URL motorgo_python-0.1.0-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
802788b45bd89b152449064d31d7d18d8649026a2b0933c501e1025734c045e0
BLAKE2b-256 checksum
How to use checksums
e2b35c74ca92fd84780cfe9cb0e149b9a170daa424e1f1e9cc58172651326037
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Security for motorgo-python 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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