btsimonh / hoverboard-firmware-hack

New Hoverboard Firmware Hack. Now written from scratch and generally much better.
GNU General Public License v3.0
22 stars 4 forks source link

Add a current limit flash control, disable PMW log by default #16

Closed EmerickH closed 5 years ago

EmerickH commented 5 years ago

TODO:

Fully working!

btsimonh commented 5 years ago

will be interested in what this does :). I never instrumented the current measurement - what does it do if over current? I could imagine options:

  1. disable pwm. ('I hit something, so all stop').
  2. maintain current position (if not travelling too fast?) - so if travelling up a slop, would not roll back...! I could also imagine a 'current warning level', provided as feedback to the controlling MCU?

For your application, this is for collision with actors without causing harm?

p-h-a-i-l commented 5 years ago

Current limit just chops the PWM, so effectively reduces the duty cycle. Simplified: The current is equivalent to motor torque.

EmerickH commented 5 years ago

Yes in my application I need a very responsive PID (high Proportional) to follow correctly a recorded trajectory, but a small max current/torque because if the robot is stuck by someone holding it for example, if the maximum current is too high, the robot will increase its power to try to go to its wanted position, until the wheels are going to skid on the floor and so loose its trajectory... (and do some black tracks on the floor). So I need to calibrate my maximum power to be enough to move the robot correctly but less than the skid limit. I also need to disable buzzer when current limit is reached.

EDIT: Also, do you know why this parameter changes nothing on my board? https://github.com/btsimonh/hoverboard-firmware-hack/blob/3ad34cfba56a00dfc176c8c48c99dc74ddb82a10/src/protocol.c#L309 OK, it was a bug on my read/write interface. I just flashed this, and the current limit seems not working... -> Fixed, everything working, I just forgot to change something

EmerickH commented 5 years ago

Everything is working now, just is anyone knows why 0x82 and 0x81 were inverted? https://github.com/btsimonh/hoverboard-firmware-hack/blob/dcdf9a0f8985401cd0768a0d439fd44861681a55/src/protocol.c#L300-L301 Also 0x86 and 0x85: https://github.com/btsimonh/hoverboard-firmware-hack/blob/dcdf9a0f8985401cd0768a0d439fd44861681a55/src/protocol.c#L305-L306

btsimonh commented 5 years ago

haha :). I guess I wrote them IPD, then cut & paste to put it in 'PID' order; I'm happy with the new numbers

btsimonh commented 5 years ago

I'm gonna merge this without checking myself - Still up to my eyes in 'real' work :( @EmerickH - I had trouble with aggressive PID values; did you find some good ones? please share.... Did you use the dead reckoning output?

EmerickH commented 5 years ago

My PID values (for positional control):

Works well: P: 300 I: 50 D: 0 pwm limit: 400 Max cur: 100-200 depending weight (=1-2A)

More responsive but more unstable: P:500 I:50 D:15 pl:150 Max cur: 100-200

Be careful: if you increases Proportional >~200 you have to lower before pwm limit and max current, else it's gonna do some impressive jumps (50cm is my record!)

I just saw a big error in my code: https://github.com/btsimonh/hoverboard-firmware-hack/blob/10858d808f135047d8fff2c94c08ca6149f28f90/inc/bldc.h#L17 This must be float not short as I've already divided by 100... I'm going to recreate a pull when I will have some time