#3948821 - 05/04/14 05:59 AM
Looking to create a timer for Airbrake indications
|
Joined: Jan 2001
Posts: 2,477
HomeFries
Air Dominance Project
|
Air Dominance Project
Member
Joined: Jan 2001
Posts: 2,477
|
I'm trying to get fancy with the airbrake routine in my DCS profile. The functionality I want is that the LMFD LED1 will remain lit when the airbrake is fully extended, and will be unlit when the airbrake is fully closed. If the airbrake is in a transitional state (or deployed in a partial state) the LED should flash. What I really need is a counter function that will work with DeferCall and a while loop. Here is what I have so far (two approaches, neither of which work at the moment) note: AirBrakeExtended is a global variable of the amount of airbrake extension in percentage (necessary since deployment and retraction often have different durations requiring a percentage of deployment). BrakeOnCycleTime/BrakeOffCycleTime are the times it takes to fully deploy and retract the brakes. "count" is in each of the functions to convert the physical percentage of deployment into a time to complete deployment or retraction.
int AnalogBrakeOutLED(int dtime, int led, int posit=0) //dtime is time to fully deploy the brake, led is whether flashing is allowed, and posit is the percent of brake deployment
{
int count;
count = dtime*posit/100;
printf("dtime = %i, count = %i\xa",dtime,count);
while(count < dtime)
{
if (HCougar[T9]) DeferCall(count, &EXEC, "count = count+500;");
else AirBrakeExtended = (count*100)/dtime;
}
if (count >= dtime)
{
AirBrakeExtended = 100;
if (led >0) Lights_LLED1(1);
}
}
int AnalogBrakeInLED(int dtime, int posit=100) //dtime is the time to fully retract the brakes, posit is the deployment position in percent
{
int count;
count = dtime*posit/100;
printf("dtime = %i, count = %i\xa",dtime,count);
while (count > dtime)
{
DeferCall(500, &EXEC, "if (!HCougar[T10]) AirBrakeExtended = (count*100)/dtime;");
count = count - 500;
//printf("%i > %i\xa",count,dtime);
}
if (count <= 0)
{
AirBrakeExtended = 0;
Lights_LLED1(0);
}
} And the macros that call the functions:
Analog_Pulse_AirbrakeOn = CHAIN(PULSE+DX27, EXEC("if (AirBrakeExtended == 0) flashLLED1(1,500);AnalogBrakeOutLED(BrakeOnCycleTime, 1, AirBrakeExtended);"));
Analog_Pulse_AirbrakeOff = CHAIN(PULSE+DX28, EXEC("if (AirBrakeExtended > 0) flashLLED1(1,500);AnalogBrakeInLED(BrakeOffCycleTime, AirBrakeExtended);")); Thanks in advance for any help,
-Home Fries
"Pacifism is a shifty doctrine under which a man accepts the benefits of the social group without being willing to pay - and claims a halo for his dishonesty." - Robert A. Heinlein
The average naval aviator, despite the sometimes swaggering exterior, is very much capable of such feelings as love, affection, intimacy, and caring. These feelings just don't involve anyone else.
|
|
#3952849 - 05/13/14 04:34 AM
Re: Looking to create a timer for Airbrake indications
[Re: HomeFries]
|
Joined: Jan 2001
Posts: 2,477
HomeFries
Air Dominance Project
|
Air Dominance Project
Member
Joined: Jan 2001
Posts: 2,477
|
I have since tried moving the counter to a separate function, and leaving DeferCall in the main function to create a timer. Unfortunately, I still get caught in an infinite loop that can eat up close to 1.5Gb of RAM. Here's the code for deploying the brake (just to keep it simple):
Analog_Pulse_AirbrakeOn = CHAIN(PULSE+DX27, EXEC("AnalogBrakeOutLED(BrakeOnCycleTime, 1, AirBrakeExtended);"));
int AnalogBrakeOutLED(int dtime, int led, int posit=0)
//dtime is time to fully deploy the brake,
//led is whether flashing is allowed,
//and posit is the percentage of brake deployment (indicating time to go before full deployment)
{
int count;
count = dtime*posit/100;
printf("dtime = %i, count = %i\xa",dtime,count); //for test
do
{
if (HCougar[T9])
{
DeferCall(count, &Speedbrake_Counter, count);
printf("count = %i\xa",count); //for test
}
else
{
AirBrakeExtended = (count*100)/dtime;
printf("%i < %i\xa",count,dtime); //for test
}
}
while(count < dtime);
if (count >= dtime)
{
AirBrakeExtended = 100;
if (led >0)
{
Lights_LLED1(1);
}
}
}
int Speedbrake_Counter(int start, int incr=500)
{
start = start+incr;
printf("start = %i\xa",start);
return start;
}
EDIT: I also tried nesting the do loop within the if/then to see if that would do anything. Same results.
int AnalogBrakeOutLED(int dtime, int led, int posit=0)
{
int count;
count = dtime*posit/100;
printf("dtime = %i, count = %i\xa",dtime,count); //for test
if (HCougar[T9])
{
do
{
DeferCall(count, &Speedbrake_Counter, count);
printf("count = %i\xa",count); //for test
}
while(count < dtime);
}
else
{
AirBrakeExtended = (count*100)/dtime;
printf("%i < %i\xa",count,dtime); //for test
}
if (count >= dtime)
{
AirBrakeExtended = 100;
if (led >0)
{
Lights_LLED1(1);
}
}
} Again, any assistance is greatly appreciated.
Last edited by HomeFries; 05/13/14 04:45 AM.
-Home Fries
"Pacifism is a shifty doctrine under which a man accepts the benefits of the social group without being willing to pay - and claims a halo for his dishonesty." - Robert A. Heinlein
The average naval aviator, despite the sometimes swaggering exterior, is very much capable of such feelings as love, affection, intimacy, and caring. These feelings just don't involve anyone else.
|
|
#3953361 - 05/14/14 10:35 AM
Re: Looking to create a timer for Airbrake indications
[Re: HomeFries]
|
Joined: Oct 2010
Posts: 83
Nicu
Junior Member
|
Junior Member
Joined: Oct 2010
Posts: 83
|
define AirBrakePoll 500 // ms
define AirBrakeInc 10 // percent per second
int Analog_Pulse_AirbrakeOn;
int Analog_Pulse_AirbrakeOff;
int AirBrakePos;
int AirBrakeOn;
int main()
{
if(Init(&EventHandle)) return 1; // declare the event handler, return on error
AutoRepeat(0, AirBrakePoll, &AirBrakeProc, 0);
Analog_Pulse_AirbrakeOn = CHAIN(PULSE+DX27, EXEC("AirBrakeOn = 1;"));
Analog_Pulse_AirbrakeOff = CHAIN(PULSE+DX28, EXEC("AirBrakeOn = 0;"));
}
int LEDState;
int AirBrakeProc(int p)
{
if(AirBrakeOn) AirBrakePos = AirBrakePos + AirBrakeInc * AirBrakePoll / 1000;
else AirBrakePos = AirBrakePos - AirBrakeInc * AirBrakePoll / 1000;
if(AirBrakePos >= 100)
{
AirBrakePos = 100;
LEDState = 1;
}
else if(AirBrakePos <= 0)
{
AirBrakePos = 0;
LEDState = 0;
}
else LEDState = !LEDState;
Lights_LLED1(LEDState);
}
|
|
#3953914 - 05/15/14 03:10 PM
Re: Looking to create a timer for Airbrake indications
[Re: HomeFries]
|
Joined: Jan 2001
Posts: 2,477
HomeFries
Air Dominance Project
|
Air Dominance Project
Member
Joined: Jan 2001
Posts: 2,477
|
Wow, Nicu! This solution is both elegant and simple. I've tried googling "AutoRepeat" and I've had no luck finding the command parameters, though it appears like a more fundamental version of REXEC. This is definitely another tool I'll add to my tool bag. I've gone ahead and made a few changes, in particular going from AirBrakeOn (renamed AirBrakeSwitch) being Boolean to being essentially an operand (and a zero value will keep AirBrakePos in its current position). This allows the LED to flash while the brake is in a fixed state inbetween fully extended and fully retracted. BrakeOnCycleTime/BrakeOffCycleTime allows for brakes with different extension/retraction times (e.g. the A-10C extends in 500ms and retracts in 2000ms, while the F-15C extends in 2000ms and retracts in 5000ms). Analog_Pulse_AirbrakeOn/Off (and Analog_AirbrakeOn/Off) set AirBrakeSwitch to 1 or -1 respectively, and Analog_Pulse_AirbrakeOn/OffStop has been added to set "AirBrakeSwitch = 0" while still pulsing DX27/28 as required for the F-15C airbrake. Analog_AirbrakeStop (just setting "AirBrakeSwitch = 0") is useful for the A-10C.
Analog_AirbrakeOn = CHAIN(DX27, EXEC("AirBrakeSwitch = 1;"));
Analog_AirbrakeOff = CHAIN(DX28, EXEC("AirBrakeSwitch =-1;"));
Analog_AirbrakeStop = EXEC("AirBrakeSwitch = 0;");
Analog_Pulse_AirbrakeOn = CHAIN(PULSE+DX27, EXEC("AirBrakeSwitch = 1;"));
Analog_Pulse_AirbrakeOff = CHAIN(PULSE+DX28, EXEC("AirBrakeSwitch =-1;"));
Analog_Pulse_AirbrakeOnStop = CHAIN(PULSE+DX27, EXEC("AirBrakeSwitch = 0;"));
Analog_Pulse_AirbrakeOffStop = CHAIN(PULSE+DX28, EXEC("AirBrakeSwitch = 0;"));
int AirBrakeProc(int p)
{
// 100%*1000(ms) / cycle time (ms)} * poll (ms)/1000(ms) = % per poll time, AirBrakeOn determines operand (-1 for retract)
// 1000ms on front end numerator/back end denominator keeps value as integer
if (AirBrakeSwitch > 0) AirBrakePos = AirBrakePos + 100000/BrakeOnCycleTime * AirBrakePoll/1000;
else if (AirBrakeSwitch < 0) AirBrakePos = AirBrakePos - 100000/BrakeOffCycleTime * AirBrakePoll/1000;
if(AirBrakePos >= 100)
{
AirBrakePos = 100;
AirbrakeLEDState = 1;
}
else if(AirBrakePos <= 0)
{
AirBrakePos = 0;
AirbrakeLEDState = 0;
}
else AirbrakeLEDState = !AirbrakeLEDState;
Lights_LLED1(AirbrakeLEDState);
} You've been given credit for the routine in my code, and you'll be given credit in the next iteration of the manual as well. Best Regards, HF
Last edited by HomeFries; 05/15/14 03:58 PM. Reason: updated code
-Home Fries
"Pacifism is a shifty doctrine under which a man accepts the benefits of the social group without being willing to pay - and claims a halo for his dishonesty." - Robert A. Heinlein
The average naval aviator, despite the sometimes swaggering exterior, is very much capable of such feelings as love, affection, intimacy, and caring. These feelings just don't involve anyone else.
|
|
|
CD WOFF
by Britisheh. 03/28/24 08:05 PM
|
|
|
|
|
|
|
|
|
|
|