Yet another hoverboard to onewheel project

Hi All

I’ve used the bipropellant firmware to flash the hoverboard controller of my self build onewheel. The onewheel uses two joined hoverboard hub motors. The bipropellant firmware did indeed seem to have some issues. I ended up removing most code, rewired some phase and hall cables, and then the motors started spinning :slight_smile:

Although the codebase looks big, the ‘hoverboard’ functionallity only comes down to one line in main.c:
pwms[i] = CLAMP(dirs[i]*(sensor_data[i].complete.Angle - sensor_data[i].Center)/3, -FlashContent.HoverboardPWMLimit, FlashContent.HoverboardPWMLimit);

That is technically only proportional control so, angle == speed.

There are a couple of improvements that i’m experimenting with that should mimic the onewheel more (although i’ve never opportunity to ride one). One of the things i noticed when riding with the original hoverboard firmware and the bipropellant firmware was that you have to keep the nose down to maintain speed, this leads to a rather uncomfortable drive. Quick fixes like multiplying the measured angle by a number will allow you to reduce the amount of tilt required for a given speed, but the board will feel ‘stiff’ afterwards. Giving it an offset tilts the nose, but then the board wants to keep you at that angle, also not nice. Maybe the following could help, and looks to be in line with the Arduino firmware from the latest post:

  • pid control of the angle, output is acceleration (not speed!)
  • pid control of the speed, output is acceleration (not speed!)

Then summing the outputs of both pid’s yields a number that can be added to the current motor pwm. The desired ‘throttle’ is determined from the I component of the balance control pid.

With initial tweaking, i found that the board was quite ridable, and when the speed loop picks up, the board changes in feel from skateboarding to surfing. This system acts like a horizontal cruise control, with the added benefit that the board becomes relatively terrain independent. The same nose tilt for the same time will give you the same speed, regardless of terrain/motor effort. Another added benefit is that the motor will maintain roughly the same speed, even when not touching the ground, so landing a drop becomes way easier.

Pushback is implemented by looking at the pwm duty cycle (and motor speed). The balance algo simply gets a new target angle 2 deg instead of 0. This raises the nose.

My findings after a 10 km test run: the sinusoidal control (3rd harmonic) from the bipropellant firmware makes the motor feel as if its ‘grinding’ all the time, like the board encounters friction (motors do not heat up, and spin near frictionless when not controlled), accompanied by a hum sound. Only after a certain speed, it seems to change drive settings and becomes butter smooth and silent.

The board is still uncomfortable to ride past 10 km/h, for some reason, you ‘feel’ that the board will not have te power to keep you balanced, im not sure if this is true, because pushback was not activated at this point, so i had at least 10% duty cycle left over, technically enough to balance at speed, given no unexpected humps.

My hypothesis is that the feeling of the board is due to the way the motor is controlled. FOC in torque mode should give more torque at higher speeds, and allow you to ‘coast’ smoothly because the motor can be left freewheeling.

What I will do today: take the FOC branch from Bula87, and port my current code from the bipropellant repo to this one. It should give FOC torque mode, the control loops should be able to remain the same, except for the pid values.

Let me know if anyone is interested in the bipropellant software version, ill put it on github then.

1 Like

@Zuen You’re right, it’s interesting to look at it. I think it is necessary to post the code on GitHub and what you said today to make an additional topic on GitHub. Together we can finally master this new firmware mode - OneWheel. If I can help in any way, please tell me.

Dear Vfear,

Will upload the firmware to my gh and post the link asap. I’ve seem to have hit a bit of a bump with proceeding with the FOC firmware. I wanted to flash the sideboard first, had a spare one so tried it (had an stm32f103 on it), unfortunatly i could not erase the chip, JFlash lite would not allow it. I suspected voltage issues, rewired some stuff, and ended up accidentally touching the 12v to the 3.3v line, and fried the sideboard… Then took a spare hoverboard, that one had the GD32 IC on the sideboards. Unfortunately same issue, unable to erase the chip.

Would you happen to know a solution to this issue? I’m using a jlink edu, and my sideboard is blue, with a green radio ic on a separate pcb that is mounted on the sideboard using headers. Silkscreen says: 2015.11.30 Ver 3.0

These are the main boards I’ve started to rewrite code for. That have the GD32 IC’s, if you have any interest in reprogramming them or helping rewrite some code base I’d sell you a set of ESC’s real cheap. I have 10+ sets that I want to turn into onewheel and go kart type projects. From what I read I thought it was best to use a st link and the st link application for flashing?

@Zuen How to Unlock MCU Flash · EFeru/hoverboard-firmware-hack-FOC Wiki · GitHub

I suppose it might be better not to use the original side board for balance, but it would be better to make an external mpu6050 with a controller and send data via uart. Since I realized that there are compatibility issues with the side boards. Not all models of side boards are flashed, said the author of EFeru Foc. And this part of the program was never completed.

@Zuen @bula87


Mpu6050 +arduino uart

1 Like

Dear Mr. Electronicist,

Thank you for your offer :slight_smile: The sideboard you show is the ‘split board’ hoverboard mainboard. I currently my onehweel working with the motherboard that is able to drive 2 motors (so the original single board hoverboard controller) and would like to leave it like that.

With regards to flashing, it might be an artifact of me trying to use jflash instead of st-link, until now that has never lead to any trouble, but wil order an st-link v2 and retry tomorrow

2 Likes

Dear @Vfear,

