Skip to main content

Command ODrive 3.6 over CAN with a simple interface

Project description

Asyncio driver for ODrive

Command ODrive over CAN with a simple interface.

  • v1.x = Odrive 3.6
  • v2.x = Odrive Pro

Source code: https://gitlab.com/roxautomation/components/odrive-can

Documentation: https://roxautomation.gitlab.io/components/odrive-can

Features

  • designed to work with asyncio
  • implements full odrive can protocol.
  • includes OdriveMock class for device simulation
  • cli tools for message inspection, backup and demo's.

Installation

pip install odrive-can

Basic usage

import asyncio
from odrive_can import ODriveCAN, CanMsg
from odrive_can.tools import UDP_Client

AXIS_ID = 0
INTERFACE = "vcan0"
SETPOINT = 50

udp = UDP_Client()  # send data to UDP server for plotting


def feedback_callback_fcn(msg: CanMsg, caller: ODriveCAN):
    """called on position estimate"""
    print(msg)
    udp.send(msg.data)


async def main():
    """connect to odrive"""
    drv = ODriveCAN(axis_id=AXIS_ID, interface=INTERFACE)

    # set up callback (optional)
    drv.feedback_callback = feedback_callback_fcn

    # start
    await drv.start()

    # check errors (raises exception if any)
    drv.check_errors()

    # set controller mode
    drv.set_controller_mode("POSITION_CONTROL", "POS_FILTER")

    # reset encoder
    drv.set_linear_count(0)

    # set axis state
    await drv.set_axis_state("CLOSED_LOOP_CONTROL")

    # set position gain
    drv.set_pos_gain(3.0)

    for _ in range(2):
        # setpoint
        drv.set_input_pos(SETPOINT)
        await asyncio.sleep(5.0)
        drv.set_input_pos(-SETPOINT)
        await asyncio.sleep(5.0)

    drv.set_input_pos(0.0)


asyncio.run(main())

CLI interface

Usage: odrive_can [OPTIONS] COMMAND [ARGS]...

Options:
--help  Show this message and exit.

Commands:
backup   Backup config to config folder
demo     demonstration of control modes
info     Print package info
inspect  Inspect and decode ODrive CAN messages
mock     Mock ODrive CAN interface

Using virtual devices

  1. create a virtual can adapter (see docs)
  2. in first terminal run odrive_can mock
  3. in second terminal run odrive_can inspect vcan0

Position control demo

odrive_can demo position --interface vcan0

Live plotting data

Demo scripts send data as json to udp://localhost:5005 . This data can be visualized with plotjuggler

(sender code is found in tools.UDP_Client)

Development

Virtual environment

create virtual envrionment with make venv

Devcontainer

  • docker folder contains devcontainer environment.
  • .devcontainer is VSCode devcontainer environment

Support

commercial support is available through www.roxautomation.com

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

odrive_can-2.0.1.tar.gz (2.3 MB view details)

Uploaded Source

Built Distribution

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

odrive_can-2.0.1-py3-none-any.whl (42.3 kB view details)

Uploaded Python 3

File details

Details for the file odrive_can-2.0.1.tar.gz.

File metadata

  • Download URL: odrive_can-2.0.1.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for odrive_can-2.0.1.tar.gz
Algorithm Hash digest
SHA256 64b0de602e862c17cedc2f713d3ecc73b09c75a7f0a88f3d33fc6770d60c4428
MD5 bd1ccd0a13277cbca9e53865b1457e93
BLAKE2b-256 dfba60266c820febc428532012bd41e91d124897608824975c746ed6a26a162e

See more details on using hashes here.

File details

Details for the file odrive_can-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: odrive_can-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 42.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.10

File hashes

Hashes for odrive_can-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9e20eb8645846a9bf3f4453f9780e5c3e70d225a5813dad326a44542129cebef
MD5 64891a8e458abfe4611dcb131c65efbc
BLAKE2b-256 c0bf7233139ee451e3c4876544e16de118de187493322b0a9921a5d9b1501ca5

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