mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
FSM Documentation
This commit is contained in:
@@ -2411,7 +2411,6 @@ The UNIT carrying the package.</p>
|
||||
<dl class="function">
|
||||
<dt>
|
||||
|
||||
<em></em>
|
||||
<a id="#(AI_CARGO_UNIT).CargoCarrier" >
|
||||
<strong>AI_CARGO_UNIT.CargoCarrier</strong>
|
||||
</a>
|
||||
|
||||
@@ -105,7 +105,7 @@ These methods define the flow of the FSM process; because in those methods the F
|
||||
<li>To handle <strong>Event</strong> moments, create methods starting with OnBefore or OnAfter concatenated with the Event name.</li>
|
||||
</ul>
|
||||
|
||||
<p><em>* The OnLeave and OnBefore transition methods may return false to cancel the transition.</em>*</p>
|
||||
<p><strong>The OnLeave and OnBefore transition methods may return false, which will cancel the transition.</strong></p>
|
||||
|
||||
<h2>1.2) Event Triggers</h2>
|
||||
|
||||
@@ -128,6 +128,95 @@ These rules define when an FSM can transition from a specific state towards an o
|
||||
|
||||
<p>The initial state can be defined using the method <a href="##(FSM).SetStartState">FSM.SetStartState</a>(). The default start state of an FSM is "None".</p>
|
||||
|
||||
<h3>Example</h3>
|
||||
|
||||
<p>This example creates a new FsmDemo object from class FSM.
|
||||
It will set the start state of FsmDemo to Green.
|
||||
2 Transition Rules are created, where upon the event Switch,
|
||||
the FsmDemo will transition from state Green to Red and vise versa.</p>
|
||||
|
||||
<pre><code> local FsmDemo = FSM:New() -- #FsmDemo
|
||||
FsmDemo:SetStartState( "Green" )
|
||||
FsmDemo:AddTransition( "Green", "Switch", "Red" )
|
||||
FsmDemo:AddTransition( "Red", "Switch", "Green" )
|
||||
</code></pre>
|
||||
|
||||
<p>In the above example, the FsmDemo could flare every 5 seconds a Green or a Red flare into the air.
|
||||
The next code implements this through the event handling method <strong>OnAfterSwitch</strong>.</p>
|
||||
|
||||
<pre><code> function FsmDemo:OnAfterSwitch( From, Event, To, FsmUnit )
|
||||
self:E( { From, Event, To, FsmUnit } )
|
||||
|
||||
if From == "Green" then
|
||||
FsmUnit:Flare(FLARECOLOR.Green)
|
||||
else
|
||||
if From == "Red" then
|
||||
FsmUnit:Flare(FLARECOLOR.Red)
|
||||
end
|
||||
end
|
||||
FsmDemo:__Switch( 5, FsmUnit ) -- Trigger the next Switch event to happen in 5 seconds.
|
||||
end
|
||||
|
||||
FsmDemo:__Switch( 5, FsmUnit ) -- Trigger the first Switch event to happen in 5 seconds.
|
||||
</code></pre>
|
||||
|
||||
<p>The OnAfterSwitch implements a loop. The last line of the code fragment triggers the Switch Event within 5 seconds.
|
||||
Upon the event execution (after 5 seconds), the OnAfterSwitch method is called of FsmDemo (cfr. the double point notation!!! ":").
|
||||
The OnAfterSwitch method receives from the FSM the 3 transition parameter details ( From, Event, To ),
|
||||
and one additional parameter that was given when the event was triggered, which is in this case the Unit that is used within OnSwitchAfter.</p>
|
||||
|
||||
<pre><code> function FsmDemo:OnAfterSwitch( From, Event, To, FsmUnit )
|
||||
</code></pre>
|
||||
|
||||
<p>For debugging reasons the received parameters are traced within the DCS.log.</p>
|
||||
|
||||
<pre><code> self:E( { From, Event, To, FsmUnit } )
|
||||
</code></pre>
|
||||
|
||||
<p>The method will check if the From state received is either "Green" or "Red" and will flare the respective color from the FsmUnit.</p>
|
||||
|
||||
<pre><code> if From == "Green" then
|
||||
FsmUnit:Flare(FLARECOLOR.Green)
|
||||
else
|
||||
if From == "Red" then
|
||||
FsmUnit:Flare(FLARECOLOR.Red)
|
||||
end
|
||||
end
|
||||
</code></pre>
|
||||
|
||||
<p>It is important that the Switch event is again triggered, otherwise, the FsmDemo would stop working after having the first Event being handled.</p>
|
||||
|
||||
<pre><code> FsmDemo:__Switch( 5, FsmUnit ) -- Trigger the next Switch event to happen in 5 seconds.
|
||||
</code></pre>
|
||||
|
||||
<p>This example is fully implemented in the following MOOSE test mission:</p>
|
||||
|
||||
|
||||
<p>Note that transition rules can be declared with a few variations:</p>
|
||||
|
||||
<ul>
|
||||
<li>The From states can be a table of strings, indicating that the transition rule will be valid if the current state of the FSM will be one of the given From states.</li>
|
||||
<li>The From state can be a "*", indicating that the transition rule will always be valid, regardless of the current state of the FSM.</li>
|
||||
</ul>
|
||||
|
||||
<p>This transition will create a new FsmDemo object from class FSM.
|
||||
It will set the start state of FsmDemo to Green.
|
||||
A new event is added in addition to the above example.
|
||||
The new event Stop will cancel the Switching process.
|
||||
So, the transtion for event Stop can be executed if the current state of the FSM is either "Red" or "Green".</p>
|
||||
|
||||
<pre><code> local FsmDemo = FSM:New() -- #FsmDemo
|
||||
FsmDemo:SetStartState( "Green" )
|
||||
FsmDemo:AddTransition( "Green", "Switch", "Red" )
|
||||
FsmDemo:AddTransition( "Red", "Switch", "Green" )
|
||||
FsmDemo:AddTransition( { "Red", "Green" }, "Stop", "Stopped" )
|
||||
</code></pre>
|
||||
|
||||
<p>The transition for event Stop can also be simplified, as any current state of the FSM is valid.</p>
|
||||
|
||||
<pre><code> FsmDemo:AddTransition( "*", "Stop", "Stopped" )
|
||||
</code></pre>
|
||||
|
||||
<h2>1.4) FSM Process Rules</h2>
|
||||
|
||||
<p>The FSM can implement sub-processes that will execute and return multiple possible states. <br/>
|
||||
|
||||
@@ -1692,9 +1692,6 @@ The group that was spawned. You can use this group for further actions.</p>
|
||||
|
||||
|
||||
|
||||
|
||||
<p> Don't repeat the group from Take-Off till Landing and back Take-Off by ReSpawning.</p>
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="function">
|
||||
@@ -2169,7 +2166,7 @@ when nothing was spawned.</p>
|
||||
<dl class="function">
|
||||
<dt>
|
||||
|
||||
<em>#number</em>
|
||||
<em></em>
|
||||
<a id="#(SPAWN).SpawnMaxGroups" >
|
||||
<strong>SPAWN.SpawnMaxGroups</strong>
|
||||
</a>
|
||||
@@ -2186,7 +2183,7 @@ when nothing was spawned.</p>
|
||||
<dl class="function">
|
||||
<dt>
|
||||
|
||||
<em>#number</em>
|
||||
<em></em>
|
||||
<a id="#(SPAWN).SpawnMaxUnitsAlive" >
|
||||
<strong>SPAWN.SpawnMaxUnitsAlive</strong>
|
||||
</a>
|
||||
@@ -2489,7 +2486,7 @@ Spawn_BE_KA50 = SPAWN:New( 'BE KA-50@RAMP-Ground Defense' ):Schedule( 600, 0.5 )
|
||||
|
||||
|
||||
|
||||
<p> Flag that indicates if all the Groups of the SpawnGroup need to be visible when Spawned.</p>
|
||||
<p> When the first Spawn executes, all the Groups need to be made visible before start.</p>
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
@@ -185,6 +185,8 @@ sub {
|
||||
|
||||
img {
|
||||
border: 0;
|
||||
max-width:100%;
|
||||
height:auto;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -500,6 +502,7 @@ h3 {
|
||||
|
||||
#main-content img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
aside#sidebar {
|
||||
|
||||
Reference in New Issue
Block a user