airdata.nas 977 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
var last_time = 0.0;
var last_speed = 0.0;
var speed_sensed = 0.0;
var sensor_step = 1.0;
var speed_filt = 0.0;
var accel_filt = 0.0;

var compute_airspeed_accel = func( speed_filt, dt ) {
    # print ( "computing forward acceleration ", dt );

    var delta_speed = speed_filt - last_speed;
    last_speed = speed_filt;

    var accel = delta_speed / dt;

    return accel;
}


var update_airdata = func( dt ) {
    # crude model of a noisy electronic pitot tube
    sensed_speed = getprop("/velocities/airspeed-kt");
    var r = rand();
    if ( r < 0.3333 ) {
	sensed_speed = sensed_speed - sensor_step;
    } elsif ( r > 0.6666 ) {
	sensed_speed = sensed_speed + sensor_step;
    }

    speed_filt = 0.97 * speed_filt + 0.03 * sensed_speed;

    var sensed_accel = 0.0;
    if ( dt > 0 ) {
	sensed_accel = compute_airspeed_accel( speed_filt, dt );
    }

    accel_filt = 0.97 * accel_filt + 0.03 * sensed_accel;

    setprop("/accelerations/airspeed-ktps", accel_filt);
}