X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FSystems%2Felectrical.hxx;h=f6f21a4534a653f958f86dd73ab6ae1de2d8af43;hb=729e28754a5ff709d0a39d82d9734c8288ea0db1;hp=30c3cc33ce753436900491d3757793f73b591ee4;hpb=9e35d336572e876e3a9ef6f9378f2038d98e4d07;p=flightgear.git diff --git a/src/Systems/electrical.hxx b/src/Systems/electrical.hxx index 30c3cc33c..f6f21a453 100644 --- a/src/Systems/electrical.hxx +++ b/src/Systems/electrical.hxx @@ -2,7 +2,7 @@ // // Written by Curtis Olson, started September 2002. // -// Copyright (C) 2002 Curtis L. Olson - curt@flightgear.org +// Copyright (C) 2002 Curtis L. Olson - http://www.flightgear.org/~curt // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -16,7 +16,7 @@ // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ @@ -32,29 +32,33 @@ # include #endif -#include STL_STRING +#include #include -SG_USING_STD(string); -SG_USING_STD(vector); +using std::string; +using std::vector; -#include -#include
+#include +#include // Forward declaration class FGElectricalSystem; -#define FG_UNKNOWN -1 -#define FG_SUPPLIER 0 -#define FG_BUS 1 -#define FG_OUTPUT 2 -#define FG_CONNECTOR 3 - // Base class for other electrical components class FGElectricalComponent { +public: + +enum FGElectricalComponentType { + FG_UNKNOWN, + FG_SUPPLIER, + FG_BUS, + FG_OUTPUT, + FG_CONNECTOR +}; + protected: typedef vector comp_list; @@ -62,7 +66,11 @@ protected: int kind; string name; - double value; + float volts; + float load_amps; // sum of current draw (load) due to + // this node and all it's children + float available_amps; // available current (after the load + // is subtracted) comp_list inputs; comp_list outputs; @@ -73,11 +81,18 @@ public: FGElectricalComponent(); virtual ~FGElectricalComponent() {} - inline string get_name() { return name; } + inline const string& get_name() { return name; } inline int get_kind() const { return kind; } - inline double get_value() const { return value; } - inline void set_value( double val ) { value = val; } + + inline float get_volts() const { return volts; } + inline void set_volts( float val ) { volts = val; } + + inline float get_load_amps() const { return load_amps; } + inline void set_load_amps( float val ) { load_amps = val; } + + inline float get_available_amps() const { return available_amps; } + inline void set_available_amps( float val ) { available_amps = val; } inline int get_num_inputs() const { return outputs.size(); } inline FGElectricalComponent *get_input( const int i ) { @@ -96,7 +111,7 @@ public: } inline int get_num_props() const { return props.size(); } - inline string get_prop( const int i ) { + inline const string& get_prop( const int i ) { return props[i]; } inline void add_prop( const string &s ) { @@ -109,24 +124,44 @@ public: // Electrical supplier class FGElectricalSupplier : public FGElectricalComponent { - SGPropertyNode_ptr _rpm_node; +public: enum FGSupplierType { - FG_BATTERY = 0, - FG_ALTERNATOR = 1, - FG_EXTERNAL = 2 + FG_BATTERY, + FG_ALTERNATOR, + FG_EXTERNAL, + FG_UNKNOWN }; - int model; - double volts; - double amps; +private: + + SGPropertyNode_ptr _rpm_node; + + FGSupplierType model; // store supplier type + float ideal_volts; // ideal volts + + // alternator fields + string rpm_src; // property name of alternator power source + float rpm_threshold; // minimal rpm to generate full power + + // alt & ext supplier fields + float ideal_amps; // total amps produced (above rpm threshold). + + // battery fields + float amp_hours; // fully charged battery capacity + float percent_remaining; // percent of charge remaining + float charge_amps; // maximum charge load battery can draw public: FGElectricalSupplier ( SGPropertyNode *node ); ~FGElectricalSupplier () {} - double get_output(); + inline FGSupplierType get_model() const { return model; } + float apply_load( float amps, float dt ); + float get_output_volts(); + float get_output_amps(); + float get_charge_amps() const { return charge_amps; } }; @@ -152,13 +187,34 @@ public: }; +// Model an electrical switch. If the rating_amps > 0 then this +// becomes a circuit breaker type switch that can trip +class FGElectricalSwitch { + +private: + + SGPropertyNode_ptr switch_node; + float rating_amps; + bool circuit_breaker; + +public: + + FGElectricalSwitch( SGPropertyNode *node ); + + ~FGElectricalSwitch() { }; + + inline bool get_state() const { return switch_node->getBoolValue(); } + void set_state( bool val ) { switch_node->setBoolValue( val ); } +}; + + // Connects multiple sources to multiple destinations with optional // switches/fuses/circuit breakers inline class FGElectricalConnector : public FGElectricalComponent { comp_list inputs; comp_list outputs; - typedef vector switch_list; + typedef vector< FGElectricalSwitch> switch_list; switch_list switches; public: @@ -166,8 +222,8 @@ public: FGElectricalConnector ( SGPropertyNode *node, FGElectricalSystem *es ); ~FGElectricalConnector () {} - void add_switch( SGPropertyNode *node ) { - switches.push_back( node ); + void add_switch( FGElectricalSwitch s ) { + switches.push_back( s ); } // set all switches to the specified state @@ -178,24 +234,16 @@ public: /** - * Model an electrical system. This is a simple system with the - * alternator hardwired to engine[0]/rpm - * - * Input properties: - * - * /engines/engine[0]/rpm - * - * Output properties: - * + * Model an electrical system. This is a fairly simplistic system * */ -class FGElectricalSystem : public FGSubsystem +class FGElectricalSystem : public SGSubsystem { public: - FGElectricalSystem (); + FGElectricalSystem ( SGPropertyNode *node ); virtual ~FGElectricalSystem (); virtual void init (); @@ -203,8 +251,10 @@ public: virtual void unbind (); virtual void update (double dt); - bool build (); - void propogate( FGElectricalComponent *node, double val, string s = "" ); + bool build (SGPropertyNode* config_props); + float propagate( FGElectricalComponent *node, double dt, + float input_volts, float input_amps, + string s = "" ); FGElectricalComponent *find ( const string &name ); protected: @@ -213,7 +263,9 @@ protected: private: - SGPropertyNode *config_props; + string name; + int num; + string path; bool enabled; @@ -221,6 +273,9 @@ private: comp_list buses; comp_list outputs; comp_list connectors; + + SGPropertyNode_ptr _volts_out; + SGPropertyNode_ptr _amps_out; };