My surge code has been coming along well so I wanted to update ya’ll on what I have been working on. Ashton’s perspective was super helpful in identifying the behavior for me. Until I read this post, I did not realize what I have been missing from the onewheel. Here is how my code works.
Surge, by its nature, is a dynamic state. You will see the surge state itself is quite simple, but because it is so dynamic, the conditions that engage and disengage surge are very important. So what is the surge state? It is the motor being driven to maximum duty using the VESC IF function mc_set_duty(). The effect of this is quite predictable. The nose will go up fast and hard so how do we control this.
First, we set some time limits so we cannot surge uncontrolled. I have set up to surge for 250ms on a 750ms period so there will be a minimum of 500ms between each surge. I believe this period is close to what it feels like when you are inching up a steep hill.
Next, we have to know when to engage surge. We want surge to start at a very high torque (current). This will allow a smooth transition into surge because we are already applying a significant amount of force to the front footpad so it will not nose up too quickly.
Finally, we have to know when to end the surge or else the board will remain out of our control. First, we need to make sure we are still accelerating after the surge so we want the nose to be pitched down a minimum angle. If we are pitched up, surge ends with an abrupt brake, which can make you lose control. Second, the pitch cannot be traveling too fast back to center. This could make us overshoot our minimum angle. Lastly, we want some traction control so we don’t lose control during wheel slip.
I am at the point where the code works and I am massaging the start and stop conditions. There is also a vesc if function mc_set_duty_noramp that I have not tried yet. You are welcome to check out my code Izzygit · GitHub Surge9 branch, but be aware that only the main branch is released. No precompiled package yet. I don’t know how to write UI yet so my UI is kind of hacky. It uses the inputs from turntilt and I changed the AppUI.
Here are some examples. Debug data shows time since last surge, duty before surge, duty at end of surge, reason for surge end. If angle speed>0, that was the fault. If angle speed=0, it was a pitch fault. If pitch fault=100%, it was traction control.
Mid speed surge
Low speed surge
Bonk resulting in traction control fault (100% pitch fault)