eferu / hoverboard-firmware-hack-foc Goto Github PK
View Code? Open in Web Editor NEWWith Field Oriented Control (FOC)
License: GNU General Public License v3.0
With Field Oriented Control (FOC)
License: GNU General Public License v3.0
Hello,
Is there a way to take a look what is inside BLDC model plant? (mexw64 file)
Hi,
I'm running the HOVERCAR variant and using an arduino to read FEEDBACK over serial connection. I have noticed that reported voltage (Feedback.batVoltage) when powering on the board is very high, like 400V, and then it gradually gets down to normal levels after 30 seconds or so.
Do you know if this is normal behaviour or perhaps an issue with hardware or software?
Thanks for this excellent project!
hello i want a firmware with foc control to use on my hoverboard with no mods
just as a hoverboard
and to have all 3 modes selectable by pussing different times the power button
and ho hold the power putton to power off
pressing will just change the modes
PLS DO THAT
I am playing with firmware and my GoKart.
Are anybody already implemented electronic brake via Arduino?
Would you share the code please?
Just to do less experiments.
If I have torq 1000, my speed is at max and I need to fully but comfortably stop what shall I send?
If I send -1000 wheels will be blocked? I need to increase back torq? -100, -200, -300? How to do it better?
Thank you.
Hey @EmanuelFeru,
Thank you very much for all your work.
I have been driving my tricycle (two 10" wheels on the back axle) for a while now using bipropellant firmware with your sinusoidal motor control. It has been great compared to the commutation method, more efficient and better max speed (40kmh with 16x LiFePo4), and no issues over 100km+. The only thing where I wished for improvements was quite noisy current limiting.
Yesterday I had time to try this FOC firmware hoping for improved battery efficiency. I chose voltage mode and drove for 10km. Current limiting is working great and not too noisy, but at one point when trying to drive up a 10cm barrier, motor diagnostics decided that motor is stalled and turned everything off. Will have to experiment more with this. Max speed was very similar to sinusoidal. When wheels were not touching the ground, sinusoidal at 500rpm used 1.1A, FOC at 500rpm used 0.9A. But I could not confirm better battery life because battery died much sooner than with bipropellant+sinusoidal. Will test more. I am using ADC control method and was hoping maybe you could help with some questions?
enable == 0 && speed < 20 && speedAvgAbs < 300
. But I think it's specific for my use case and this could be somewhere in motor control? I like to be able to freely move my tricycle using my feet for a meter or two.rtY_Right.n_mot
) I could reach was about 850. As far as I see, current limit wasn't reached and I have printed these values: adc=4095 cmd=1500 speed=1467 rpml=0699 rpmr=-854
. Later I have confirmed with GPS that max speed is about 40kmh (850rpm)
when driving. Of course it's more than enough for my use case, but I am curious, what could be limiting max rpm? I have tried upping these values: FIELD_WEAK_MAX 7
, I_DC_MAX 17
. What is a safe limit for FIELD_WEAK_MAX
?Thanks again!
Would you add Mode switch via UART please? Just to make possible switching between Speed and Torq.
Thank you.
Emanuel, Thanks for all your help. My project of building a direct drive force feedback steering wheel for racing simulator is working well. However, I would like to reduce the "Cogginess" of hoverboard motor that I can feel in high torque, low speed situations. I am using torque mode for this application.
Is there a method to calibrate/commutate the offsets between the hall sensor position to the motor poles? I can't find anything in the documentation.
Would sinusoidal be better then FOC for this application? Have plenty of torque, just need smoother motion.
Thanks
Today I tried sinusoidal type and noticed one difference (issue?) compared to sinusoidal in bipropellant. Sometimes when starting from a standstill, I have almost no acceleration and the wheels sounds like they are at current limit. Max speed is <10kmh, the wheels are screaming and the only way to fix is to lift the wheels above ground and let them turn at higher rpm. Happened three times with sinusoidal and something similar happened once with FOC. But with FOC the issue fixed by itself after driving for a few meters.
Not sure how to reproduce yet. I think this happens when motors are disabled (enable=0
) and wheels move for a few rotations. Will update if I figure out a more reliable way to reproduce.
Hello. I want to make a firmware VARIANT_PWM using - RoboDurden's online compiler.
Please tell me which lines need to be uncommented?
I've commented out the VARIANT_PWM string, but it doesn't work, so I guess I need to do something else?
There are times in my application where i would like to push my cart manually. Any way to put the board in a mode that allows the wheels to spin freely with no resistance. Currently I have to turn the board off completely. I would rather switch to a freewheel mode from my remote.
Let me start with a big thank you for your work and keeping this in active development!
I've an use-case with a balancing single-wheel skateboard ("Onewheel") and I'm using a heavily modified version of your FOC firmware.
Reasons for the modifications:
My fork is here, but I removed most of the code for the variants I didn't use to make debugging easier. So it's probably NOT easy comparing to your original.
But the motor control code is unchanged, so maybe you could still help me with 2 questions:
I started with Type:Sinusodial and Mode:Voltage and implemented a balancing PID in the main loop. The balancing worked and the torque was pretty smooth, but as soon as there was some additional load (rough ground, incline, ...), the motor(s) would 'whine' and then stop. I assume that the 'overload' protection in your controller kicked in faster then my main-loop PID could increase the target voltage. The main loop runs slower than your controller, right? Do you have another theory what could cause the motors to stop?
So I switched to Type:FOC Mode:Speed, because I understand there is an internal regulation to increase the power in case of additional load. But now my PID values were all wrong (everything was much to fast and powerful leading to oscillation). When I scale down my values, the motors don't run smooth, but choppy and loud.
I have two theories, maybe you can give me some advise:
(Btw: I made all the tests for the issue above with only one motor (2 connected, but pwmr = 0
), to avoid any interference from the other problem below)
pwmr = pwml
).Thanks a lot for your time and hopefully your answers.
PS: I now have another HW set available (GD32F103 on both main and sensor boards). I will try your un-modified firmware on both main and sensorboard there too.
Hi. I really appreciate you, that is a really nice work. Thank you for that.
Currently I am making my own e scooter. I am a prep student so I don't know much about firmwares and codes. There are some points that I couldn't understand. Can you help me with those?
İnside the config.h there are some variables about battery. In the comment section you explained calibration of the battery. But I couldn't understand the explanation. What does "see How to calibrate" means? Is there any explanation about how to calibrate? If there how can I see it? And also what does nr 5 and value 6 means? How can I see them?
On my scooter I will use a key switch as on off button so it will not work like on off button (press once and release turn on, press once and release turn off). When the key switch is at the on position my board should work, when it is at off position board should be turned off.
Those are my questions for now. İf I have new questions can I ask? Thanks.
Hi,
fantastic project :) Sorry if this is a silly question but how do you change modes?
Closed issue. Missed the line in config.h
When I build the USART Variant and upload the firmware to the board i get continuous "harsh' beeps and no response from any serial commands.
All works well when I build the ADC Variant and run motors with potentiometers.
What do the harsh beeps indicate? I assume it means firmware isn't right.
Can you provide guidance on how to properly build the USART variant. What lines to change in config.h
appreciate any help
Hi,
I need to control only one motor e.g. left one.
If second motor (right) is disconnected, apart from diagnosing it as faulty, does the left side motor works as usual?
Thanks and I apologise for not testing it myself, I have no experience with reflashing the main board just want to know if I can start to learn it or use a different controller.
And one more question for another project. How does VARIANT_HOVERBOARD work? I want to make an onewheel project(https://onewheel.com/), will this option work for me? There's a caveat the Board should only start to keep balance when both feet are on the Board.
Is it possible to drive the motors of "offroad" hoverboards with this driver as well? They seem to have the same connectors but I am wondering since all the hoverboard hacks seem to revolve around the 250W versions ..
Great project. Speed mode works well for my application but when the speed is small 1-7 the motor pauses between control cycle steps. Is there a way to reduce the pause time to get more continuous rotation in the low 1-7 speed range.
Thanks for sharing your work.
The calculation of input value from raw ADC in the following line can cause incorrect value :
https://github.com/EmanuelFeru/hoverboard-firmware-hack-FOC/blob/62873aad578a20834bc4c036954801f2b4fb23cd/Src/main.c#L280
When ADC_MIN > 0 and raw ADC value > ADC_MAX, cmd will be > 1000 (the maximum allowed value normally).
When raw ADC value is very above ADC_MAX and ADC_MIN is not very small, you can get cmd value > 2047.
When cmd is then converted to fixdt(1,16,4) in the following code, an overflow occurs and final output value is negative, causing reverse operation.
To correct this issue, the first referenced line has to be replaced by :
cmd2 = CLAMP(adc_buffer.l_rx2 - ADC2_MIN, 0, ADC2_MAX - ADC2_MIN) * 1000 / (ADC2_MAX - ADC2_MIN); // ADC2
or simpler and more clear :
cmd2 = CLAMP((adc_buffer.l_rx2 - ADC2_MIN) * 1000 / (ADC2_MAX - ADC2_MIN), 0, 1000); // ADC2
Of course, the same has to be done for cmd1.
Hello Emanuel,
First, congratulations for nice code,
After some try catch with the code and one hoverboard, I start realize your project.
This is about limitations on FOC and low speed, and I understand than at low velocity is moving by torque , and with enough speed FOC starts.
The motor has differential encoder, and I need an extra sensor for position zero degrees, obviously with offset to proper setup, but differential encoder hasn't enough precision for my application.
No big load attached to the motor, minus than the weight of the tire, and the tire is not present, for this application.
I need the precision on rotor angle, but the movement I need for my application is a little bit strange:
The movement starts at 0 degrees.
I need to start with velocity enough to start FOC properly, and synchronize positions.
The move reverse at 180 degrees after and comebacks to 0 degrees.
Some accelerations and decelerations for smooth move.
The precision is important only near 180 degrees, in fact the target is in range between 160 and 180 degrees.
I understand than in the reverse movement, velocity comes to zero,
The question is:
Is possible to use FOC angle rotation, in this move and get enough repetitive on the move,mechanically?,
that we don't know exactly where position it really stops,
If the answer is yes, which kind of precision you belibel I get with FOC angle rotation?, if compare with differential encoder, understanding than one AD converter is not perfect, and the electronics made in china is far perfection.
If the answer is not,
Focus on the reverse move,
Target 170 degrees.
With FOC angle rotation before low velocity,
Disconnect FOC
start reverse by torque,
understand than now, we don't know where is the rotor by FOC,
differential encoder is not used yet, only after that to get zero degrees position.
Do you thing than this can has repetitive mechanically?,
everything and knowing that we don't know exactly where position it really stops,
and reverse.
Thanks for your time and great job with this hack, is not common, congratulations .
Hi Emanuel!
I use your non-FOC version for my robot lawnmower project https://www.youtube.com/watch?v=JAYIfTFY9Fk&t=7s . And it work as a charm. However, I saw you added speed feedback mode in the FOC-version and I wanted to try that for my mower, but the USART- version won't upload to the hover-main board. I't gives a continuous beeping every second. The LED on my ST-LINK V2 toggles between blue and red after the upload attempt. I tried the ADC-version and it uploaded without issues.
Problem: cannot calibrate as per https://github.com/EmanuelFeru/hoverboard-firmware-hack-FOC/blob/master/Inc/config.h#L98 because the required ADC raw values for speed (ADC2) and steering (ADC1) are not in debug output due to incomplete / commented code from
https://github.com/EmanuelFeru/hoverboard-firmware-hack-FOC/blob/master/Src/main.c#L336
It probably should look like:
// ####### DEBUG SERIAL OUT #######
#ifdef CONTROL_ADC
setScopeChannel(0, (int)adc_buffer.l_tx2); // 1: ADC1
setScopeChannel(1, (int)adc_buffer.l_rx2); // 2: ADC2
#else
setScopeChannel(0, (int16_t)speedR); // 1: output command: [-1000, 1000]
setScopeChannel(1, (int16_t)speedL); // 2: output command: [-1000, 1000]
#endif
or just get extended to output all these values.
(the wheels are spinning, albeit with some noise from the control board)
Hello Emanuel,
First of all, thank you very much for the hard work you´ve put into this.
I've tried building both the Hovercar and the ADC variant, and ADC variant is working fine. I don't seem to get the Hovercar variant working as expected though, the motors are spinning back and forth when potientiometer is in the middle (I guess this has something to do with the Torque mode?), and the brake won't work at all.
Still, to be able to debug this I would like to see some text in the serial monitor. I just get a lot of random characters and no text; this is so also for the ADC variant. Tried the NiklasFauth master fork and I get the text in the monitor just fine. I've tried digging into the codebase, but I can't see anything that's off.
Using following settings in Putty:
Baud rate: 115200
Data bits: 8
Stop bits: 1
No parity
Flow control: XON/XOFF
Do you have any idea what might be going on?
Tried disabling the "FEEDBACK_SERIAL_USART3 and enabled "DEBUG_SERIAL_USART3" but output is the same.
I have no sideboard connected at all.
Best regards,
Jens Nilsson
I am using a hoverboard motor for a sim racing direct drive steering wheel. Using ADC torque control works great except when I let go of the wheel, it oscillates badly because there is no friction to slow down any command given. Thinking it would be pretty easy to add a torque coefficient, just not sure how and where.
Basically cmd = cmd - (velocity /friction)
any advice on the best way to do this?
Hi,
I finally managed to get hold of an "old" STM-based hoverboard and awed by your video, I want to hook up my ST-Link and get the wheels spinning -- but I have a few questions and maybe you could take some time off improving the code and add a few pointers to the readme... :-)
Hi. Can i combine this repo with your hoverboard-sideboard-hack to make my hoverboard works same as a normal hoverboard?
If it's possible, which VARIANT i should use?
Thank you very much.
Hi Emanuel,
I have taken 4 ten inch wheels and mainboard from 2 Hoverboards. Constructed my own skatebord and using Benjaf repository to make and build a software which uses PWM as remote. Hence I have a 4 wheel drive and it does around 20 km/h.
https://github.com/benjaf/hoverboard-firmware-hack-esk8
I would be really happy if you could add PWM control to your sw. I would like to try it with my skateboard. My skateboard makes 12 km with 4 Hoverboard batteries.
Many thx for your great effort so far!
BR Stefan
This should use the #defines - it's defaulting to the wrong peripheral/channel:
https://github.com/EmanuelFeru/hoverboard-firmware-hack-FOC/blob/1cc8b3475fc2929dea1685a7dc824458ae5e8e9e/Src/comms.c#L64
@EmanuelFeru : Thanks for the nice working FOC Hack. I will use this for my bobbycar build. I think about changing my motors too delta configuration to get more maximum speed (and less torque). Is you FOC able to handle this? I see two problems (correct me if I am wrong). Commutation will change by 30deg, so no chance to fix this by changing commutation order (only x times 60deg). Maybe this can be fixed by an offset in the position estimator? With change of the motor constants maybe also some parameters of your control loop have to be adapted. Do you have an idea which parameters to scale (by root(3)?). Thanks
(for the ADCmid option I also added a deadzone option, I can make the code nice and share it with you, if you are interested)
Hi
I use this source for the wheelchair, It's very good with low noise but when I change the direction of the motor suddenly by the joystick mainboard has been turned off.
How can I make it smoother with the config file?
Do I need to write my speed PID?
Thank you ...
What changes are required to allow "reversing" of the speed? Should this be done at the CONTROL_xxx level (main.c) or would the introduction of e.g. SPEED_OFFSET and STEER_OFFSET be preferable?
Btw,
#define INVERT_R_DIRECTION
#define INVERT_L_DIRECTION
seem both to be defined by default, but there is no explanation as to why this is required in addition to SPEED_COEFFICIENT.
needed to change this to uint16 to make it work.
However there still seem to be a lot of transmission errors. (I get problems in every 5-6th received string)
I use two hoverboards in my 4WD project. I control boards via ESP32. Use 2 UARTs. When I push power button at main board (where ESP takes power), the second board also switches on (surprise). BUT when I push button again only main board switches off but second still working.
I think that everything could be controlled software.
Is it possible to add feature to turn off second board when main board receive command to switch off (hard button)?
Is it possible to implement UART switch OFF?
Thank you.
without Hall sensors, eg. Sensor less motors. And bidirectional operation.
I've been pushing the power button when flashing and was annoyed that the board would power off when I released it [afterwards]. This change seems to fix that, though it probably would be better to handle/copy the flags directly after reset:
// ####### POWEROFF BY POWER-BUTTON #######
// unless the button is still being pressed after there was a software reset (programmer/debugger)
if (HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN) ) {
// disable motors
enable = 0;
// wait until button is released
while (HAL_GPIO_ReadPin(BUTTON_PORT, BUTTON_PIN)) {}
// don't power off immediately after software reset
if( __HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) ) {
// clear reset flags
__HAL_RCC_CLEAR_RESET_FLAGS();
} else {
// release power latch
poweroff();
}
}
What happen to hoverboard when charging? Because i don't see anything involve CHAGRING in main.c.
Sorry i have to ask you before i try, i don't want anything explode.
Thank you very much.
Hi everyone, I'm new in all of this. i tried PWM version I compiled successfully but no mater what i do steering is not working.Throttle is working. Also with using potentiometers everything working well. can you please advise me how can fix it?
Hi,
I'm a new member of this wonderful forum. I would like you to help me find a solution to my problem, please!
So, my problem is that I purchased Hoverboard for robot projects. Unfortunately, I discovered that it is not original. My project is to control their motors with Arduino. So, I tried to work on it, but I made a mistake and I lost the firmware. There are three CPUs and I only work with one of them. I will mention it in the pictures.
If you can help me get him back to work as they were or given me a solution to control it with Arduino for a robot project ( forward, backward, turn left, and right, with variable speed).
I would be very grateful.
type of board => YK95 V1.1
Hi. I want to use a 65volt battery . But the Board turns on and off immediately. Although everything works from 40v. Please tell me what to correct for work from 65 V. Thanks.
https://www.pionierland.de/hoverhack
i dream you like it :-)
Hi,
i'm trying to control the hoverboard (10" hoverboard) motors through a serial link in python. It works fine in voltage mode but when trying to use the speed mode (wheels off the ground for safety), whatever speed value i send (sending speed of one), the motor revs up to a high speed (lot higher than what i expect). Is the USART control compatible with the speed mode ? Any idea of what is causing my issue ?
thanks
Not that important. But i have a lot of boards with 2 mosfet burned but one motor fully functional. The Fauth firmware still works but you z_errCode shuts everything down.
I tried to uncomment the two apperances in main.c but there is also error checking in the low level src files.
I am currently preparing an efficiency comparison for 250/350/450 Watt motors an would like to also compare with your firmware like i did in https://youtu.be/DILzw6RzPkE
Maybe you want to think about this issue for further updates.
Would you add hoverboard Beeper control via UART?
Thank you.
Is it possible to implement a hold mode to act as a stationary brake?
Not sure if this is doable at all, but if the controller could hold the motors while not driving. At least for a limited time and maybe at a relatively low amperage as to not overheat the motors or the controller itself.
Ignore. Found out that Speed mode does exactly this.
Hello.
Thank you for your project.
I have a problem.
I compiled online your firmvare with options UART and Torq control
I connect WEMOS D1 mini (esp8266) to UART 3 (via SoftwareSerial)
I made a sketch and send command Send(0,300) evey 100ms.
When I send any value different from 0 the wheels start spinning. BUT the speed never changes. 100, 300, 1000 - doesn't matter. 0 - stops spinning.
My board is GD32 - could it be a problem?
What it wrong?
Please help.
Thank you in advance.
The standard PPM code does not include deadband. Since the input from the receiver is rarely a true zero, you will see some jittering and wheels will rotate instead of staying in neutral position when no throttle is required.
Benjaf has created a fix for this (although PWM) in his fork of the original firmware hack. https://github.com/benjaf/hoverboard-firmware-hack-esk8. Hopefully this can be integrated in the FOC firmware as it is in my opinion quite essential for a proper functional PPM variant.
From line 125 in control.c the following code has been added:.
https://github.com/benjaf/hoverboard-firmware-hack-esk8/blob/9aca8c7939ec418b41ac4995fb3cfb2911dfd727/Src/control.c#L125-L135
In config.h the amount of deadband is set with the following line of code:
https://github.com/benjaf/hoverboard-firmware-hack-esk8/blob/9aca8c7939ec418b41ac4995fb3cfb2911dfd727/Inc/config.h#L69
Also, but perhaps this just a feature request. In current settings the motors will actively brake on 1500ms signal, but on e-boards most people would want to freewheel at 0 throttle and brake with reverse. Benjaf modified this piece of code in main.c
https://github.com/benjaf/hoverboard-firmware-hack-esk8/blob/9aca8c7939ec418b41ac4995fb3cfb2911dfd727/Src/main.c#L282-L287
For better start I want to implement some kind of traction control or something like that. If one of the wheels slips the torq shall be decreased for this wheel.
Any suggestions how to do it? At present time I Send(0,1000) via UART so there are no personal torq values for each wheels. Or I can play with steer?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.