1
0
Fork 0

Replacement of blackout/redout implementation with a sophisticated model developed for military simulators - research and implementation by Nikolai Verner Christensen

This commit is contained in:
Thorsten Renk 2016-11-21 10:06:35 +02:00
parent ec6855f2fc
commit 52e5592442
3 changed files with 894 additions and 77 deletions

View file

@ -0,0 +1,863 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
###################################################################################
## ##
## Improved redout/blackout system for Flightgear ##
## ##
## Author: Nikolai V. Chr. ##
## ##
## Todo: Tie in with Thorstens ALS greyout and tunnel vision filters ##
## ##
## ##
## Version 2.03 License: GPL 2.0 ##
## ##
###################################################################################
-->
<PropertyList>
<params>
<onset-b>sim/rendering/redout/parameters/blackout-onset-g</onset-b>
<fast-b>sim/rendering/redout/parameters/blackout-complete-g</fast-b>
<onset-r>sim/rendering/redout/parameters/redout-onset-g</onset-r>
<fast-r>sim/rendering/redout/parameters/redout-complete-g</fast-r>
<onset-t-b>sim/rendering/redout/parameters/onset-blackout-sec</onset-t-b>
<fast-t-b>sim/rendering/redout/parameters/fast-blackout-sec</fast-t-b>
<onset-t-r>sim/rendering/redout/parameters/onset-redout-sec</onset-t-r>
<fast-t-r>sim/rendering/redout/parameters/fast-redout-sec</fast-t-r>
<rec-f>sim/rendering/redout/parameters/recover-fast-sec</rec-f>
<rec-s>sim/rendering/redout/parameters/recover-slow-sec</rec-s>
<log>
<g-force>sim/rendering/redout/internal/log/g-force</g-force>
<onset-b>sim/rendering/redout/internal/log/onset-b</onset-b>
<fast-b>sim/rendering/redout/internal/log/fast-b</fast-b>
<g-force-r>sim/rendering/redout/internal/log/g-force-r</g-force-r>
<onset-r>sim/rendering/redout/internal/log/onset-r</onset-r>
<fast-r>sim/rendering/redout/internal/log/fast-r</fast-r>
</log>
<g-force>sim/rendering/redout/internal/g-force</g-force>
<g-force-inv>sim/rendering/redout/internal/g-force-inv</g-force-inv>
<blackout>sim/rendering/redout/internal/blackout</blackout>
<redout>sim/rendering/redout/internal/redout</redout>
<alpha>sim/rendering/redout/alpha</alpha>
<red>sim/rendering/redout/red</red>
<inside>sim/current-view/internal</inside>
<sum>sim/rendering/redout/internal/sum</sum>
<enable>sim/rendering/redout/enabled</enable>
</params>
<filter><!-- check for NaN -->
<type>gain</type>
<gain>0</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<not>
<less-than>
<property alias="/params/blackout"/>
<value>1000.0</value>
</less-than>
<greater-than>
<property alias="/params/blackout"/>
<value>-1000.0</value>
</greater-than>
</not>
</condition>
</enable>
<input>
<value>0</value>
</input>
<output alias="/params/blackout"/>
</filter>
<filter><!-- check for NaN -->
<type>gain</type>
<gain>0</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<not>
<less-than>
<property alias="/params/redout"/>
<value>1000.0</value>
</less-than>
<greater-than>
<property alias="/params/redout"/>
<value>-1000.0</value>
</greater-than>
</not>
</condition>
</enable>
<input>
<value>0</value>
</input>
<output alias="/params/redout"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<!-- check if blackout onset has sane value. -->
<condition>
<or>
<less-than>
<property alias="/params/onset-b"/>
<value>1.25</value>
</less-than>
</or>
</condition>
</enable>
<input>
<expression>
<max>
<property alias="/params/fast-b"/>
<value>1.25</value>
</max>
</expression>
</input>
<output alias="/params/onset-b"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<!-- check if blackout complete has sane value. -->
<condition>
<or>
<greater-than>
<property alias="/params/onset-b"/>
<property alias="/params/fast-b"/>
</greater-than>
<less-than>
<property alias="/params/fast-b"/>
<value>1.5</value>
</less-than>
</or>
</condition>
</enable>
<input>
<expression>
<max>
<sum>
<property alias="/params/onset-b"/>
<value>0.50</value>
</sum>
<value>1.5</value>
</max>
</expression>
</input>
<output alias="/params/fast-b"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<!-- check if redout onset has sane value. -->
<condition>
<or>
<greater-than>
<property alias="/params/onset-r"/>
<value>-1.00</value>
</greater-than>
</or>
</condition>
</enable>
<input>
<expression>
<min>
<property alias="/params/fast-r"/>
<value>-1.00</value>
</min>
</expression>
</input>
<output alias="/params/onset-r"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<!-- check if redout complete has sane value. -->
<condition>
<or>
<greater-than>
<property alias="/params/fast-r"/>
<property alias="/params/onset-r"/>
</greater-than>
<greater-than>
<property alias="/params/fast-r"/>
<value>-1.25</value>
</greater-than>
</or>
</condition>
</enable>
<input>
<expression>
<min>
<sum>
<property alias="/params/onset-r"/>
<value>-0.50</value>
</sum>
<value>-1.25</value>
</min>
</expression>
</input>
<output alias="/params/fast-r"/>
</filter>
<filter>
<type>gain</type>
<gain>-1</gain>
<enable>
<!-- check if JSBSim is the FDM. -->
<condition>
<property alias="/params/enable"/>
<less-than>
<property>fdm/jsbsim/aero/alpha-deg</property>
<value>180.0</value>
</less-than>
<greater-than>
<property>fdm/jsbsim/aero/alpha-deg</property>
<value>-180.0</value>
</greater-than>
</condition>
</enable>
<input>
<expression>
<div>
<property>accelerations/pilot/z-accel-fps_sec</property>
<value>32.174</value>
</div>
</expression>
</input>
<output alias="/params/g-force"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<!-- check if YaSim is the FDM. -->
<condition>
<property alias="/params/enable"/>
<not>
<less-than>
<property>fdm/jsbsim/aero/alpha-deg</property>
<value>180.0</value>
</less-than>
<greater-than>
<property>fdm/jsbsim/aero/alpha-deg</property>
<value>-180.0</value>
</greater-than>
</not>
</condition>
</enable>
<input>
<property>accelerations/pilot-g[0]</property>
</input>
<output alias="/params/g-force"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
</condition>
</enable>
<input>
<expression>
<log10>
<property alias="/params/fast-b"/>
</log10>
</expression>
</input>
<output alias="/params/log/fast-b"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
</condition>
</enable>
<input>
<expression>
<log10>
<property alias="/params/onset-b"/>
</log10>
</expression>
</input>
<output alias="/params/log/onset-b"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<less-than-equals>
<property alias="/params/g-force"/>
<value>1</value>
</less-than-equals>
</condition>
</enable>
<input>
<value>0</value>
</input>
<output alias="/params/log/g-force"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<greater-than>
<property alias="/params/g-force"/>
<value>1</value>
</greater-than>
</condition>
</enable>
<input>
<expression>
<log10>
<property alias="/params/g-force"/>
</log10>
</expression>
</input>
<output alias="/params/log/g-force"/>
</filter>
<filter><!-- reduce blackout -->
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<less-than>
<property alias="/params/g-force"/>
<property alias="/params/onset-b"/>
</less-than>
</condition>
</enable>
<input>
<expression>
<min>
<value>1</value>
<max>
<value>0</value>
<dif>
<property alias="/params/blackout"/>
<product>
<property>sim/time/delta-sec</property>
<div>
<value>1</value>
<max>
<value>0</value>
<sum>
<property alias="/params/rec-f"/>
<product>
<div>
<dif>
<property alias="/params/log/g-force"/>
<log10>
<value>1</value>
</log10>
</dif>
<dif>
<property alias="/params/log/onset-b"/>
<log10>
<value>1</value>
</log10>
</dif>
</div>
<dif>
<property alias="/params/rec-s"/>
<property alias="/params/rec-f"/>
</dif>
</product>
</sum>
</max>
</div>
</product>
</dif>
</max>
</min>
</expression>
</input>
<output alias="/params/blackout"/>
</filter>
<filter><!-- increase blackout -->
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<greater-than-equals>
<property alias="/params/g-force"/>
<property alias="/params/onset-b"/>
</greater-than-equals>
</condition>
</enable>
<input>
<expression>
<min>
<value>1</value>
<max>
<value>0</value>
<sum>
<property alias="/params/blackout"/>
<product>
<property>sim/time/delta-sec</property>
<div>
<value>1</value>
<max>
<value>0</value>
<pow>
<value>10</value>
<sum>
<log10>
<property alias="/params/onset-t-b"/>
</log10>
<product>
<div>
<dif>
<property alias="/params/log/g-force"/>
<property alias="/params/log/onset-b"/>
</dif>
<dif>
<property alias="/params/log/fast-b"/>
<property alias="/params/log/onset-b"/>
</dif>
</div>
<dif>
<log10>
<property alias="/params/fast-t-b"/>
</log10>
<log10>
<property alias="/params/onset-t-b"/>
</log10>
</dif>
</product>
</sum>
</pow>
</max>
</div>
</product>
</sum>
</max>
</min>
</expression>
</input>
<output alias="/params/blackout"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
</condition>
</enable>
<input>
<expression>
<log10>
<product>
<value>-1</value>
<dif>
<property alias="/params/fast-r"/>
<value>2</value>
</dif>
</product>
</log10>
</expression>
</input>
<output alias="/params/log/fast-r"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
</condition>
</enable>
<input>
<expression>
<log10>
<product>
<value>-1</value>
<dif>
<property alias="/params/onset-r"/>
<value>2</value>
</dif>
</product>
</log10>
</expression>
</input>
<output alias="/params/log/onset-r"/>
</filter>
<filter>
<type>gain</type>
<gain>-1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
</condition>
</enable>
<input>
<expression>
<dif>
<property alias="/params/g-force"/>
<value>2</value>
</dif>
</expression>
</input>
<output alias="/params/g-force-inv"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<less-than-equals>
<property alias="/params/g-force-inv"/>
<value>1</value>
</less-than-equals>
</condition>
</enable>
<input>
<value>0</value>
</input>
<output alias="/params/log/g-force-r"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<greater-than>
<property alias="/params/g-force-inv"/>
<value>1</value>
</greater-than>
</condition>
</enable>
<input>
<expression>
<log10>
<property alias="/params/g-force-inv"/>
</log10>
</expression>
</input>
<output alias="/params/log/g-force-r"/>
</filter>
<filter><!-- reduce redout -->
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<greater-than>
<property alias="/params/g-force"/>
<property alias="/params/onset-r"/>
</greater-than>
</condition>
</enable>
<input>
<expression>
<min>
<value>1</value>
<max>
<value>0</value>
<dif>
<property alias="/params/redout"/>
<product>
<property>sim/time/delta-sec</property>
<div>
<value>1</value>
<max>
<value>0</value>
<sum>
<property alias="/params/rec-f"/>
<product>
<div>
<dif>
<property alias="/params/log/g-force-r"/>
<log10>
<value>1</value>
</log10>
</dif>
<dif>
<property alias="/params/log/onset-r"/>
<log10>
<value>1</value>
</log10>
</dif>
</div>
<dif>
<property alias="/params/rec-s"/>
<property alias="/params/rec-f"/>
</dif>
</product>
</sum>
</max>
</div>
</product>
</dif>
</max>
</min>
</expression>
</input>
<output alias="/params/redout"/>
</filter>
<filter><!-- increase redout -->
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<less-than-equals>
<property alias="/params/g-force"/>
<property alias="/params/onset-r"/>
</less-than-equals>
</condition>
</enable>
<input>
<expression>
<min>
<value>1</value>
<max>
<value>0</value>
<sum>
<property alias="/params/redout"/>
<product>
<property>sim/time/delta-sec</property>
<div>
<value>1</value>
<max>
<value>0</value>
<pow>
<value>10</value>
<sum>
<log10>
<property alias="/params/onset-t-r"/>
</log10>
<product>
<div>
<dif>
<property alias="/params/log/g-force-r"/>
<property alias="/params/log/onset-r"/>
</dif>
<dif>
<property alias="/params/log/fast-r"/>
<property alias="/params/log/onset-r"/>
</dif>
</div>
<dif>
<log10>
<property alias="/params/fast-t-r"/>
</log10>
<log10>
<property alias="/params/onset-t-r"/>
</log10>
</dif>
</product>
</sum>
</pow>
</max>
</div>
</product>
</sum>
</max>
</min>
</expression>
</input>
<output alias="/params/redout"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
</condition>
</enable>
<input>
<expression>
<dif>
<property alias="/params/blackout"/>
<property alias="/params/redout"/>
</dif>
</expression>
</input>
<output alias="/params/sum"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<equals>
<property alias="/params/inside"/>
<value>1</value>
</equals>
<less-than>
<property alias="/params/sum"/>
<value>0</value>
</less-than>
</condition>
</enable>
<input>
<value>1</value>
</input>
<output alias="/params/red"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<equals>
<property alias="/params/inside"/>
<value>1</value>
</equals>
<less-than>
<property alias="/params/sum"/>
<value>0</value>
</less-than>
</condition>
</enable>
<input>
<expression>
<product>
<property alias="/params/sum"/>
<value>-1</value>
</product>
</expression>
</input>
<output alias="/params/alpha"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<equals>
<property alias="/params/inside"/>
<value>1</value>
</equals>
<greater-than-equals>
<property alias="/params/sum"/>
<value>0</value>
</greater-than-equals>
</condition>
</enable>
<input>
<value>0</value>
</input>
<output alias="/params/red"/>
</filter>
<filter>
<type>gain</type>
<gain>1</gain>
<enable>
<condition>
<property alias="/params/enable"/>
<equals>
<property alias="/params/inside"/>
<value>1</value>
</equals>
<greater-than-equals>
<property alias="/params/sum"/>
<value>0</value>
</greater-than-equals>
</condition>
</enable>
<input>
<property alias="/params/sum"/>
</input>
<output alias="/params/alpha"/>
</filter>
<filter>
<type>gain</type>
<gain>0</gain>
<enable>
<condition>
<or>
<not>
<property alias="/params/enable"/>
</not>
<equals>
<property alias="/params/inside"/>
<value>0</value>
</equals>
</or>
</condition>
</enable>
<input>
<value>0</value>
</input>
<output alias="/params/alpha"/>
</filter>
<filter>
<type>gain</type>
<gain>0</gain>
<enable>
<condition>
<not>
<property alias="/params/enable"/>
</not>
</condition>
</enable>
<input>
<value>0</value>
</input>
<output alias="/params/blackout"/>
</filter>
<filter>
<type>gain</type>
<gain>0</gain>
<enable>
<condition>
<not>
<property alias="/params/enable"/>
</not>
</condition>
</enable>
<input>
<value>0</value>
</input>
<output alias="/params/redout"/>
</filter>
</PropertyList>

