Velocity Control using PWM input

Hello all,

Is it possible to use PWM input to control motor speed while in Velocity Control mode?
I see that PWM can be used to control position while in Position Control mode, but have not yet found any descriptions or functions for controlling Velocity using PWM.

Any input is greatly appreciated.
Many thanks.

Hi bickela

Yes I believe you can use the PWM signal to control any function that you like (within reason). See the interface docs here.

I have not tested this myself but I believe you should be able to follow the example given in the docs with the only change being:

 In [1]: odrv0.config.gpio4_pwm_mapping.min = -1500
 In [2]: odrv0.config.gpio4_pwm_mapping.max = 1500
 In [3]: odrv0.config.gpio4_pwm_mapping.endpoint = odrv0.axis0.controller._remote_attributes['pos_setpoint']

to

 In [1]: odrv0.config.gpio4_pwm_mapping.min = -1500
 In [2]: odrv0.config.gpio4_pwm_mapping.max = 1500
 In [3]: odrv0.config.gpio4_pwm_mapping.endpoint = odrv0.axis0.controller._remote_attributes['vel_setpoint']

You would also need to setup the board with odrivetool to be operating in CTRL_MODE_VELOCITY_CONTROL. Let us know how you go as I don’t think too many people have tested this feature yet.

Cheers

Richard,

Thank you very much!
I will test this method and report back.

Many thanks,
Aaron

Unfortunately when I attempt to set odrv0.config.gpio3_pwm_mapping.min I get the following error:

In [21]: odrv0.config.gpio3_pwm_mapping.min = -200
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\fibre\shell.py in ()
----> 1 odrv0.config.gpio3_pwm_mapping.min = -200

~\Anaconda3\lib\site-packages\fibre\remote_object.py in getattribute(self, name)
_ 205 return attr_
_ 206 else:_
–> 207 return object.getattribute(self, name)
_ 208 #raise AttributeError(“Attribute {} not found”.format(name))_
_ 209_

AttributeError: ‘RemoteObject’ object has no attribute ‘gpio3_pwm_mapping’

I have no issues controlling the motor using USB (odrivetool). I followed the hoverboard example and had no issues up until I try to configure the gpio.

Is it possible that this is due to having firmware [0.4.1] installed?

Thanks again.

Looking at the changelog it appears you need 4.2 for the PWM feature. https://github.com/madcowswe/ODrive/blob/master/CHANGELOG.md

Try updating to 4.2 and see how you go.

With some basic modification to the current PWM input code, we should be able to use PWM to control the spindle speed. Currently it is set up to understand the 1ms to 2ms style PWM signal used for hobby RC stuff, but I take it that spindle speed PWM signals are 0 to 100% style.

If you want to dig into the code, the place is here.
Otherwise, feel free to submit a feature request.

Richard, madcowswe,
Thanks for the advice.

I just ran odrivetool dfu and when the system restarted the odrive does not connect to USB. If I connect and disconnect the USB the computer does not recognize the connection.
If I set the dip switch to dfu mode the STM32 BOOTLOADER shows up in Device manager and when run odrivetool dfu I get:

ODrive control utility v0.4.0.post3
Waiting for ODrive...

IndexError                                Traceback (most recent call last)
~\Anaconda3\Scripts\odrivetool in <module>()
    139         print_version()
    140         import odrive.dfu
--> 141         odrive.dfu.launch_dfu(args, logger, app_shutdown_token)
    142
    143     elif args.command == 'liveplotter':

~\Anaconda3\lib\site-packages\odrive\dfu.py in launch_dfu(args, logger, cancellation_token)
    448     firmware = FirmwareFromFile(args.file) if args.file else None
    449
--> 450     update_device(device, firmware, logger, cancellation_token)
    451
    452

~\Anaconda3\lib\site-packages\odrive\dfu.py in update_device(device, firmware, logger, cancellation_token)
    266         if otp_data[0] == 0:
    267             otp_data = otp_data[16:]
--> 268         if otp_data[0] == 0xfe:
    269             hw_version = (otp_data[3], otp_data[4], otp_data[5])
    270         else:

IndexError: array index out of range

Did I brick my odrive?

You can check the section “Upgrading firmware with a different DFU tool” in the docs, and try that.

Thank you everyone. I was able to get it reflashed and everything seems to be working. And yes, the PWM control I need is a 0~100% type. I will submit a feature request.

is it now possible to use 0-100% pwm signal?

It is not. This feature has come up several times recently as a request, so it’s moved up my priority list, but it is not yet available in the master branch, sorry

okay, when approximately may it be available?

Hi bickela,can you illustrate how to config ODrive if i intend to use PWM input to control motor’s position?
I did the config for the former target:
odrv0.axis0.config.enable_step_dir = True

odrv0.config.enable_uart = False

odrv0.config…counts_per_step = 100

may I do other configrations,it is great appreciate for your any reply!

HoaDu

Sorry, I am just a user. I am in same position as you. I would like to use a PWM input control for motor velocity, but functionality has not yet been implemented in a manner that I can use.