NEED A FEW TESTERS WITH FOCBOX UNITY BUILDS - Low-speed Braking Fix Needs Testing

Hey guys, poured some hours this weekend into fixing low-speed FOC braking in the unity firmware. This change can easily be applied to any VESC based design as well if/when I confirm it works well without introducing any unforeseen behaviors on different builds.

Let’s start with the TLDR. Would love it if some experienced people with builds that contain a focbox unity could download and test this FW update. Bonus points if your build experiences the low-speed braking issue. Should be safe I’ve ridden like 10-20 miles on my board with this FW rev but maybe take it slow to start. PLEASE ONLY DO THIS IF YOU ARE FAMILIAR WITH FW UPDATES FOR VESC BASED CONTROLLERS

DOWNLOAD LINK FOR FOCBOX UNITY TEST FW

Now for the details. For context this is a thread discussing the issue:

Maybe slightly wrong to start new topic but I need testers and want to make sure this wasn’t a post buried in a thread. I tried tons of different stuff and what ended up fixing the issue is the following snippet (this is how it is currently) :

// When the filtered duty cycle in sensorless mode becomes low in brake mode, the
// observer has lost tracking. Use duty cycle control with the lowest duty cycle
// to get as smooth braking as possible.
if (m_control_mode == CONTROL_MODE_CURRENT_BRAKE
		&& fabsf(duty_filtered) < 0.03) {
	control_duty = true;
	duty_set = 0.0;
}

And changed it to:

if (m_control_mode == CONTROL_MODE_CURRENT_BRAKE
        && fabsf(duty_filtered)*GET_INPUT_VOLTAGE() < 0.5
        && (fmax( m_iq_set , 0.5/m_conf->foc_motor_r ) >  (double) fabsf(m_motor_state.iq_filter))) {
      control_duty = true;
      duty_set = 0.0;
    }

Essentially before, anytime your board dropped to 3% of the maximum voltage (AKA you were going 3% of max speed) while braking the motor controller would short all leads together. This is necessary because brakes should always oppose motion and at very low speed even a sensored motor only has a good sense of speed and not of its velocity. Thus the sign of the velocity might change rapidly and cause the motor to vibrate, so instead by shorting the leads of the motor we guarantee a viscous damping force. Problem is the 3% duty cycle means different things for different setups. Imagine a build running 12V and 0.1 ohm winding resistance for the sake of example. At 3% duty cycle shorting the motor leads induces a current of

0.03*12V/(2/3*0.1ohm) = 5.4 Amps

This is probably not going to result in much braking force. Now imagine a build running 50V and 20 mOhm winding resistance (probably a high kv motor 6374 or bigger)

0.03*50V/(2/3*0.02ohm) = 112 Amps

This is an extreme example but 112 amps is likely to throw lots of people from their boards. So the first change I made was to remove the dependence of source voltage on the switch-over to duty-cycle control. Instead of 3% duty cycle we instead switch over at 0.5V (duty cycle*source voltage). This is acceptable because the voltage resolution of ADC doesn’t change with different source voltages (fixed resistor voltage dividers for this measurement) so if 3% duty cycle works at 12V then that voltage should work for any source voltage. Here is the part of the if statement that handles that:

fabsf(duty_filtered)*GET_INPUT_VOLTAGE() < 0.5

The second change I made is a bit trickier, this is to fix the brakes “sticking” so to speak. Once you enter this low speed mode the duty is commanded to zero and you never stop shorting the motor leads until you either exceed the maximum motor amps or you release the brake fully. Mainly this is noticeable on steep downhills, hold in your brakes till you come to a complete stop then feather off most of the way but not all. You will realize your board is locked in with very strong braking force regardless of how you feather the throttle. This was a bit trickier to make an exit condition for. Essentially you don’t want to exit if either the current commanded motor amps are less than the induced amps OR if your current phase voltage would be too low to brake properly. Trouble is we have commanded the phase voltage to zero, so instead we have to figure out what the phase voltage would be if we weren’t shorting the leads. This can be done since we know the amps flowing and the winding resistance. Note that I compute it with a bit of added cushion to try and introduce a bit of hysteresis to prevent rapid mode switching or inaccuracies due to changing winding resistance. This is the part of the if statement that computes this:

fmax( m_iq_set , 0.5/m_conf->foc_motor_r ) >  (double) fabsf(m_motor_state.iq_filter)
19 Likes

I can give it a go when I get home today. But what diameter wheels is this proplem most forseen with? @thisguyhere I have 107mm’s and a gear drive and haven’t had any problems with braking.

For most setups it’s mainly just a nuisance. Before you update play around a bit with very low speed and soft braking. Notice the stiff ramp up in braking force right before you stop. With some setups it isn’t noticeable much at all on others it’s extremely obvious.

3 Likes

I’ve noticed this with my hummie hubs since forever, lol. That last 2 or 3 mph, the brake force is super strong, throw off strong. But great at any other speed. I first noticed this 3 years ago with the 4.12 and every vesc since then.

6 Likes

It’s one of those things you can overlook, but why not just fix it.

4 Likes

107mm wasn’t an issue, the 160mm psycho sixshooters is when it happens for me.

i’ll test the unity as soon as i get all my battery orders out the door, hopefully in the next week or so.

1 Like

Alirght, would love to help but don’t see how as i don’t have a problem with my setup.

1 Like

If you can just flash the firmware and confirm that everything continues to work as expected that is also helpful :smile: but don’t feel obligated.

2 Likes

Ok yeah I could do that. Will update you.

Do it for Science but maybe wear extra padding as a just in case

1 Like

I got it covered

4 Likes

I don’t have a FOCBOX unity but I am running two normal FOCBOX’s with this issue. Like @evoheyax said it is extreemely strong last 2-3 mph. Makes sense to equal out to about 2-3% of the voltage. I only run 90mm wheels.

Yeah the change for regular focbox is identical just needs to be compiled. Wanna make sure this works for people.

6 Likes

Great to hear, now that I’m running 4 focboxes! Can’t wait to try it out!

1 Like

From what I read tho basically you were saying even if you feather off the brake {in your fixed version} it will still have the same amount of brake force? Or were you explaining the problem version?

Was I reading this wrong? I feel like as you feather off the brake, you would want the brake force to decrease gradually, like it normally does?

Yeah the brake force should now release as expected. Previously it did not. Sorry if that was ambiguous.

3 Likes

Okay good haha, no that is probably my misreading

I would love to test this, but with my gearing and wheels the braking is completely smooth :frowning:

Yes! I can’t wait to test this (dual focbox, no unity) when these get compiled for other vescs.

I’m even considering forking acks fw and making the changes myself until this gets pushed elsewhere by someone else… Hmmmmm…

Anyways thanks @Deodand for putting in the work to get this fixed!

1 Like

a bit of update @thisguyhere @Deodand i actually realized that i do have this problem. i just never noticed it because i jumped off the board for the last few mph so it was never a concern for me. i got home late today but im getting the firmware on the unity now and i’l test tomorrow. what motor and brake settings do you recommend to test it @Deodand?

4 Likes