How to use the odrive.find_any function in odrive

To help you get started, we’ve selected a few odrive examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github madcowswe / ODrive / tools / odrive / tests.py View on Github external
def rediscover(self):
        """
        Reconnects to the ODrive
        """
        self.handle = odrive.find_any(
            path="usb", serial_number=self.yaml['serial-number'], timeout=15)#, printer=print)
        for axis_idx, axis_ctx in enumerate(self.axes):
            axis_ctx.handle = self.handle.__dict__['axis{}'.format(axis_idx)]
github dpoulson / r2_control / controllers / ps3 / r2_ps3.py View on Github external
#### Open a log file
f = open(log_file, 'at')
f.write(datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') +
        " : ****** ps3 started ******\n")
f.flush()

if not args.dryrun:
    if __debug__:
        print("Not a drytest")
    if _config.get('Drive', 'type') == "Sabertooth":
        drive = SabertoothPacketSerial(address=int(_config.get('Drive', 'address')),
                                   type=_config.get('Drive', 'type'),
                                   port=_config.get('Drive', 'port'))
    elif _config.get('Drive', 'type') == "ODrive":
        print("finding an odrive...")
        drive = odrive.find_any() #"serial:" + _config.get('Drive', 'port'))
        #drive.axis0.controller.config.control_mode = CTRL_MODE_VELOCITY_CONTROL
        #drive.axis1.controller.config.control_mode = CTRL_MODE_VELOCITY_CONTROL
        drive.axis1.controller.vel_ramp_enable = True
        drive.axis0.controller.vel_ramp_enable = True

    #dome = SabertoothPacketSerial(address=int(_config.get('Dome', 'address')),
    #                              type=_config.get('Dome', 'type'),
    #                              port=_config.get('Dome', 'port'))

pygame.display.init()

if args.curses:
    print('\033c')
    locate("-=[ PS3 Controller ]=-", 10, 0)
    locate("Left", 3, 2)
    locate("Right", 30, 2)
github LuSeKa / HoverBot / tools / ODrive_hoverboard_motor_setup_part_02.py View on Github external
# based on https://docs.odriverobotics.com/hoverboard.html
import odrive
import time

motor_calibration_time = 6
encoder_calibration_time = 12

input("Make sure that the wheels are free to turn. Don't get hurt!\nPress ENTER to proceed.")

print("Searching for ODrive...")
odrv0 = odrive.find_any()
print("Odrive detected!")

print("--------------Motor Calibration--------------------------------")
print("Calibrating motors...")
odrv0.axis0.requested_state = 4 # AXIS_STATE_MOTOR_CALIBRATION
odrv0.axis1.requested_state = 4 # AXIS_STATE_MOTOR_CALIBRATION
time.sleep(motor_calibration_time)
if odrv0.axis0.motor.is_calibrated == 1 and odrv0.axis1.motor.is_calibrated == 1:
	print("Motor successfully calibrated! Proceeding...")
else:
	print("Could not calibrate motor. Something is wrong.")
	print("Have you ran the first script to set all parameters?")
	print("If yes and the wiring looks good, reset the ODrive and try again.\nExiting.")
	quit()
print("Saving motor calibration")
odrv0.axis0.motor.config.pre_calibrated = True
github madcowswe / ODrive / tools / odrive / dfu.py View on Github external
"  observed: " + observed_snippet)
        print('Verifying... done            \r', end='', flush=True)
    finally:
        print('', flush=True)


    # If the flash operation failed for some reason, your device is bricked now.
    # You can unbrick it as long as the device remains powered on.
    # (or always with an STLink)
    # So for debugging you should comment this last part out.

    # Jump to application
    dfudev.jump_to_application(0x08000000)

    logger.info("Waiting for the device to reappear...")
    device = odrive.find_any("usb", serial_number,
                    cancellation_token, cancellation_token, timeout=30)

    if did_backup_config:
        odrive.configuration.restore_config(device, None, logger)
        os.remove(odrive.configuration.get_temp_config_filename(device))

    logger.success("Device firmware update successful.")
github madcowswe / ODrive / tools / setup_hall_as_index.py View on Github external
import odrive
from odrive.utils import dump_errors
from odrive.enums import *
import time