Thank you for your reply, I will order an st-link v2, just to test out the procedure you link to on the gh page. Until now, my jlink has been able to perform all programming & unlocking tasks, but maybe this was one step too far. When connecting the IC, it told me it was locked, and needed unlocking, normally this procedure works (although with Nordic IC’s, and regular stm’s). With regards to gyro control in general I had a couple of considerations before choosing to use the original sideboard with the original firmware on bipropellant:

  • I was a hardware&firmware engineer for quite some time, and the MPU6050 is a dragon, it looks easy, but making sure that thing never crashes, or bug’s out is rather difficult.
  • More variabels: By flashing the sideboard firmware, I would introduce another variable to the system that could fail by my incompetence, making debugging harder, and getting confidence in riding the board will also take longer.
  • The orginal PCB has the footpad sensors, which is also rather convenient.

Now I also do see a lot of advantages and fun of using a custom sideboard. It could be the brains, and just control the hoverboard ESC board via uart/pwm. The balancing algorithm could live in the arduino, that does not also have to bother with the high speed motor control. Also the option for different types of footpad sensor & behaviour is possible.

So I guess there’s three routes to explore:

  • Flash the sideboard using an st-link v2
  • Update the FOC code to work with the original sideboard firmware (should not be difficult)
  • (Temporarily) Make an arduino + mpu6050 (or other acc+gyro +dmp)

Route 1 and 3 make the most sense for now, and would block the least amount of time. I’ll do both and report back tomorrow (since getting the st-link & arduino + mpu6050 will take a day).

The video you attached, is the motor controlled bij FOC? It looks snappy :slight_smile:

I’m not allowed to attach a picture of my current board, it’s a bit rough, but im not unhappy with how it came out. Will send when allowed :slight_smile:

1 Like

Dear @Vfear,

Good news, went through my junk pile and found an st-link v2, and mpu6050 and and arduino :stuck_out_tongue: Will give that combo a try this afternoon.

yes FOC, haven’t set it up yet

this is a really good idea, as there will be no compatibility issues (there are many different types of side boards) … maybe this is not a problem, I want to make it so that it would be accessible to everyone without problems) we need to check everything

Dear @Vfear,

I tried the ST-LINK route, it allows me to disable the readout protection → however only when using connect under reset mode. Then I was able to clear the memory. But now the st-link utility does not allow me to flash the chip, it just throws a: programming error @: 0x080000000. So I guess i’m going to have to rig up and arduino + MPU6050 this evening.

Kind regards

@Zuen Is the wiring sequence correct? =)

On the side boards there is a different sequence for connecting wires

@Vfear,

My sideboard looks newer, can’t post pictures, but its the sideboard that also has the bluetooth audio amplifier on it (which i desoldered). They come from a spare hoverboard that has a single ESC, and two sideboards. I’ve figured out the wiring, st-link can read everyting on the chip, and erase it. But for some reason it failes when flashing → I did the unlocking.
Jlink complains about not beeing able to download RAMCode
ST-Link complains without an error, just failed to flash

The funny thing-> I am able to individually set bits in the flash memory, write them, and they persist over a power cycle. So flash memory is ok, programmer is ok, wiring is ok… There’s just something in this processor that disallows dumping the .bin file on it via st-link.

@Zuen I also had the same problems with firmware … out of 3 boards, only 1 flashed (and still didn’t work, something was wrong with them), so I think it’s the right choice to make a custom side board.

@Vfear ok the gd32 sideboard looks like a dead end then. I’m now breadboarding an arduino due with mpu6050 as gyro, using the MPU-6050 DMP, that seems to use a complementary filter internally. Sounds odd, but my preference might actually be using the original sideboard, and updating the FOC branch to use the original protocol.

My reasoning is as following:
-There are only a couple of sideboard protocols, it’s up to the user to select the right one, but if you are busy with this kind of projects, I think you’ll be able to hook up a scope and count transitions/bit times on the uart to figure out bitrate and amount of bytes used. Especially if clear documentation is provided. We could even build an arduino script to figure it out automatically.
-The original sideboard firmware is rock solid, i’ve never had a sideboard fail in operation, nor did it give me ‘wrong’ readings ‘ever’.
-The MPU-6050 looks simple, but is really complicated. The DMP has issues determining angle on relatively fast angle changes, and tends to overshoot in the wrong direction. During testing with an Arduino DUE & MPU-6050, using off the shelve library + example code, it locked up twice without an apparent reason, but is now running stable for an hour, that kind of stuff scares me if im driving around at 10/15 mph on a single wheel, and I don’t have time to completely rewrite the MPU-6050 driver ( we did that in the company I used to work for, but still that thing remained an unstable total b#*ch, and we were definately no noobs).
-A custom side board is easily made, but getting those in the hand’s of makers is difficult. If you take bare components, many won’t be to source and to solder those by hand. If you take break-out boards, you are dependent on them staying around and be (locally) sourceable.

All in all, the situation is not ideal, either there’s dealing with different protocols & baudrates from different manufacturers vs building custom PCB’s and making sure they are accesable by the community. Let me know your thoughts?

@Vfear, a happy compromise would be to use the original sideboard protocol, but also offer an (arduino) software library that could send messages using the same original protocol. So people with sideboards with naitive firmware will be able to use the FOC repo, people with custom sideboards will have an easy setup. Also the current sideboard STM code could be updated to use the original hoverboard comm’s protocol.

In that case, there’s 3 hardware options, that should serve everyone, regardless of their current firmware state of the sideboards/custom boards (native vs custom).

@Zuen Yes, that’s right, I agree with you. stability while riding on one wheel is the most important thing, it’s safety