headset.nas 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # headset animation
  2. #
  3. #
  4. # code for force calc. taken from aircrane
  5. var headset = {
  6. init: func() {
  7. me.accel = props.globals.getNode("sim/model/bk117/headset/angle-damped-rad", 1);
  8. me.oscillation = props.globals.getNode("sim/model/bk117/headset/oscillation-norm", 1);
  9. me.ax = props.globals.getNode("/accelerations/pilot/x-accel-fps_sec");
  10. me.ay = props.globals.getNode("/accelerations/pilot/y-accel-fps_sec");
  11. me.az = props.globals.getNode("/accelerations/pilot/z-accel-fps_sec");
  12. me.oszil = 0; # osciallation phase
  13. me.Aoszil = aircraft.lowpass.new(6); # osciallation amplitude decays with some delay
  14. me.Aout = aircraft.lowpass.new(1);
  15. me.impulsold = 0;
  16. },
  17. update: func() {
  18. me.oszil += 0.3; # rad/s approx. 0.5 Hz
  19. var ay = me.ay.getValue() or 0;
  20. var az = me.az.getValue() or 0;
  21. # use pilot y body frame accelerations, use thresh. to suppress noise
  22. var angle = math.pi/2 + math.atan2(az, ay);
  23. var swing = me.Aout.filter( (math.abs(angle) > 0.003) ? -angle : 0 );
  24. me.accel.setValue(swing);
  25. me.Aoszil.filter(math.abs(swing) * 10);
  26. me.oscillation.setValue( math.cos(me.oszil) * min(me.Aoszil.filter(0), 1.0) / 1.5 );
  27. }
  28. };
  29. setlistener("/sim/signals/fdm-initialized", func {
  30. headset.init();
  31. var headsettimer = maketimer(0.05, func headset.update(); );
  32. headsettimer.start();
  33. });