print("Finding an odrive...")
odrv = odrive.find_any()

# axes = [odrv.axis0, odrv.axis1];
axes = [odrv.axis0];

flip_index_search_direction = False
save_and_reboot = True

print("Setting config...")
# Settings to protect battery
odrv.config.dc_bus_overvoltage_trip_level = 14.8
odrv.config.dc_bus_undervoltage_trip_level = 8.0
odrv.config.brake_resistance = 0
for ax in axes:
    ax.motor.config.requested_current_range = 25
    ax.motor.config.calibration_current = 10
    ax.motor.config.current_lim = 10
github madcowswe / ODrive / tools / odrive_demo.py View on Github external
#!/usr/bin/env python3
"""
Example usage of the ODrive python library to monitor and control ODrive devices
"""

from __future__ import print_function

import odrive
from odrive.enums import *
import time
import math

# Find a connected ODrive (this will block until you connect one)
print("finding an odrive...")
my_drive = odrive.find_any()

# Find an ODrive that is connected on the serial port /dev/ttyUSB0
#my_drive = odrive.find_any("serial:/dev/ttyUSB0")

# Calibrate motor and wait for it to finish
print("starting calibration...")
my_drive.axis0.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE
while my_drive.axis0.current_state != AXIS_STATE_IDLE:
    time.sleep(0.1)

my_drive.axis0.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL

# To read a value, simply read the property
print("Bus voltage is " + str(my_drive.vbus_voltage) + "V")

# Or to change a value, just assign to the property
github LuSeKa / HoverBot / tools / ODrive_hoverboard_motor_setup_part_01.py View on Github external
# based on https://docs.odriverobotics.com/hoverboard.html
import odrive

# Paramters for HoverBot. Probably no need to change.
pole_pairs = 15
resistance_calib_max_voltage = 4
requested_current_range = 25
current_control_bandwidth = 100
cpr = pole_pairs * 6
encoder_bandwidth = 100
vel_limit = 5000
current_limit = 5

print("Searching for ODrive...")
odrv0 = odrive.find_any()
print("Odrive detected!")
print("-------------Motor parameters----------------------------------")
print("Setting number of pole pairs to {}".format(pole_pairs))
odrv0.axis0.motor.config.pole_pairs = pole_pairs
odrv0.axis1.motor.config.pole_pairs = pole_pairs
print("Setting maximum calibration voltage to {}".format(resistance_calib_max_voltage))
odrv0.axis0.motor.config.resistance_calib_max_voltage = resistance_calib_max_voltage
odrv0.axis1.motor.config.resistance_calib_max_voltage = resistance_calib_max_voltage
print("Setting current range to {}".format(requested_current_range))
odrv0.axis0.motor.config.requested_current_range = requested_current_range
odrv0.axis1.motor.config.requested_current_range = requested_current_range
print("Setting current control bandwidth to {}".format(current_control_bandwidth))
odrv0.axis0.motor.config.current_control_bandwidth = current_control_bandwidth
odrv0.axis1.motor.config.current_control_bandwidth = current_control_bandwidth
print("--------------Encoder parameters-------------------------------")
print("Configuring for hall encoders")
github madcowswe / ODrive / tools / odrive / dfu.py View on Github external
serial_number = args.serial_number
    find_odrive_cancellation_token = Event(cancellation_token)

    logger.info("Waiting for ODrive...")

    devices = [None, None]

    # Start background thread to scan for ODrives in DFU mode
    def find_device_in_dfu_mode_thread():
        devices[0] = find_device_in_dfu_mode(serial_number, find_odrive_cancellation_token)
        find_odrive_cancellation_token.set()
    threading.Thread(target=find_device_in_dfu_mode_thread, daemon=True).start()

    # Scan for ODrives not in DFU mode
    # We only scan on USB because DFU is only implemented over USB
    devices[1] = odrive.find_any("usb", serial_number,
        find_odrive_cancellation_token, cancellation_token)
    find_odrive_cancellation_token.set()
    
    device = devices[0] or devices[1]
    firmware = FirmwareFromFile(args.file) if args.file else None

    update_device(device, firmware, logger, cancellation_token)