Analog joystick to control velocity - need pointers for FW changes

This is a re-post of the issue I posted a week ago; posting under ‘Support’ with more details of what worked and what doesn’t for me.
I am trying to control velocity with analog joystick and would like to use 0.4.11 firmware since I may have to use rev 3.6 56V board I have to use 36V hoverboard motors.
My fallback is to use rev 3.5 24V board, but not sure that I will get sufficient power at 24Volts
I had made changes to code in Nov '18 as suggested here: https://github.com/madcowswe/ODrive/pull/243
and they seemed to work. However, the motors do not completely stop at the joystick’s neutral position - likely because there is some noise coming from the potentiometers (need to check this).

I tried changing a few things in lowlevel.cpp:

  1. Tried to comment our RC PWM code - since I do not intend to use GPIOs for PWM. I did this because GPIO 3 and 4 can be used for PWM or analog mapping. This did not compile since 2 functions pwm_in_init and pwm_in_cb are used by other modules.
  2. Tried to limit iteration to GPIO 1 & 2 in function pwm_in_cb in lowlevel.cpp by changing GPIO_COUNT to 2 (hardcoded just to try). This compiled but no effect.
  3. In communications.cpp commented out pwm_mapping for GPIO 3 & 4. I did not think this would fix the problem but thought was worth trying since I do get lost between all different FW files. It does work to the extent that Odrivetool’s odrv0.config command does not show gpio3 and 4 for pwm mapping - only shows analog mapping.

I am currently trying the 3.5 24V board which worked with the Nov 18 version (with the changes mentioned above).

I really need the issue fixed urgently. I think the Nov version based on firmware rev 0.4.7 or earlier was quite different than 0.4.11 version.

To get going immediately, I can also temporarily use the source code for the Nov. 18 version and make the changes.

If anyone has suggestions on what I should try, please advise.

Thanks,

Anil

As far as I’m aware, there have been no changes to the GPIO analog mapping behaviour. You shouldn’t have to make any firmware changes.

What GPIOs are you plugging your joystick into?

I am using GPIO3 and GPIO4.
As I mentioned, it seemed to work with a version of 0.4.7 unreleased firmware. I think I have located those source files and should be able to compile and retry that code again. Since that FW works, I am suspecting a FW issue and not hardware problems.

3 & 4 are set to step/dir by default, so you have to disable that (odrv0.axis1.config.enable_step_dir = False).

And then you should be able to map it with an analog mapping, I think ?

I will definitely try that tomorrow for 0.4.11 FW
The source for the firmware that worked is at

I created a new binary from this base today and it seems to work. This is fyi since you may be able to compare this with the latest code to make sure that the solution you suggested is the only solution. I tried to compare low_level.cpp and main.cpp between the two code bases and did not find any relevant differences. But I am not a SW engr - in fact have been away from real HW , SW and FW for decades. So a bit slow (and sometimes clueless) on finding root causes.

Thanks again.

Hi Wetmelon,
I tried issuing odrv0.axis1.config.enable_step_dir = False (also for axis0) before

odrv0.config.gpio3_analog_mapping.min = -2000
odrv0.config.gpio3_analog_mapping.max = 2000
odrv0.config.gpio3_analog_mapping.endpoint =
odrv0.axis0.controller._remote_attributes[‘vel_setpoint’]
odrv0.config.gpio4_analog_mapping.min = -2000
odrv0.config.gpio4_analog_mapping.max = 2000
odrv0.config.gpio4_analog_mapping.endpoint =
odrv0.axis1.controller._remote_attributes[‘vel_setpoint’]

upon saving config and renbooting. when I issue
In [1]: odrv0.axis0.controller.vel_setpoint
I get Out[1]: 0.0

on rev 0.4.11 firmware but get the values reflecting the joystick inputs on the variant of 0.4.7 firmware from the repository above.

Is it possible to check the differences between the two versions related to this?

I have been stuck here for a while now.

Please help.

Anil

Hi Anil,

I was able to confirm that there was a regression in the analog input feature in recent firmware versions. Thanks for your clear report of the issue. I was able to fix it.

In [4]:  odrv0.config.gpio3_analog_mapping.min = -2000
   ...:  odrv0.config.gpio3_analog_mapping.max = 2000
   ...:  odrv0.config.gpio3_analog_mapping.endpoint = odrv0.axis0.controller._remote_attributes['vel_setpoint']

In [5]: odrv0.axis0.controller.vel_setpoint
Out[5]: -1042.96875

In [6]: odrv0.axis0.controller.vel_setpoint
Out[6]: -1053.7109375

In [7]: odrv0.axis0.controller.vel_setpoint
Out[7]: -1041.9921875

The fix is available on devel. Are you able to pull and flash devel to test?

Oskar,

That works perfectly! Thank you!!

I assume for 3.6- 56V version board, I change the config file accordingly?

Yes set it to your hardware version in the tup.config.

Hi Oskar,

I have successfully got the analog joystick working with 3.5-24V board, I have also implemented a dead zone for the joystick’s neutral position and enable/disable switch using GPIO 8.

When I try the dev version of the FW on 3.6-56V board WITHOUT my changes, the system does not work properly. Both motors start running. Axis 0 stops in a few seconds with motor error of x01000, but axis1 keeps running.