View file

@ -1,14 +1,9 @@
# Damped G value - starts at 1.
var GDamped = 1.0;
var previousG = 1.0;
var running_redout = 0;
var running_compression = 0;
var fdm = "jsb";
var blackout_start = nil;
var blackout_end = nil;
var redout_start = nil;
var redout_end = nil;
var compression_rate = nil;
var internal = nil;
@ -17,7 +12,7 @@ var lp_red = nil;
var run = func {
if (running_redout or running_compression)
if (running_compression)
{
var GCurrent = 1.0;
@ -51,28 +46,6 @@ var run = func {
if (internal)
{
if (running_redout)
{
if (GDamped > blackout_start)
{
# Blackout
setprop("/sim/rendering/redout/red",0);
setprop("/sim/rendering/redout/alpha",
(GDamped - blackout_start) / (blackout_end - blackout_start));
}
elsif (GDamped < redout_start)
{
# Redout
setprop("/sim/rendering/redout/red",1);
setprop("/sim/rendering/redout/alpha",
abs((GDamped - redout_start) / (redout_end - redout_start)));
}
else
{
setprop("/sim/rendering/redout/alpha",0);
}
}
if (running_compression)
{
# Apply any compression due to G-forces
@ -84,51 +57,20 @@ var run = func {
}
}
}
else
{
# Not in cockpit view - remove all redout/blackout
setprop("/sim/rendering/redout/alpha",0);
}
settimer(run, 0);
}
else
{
# Disabled - remove all redout/blackout
setprop("/sim/rendering/redout/alpha",0);
}
}
var check_params = func() {
blackout_start = getprop("/sim/rendering/redout/parameters/blackout-onset-g");
blackout_end = getprop("/sim/rendering/redout/parameters/blackout-complete-g");
redout_start = getprop("/sim/rendering/redout/parameters/redout-onset-g");
redout_end = getprop("/sim/rendering/redout/parameters/redout-complete-g");
if ((blackout_start == nil) or
(blackout_end == nil) or
(redout_start == nil) or
(redout_end == nil) )
{
# No valid properties - no point running
running_redout = 0;
}
}
var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized",
func {
removelistener(fdm_init_listener); # uninstall, so we're only called once
fdm = getprop("/sim/flight-model");
running_redout = getprop("/sim/rendering/redout/enabled");
running_compression = getprop("/sim/rendering/headshake/enabled");
internal = getprop("/sim/current-view/internal");
lp_black = aircraft.lowpass.new(0.2);
lp_red = aircraft.lowpass.new(0.25);
setlistener("/sim/rendering/redout/parameters", func {
# one parameter has changed, read them all in again
check_params();
}, 1, 2);
setlistener("/sim/current-view/internal", func(n) {
internal = n.getBoolValue();
});
@ -138,7 +80,7 @@ var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized",
}, 1);
setlistener("/sim/rendering/headshake/enabled", func(n) {
if ((running_compression == 0) and (running_redout == 0) and n.getBoolValue())
if ((running_compression == 0) and n.getBoolValue())
{
running_compression = 1;
# start new timer now
@ -150,19 +92,6 @@ var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized",
}
}, 1);
setlistener("/sim/rendering/redout/enabled", func(n) {
if ((running_compression == 0) and (running_redout == 0) and n.getBoolValue())
{
running_redout = 1;
# start new timer now
run();
}
else
{
running_redout = n.getBoolValue();
}
}, 1);
# Now we've set up the listeners (which will have triggered), run it.
run();
}

