Regen braking toggling
Regen braking is a motor controller feature where we can regenerate power when braking. We need to support toggling regen braking so that we can disable it when running brakes tests for dynamics.
To increase the robustness and flexibility of the system and reduce annoying distributed-systems problems, we’re going to have centre console as the source of truth for the regen-braking setting, leaving steering stateless. This fits with the rest of the systems, and if for example we want to automatically enable regen braking when transitioning into drive, we can do that from centre console. We’re also going to be a bit careful to ensure consistency between the regen braking state in centre console, what MCI is doing, and what the driver display says the state is.
Breakdown by board
Steering
Steering transmits a “regen braking toggle request” CAN message whenever the regen braking toggle button is pressed. It has no state, it’s just a request to toggle the regen braking state.
Changes required: add a non-critical REGEN_BRAKING_TOGGLE_REQUEST
CAN message. In steering_can.c, get rid of all the state-holding s_enable_regen_braking
stuff, and just send a REGEN_BRAKING_TOGGLE_REQUEST
message in the STEERING_REGEN_BRAKE_EVENT
case.
Centre console
Centre console has a module which handles the “regen braking toggle request” CAN messages and manages the regen braking state. Upon receiving a toggle request, it toggles the internal state, sends a critical “regen braking” CAN message with the new state, and requests an ACK from MCI. If the ACK fails, it reverts to the old regen braking state and sends another “regen braking” CAN message to reset MCI/driver display to the old state. We do this in order to ensure consistency between MCI/centre console/driver display.
Also, the module should have a function to set the regen braking state manually. This function should update the internal state and send CAN messages with the behaviour described above. Call the function to enable regen braking when the power main sequence finishes so we have a consistent default across the system.
Changes required: add a regen_braking_toggle
module in centre console that behaves as described above. Use the existing REGEN_BRAKING
message as the “regen braking” CAN message, but change its message ID so it’s <13, so it’s considered critical and has ACKs enabled.
MCI
MCI receives the “regen braking” CAN messages (i.e. SYSTEM_CAN_MESSAGE_REGEN_BRAKING
) from centre console and updates an internal regen braking state. When regen braking is disabled, in mci_output.c, set the current to zero when the target velocity is less than the actual velocity of the motor. Default to regen braking enabled.
Driver display
Driver display also receives the “regen braking” CAN messages (i.e. SYSTEM_CAN_MESSAGE_REGEN_BRAKING
) and uses them to update the UI. The default should be regen braking enabled when we’re in on main power (i.e. ready-to-drive).