btsimonh / hoverboard-firmware-hack

New Hoverboard Firmware Hack. Now written from scratch and generally much better.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Porting to gen2 hoverboards

gaucho1978 opened this issue · comments

Your work is amazing. I have gen2 hoverboard (the one with 2 boards instead of one) and I would like to be able to restore it with hoverboard functionality. Any hint?

hi @gaucho1978,
no, I torched one of my twin boards (managed to supply 36v to a processor pin). When I ordered replacements, it came as the more standard single board, so I just fitted that.
I would recommend finding a single motherboard set on ebay, and fitting that, then you can install this kind of firmware and have both computer control capability, and a pretty good replica of original hoverboard functionality.
s

(be aware the plastics are slightly different, and not easy to get hold of). I did find a repo of a port to the dual board variety, but it was much less developed than the original of this repo... and i did not find documentation of the protocol between the boards.

were you able to flash some new firmware on it? i would like to build up my own quad (4x4) e-longboard. do you think those boards can do the job?

Tequilahat i've seen your board but it is different than mine. Mine is like the one found on flo (https://github.com/flo199213/Hoverboard-Firmware-Hack-Gen2) repository (you linked it, so you know it). Anyway I'm still waiting the programmer

Btsimonh thank you. I Will flash mine then if my lawn mower project Will fail, i Will try to port your code on my board. The protocol between the 2 boards it is not documented on flo repository (https://github.com/flo199213/Hoverboard-Firmware-Hack-Gen2) but it is easy, reading the code, to understand how it is structured. I Think the hard part is to read the accelerometers and to correcly use that data. But i suppose i can copy your code for this!

Another thing that i need to do is to exactly control the movement of the robot. For this reason i suppose that i have to check the position of the motors coming from the hall connectors and to count the Number of turns of the wheels to know where the robot is inside the garden (once he stored the perimeter of the garden thanks to proximity sensors).
I think i Will implement something to let me tell the robot: "go straight for 90cm then turn 90degrees on the right "

the problem will be the accellerometers - i don't know if that repo has code to read the chip, but I do not know of any code - i get the data from external boards over serial.....
The hall sensors give you ~6mm resolution in wheel position, and the dead reckoning code gives you X/Y assuming no slippage (you would need this code outside the boards, as your boards are separate?). The position control in my repo is not bad - you can ask each wheel to move to a certain position, e.g. fwd 10cm, but the accelleration curves could do with some finesse - i.e. it would be better to be able to say 'move fwd 10cm at 2cm per sec'.
In speed control mode, you can say 'move fwd at 10cm per sec'.
Ideally, we'd implement a command which said 'go here via these waypoints at this speed'.
I am also considering driving a lawn mower :). Measuring absolute position is a real challenge. For your controller, I'd recommend RPIZeroW (I mounted one inside my HB running off 12v->Dc/DC -> 5v, and connect usb serial and usb STLINK, then SSH to RPi for flashing. I use Node Red for control - easy web based javascript).
The RPi would allow for a Camera with OpenCV, and you could use wireless signal strength for triangulation; you could even place a few BluetoothLE devices for more signal strengths to measure....

the problem will be the accellerometers - i don't know if that repo has code to read the chip, but I do not know of any code - i get the data from external boards over serial.....
The hall sensors give you ~6mm resolution in wheel position, and the dead reckoning code gives you X/Y assuming no slippage (you would need this code outside the boards, as your boards are separate?). The position control in my repo is not bad - you can ask each wheel to move to a certain position, e.g. fwd 10cm, but the accelleration curves could do with some finesse - i.e. it would be better to be able to say 'move fwd 10cm at 2cm per sec'.
In speed control mode, you can say 'move fwd at 10cm per sec'.
Ideally, we'd implement a command which said 'go here via these waypoints at this speed'.
I am also considering driving a lawn mower :). Measuring absolute position is a real challenge. For your controller, I'd recommend RPIZeroW (I mounted one inside my HB running off 12v->Dc/DC -> 5v, and connect usb serial and usb STLINK, then SSH to RPi for flashing. I use Node Red for control - easy web based javascript).
The RPi would allow for a Camera with OpenCV, and you could use wireless signal strength for triangulation; you could even place a few BluetoothLE devices for more signal strengths to measure....

