1
0
Fork 0

Tentative fix for accelerometers using YaSim properties in JSBSim or optionally generated properties

This commit is contained in:
Thorsten Renk 2016-11-23 15:34:04 +02:00
parent 52e5592442
commit a27a82b4ad
3 changed files with 926 additions and 962 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,98 +1,78 @@
# Damped G value - starts at 1. # Damped G value - starts at 1.
var GDamped = 1.0; var GDamped = 1.0;
var previousG = 1.0; var previousG = 1.0;
var running_compression = 0; var running_compression = 0;
var fdm = "jsb"; var fdm = "jsb";
var compression_rate = nil; var compression_rate = nil;
var internal = nil; var internal = nil;
var lp_black = nil; var lp_black = nil;
var lp_red = nil; var lp_red = nil;
var run = func { var run = func {
if (running_compression) if (running_compression)
{ {
var GCurrent = 1.0; GDamped = getprop("/accelerations/pilot-gdamped");
if (fdm == "jsb") if (internal)
{ {
GCurrent = getprop("/accelerations/pilot/z-accel-fps_sec"); if (running_compression)
if (GCurrent != nil) GCurrent = - GCurrent / 32; {
} # Apply any compression due to G-forces
else if (GDamped != previousG)
{ {
GCurrent = getprop("/accelerations/pilot-g[0]"); var current_y_offset = getprop("/sim/current-view/y-offset-m");
} setprop("/sim/current-view/y-offset-m", current_y_offset - (GDamped - previousG) * compression_rate);
previousG = GDamped;
if (GCurrent == nil) }
{ }
GCurrent = 1.0; }
}
settimer(run, 0);
# Updated the GDamped using a filter. }
if (GDamped < 0) }
{
# Redout happens faster and clears quicker var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized",
GDamped = lp_red.filter(GCurrent); func {
} removelistener(fdm_init_listener); # uninstall, so we're only called once
else fdm = getprop("/sim/flight-model");
{
GDamped = lp_black.filter(GCurrent); if (fdm == "jsb") {
} # this is used in the g-force property rules.
setprop("/sim/rendering/redout/internal/jsb", 1);
setprop("/accelerations/pilot-gdamped", GDamped); } else {
setprop("/sim/rendering/redout/internal/jsb", 0);
if (internal) }
{
if (running_compression) running_compression = getprop("/sim/rendering/headshake/enabled");
{ internal = getprop("/sim/current-view/internal");
# Apply any compression due to G-forces lp_black = aircraft.lowpass.new(0.2);
if (GDamped != previousG) lp_red = aircraft.lowpass.new(0.25);
{
var current_y_offset = getprop("/sim/current-view/y-offset-m"); setlistener("/sim/current-view/internal", func(n) {
setprop("/sim/current-view/y-offset-m", current_y_offset - (GDamped - previousG) * compression_rate); internal = n.getBoolValue();
previousG = GDamped; });
}
} setlistener("/sim/rendering/headshake/rate-m-g", func(n) {
} compression_rate = n.getValue();
}, 1);
settimer(run, 0);
} setlistener("/sim/rendering/headshake/enabled", func(n) {
} if ((running_compression == 0) and n.getBoolValue())
{
var fdm_init_listener = _setlistener("/sim/signals/fdm-initialized", running_compression = 1;
func { # start new timer now
removelistener(fdm_init_listener); # uninstall, so we're only called once run();
fdm = getprop("/sim/flight-model"); }
running_compression = getprop("/sim/rendering/headshake/enabled"); else
internal = getprop("/sim/current-view/internal"); {
lp_black = aircraft.lowpass.new(0.2); running_compression = n.getBoolValue();
lp_red = aircraft.lowpass.new(0.25); }
}, 1);
setlistener("/sim/current-view/internal", func(n) {
internal = n.getBoolValue(); # Now we've set up the listeners (which will have triggered), run it.
}); run();
}
setlistener("/sim/rendering/headshake/rate-m-g", func(n) { );
compression_rate = n.getValue();
}, 1);
setlistener("/sim/rendering/headshake/enabled", func(n) {
if ((running_compression == 0) and n.getBoolValue())
{
running_compression = 1;
# start new timer now
run();
}
else
{
running_compression = n.getBoolValue();
}
}, 1);
# Now we've set up the listeners (which will have triggered), run it.
run();
}
);

View file

@ -266,7 +266,7 @@ Started September 2000 by David Megginson, david@megginson.com
<recover-slow-sec type="double">15</recover-slow-sec> <recover-slow-sec type="double">15</recover-slow-sec>
</parameters> </parameters>
<internal> <internal>
<g-force type="double">1</g-force> <jsb type="bool">false</jsb>
<g-force-inv type="double">1</g-force-inv> <g-force-inv type="double">1</g-force-inv>
<blackout type="double">0</blackout> <blackout type="double">0</blackout>
<redout type="double">0</redout> <redout type="double">0</redout>
@ -919,6 +919,11 @@ Started September 2000 by David Megginson, david@megginson.com
<warp-easing-duration-secs type="double">10</warp-easing-duration-secs> <warp-easing-duration-secs type="double">10</warp-easing-duration-secs>
</time> </time>
</sim> </sim>
<!-- accelerations -->
<accelerations>
<pilot-gdamped type="double">1.0</pilot-gdamped>
<pilot-g type="double">1.0</pilot-g>
</accelerations>
<!-- mouse mode --> <!-- mouse mode -->
<devices> <devices>
<status> <status>