How to use the odrive.utils 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 run_test(self, axis0_ctx: AxisTestContext, axis1_ctx: AxisTestContext, logger):
        load_ctx = axis0_ctx
        driver_ctx = axis1_ctx
        if driver_ctx.name == 'top-odrive.black':
            # odrive.utils.start_liveplotter(lambda: [driver_ctx.odrv_ctx.handle.vbus_voltage])
            odrive.utils.start_liveplotter(lambda: [driver_ctx.handle.motor.current_control.Iq_measured, 
                                                    driver_ctx.handle.motor.current_control.Iq_setpoint])

        # Set up viscous fluid load
        logger.debug("activating load on {}...".format(load_ctx.name))
        load_ctx.handle.controller.config.vel_integrator_gain = 0
        load_ctx.handle.motor.config.current_lim = self._load_current
        load_ctx.odrv_ctx.handle.config.brake_resistance = 0 # disable brake resistance, the power will go into the bus
        load_ctx.handle.controller.set_vel_setpoint(0, 0)

        request_state(load_ctx, AXIS_STATE_CLOSED_LOOP_CONTROL)

        driver_test = TestHighVelocity(
                override_current_limit=self._driver_current,
                load_current=self._load_current, brake=False)
        driver_test.check_preconditions(driver_ctx, logger)
        driver_test.run_test(driver_ctx, logger)
github madcowswe / ODrive / tools / odrive / tests.py View on Github external
time.sleep(0.005)

        test_assert_no_error(load_ctx)
        test_assert_no_error(driver_ctx)

        logger.debug("using {} as driver against load, vel=20000...".format(driver_ctx.name))
        set_limits(driver_ctx, logger, vel_limit=20000, current_limit=50)
        init_pos = driver_ctx.handle.encoder.pos_estimate
        driver_ctx.handle.controller.set_pos_setpoint(init_pos + 100000, 0, 0)
        request_state(driver_ctx, AXIS_STATE_CLOSED_LOOP_CONTROL)
        #for _ in range(int(5*4000/5)):
        #    logger.debug(str(driver_ctx.handle.motor.current_control.Iq_setpoint))
        #    time.sleep(0.005)
        time.sleep(7)

        odrive.utils.print_drv_regs("load motor ({})".format(load_ctx.name), load_ctx.handle.motor)
        odrive.utils.print_drv_regs("driver motor ({})".format(driver_ctx.name), driver_ctx.handle.motor)

        test_assert_no_error(load_ctx)
        test_assert_no_error(driver_ctx)
github madcowswe / ODrive / tools / odrive / dfu.py View on Github external
else:
        serial_number = device.__channel__.usb_device.serial_number
        dfudev = None

        # Read hardware version as reported from firmware
        hw_version_major = device.hw_version_major if hasattr(device, 'hw_version_major') else 0
        hw_version_minor = device.hw_version_minor if hasattr(device, 'hw_version_minor') else 0
        hw_version_variant = device.hw_version_variant if hasattr(device, 'hw_version_variant') else 0
        hw_version = (hw_version_major, hw_version_minor, hw_version_variant)

    if hw_version < (3, 5, 0):
        print("  DFU mode is not supported on board version 3.4 or earlier.")
        print("  This is because entering DFU mode on such a device would")
        print("  break the brake resistor FETs under some circumstances.")
        print("Warning: DFU mode is not supported on ODrives earlier than v3.5 unless you perform a hardware mod.")
        if not odrive.utils.yes_no_prompt("Do you still want to continue?", False):
            raise OperationAbortedException()

    fw_version_major = device.fw_version_major if hasattr(device, 'fw_version_major') else 0
    fw_version_minor = device.fw_version_minor if hasattr(device, 'fw_version_minor') else 0
    fw_version_revision = device.fw_version_revision if hasattr(device, 'fw_version_revision') else 0
    fw_version_prerelease = device.fw_version_prerelease if hasattr(device, 'fw_version_prerelease') else True
    fw_version = (fw_version_major, fw_version_minor, fw_version_revision, fw_version_prerelease)

    print("Found ODrive {} ({}) with firmware {}{}".format(
                serial_number,
                get_hw_version_string(hw_version),
                get_fw_version_string(fw_version),
                " in DFU mode" if dfudev is not None else ""))

    if firmware is None:
        if hw_version == (0, 0, 0):
github madcowswe / ODrive / tools / setup.py View on Github external
fibre_link = os.path.join(os.path.dirname(
                    os.path.realpath(__file__)), "fibre")
  if not os.path.exists(fibre_link):
    if sys.version_info > (3, 3):
      os.symlink(fibre_src, fibre_link, target_is_directory=True)
    else:
      os.symlink(fibre_src, fibre_link)

# TODO: find a better place for this
if not creating_package:
  import platform
  if platform.system() == 'Linux':
    import odrive.utils
    from fibre.utils import Logger
    try:
      odrive.utils.setup_udev_rules(Logger())
    except PermissionError:
      print("Warning: could not set up udev rules. Run `sudo odrivetool udev-setup` to try again.")

try:
  setup(
    name = 'odrive',
    packages = ['odrive', 'odrive.dfuse', 'fibre'],
    scripts = ['odrivetool', 'odrivetool.bat', 'odrive_demo.py'],
    version = version,
    description = 'Control utilities for the ODrive high performance motor controller',
    author = 'Oskar Weigl',
    author_email = 'oskar.weigl@odriverobotics.com',
    license='MIT',
    url = 'https://github.com/madcowswe/ODrive',
    keywords = ['odrive', 'motor', 'motor control'],
    install_requires = [