RoboDurden / Hoverboard-Firmware-Hack-Gen2.x

with different defines_2-x.h for different board layouts :-) Compiles with Keil version 6
GNU General Public License v3.0
73 stars 24 forks source link

Adding FOC :-) (Wrong values in CLAMP betwen master and slave communication) #4

Open matixan opened 1 year ago

matixan commented 1 year ago

Im preety sure that there should be ifdef debug for that. Actually its clamped to -300 and 300. I spend smth like 5 hours figuring this out haha

from https://github.com/RoboDurden/Hoverboard-Firmware-Hack-Gen2.x/blob/7b813004fa396eb26c3ab954c94fd942e53689ae/HoverBoardGigaDevice/Src/commsMasterSlave.c#L151 to

// Calculate result pwm value -1000 to 1000
    #ifdef TEST_SPEED
    pwmSlave = CLAMP(pData->iPwmSlave,-300,300);
    #else
    pwmSlave = CLAMP(pData->iPwmSlave,-1000,1000);
    #endif
RoboDurden commented 1 year ago

Oh thank you very much for opening this issue. Yes i feel very emberassed because this must have been me when i rewrote the comms files. It is so much pain when wasting hours on bug that other have made carelessly.

matixan commented 1 year ago

Thanks for fast response! Im glad someone is actively working on these split boards. It looks like every newer hoverboard is using some variants of these split boards. Ill be mind blowed if someone were ablo to run FOC on it. Big win for https://github.com/Kambodia91/Hoverboard-firmware-hack-FOC-MASTER-SLAVE and @candas1 for trying this out. I belive that in close future it will work on gd32f130 as well.

RoboDurden commented 1 year ago

I have already tried the Candas1 FOC code but i do not have the PlatformIO toolchain installed and with Keil compiler v6 it gives a ton of errors. I still dream to first build a object oriented hoverboard OS and then implement this gen2.x code and afterwards add the FOC code. Unfortunately i can not debug with the Keil IDE. My oo-code is compiling but the main() is not called or some uart libraries are not c++ compatible :-( And as i strongly dislike linux, all these stm32 enviroments are no pleasure to me.

RoboDurden commented 1 year ago

@matixan if have uploaded my oo-code. If you have Keil installed, please take a quick look at https://github.com/RoboDurden/Hoverboard-ObjectOriented-OperatingSystem

Candas1 commented 1 year ago

Just to clarify, I haven't done anything:

I had started back then an inventory of those boards

There are many variants of splitboards with:

And there are different firmwares with different features.

I looked in the past if there are Hardware Abstraction layers than can cover at least GD32F130 and STM32F103 but HALs like libopencm3 only partially cover GD32F130

There are also other firmwares with broader scope that lack some features but bring other features and have a community with more active members like simplefoc

So you have to pick your battle.

RoboDurden commented 1 year ago

Thank you @Candas1 for posting here :-) I already feared that these split boards have no phase current sensing via MOSFET shunt voltages and that this might be needed for foc. Still have not found the happiness to understand foc. So thanks for the info that FOC needs phase currents.

And bad news that the new Artery boards also no longer offer that feature.

It seems that all boards with nice dedicated gate driver chips have no phase current sensing ?

There are new algorithms for sensor less bldc that can calculate the position and start under full load. Maybe the phase currents can somehow be calulated only with the total current and then phases ?

As I said, i never really digged in the theory of FOC :-/

matixan commented 1 year ago

I have some progress regarding @Candas1 fork. It compiles out of the box with some warnings(I changed mcu to C8) I flashed it anyway and theres no smoke. I got CLI ASCII working on steering uart, buzzer beeps when motors disconnected, standstill is IMO working as motor is resisting when im trying to run it by hand. Turning off dont work at all, also no sound on startup. Actually whole code is very mixed as theres loop() running from main(). Also theres some debug info. image Im gonna dig deeper as it might be working. My platform is TTSD22 with 10 inch motors. Now im figuring out how i can controll the motor

EDIT: after uncomenting more code motor is spinning

matixan commented 1 year ago

I have already tried the Candas1 FOC code but i do not have the PlatformIO toolchain installed and with Keil compiler v6 it gives a ton of errors.

I dont think platformio is problematic, it downloaded everything itself

Candas1 commented 1 year ago

I have some progress regarding @Candas1 fork. It compiles out of the box with some warnings(I changed mcu to C8) I flashed it anyway and theres no smoke. I got CLI ASCII working on steering uart, buzzer beeps when motors disconnected, standstill is IMO working as motor is resisting when im trying to run it by hand. Turning off dont work at all, also no sound on startup. Actually whole code is very mixed as theres loop() running from main(). Also theres some debug info. image Im gonna dig deeper as it might be working. My platform is TTSD22 with 10 inch motors. Now im figuring out how i can controll the motor

EDIT: after uncomenting more code motor is spinning

Cool Yeah during my test I was controlling from debug so I probably commenting something out

Candas1 commented 1 year ago

I have already tried the Candas1 FOC code but i do not have the PlatformIO toolchain installed and with Keil compiler v6 it gives a ton of errors.

I dont think platformio is problematic, it downloaded everything itself

Vscode/platformio is nice, you can even get it to run in the cloud (limited time)

https://user-images.githubusercontent.com/20670049/225224072-07f61967-c070-415e-93df-e448801b5544.mp4

Candas1 commented 1 year ago

And just one comment, I have probably left the fork in Sinusoidale, not FOC.

RoboDurden commented 1 year ago

I dont think platformio is problematic, it downloaded everything itself

Can you debug a gen 2 board with a simple st-link v2 clone on platformIO ??? Then I might give it a try to make progress with my oo repo. Can you debug a gen 1 board = stm32f103 ???

matixan commented 1 year ago

I have only one set of mainboards. Debug works, but i had to change flash id to even fit debug code. image

At this moment my progress will slow down due to burned phase. I tried to stop motor unplugging battery :)) There you can find my repo : https://github.com/matixan/Hoverboard-hack-FOC-for-split-boards

RoboDurden commented 1 year ago

After unplugging the battery, the capacitors should get drained and the board turning off. Spinning motors might generator electricity and the energy gets pumped into the capacitors until they blow?

You might want to check my hoverboard repair videos. https://youtu.be/zo2Att8zO3A

Will install Pio on some sunny spring day. Living outdoor with my solar car again..

QGB commented 1 year ago

can not get steer data (always 0)

RoboDurden commented 1 year ago

One liners don't start me thinking.