doppelhub / MuddersMIMA

Mudders Take on Manual IMA Control in the G1 Honda Insight
GNU General Public License v3.0
2 stars 4 forks source link

mode 1: brake detection alternates on / off #10

Open Hurricos opened 8 months ago

Hurricos commented 8 months ago

Edit: I believe you've commented on the forums RE: changes to improve brake-off detection; separately, it seems this TODO requests it intentionally, but the implementing commit 15e8938a321050a84cbf16b3732b58566b6ac1a8 still includes the TODO:

  //JTS2doNow: When brake pressed, gpio_getBrakePosition_bool() alternates between "Lights ON" & "Lights OFF"

I'll review this TODO more closely before I have more questions.

Continuous BRAKE detection isn't working in mode 1: when one connects the brake switch, it is initially detected as pressed, but 250 < interval < 750ms later is read as 'released' even if the brake is still depressed (before alternating back to pressed). This impairs the effectiveness of any solutions which monitor brake position continuously.

I think I know why this is happening:

In mode 1 (=>BRAKE_LIGHT_AUTOMATIC), the initial brake press is read without issue (great for safety!), because if LiControl isn't driving the brake light,

# MuddersMIMA.git:muddersMIMA_firmware/brakeLights.cpp::L44

        else ... { gpio_brakeLights_floatPin(); }

However, once [the FET driver is fully released?], the brake lights [are detected as on by the brake switch], and in mode 1 (=>BRAKE_LIGHT_AUTOMATIC) the firmware assumes it is the one driving it on and turns it off, forcing the GPIO input off (though brake lights and other things feeling the switch stay on).

# MuddersMIMA.git:muddersMIMA_firmware/brakeLights.cpp::L43
        else if(gpio_getBrakePosition_bool() == BRAKE_LIGHTS_ARE_ON)           { gpio_brakeLights_turnOff();  }

I'll test the change I have in mind for this; it involves tracking whether LiControl is asserting the brake on, and leaving the brake GPIO floating otherwise.

@doppelhub please let me know if there are any concerns with the electronics side of this. I'll live if I fry my own boards, but not if this is misguided and risks other users' safety. I think I see the issue; see comment below.

Additional note: I believe that TODO is unrelated to BRAKE_LIGHT_PULSE, which is for LiControl-driven braking; note that as a business, publishing firmware which makes brake lights flash may run afoul of NHTSA recommendations and federal law.

Hurricos commented 8 months ago

I see the issue with my proposed change:

diff --git a/muddersMIMA_firmware/brakeLights.cpp b/muddersMIMA_firmware/brakeLights.cpp
index 8e4f1d1..8d94a43 100755
--- a/muddersMIMA_firmware/brakeLights.cpp
+++ b/muddersMIMA_firmware/brakeLights.cpp
@@ -40,7 +40,7 @@ uint8_t brakeLights_handler(void)
        //JTS2doNow: When brake pressed, gpio_getBrakePosition_bool() alternates between "Lights ON" & "Lights OFF"
        if     (joystickPercent < JOYSTICK_MIN_ALLOWED_PERCENT)                { gpio_brakeLights_turnOff(); } //joystick input too low 
        else if(joystickPercent < TURN_BRAKE_LIGHTS_ON_BELOW_JOYSTICK_PERCENT) { gpio_brakeLights_turnOn();  } //strong regen
-       else if(gpio_getBrakePosition_bool() == BRAKE_LIGHTS_ARE_ON)           { gpio_brakeLights_turnOff();  }
+       else if(gpio_getBrakePosition_bool() == BRAKE_LIGHTS_ARE_ON)           { gpio_brakeLights_floatPin(); } //not controlling brake light, so don't assert it
        else                                                                   { gpio_brakeLights_floatPin(); }
    }
    else if(brakeLightMode == BRAKE_LIGHT_FORCE_ON) { gpio_brakeLights_turnOn();  }

The issue is that in mode 1, if the brake pedal is pressed, BRAKE_D goes high, making BRAKE_uC go high and activating the BRAKE_EN input of U1, the high-side FET driver. We need to drive the high-side FET low for long enough to disable the FET before we can resolve whether the brake switch is supplying voltage on BRAKE_RAW.