dear @btsimonh I would like to do the following, on the 2 boards firmware:

  1. implement PPM input (it is implemented in your code, so I suppose I can copy something from you)
  2. control the robot with my radio control (I play with ardupilot, and multicopters in general, so I have some spare radio controls)
  3. To don't use external boards. the challenge is to use the internal GD32 chip to control everything.
  4. the 2 boards communicate through a serial port and they both use GD32 chip. I don't need to have real time communication since the master board can tell to the slave board "go forward 50 steps at speed xxx km/h". Once it reaches the destination point, the slave board can tell to the master "I'm arrived! what's next movement?"
  5. Next objective will be to read proximity sensors. Each board has a free serial port, so I suppose I can connect at least 2 proximity sensors (the best is to connect 4 proximity sensors, for this reason I'm lloking for proximity sensors that can be connected in a chain like on a 485 bus, in order to be able to connect 4 sensors on a single differential serial port).
  6. If I will fail, I will remount the hoverboard and then I will need your code to implement HB functionality. The accelerometer on my board is directly connected through 2 gpio pins. on its repo Flo wrote the model of accelerometer but on my board I can't identity the label on the integrated circuit. It is possible it is a Chinese chip with the same functionality. I will investigate on this just if I need to. Moreover if one wheel of the lawn mower rotates on the grass without real movement of the robot, to use even the accelerometers could be a solution to increase reliability on the position calculation.

The hall sensors give you ~6mm resolution in wheel position, and the dead reckoning code gives you X/Y assuming no slippage (you would need this code outside the boards, as your boards are separate?). The position control in my repo is not bad - you can ask each wheel to move to a certain position, e.g. fwd 10cm, but the accelleration curves could do with some finesse - i.e. it would be better to be able to say 'move fwd 10cm at 2cm per sec'.
....

according to the code on the Flo repository, I can read that the motor control routine sets the 3 phases to 90 degrees in advance respect to the current position of the motor. This is done considering only 6 possible positions of the motor. So the easy way to implement position control, could be to read the position just in the 6 positions, and to stop the motor once it reach the position. SO the command could say: make 12 steps forward, and the motors will perform 2 complete rotations.
Do you think that this approach with "minimal" modifications of the original code will work?

those '6' positions are repeated around the wheel. each 'position' is ~6mm of movement. The 90 degrees refers to the phase of the signal, not the angle of the wheel....

those '6' positions are repeated around the wheel. each 'position' is ~6mm of movement. The 90 degrees refers to the phase of the signal, not the angle of the wheel....

:-O really?!!!!!

looking at this picture ( https://raw.githubusercontent.com/flo199213/Hoverboard-Firmware-Hack-Gen2/master/Raumzeigerdiagramm.png ) it seems that a complete rotation of the phases correspond to a rotation of the motor. Instead you are telling that one position is around 6mm so, one rotation of the phases is 36mm that correspond to 1/14 of the rotation of the wheel (wheels of 6,5" so the perimeter is 519mm) .
Are you sure?

yes, sure, but not on the exact numbers (have a feeling there are 60 'positions', it's in the code).
Each 'position' is effectively one magnet on the inside of the wheel drum (or maybe half a magnet, i don't know). So you have quite fine knowledge of position and speed by hearing the hall input changes :).
Think of the wheel as a linear motor wrapped into a circle.

thank you.

commented

@gaucho1978 Your Diagram indicates One "electrical" revolution - where all 6 hall phases are stepped through. This would be the same, if you had only three windings and 1 magnet pole pair.
If you have 2 pole pairs, one mechanical revolution equals 2 "electrical" revoltuions. I don't know exactly how many pole pairs our motors have, but it's a lot.
You can find some nice illustrations here: https://electronics.stackexchange.com/questions/224797/3-phase-induction-motors-with-poles-not-equal-to-3x

@btsimonh and @p-h-a-i-l which IDE do you suggest me to use?
I want to use Microsoft windows 10.
I want it opensource (or cracked)
I will use st link programmer.
I like visual studio ide but I've seen that visual GDB is not free.

see the readme.md for programming instructions using openocd.
my preference is VSCODE + Platform.io, i'm on windows 10.
I've not done any live debugging as such.....

see the readme.md for programming instructions using openocd.
my preference is VSCODE + Platform.io, i'm on windows 10.
I've not done any live debugging as such.....

thank you @btsimonh .
ok, I'm downloading VSCODE and platformio.io. Is it a free solution? any known problem? any hint?

all free - it should go swimingly - but these things never do! In theory, platform.io will automatically download tools and libraries as required - just open this project folder, and try a build. Then duplicate, rename, strip and add the files from the other repo.... (then hit all the differences between keil and pio!)...

commented

Actually, found an image some took of an opened hoverboard motors.
c137f9e7-3e35-4c41-a01f-1722cb4ce356
You can see the small hall sensor PCB. It only detects one position, which is still one electrical revolution.

commented

I use platformio in vscode on linux

all free - it should go swimingly - but these things never do! In theory, platform.io will automatically download tools and libraries as required - just open this project folder, and try a build. Then duplicate, rename, strip and add the files from the other repo.... (then hit all the differences between keil and pio!)...

@btsimonh I compiled your code with success (just some warning on unsigned long assigned to long variables)
then I copied inc and src and RTE folders from Flo repository to the folder with your code
then I tried recompiling but it fails with this error:
src\comms.c:31:10: fatal error: gd32f1x0.h: No such file or directory

That .h file is not available on Flo repository but there is a RTE folder with something related to gd32 chip.
What should I do?

May be it's easier if I begin with keil...
what do you think?
Is it a so bad IDE?

not used it for years; but should be ok. It is apparently free for small code (which this should be...), and it should at least work - platform.io can be a little 'opaque' in how it is working/what it's adding automagically.

commented

Keil should be ok, but you will quickly run into the 32k limit.
I wanted an IDE which can be used an windows and linux, and I really like how simple it is to get a new system running with vscode and platform.io.
What I don't like, is the missing multi window support of vscode and debugging is a premium feature of platformio.

ok @btsimonh and @p-h-a-i-l but then how should I solve the found problem?
how to find or create the library for gd32 arm?
I can't find anything on the web.
I opened 2 threads on the platformio community website but no luck up to now.
If I well understood from your message 32kB could be a limitation for my project, so it's not the best choice...

@btsimonh I've seen that you forked the Flo repository https://github.com/btsimonh/Hoverboard-Firmware-Hack-Gen2
did you made any interesting change?
p.s.> I'm downloading keil

hi @gaucho1978,
no, I torched one of my twin boards (managed to supply 36v to a processor pin). When I ordered replacements, it came as the more standard single board, so I just fitted that.
I would recommend finding a single motherboard set on ebay, and fitting that, then you can install this kind of firmware and have both computer control capability, and a pretty good replica of original hoverboard functionality.
s

@btsimonh how did you fried your board? bad soldering? bad connections?

I successfully compiled with keil. Now I need to try to flash it.

@btsimonh how did you fried your board? bad soldering? bad connections?

stupidity.
The 'on' button connector carries 36v, not 3.3. Had a flying lead on it so i could reboot quickly (kind of related to attempts to extract the firmware... the STM hack involved pausing the CPU just after startup). Somehow I managed to connect this to a CPU pin directly.

p.s. - no changes in my repo...

@btsimonh how did you fried your board? bad soldering? bad connections?

stupidity.
The 'on' button connector carries 36v, not 3.3. Had a flying lead on it so i could reboot quickly (kind of related to attempts to extract the firmware... the STM hack involved pausing the CPU just after startup). Somehow I managed to connect this to a CPU pin directly.
p.s. - no changes in my repo...

I read about methods to extract firmware from st32 chip. I understood it is not easy and may be new chips are protected against these attacks.

commented

What kind of attacks? Glitching?

commented

Interesting.. Do you know if this attack is possible on STM32F1 too?
But maybe that's not a very viable attack. If the full flash was used, It would take 6 months to extract :)

the GD32 did not seem to behave as described in the papers.... I found a bit of code which operated the debug interface, and put it in an 8266, then modified it to perform the attack.... I think also the STM32F1 was not vulnerable.

Hi guys. Were you able to use the motors with the Gen2 boards? I want to try with a different board that I have. But I dont know how to tell if the pins share th same conections. Could you advise me please?
2