<Gauge Name="abrk" Version="1.0">
  <Update Hidden="Yes">
    (L:ABrkactiv, number) (L:ABrkactivlast, number) !=
    if{
    (L:ABrkactiv, number) (&gt; L:ABrkactivlast, number)
	
    (L:ABrkactiv, number) 0 ==
	(L:ABrkactivlast, number) 2 != &amp;&amp;
    if{
	0 (&gt; L:BrakesWaitNotify, number)
    0 (&gt; L:AB_ABrkpidOut2, number)
    0 (&gt; L:AB_ABrkIntegral, number)
    0 (&gt; L:BRKPIDCOUNTER2, number)   
	
	1 (>L:Autobrake_position, bool)
    0 (>L:RTOCond, number)
    0 (>L:LandCond, number)
    2 (>L:ABrkactiv, number)
    0 (>L:RTOAble, number)
    0 (>L:LandAble, number) 
	
    -16384 (&gt;L:AXIS_LEFT_BRAKE_SET)
    -16384 (&gt;L:AXIS_RIGHT_BRAKE_SET) }
	
	}
	
    (L:ABrkactiv, number) 1 == 
	(L:Green_Pressure, number) 1500 &gt; &amp;&amp;
    (L:Pause2_code, bool) 0 == &amp;&amp;
	(L:MP_CONN, number) 0 == &amp;&amp;
    if{
    <!--wait(dt) XML DEF 18Hz-->
    1.8 (&gt;L:AB_ABrkdt, number)

    <!--setpoint - process_feedback = error-->
    (L:SetAcceleration, number) (A:ACCELERATION BODY Z, Feet per second squared) (L:ACCELERATION BODY Z, Feet per second squared) + - /-/ (&gt; L:AB_ABrkSetErr, number)

    <!--integral + (error*dt) = integral-->
    (L:AB_ABrkSetErr, number) (L:AB_ABrkdt, number) * (L:AB_ABrkIntegral, number) + 2000 min -2000 max (&gt;L:AB_ABrkIntegral, number)

    <!--(error - previous_error)/dt = derivative-->
    (L:AB_ABrkSetErr, number) (L:AB_ABrkPrevERR,number) - (L:AB_ABrkdt, number) / (&gt;L:AB_ABrkDerivative, number)

    <!--(Kp*error) + (Ki*integral) + (Kd*derivative) = output-->
    1 (&gt;L:AB_ABrkLoopGain, number) 0.2 (&gt;L:AB_ABrkInt, number) 0 (&gt;L:AB_ABrkDif, number)

    (L:AB_ABrkSetErr, number) (L:AB_ABrkLoopGain, number) * (L:AB_ABrkInt, number) (L:AB_ABrkIntegral, number) * + (L:AB_ABrkDif, number) (L:AB_ABrkDerivative, number) * + (&gt;L:AB_ABrkpidOut2, number)

    <!-- Output and windup limiting -->
    (L:AB_ABrkpidOut2, number) 100 min 0 max 2 * 100 - (&gt;L:AB_ABrkpidOut2, number)
    (L:AB_ABrkpidOut2, number) 163.83 * (&gt;L:AXIS_LEFT_BRAKE_SET)
    (L:AB_ABrkpidOut2, number) 163.83 * (&gt;L:AXIS_RIGHT_BRAKE_SET)

    <!--previous_error = error-->
    (L:AB_ABrkSetErr, number) (&gt; L:AB_ABrkPrevERR,number) } 
        
    <!--Power Set-->
    (L:Autobrake_position, bool) 0 ==
    if{
    -13.5 (&gt;L:SetAcceleration, number)	}

    (L:Autobrake_position, bool) 1 ==
    if{
    (A:Acceleration Body Z, feet per second squared) 2 + (&gt;L:SetAcceleration, number)	}
    
    (L:Autobrake_position, bool) 2 ==
    if{
    -5.9 (&gt;L:SetAcceleration, number) }

    (L:Autobrake_position, bool) 3 ==
    if{
    -9.7 (&gt;L:SetAcceleration, number)	}

    <!--RTO Conditions-->
    (A:GROUND VELOCITY, knot) 80 &lt;
    (L:Throttle_ani_fix_L, number) 75 &gt;= &amp;&amp;
    (L:Throttle_ani_fix_R, number) 75 &gt;= &amp;&amp;
    (A:Radio height,feet) 11.8 - 5 &lt; &amp;&amp;
    if{
    1 (>L:RTOCond, number) }
    
    <!--Land Conditions-->
    (A:GROUND VELOCITY,knots) 110 &gt;
    (A:Radio height,feet) 11.8 - 5 &gt; &amp;&amp;
    if{
    1 (>L:LandCond, number) }

    (A:Radio height,feet) 11.8 - 5 &lt; 
    (L:Throttle_ani_fix_L, number) 25 &lt;= &amp;&amp;
    (L:Throttle_ani_fix_R, number) 25 &lt;= &amp;&amp;
    (L:RTOCond, number) 1 == &amp;&amp;
	(A:GROUND VELOCITY, knots) 72 &gt; &amp;&amp;
    if{
    1 (>L:RTOAble, number) }
    els{
    0 (>L:RTOAble, number) }

    (L:FADEC_L, number) 10 &lt;
    (L:FADEC_R, number) 10 &lt; &amp;&amp;
    (A:Radio height,feet) 11.8 - 5 &lt; &amp;&amp;
    (L:LandCond, number) 1 == &amp;&amp;
    if{
    1 (>L:LandAble, number) }
    els{
    0 (>L:LandAble, number) }
    
    (L:LandAble, number) 1 ==
    (L:RTOAble, number) 1 == ||
    (A:Radio height,feet) 11.8 - 5 &lt; &amp;&amp;
    if{
    1 (>L:ABrkactiv, number) }
	
    
    <!--Detect External Braking-->
    (A:GROUND VELOCITY, knot) 2 &lt;
    (L:Autobrake_position, bool) 1 == ||
    (L:Throttle_ani_fix_L, number) 100 == ||
    (L:Throttle_ani_fix_R, number) 100 == ||
    (A:Radio height,feet) 11.8 - 5 &lt; &amp;&amp;
    (L:ABrkactiv, number) 1 == &amp;&amp;
    if{    
    0 (>L:ABrkactiv, number) }
	
	(A:Gear Handle Position,bool) 0 ==
	(L:Autobrake_position, bool) 0 == &amp;&amp;	
    (A:Radio height,feet) 11.8 - 40 &gt; &amp;&amp;
	(L:Flightmode, number) 5 &gt;= &amp;&amp;
	
	(L:Autobrake_position, bool) 0 == &amp;&amp; 
	if{
	1 (&gt; L:Autobrake_position, bool) }

	
	<!--  AUTO BRK flash -->
	(L:Load2, bool) 1 ==
	if{
		(L:Autobrake_position) 1 ==
		(L:Autobrake_position_history) 0 ==
		(L:Autobrake_position_history) 2 == ||
		(L:Autobrake_position_history) 3 == || &amp;&amp;
		(L:Auto_BRK_flash_start, bool) 1 == ||
		if{
			1 (&gt; L:Auto_BRK_flash_start, bool)
			(L:Auto_BRK_flash_no_state, bool) 0 ==
			if{
				(L:Autobrake_position_history) (&gt; L:Auto_BRK_flash_no, number)
				1 (&gt; L:Auto_BRK_flash_no_state, bool)
			}
			(L:Auto_BRK_flash_cnt, number) 1 + (&gt; L:Auto_BRK_flash_cnt, number)
		}
		(L:Auto_BRK_flash_cnt, number) 180 ==
		if{
			0 (&gt; L:Auto_BRK_flash_start, bool)
			0 (&gt; L:Auto_BRK_flash_cnt, number)
			1 (&gt; L:Auto_BRK_flash_no, number)
			0 (&gt; L:Auto_BRK_flashstate, bool)
			0 (&gt; L:Auto_BRK_flash_no_state, bool)
		}
		
		(L:Auto_BRK_flash_cnt, number) 1 ==
		(L:Auto_BRK_flash_cnt, number) 19 == ||
		(L:Auto_BRK_flash_cnt, number) 37 == ||
		(L:Auto_BRK_flash_cnt, number) 55 == ||
		(L:Auto_BRK_flash_cnt, number) 73 == ||
		(L:Auto_BRK_flash_cnt, number) 91 == ||
		(L:Auto_BRK_flash_cnt, number) 109 == ||
		(L:Auto_BRK_flash_cnt, number) 127 == ||
		(L:Auto_BRK_flash_cnt, number) 145 == ||
		(L:Auto_BRK_flash_cnt, number) 163 == ||
		(L:Auto_BRK_flash_cnt, number) 181 == ||
		if{
			1 (&gt; L:Auto_BRK_flashstate, bool)
		}
		(L:Auto_BRK_flash_cnt, number) 10 ==
		(L:Auto_BRK_flash_cnt, number) 29 == ||
		(L:Auto_BRK_flash_cnt, number) 47 == ||
		(L:Auto_BRK_flash_cnt, number) 65 == ||
		(L:Auto_BRK_flash_cnt, number) 83 == ||
		(L:Auto_BRK_flash_cnt, number) 101 == ||
		(L:Auto_BRK_flash_cnt, number) 119 == ||
		(L:Auto_BRK_flash_cnt, number) 137 == ||
		(L:Auto_BRK_flash_cnt, number) 155 == ||
		(L:Auto_BRK_flash_cnt, number) 173 == ||
		(L:Auto_BRK_flash_cnt, number) 191 == ||
		if{
			0 (&gt; L:Auto_BRK_flashstate, bool)
		}
		
		(L:Autobrake_position) (&gt; L:Autobrake_position_history)
	}
	

  </Update>
</Gauge>