Both axes show velo setpoint around -500. This behavior also repeats when I disconnect the joystick completely. It seems like the analog inputs are not working properly on the 3.6-56V version??

Can you please look into this?

Also, I have a 24V Li battery which charges up to 29.2 volts and then I cannot use it with the 24V board. Is there a ‘safe’ way to change the settings for the 24V board to allow it to run up to 29.5 V?

Thanks,

Anil

Nice well done!

Are you sure? You can run dump_errors(odrv0) to get a more readable error print out.

No, the hardware cannot take higher voltages.

One thing to check is if you have set the correct board version in your tup.config

HI Oskar,

I am suspecting that GPIO3 and 4 are floating on the 56V board - possibly because some jumpers or resistors are not soldered. Do you think this is a possibility?

Both inputs read value around -500 when the range is set to -800 to +800, so my guess is that the analog inputs are reading about +1V, perhaps 0.8V.

Here is my tup.comfig:

Copy this file to tup.config and adapt it to your needs

make sure this fits your board

CONFIG_BOARD_VERSION=v3.6-56V
CONFIG_USB_PROTOCOL=native
CONFIG_UART_PROTOCOL=ascii
CONFIG_DEBUG=false

Uncomment this to error on compilation warnings

#CONFIG_STRICT=true

Anil

Hi Anil,

I used the devel branch, had CONFIG_BOARD_VERSION=v3.6-56V like you. There is no pinout difference between v3.5 and v3.5, so I used a v3.5 board I had plugged in at the time. I used a wire to directly connect GPIO3 to AVCC, AGND, and also I tried having it floating.

Here is the result:

Connected to ODrive 387937573437 as odrv0
In [1]: odrv0.axis0.controller.vel_setpoint
Out[1]: 0.0

In [2]: odrv0.config.gpio3_analog_mapping.min = -800

In [3]: odrv0.config.gpio3_analog_mapping.max = 800

In [4]: odrv0.config.gpio3_analog_mapping.endpoint = odrv0.axis0.controller._remote_attributes['vel_setpoint']

In [5]: odrv0.axis0.controller.vel_setpoint
Out[5]: 798.046875

In [6]: odrv0.axis0.controller.vel_setpoint
Out[6]: 797.2657470703125

In [7]: odrv0.axis0.controller.vel_setpoint
Out[7]: -797.65625

In [8]: odrv0.axis0.controller.vel_setpoint
Out[8]: -800.0

In [9]: odrv0.axis0.controller.vel_setpoint
Out[9]: -800.0

In [10]: odrv0.axis0.controller.vel_setpoint
Out[10]: -455.078125

In [11]: odrv0.axis0.controller.vel_setpoint
Out[11]: -450.390625

In [12]: odrv0.axis0.controller.vel_setpoint
Out[12]: -461.328125

As you can see the output to the vel_setpoint is working correctly. I would suggest that you measure the voltage to GND at the GPIO input and check that your joystick and wiring is working correctly.

Hi Oskar,

I connected only the joystick to the 3.6 board (no motors connected) and setup according to your instructions above (I had done that previously).

I connected the oscilloscope this time to the joystick outputs and the voltage does change as I move the joystick, However, the vel_setpoint readings for both axes are consistently around -480 to -545, regardless of the joystick position - though the oscilloscope readings are linear.

I have captured the odrivetool screen below -

image

I will be traveling so cannot try the working 3.5 24V board to confirm proper behaviour - however, the motors do run as expected with that board.

With 3.6 volts motors run fast (since the reading is approx -500 for the system, and one of the axes errors out with error x1000.

Not sure what is going on.

Anil

Here are the photos of the hardware connected (not proud of the soldering job, but it works for now)

Hi Oskar,

I received my second 3.6-56V board. I updated it with the ‘Dev’ version of the firmware, included my changes and the joystick seems to work!! Happy about the progress. Looks like the first 3.6 board has HW issues. I will pursue this more - just to make sure; however almost sure that the analog inputs are not reaching the ST chip for some reason. (or broken ST chip - unlikely I think).

I am still having problems with one of the motors, It very frequently errors out with error code x01000.
dump_errors(odrv0) says that axis - motor failed and motor - cuurent unstable.

Any guess what may be going wrong for this motor.?
My config parameters are:
odrv0.axis0.motor.config.resistance_calib_max_voltage = 4

odrv0.axis0.motor.config.pole_pairs = 10

odrv0.axis0.motor.config.requested_current_range = 25

odrv0.axis0.motor.config.current_control_bandwidth = 100

odrv0.axis0.encoder.config.mode = ENCODER_MODE_HALL

odrv0.axis0.encoder.config.cpr = 60

odrv0.axis0.encoder.config.bandwidth = 100

odrv0.axis0.encoder.config.ignore_illegal_hall_state = True

odrv0.axis0.controller.config.vel_gain = 0.02

odrv0.axis0.controller.config.pos_gain = 1

odrv0.axis0.controller.config.vel_integrator_gain = 0

odrv0.axis0.controller.config. vel_limit = 1000

odrv0.axis0.controller.config.control_mode = CTRL_MODE_VELOCITY_CONTROL

Let me know if I should try to change any of these parameters to make the motor run more reliably.

Thanks,

Anil