Access to "output controller state"
12 posts
• Page 2 of 2 • 1, 2
Re: Access to "output controller state"
J2Kbr wrote:magNz wrote:So.. at each iteration of the main loop we run through all combos that are in a running state and advances the state of those where the time they have sat idle since the initial call to wait has hit the wait time ?
correct, this is how it works. Each combo has 3 control variables: (1) a flag to know if the combo is running or not, (2) an variable that holds the current state of the state machine and (3) an timeout variable for the current state.
Did you know you can read, and even update, each of theses control variables? just index the combo name with [], where:
ComboName[0] is (1)
ComboName[1] is (3)
ComboName[2] is (2)magNz wrote:I hope this is not too frustrating for you as I am trying to understand how it works a bit better..
of course not, I like when users get interest on "behind-the-scene" stuff.
Ok. I am still a bit confused while I can't access the output value of XB_LT (or SHOOT) in that case.
e.g. given this code
- Code: Select all
set_val(SHOOT, 100);
wait(66);
set_val(SHOOT, 0);
wait(100);
The way I understand it now working is that whenever we combo_run a combo it gets pushed onto some kind of stack where each of those state machine is executed after each main iteration.
Now, in the case of the combo above it would set SHOOT to 100 then hit the main loop 6-7x (given a 10ms iteration time and the wait of 66), then set SHOOT to 0 and be idle for another approximately 10 iterations before being done with the combo. Correct ?
The thing that confuses me then would be why
- Code: Select all
set_val (TRACE_2, get_val (SHOOT))
inside main would not pick up SHOOT going to 0 after ~66ms and then staying 0 for another ~100ms. The only way this would make sense to me is if whatever I am doing in the combo "only happens in the scope of the combo". In other words if I had a combo that presses XB_LT for 2000ms via wait in reality the trigger would only be pressed whenever the combo is being executed at the end of main. It's not a solid graph where XB_LT hits 100 for 2000ms straight but in reality hits it every 10ms for a bit ?
In essence what I am trying to do is check inside a main function whether the combo that does the shooting still is "pressing the trigger" or has moved on to the next wait. I guess the only way to do this is either move my code from main into the combo or play around with set_bit/get_bit ?
- magNz
- Corporal
- Posts: 5
- Joined: Mon Jan 09, 2017 3:40 pm
Re: Access to "output controller state"
Okay, as you are familiar with programming, please see the code/pseudo-code below and comments, it shows an combo structure, how the control variables are used and the state machine. Hopefully it helps you to better understand what is done internally when an combo is executed.
- Code: Select all
// Combo variables initialization
COMBOVAR: is_running = 0
COMBOVAR: timeout = 0
COMBOVAR: state = 0
main {
// Set XB1_LT to 50
set_val(XB1_LT, 50);
//
// GPC MAIN CODE HERE ...
//
combo_run(XYZ) DO {
is_running = 1
}
//
// GPC MAIN CODE HERE ...
//
// This will make TRACE_1 = 50
set_val(TRACE_1, get_val(XB1_LT));
// Note here the combo XYZ have not ran yet,
// so XB1_LT still 50 and not 100 or 0.
// Let's run the last combo to show the XB1_LT on TRACE_2
combo_run(ShowLTValue);
}
//
// the main code is done, now we will execute the combo codes
//
combo XYZ {
IF NOT is_running GOTO COMBO_END
IF timeout > 0 DO
timeout = timeout - get_rtime()
IF timeout <= 0 DO
state++
END_IF
END_IF
GOTO state
STATE_0:
set_val(XB1_LT, 100);
wait(66) DO {
IF timeout <= 0 DO
timeout = 66
END_IF
}
GOTO COMBO_END
STATE_1:
set_val(XB1_LT, 0);
wait(100) DO {
IF timeout <= 0 DO
timeout = 100
END_IF
}
GOTO COMBO_END
STATE_2: // Finishing State
is_running = 0
timeout = 0
state = 0
COMBO_END:
}
// At this point XB1_LT is 0 or 100, depending on the current state
// of the combo XYZ. So here your can place an combo to display the updated
// value of XB1_LT, like this:
combo ShowLTValue {
// This will make TRACE_2 equal to 0 or 100
set_val(TRACE_2, get_val(XB1_LT));
}
ConsoleTuner Support Team
-
J2Kbr - General of the Army
- Posts: 20323
- Joined: Tue Mar 18, 2014 1:39 pm
12 posts
• Page 2 of 2 • 1, 2
Return to GPC1 Script Programming
Who is online
Users browsing this forum: Google [Bot] and 73 guests