EFeru / hoverboard-firmware-hack-FOC

With Field Oriented Control (FOC)
GNU General Public License v3.0
1.12k stars 926 forks source link

Link to Hoverboard-Hack-FOC-PID-Servo #139

Closed vamfun closed 2 years ago

vamfun commented 3 years ago

Not really an issue but @Candas1 mentioned that this variant might be worth evaluating. https://github.com/vamfun/Hoverboard-Hack-FOC-PID-Servo

I modified a fork to allow ADC inputs to PID control the motors as 360 deg servos using the Hall sensor feedbacks. Unfortunately I am using a motherboard variant that has 5 GPIO changes but restore these to your board and you can try it. Appreciate any feedback.

The motors are very responsive. They can step a full rotation in an 1/8 of a second. image

Smaller Step responses https://drive.google.com/file/d/1IOkOEM-Gued34fLKB2XDOmWFyVLXCoLo/view?usp=sharing

EFeru commented 3 years ago

@vamfun the graph looks very cool! Do you have a movie to see live how is the motor behaving? I would like to see also smaller position targets.

Candas1 commented 3 years ago

Hi, I tried it yesterday but I forgot to record... I had some problems with the firmware not reacting sometimes but I need to fix my ADC set up.

I will try again this evening. It's really interesting for robotics.

Candas1 commented 3 years ago

Position control https://youtu.be/VpphzLXatIo

Under load https://youtu.be/Ai6PMY9mlt0

It works very good šŸ‘šŸ‘šŸ‘

EFeru commented 3 years ago

I like it too! šŸ‘

Candas1 commented 3 years ago

And this was for fun lol https://youtu.be/pM6i7bIdHPE

vamfun commented 3 years ago

Glad to see it worked for you. Wheel driving wheel is a form of power steeringšŸ˜Ž

I haven't got a good method of plotting yet..right now I'm using excel and it's a bit tedious. I'll do a few smaller steps soon.

I've done some theoretical predictions based upon a first order motor response with tau = .02 calculated from motor constants and Wheel inertia. Here is the block diagram for the PID control loop.
image

The calculated rise time defined by time from 0 to 100% using the damping ratio of .5 and wn =48.3 is 50 ms . The smaller step responses I added to the original post show about 60 ms ,however, smaller steps are affected by the course resolution of the Hall sensors. But Iā€™m happy with the agreement. Kv for my motors a bit higher than others at 17.5 rpm/volt. ... others Iā€™ve seen are at Kv = 16.

Candas1 commented 3 years ago

And another one for fun: https://youtu.be/QBDGHEpJk08

Inspired by this: https://youtu.be/kCHiuNaOTdY

vamfun commented 3 years ago

I added the smaller step responses to my original post.

@Candas1 I found the links interesting. The hoverboard is a perfect setup for your little servo slaving experiment.

pigiit commented 3 years ago

Hi, I tried it for my board controlling the wheels with the RC and the receiver connected to the sideboard...I like it! Great work!

vamfun commented 3 years ago

Thanks...Iā€™m adding these encoders for higher resolution. They fit nicely on the interior of the wheel hub. https://www.andymark.com/products/lamprey-absolute-encoder

http://vamfun.wordpress.com Robot musing blog iPhone

On Apr 11, 2021, at 2:26 PM, pigiit @.***> wrote:

ļ»æ Hi, I tried it for my board controlling the wheels with the RC and the receiver connected to the sideboard...I like it! Great work!

ā€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

EFeru commented 3 years ago

If you install an encoder, maybe you can try feeding the angle to motor control as well in bldc.c That functionality I did not test it yet, but it is there as input. https://github.com/EmanuelFeru/hoverboard-firmware-hack-FOC/blob/0709e4cb62ef1d0bfedfc6bc3187614d5862acd6/Src/bldc.c#L188

And you need to activate the external angle measurement by making this parameter 1: https://github.com/EmanuelFeru/hoverboard-firmware-hack-FOC/blob/0709e4cb62ef1d0bfedfc6bc3187614d5862acd6/Src/util.c#L240

vamfun commented 3 years ago

I saw where the input is used. Are there any defines or switches that need to be set or do you comment out the hall sensors??

http://vamfun.wordpress.com Robot musing blog iPhone

On Apr 11, 2021, at 10:51 PM, EmanuelFeru @.***> wrote:

ļ»æ If you install an encoder, maybe you can try feeding the angle to motor control as well in bldc.c That functionality I did not test it yet, but it is there as input.

ā€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

EFeru commented 3 years ago

