Explain what this C# code does in simple terms: // Don't start computing resistance until the bleed resistors have been engaged for a bit
// Determined as engaged if shorting contactor is closed
bleedResEnabled_ton(IN := K_HV0_CLS.pv, PT := T#1S);
IF bleedResEnabled_ton.Q THEN
//Compute raw bleed resistor resistance and its filtered value
// Absolute value check ensures stack voltage and current are not negative values
IF CT_HV3.pv > 1E-1 AND VT_HV3.pv > 1E-1 THEN
BLEED_RES_OHMS.SetPV(VT_HV3.pv / CT_HV3.pv);
END_IF
// Filtering resistance reading with weighted average filter, period of 100ms
BLEED_RES_OHMS_FILT.SetPV(FFilt(input:=BLEED_RES_OHMS.pv, tFilt:=c_secForSlopeCal_i16, tCycle:=0.1, init:=FALSE, filtPrev:=BLEED_RES_OHMS_FILT.pv));
// delay the slope calculation until 5 sec after filtered value is low enough. mainly due to the slope calculation uses 5 sec of data
// this makes sure the slope is calculated when the last 5 sec data is low enough.
// Note: Timer and slope alarm tied to resistance alarm limit to mirror HD+, where it has multiple resistor configurations
// For 70kW, alarm limit doesn't get altered in the logic, but kept consistent logic format
resSlopeEnabled_ton ( IN := ( BLEED_RES_OHMS_FILT.pv < A3_BLEED_RES_OHMS_L_25500.lim_f32*1.15), PT := T#5S );
// latch the _ton, such that once BLEED_RES_SLOPE starts, it'll always keep calculating (no stale values)
IF resSlopeEnabled_ton.Q THEN
resSlopeEnabled_b8 := TRUE;
// ELSE: no change of the resSlopeEnabled_b8 value, covered in outer ELSE loop
END_IF
// Keep an array of filtered bleed resistance values with one new value every second
//Run a one-second timer
// 900 ms TRUE + 100 ms FALSE since this is called every 100 ms
// Timer is called at lower level than application, loop 100 ms execution may not line up with timer timeout
populateResistanceArray_ton(IN := TRUE, PT := T#900MS);
//Keep an array of filtered bleed resistance values with one new value every second
// Every time the timer elapses, reset the timer and shift every element in the array down one position.
IF populateResistanceArray_ton.Q THEN
// reset timer
populateResistanceArray_ton(IN := FALSE);
FOR i_i16 := 1 TO c_secForSlopeCal_i16 DO
filteredResArray_f32[i_i16-1] := filteredResArray_f32[i_i16];
END_FOR
// push latest reading to last entry of array
filteredResArray_f32[c_secForSlopeCal_i16] := BLEED_RES_OHMS_FILT.pv;
// Should we update thes slope value?
// 1. have filtered resistance data for c_secForSlopeCal_i16?
// 2. slope calculation enabled(started)?
IF ( ( filteredResArray_f32[0] > 0 ) AND resSlopeEnabled_b8 ) THEN
BLEED_RES_SLOPE.SetPV( (filteredResArray_f32[c_secForSlopeCal_i16] - filteredResArray_f32[0]) / INT_TO_REAL(c_secForSlopeCal_i16) );
END_IF
END_IF
ELSE
populateResistanceArray_ton(IN := FALSE);
resSlopeEnabled_ton(IN := FALSE);
resSlopeEnabled_b8 := FALSE;
FOR i_i16 := 0 TO c_secForSlopeCal_i16 DO
filteredResArray_f32[i_i16] := 0;
END_FOR
// Logic derived and developed concurrently with HD+'s freeze startup resistor (similar part with different resistance)
BLEED_RES_OHMS.SetPV( A3_BLEED_RES_OHMS_L_25500.lim_f32/0.855 );
BLEED_RES_SLOPE.SetPV(0.0);
BLEED_RES_OHMS_FILT.SetPV(FFilt(input := BLEED_RES_OHMS.pv, tFilt:=c_secForSlopeCal_i16, tCycle:=0.1, init:=TRUE, filtPrev:= BLEED_RES_OHMS.pv));
END_IF