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.

Is there any update when this feature will be available? I have a Dynomotion kflop CNC controller which outputs a 0-100% PWM at 10khz ( I can change this and lower it, but not recommended to lower ) also a direction output ( held high to change direction ) I require precise velocity control, It will also be closed loop the Kflop controller and the Odrive or may setup Odrive to run motor just off the hals. I did have a look through the PWM part of the code but not sure what exactly needs to be changed. I see mentioned else where the PWM is using interrupt and not recommended to go over 500hz?

Hi, my robotic team is using this with hoverboard wheels, with the RC PWM to control the speed. There seems to be no perfect way to stop, I was just wondering if others have any solution to this? Setting it to half way between full speed forward and full speed backwards doesn’t get it to “stop” only very slow. Any advice?

Question about the PWM implementation: After parsing through the code you’ve linked I’m gathering that the PWM is getting converted through an ADC from a timing perspective, not an analog signal perspective, correct?

Reason I ask is because I’ve noticed (with other controllers) that the analog signal generated from the arduino can vary depending on whether or not the arduino is connected to a PC via a USB cable. In this case I’m using an arduino to generate the PWM in an effort to get around this analog signal issue, with the hopes that the odrive is utilizing the PWM signal’s timing to convert regardless of the signal’s amplitude.

Let me know if this is an incorrect assumption.

Thanks

We capture a timer counter on interrupt and then measure the high time, no ADC involved.

1 Like