View file

@ -254,11 +254,32 @@ Started September 2000 by David Megginson, david@megginson.com
<redout>
<enabled type="bool" userarchive="y">true</enabled>
<parameters>
<blackout-onset-g type="double">3.5</blackout-onset-g>
<blackout-complete-g type="double">5</blackout-complete-g>
<redout-onset-g type="double">-2</redout-onset-g>
<redout-complete-g type="double">-4</redout-complete-g>
<blackout-onset-g type="double">2.5</blackout-onset-g>
<blackout-complete-g type="double">4.5</blackout-complete-g>
<onset-blackout-sec type="double">300</onset-blackout-sec>
<fast-blackout-sec type="double">10</fast-blackout-sec>
<redout-onset-g type="double">-2</redout-onset-g>
<redout-complete-g type="double">-4</redout-complete-g>
<onset-redout-sec type="double">45</onset-redout-sec>
<fast-redout-sec type="double">7.5</fast-redout-sec>
<recover-fast-sec type="double">7</recover-fast-sec>
<recover-slow-sec type="double">15</recover-slow-sec>
</parameters>
<internal>
<g-force type="double">1</g-force>
<g-force-inv type="double">1</g-force-inv>
<blackout type="double">0</blackout>
<redout type="double">0</redout>
<sum type="double">0</sum>
<log>
<g-force type="double">0</g-force>
<onset-b type="double">0</onset-b>
<fast-b type="double">0</fast-b>
<g-force-r type="double">0</g-force-r>
<onset-r type="double">0</onset-r>
<fast-r type="double">0</fast-r>
</log>
</internal>
</redout>
<headshake>
<enabled type="bool" userarchive="y">false</enabled>
@ -510,6 +531,10 @@ Started September 2000 by David Megginson, david@megginson.com
<name>Local Weather Rules </name>
<path>Environment/local-weather-rules.xml</path>
</property-rule>
<property-rule>
<name>g force effects</name>
<path>Aircraft/Generic/g-forces.xml</path>
</property-rule>
</systems>
<instrumentation>
<path>Aircraft/Generic/generic-instrumentation.xml</path>