There is no need because the hall sensors are ignored inside the controller itself.

gnbl commented 3 years ago

Fantastic, just what I need: a cheap, high-torque, open source servodrive! So this now almost competes with VESC and ODrive. Can this be integrated as "POSITION MODE"? Power steering (allowing remote control) would be awesome with a steering torque sensor (two high resolution encoders and a torsion bar)...

gnbl commented 3 years ago

Under load https://youtu.be/Ai6PMY9mlt0

The noise is due to the low resolution of the position sensors?

vamfun commented 3 years ago

If you install an encoder, maybe you can try feeding the angle to motor control as well in bldc.c That functionality I did not test it yet, but it is there as input.

https://github.com/EmanuelFeru/hoverboard-firmware-hack-FOC/blob/0709e4cb62ef1d0bfedfc6bc3187614d5862acd6/Src/bldc.c#L188

And you need to activate the external angle measurement by making this parameter 1:

https://github.com/EmanuelFeru/hoverboard-firmware-hack-FOC/blob/0709e4cb62ef1d0bfedfc6bc3187614d5862acd6/Src/util.c#L240

I'm getting ready to test the added encoders... I assume that the phasing of the encoder should match the electrical angle.

I'm having some issues with my motor rollover counting function. I tried calling the function in main but the motor phase rate of change exceeds 180deg /5ms at maximum speed. I tried moving the routine to the bldc.c 1600 HZ DMA1_Channel1_IRQHandler(void) { ... } but I'm sure its exceeding the .625 ms execution window . Have you done accurate timing measurements of this loop to show what margin there is for added code? I have a feeling margin is very slim. I really just need to call it at 400 Hz. I can modify main to accommodate this but it would be easier to just call it in a faster loop.

EFeru commented 3 years ago

In DMA1 there is not so much margin, i think around 20% time from the 0.625ms calculation window. Especially Speed mode takes the most, followed by Torque, Voltage, Sinusoidal, and Communtation which is the lightest. There is an issue I think where I calculated the computational times with an oscilloscope, maybe you can find it.

vamfun commented 3 years ago

Ok..rewrote rollover MotorPos routine and got the execution down from 54 us to 5 us with more efficient code so it now works in bldc.c. Unfortunately I shorted my USB ports and blew the motherboard requiring a laptop replacementā€¦twice !! within one week just before getting to the encoder testing plus the hoverboard went hard over and flew off my support box burning out a power supply and a $40 encoder. Not a good week. I going to have to limp along with my old xp laptop for awhile.

http://vamfun.wordpress.com Robot musing blog iPhone

On Jun 15, 2021, at 8:52 AM, EmanuelFeru @.***> wrote:

ļ»æ In DMA1 there is not so much margin, i think around 20% time from the 0.625ms calculation window. Especially Speed mode takes the most, followed by Torque, Voltage, Sinusoidal, and Communtation which is the lightest. There is an issue I think where I calculated the computational times with an oscilloscope, maybe you can find it.

ā€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

s56jsc commented 3 years ago

Great job! I try to upload it on my mower, but something not work. I did modificate GPIO on defines.h for my board, but something not work property. When I power on in next second it turn off. Also when I build file I got some warnings image

best regards Simon

vamfun commented 3 years ago

Hi Simon Not sure why you are using the PID in your mower. The command over usart is a wheel position command and it is scaled for 1000 counts equal 180 degrees. -1000 to 1000 gives one rotation. You can make it a rate command by setting Kp =1 and removing the wheel feedback. Ie. PID.feedback = 0.

The shut off shortly after turn on might be due to a gpio problem. I had that phenomenon when the battery voltage was not being measured and the under voltage shutdown was triggered. Check the debug print to see measured battery voltage.

Donā€™t worry about the warningsā€¦ you can add a # include to config.h if it isnā€™t there to eliminate the printf warnings.

Chris

http://vamfun.wordpress.com Robot musing blog iPhone

On Aug 10, 2021, at 10:32 AM, Simon @.***> wrote:

ļ»æ Great job! I try to upload it on my mower, but something not work. I did modificate GPIO on defines.h for my board, but something not work property. When I power on in next second it turn off. Also when I build file I got some warnings

best regards Simon

ā€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

s56jsc commented 3 years ago

OK understand. I was thinking to use in speed mode with PID. I did PID in arduino code it work, but not as I wont. Anyway I'm giving up with 4x hoverboard wheel on mower. It it simple not enough torque for mower. I will use 24V motor with reductor and PWM. This is what I know well. With this wheel I will build bobby car or similar

BR Simon