From 940d12528bf6453d43d3135be696d3868fdd683b Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 27 May 2003 19:12:33 +0000 Subject: [PATCH] Add a very simplistic (small single engine type) annunciator model. With the exception of flashing the annunciator light for 10 seconds and then going steady on, this could almost be done entirely in an xml instrument ... --- src/Instrumentation/Makefile.am | 26 ++-- src/Instrumentation/annunciator.cxx | 194 ++++++++++++++++++++++++++++ src/Instrumentation/annunciator.hxx | 69 ++++++++++ 3 files changed, 277 insertions(+), 12 deletions(-) create mode 100644 src/Instrumentation/annunciator.cxx create mode 100644 src/Instrumentation/annunciator.hxx diff --git a/src/Instrumentation/Makefile.am b/src/Instrumentation/Makefile.am index bf4a56875..0829c1ced 100644 --- a/src/Instrumentation/Makefile.am +++ b/src/Instrumentation/Makefile.am @@ -1,16 +1,18 @@ noinst_LIBRARIES = libInstrumentation.a -libInstrumentation_a_SOURCES = instrument_mgr.cxx instrument_mgr.hxx \ - dme.cxx dme.hxx \ - gps.cxx gps.hxx \ - gyro.cxx gyro.hxx \ - airspeed_indicator.cxx airspeed_indicator.hxx \ - attitude_indicator.cxx attitude_indicator.hxx \ - altimeter.cxx altimeter.hxx \ - turn_indicator.cxx turn_indicator.hxx \ - slip_skid_ball.cxx slip_skid_ball.hxx \ - heading_indicator.cxx heading_indicator.hxx \ - vertical_speed_indicator.cxx vertical_speed_indicator.hxx \ - mag_compass.cxx mag_compass.hxx +libInstrumentation_a_SOURCES = \ + instrument_mgr.cxx instrument_mgr.hxx \ + annunciator.cxx annunciator.hxx \ + dme.cxx dme.hxx \ + gps.cxx gps.hxx \ + gyro.cxx gyro.hxx \ + airspeed_indicator.cxx airspeed_indicator.hxx \ + attitude_indicator.cxx attitude_indicator.hxx \ + altimeter.cxx altimeter.hxx \ + turn_indicator.cxx turn_indicator.hxx \ + slip_skid_ball.cxx slip_skid_ball.hxx \ + heading_indicator.cxx heading_indicator.hxx \ + vertical_speed_indicator.cxx vertical_speed_indicator.hxx \ + mag_compass.cxx mag_compass.hxx INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src diff --git a/src/Instrumentation/annunciator.cxx b/src/Instrumentation/annunciator.cxx new file mode 100644 index 000000000..45ced6d18 --- /dev/null +++ b/src/Instrumentation/annunciator.cxx @@ -0,0 +1,194 @@ +// annunciator.hxx - manage the annunciator states +// Written by Curtis Olson, started May, 2003. + +#include + +#include + +#include
+#include
+ +#include "annunciator.hxx" + + +Annunciator::Annunciator (): + timer0( 0.0 ), + timer1( 0.0 ), + timer2( 0.0 ), + timer3( 0.0 ), + timer4( 0.0 ) +{ +} + +Annunciator::~Annunciator () +{ +} + +void +Annunciator::init () +{ + _volts = fgGetNode( "/systems/electrical/volts", true ); + _vac_l = fgGetNode( "/systems/vacuum[0]/suction-inhg", true ); + _vac_r = fgGetNode( "/systems/vacuum[1]/suction-inhg", true ); + _fuel_l = fgGetNode( "/consumables/fuel/tank[0]/level-gal_us", true ); + _fuel_r = fgGetNode( "/consumables/fuel/tank[1]/level-gal_us", true ); + _oil_px = fgGetNode( "/engines/engine[0]/oil-pressure-psi", true ); + + _ann_volts = fgGetNode( "/instrumentation/annunciator/volts", true ); + _ann_vac_l = fgGetNode( "/instrumentation/annunciator/vacuum-left", true ); + _ann_vac_r = fgGetNode( "/instrumentation/annunciator/vacuum-right", true ); + _ann_fuel_l = fgGetNode( "/instrumentation/annunciator/fuel-left", true ); + _ann_fuel_r = fgGetNode( "/instrumentation/annunciator/fuel-right", true ); + _ann_oil_px = fgGetNode( "/instrumentation/annunciator/oil-pressure", true ); +} + +void +Annunciator::update (double dt) +{ + // timers + timer0 += dt; + timer1 += dt; + timer2 += dt; + timer3 += dt; + timer4 += dt; + + if ( _volts->getDoubleValue() < 5.0 ) { + // Not enough juice to illuminate the display + _ann_volts->setBoolValue( false ); + _ann_vac_l->setBoolValue( false ); + _ann_vac_r->setBoolValue( false ); + _ann_fuel_l->setBoolValue( false ); + _ann_fuel_r->setBoolValue( false ); + _ann_oil_px->setBoolValue( false ); + } else { + // Volts + if ( _volts->getDoubleValue() < 24.5 ) { + if ( timer1 < 10 ) { + double rem = timer0 - (int)timer0; + if ( rem <= 0.5 ) { + _ann_volts->setBoolValue( true ); + } else { + _ann_volts->setBoolValue( false ); + } + } else { + _ann_volts->setBoolValue( true ); + } + } else { + _ann_volts->setBoolValue( false ); + timer1 = 0.0; + } + + if ( _fuel_l->getDoubleValue() < 5.0 + && _fuel_r->getDoubleValue() < 5.0 ) + { + if ( timer2 < 10 ) { + double rem = timer0 - (int)timer0; + if ( rem <= 0.5 ) { + _ann_fuel_l->setBoolValue( true ); + _ann_fuel_r->setBoolValue( true ); + } else { + _ann_fuel_l->setBoolValue( false ); + _ann_fuel_r->setBoolValue( false ); + } + } else { + _ann_fuel_l->setBoolValue( true ); + _ann_fuel_r->setBoolValue( true ); + } + } else if ( _fuel_l->getDoubleValue() < 5.0 ) { + if ( timer2 < 10 ) { + double rem = timer0 - (int)timer0; + if ( rem <= 0.5 ) { + _ann_fuel_l->setBoolValue( true ); + } else { + _ann_fuel_l->setBoolValue( false ); + } + } else { + _ann_fuel_l->setBoolValue( true ); + } + _ann_fuel_r->setBoolValue( false ); + } else if ( _fuel_r->getDoubleValue() < 5.0 ) { + if ( timer2 < 10 ) { + double rem = timer0 - (int)timer0; + if ( rem <= 0.5 ) { + _ann_fuel_r->setBoolValue( true ); + } else { + _ann_fuel_r->setBoolValue( false ); + } + } else { + _ann_fuel_r->setBoolValue( true ); + } + _ann_fuel_l->setBoolValue( false ); + } else { + _ann_fuel_l->setBoolValue( false ); + _ann_fuel_r->setBoolValue( false ); + timer2 = 0.0; + } + + // vacuum pumps + if ( _vac_l->getDoubleValue() < 3.0 + && _vac_r->getDoubleValue() < 3.0 ) + { + if ( timer3 < 10 ) { + double rem = timer0 - (int)timer0; + if ( rem <= 0.5 ) { + _ann_vac_l->setBoolValue( true ); + _ann_vac_r->setBoolValue( true ); + } else { + _ann_vac_l->setBoolValue( false ); + _ann_vac_r->setBoolValue( false ); + } + } else { + _ann_vac_l->setBoolValue( true ); + _ann_vac_r->setBoolValue( true ); + } + } else if ( _vac_l->getDoubleValue() < 3.0 ) { + if ( timer3 < 10 ) { + double rem = timer0 - (int)timer0; + if ( rem <= 0.5 ) { + _ann_vac_l->setBoolValue( true ); + } else { + _ann_vac_l->setBoolValue( false ); + } + } else { + _ann_vac_l->setBoolValue( true ); + } + _ann_vac_r->setBoolValue( false ); + } else if ( _vac_r->getDoubleValue() < 3.0 ) { + if ( timer3 < 10 ) { + double rem = timer0 - (int)timer0; + if ( rem <= 0.5 ) { + _ann_vac_r->setBoolValue( true ); + } else { + _ann_vac_r->setBoolValue( false ); + } + } else { + _ann_vac_r->setBoolValue( true ); + } + _ann_vac_l->setBoolValue( false ); + } else { + _ann_vac_l->setBoolValue( false ); + _ann_vac_r->setBoolValue( false ); + timer3 = 0.0; + } + + // Oil pressure + if ( _oil_px->getDoubleValue() < 20.0 ) { + if ( timer4 < 10 ) { + double rem = timer0 - (int)timer0; + if ( rem <= 0.5 ) { + _ann_oil_px->setBoolValue( true ); + } else { + _ann_oil_px->setBoolValue( false ); + } + } else { + _ann_oil_px->setBoolValue( true ); + } + } else { + _ann_oil_px->setBoolValue( false ); + timer4 = 0.0; + } + } +} + + +// end of annunciator.cxx diff --git a/src/Instrumentation/annunciator.hxx b/src/Instrumentation/annunciator.hxx new file mode 100644 index 000000000..861b9306f --- /dev/null +++ b/src/Instrumentation/annunciator.hxx @@ -0,0 +1,69 @@ +// annunciator.hxx - manage the annunciator states +// Written by Curtis Olson, started May, 2003. + + +#ifndef __INSTRUMENTS_ANNUNCIATOR_HXX +#define __INSTRUMENTS_ANNUNCIATOR_HXX 1 + +#ifndef __cplusplus +# error This library requires C++ +#endif + +#include + +#include
+ + +/** + * Model the annunciators. This is innitially hard coded for a C172S + * + * Input properties: + * + * Amps + * L/R Fuel qty + * L/R Vacuum pumps + * Oil pressure + * + * Output properties: + * + * /instrumentation/airspeed-indicator/indicated-speed-kt + */ +class Annunciator : public FGSubsystem +{ + + // timers + double timer0; // used to sync flashing + double timer1; + double timer2; + double timer3; + double timer4; + + // inputs + SGPropertyNode *_volts; + SGPropertyNode *_vac_l; + SGPropertyNode *_vac_r; + SGPropertyNode *_fuel_l; + SGPropertyNode *_fuel_r; + SGPropertyNode *_oil_px; + + // outputs + SGPropertyNode *_ann_volts; // VOLTS (red) + SGPropertyNode *_ann_vac_l; // L VAC (amber) + SGPropertyNode *_ann_vac_r; // VAC R (amber + SGPropertyNode *_ann_fuel_l; // L LOW FUEL (amber) + SGPropertyNode *_ann_fuel_r; // LOW FUEL R (amber) + SGPropertyNode *_ann_oil_px; // OIL PRESS (red) + +public: + + Annunciator (); + virtual ~Annunciator (); + + virtual void init (); + virtual void update (double dt); + +private: + +}; + +#endif // __INSTRUMENTS_ANNUNCIATOR_HXX -- 2.39.5