Skip to main content

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

Metadata

Release files for odrive-can 2.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 odrive-can 2.1.0
File Size Uploaded
odrive_can-2.1.0.tar.gz 2.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for odrive-can 2.1.0
File Interpreter ABI Platform
odrive_can-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 2.3 MB

Release files / odrive_can-2.1.0.tar.gz

Download URL odrive_can-2.1.0.tar.gz
Size 2.3 MB
Tags Source
SHA-256 checksum
How to use checksums
5738a8e7e4730b319cbb9e93a0aabed5ccb5c4d0b238812dbfe87204b85d21e0
BLAKE2b-256 checksum
How to use checksums
9dc7c76e99e4ef378614d0ca4618d686f6ad4a5f9b1b7ff903a9fa8833d0b491
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.10

Release files / odrive_can-2.1.0-py3-none-any.whl

Download URL odrive_can-2.1.0-py3-none-any.whl
Size 42.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f18b72d1b48bfeab9fdd14c21b6f8063067e076c460c6b9cd7a33f931c8a7df3
BLAKE2b-256 checksum
How to use checksums
2411312de1a06f95776c4ba4dafe376baa9ef810b56f5b3adb5e229409135358
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.10

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.2

2 release files

2.0.1

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.12.2

2 release files

0.12.0

2 release files

0.11.1

2 release files

0.10.0

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.6

2 release files

0.3.5

2 release files

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