1 // electrical.hxx - a flexible, generic electrical system model.
3 // Written by Curtis Olson, started September 2002.
5 // Copyright (C) 2002 Curtis L. Olson - http://www.flightgear.org/~curt
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #ifndef _SYSTEMS_ELECTRICAL_HXX
25 #define _SYSTEMS_ELECTRICAL_HXX 1
28 # error This library requires C++
41 #include <simgear/props/props.hxx>
42 #include <simgear/structure/subsystem_mgr.hxx>
45 // Forward declaration
46 class FGElectricalSystem;
53 #define FG_CONNECTOR 3
55 // Base class for other electrical components
56 class FGElectricalComponent {
60 typedef vector<FGElectricalComponent *> comp_list;
61 typedef vector<string> string_list;
74 FGElectricalComponent();
75 virtual ~FGElectricalComponent() {}
77 inline string get_name() { return name; }
79 inline int get_kind() const { return kind; }
81 inline float get_volts() const { return volts; }
82 inline void set_volts( float val ) { volts = val; }
84 inline float get_load_amps() const { return load_amps; }
85 inline void set_load_amps( float val ) { load_amps = val; }
87 inline int get_num_inputs() const { return outputs.size(); }
88 inline FGElectricalComponent *get_input( const int i ) {
91 inline void add_input( FGElectricalComponent *c ) {
92 inputs.push_back( c );
95 inline int get_num_outputs() const { return outputs.size(); }
96 inline FGElectricalComponent *get_output( const int i ) {
99 inline void add_output( FGElectricalComponent *c ) {
100 outputs.push_back( c );
103 inline int get_num_props() const { return props.size(); }
104 inline string get_prop( const int i ) {
107 inline void add_prop( const string &s ) {
108 props.push_back( s );
114 // Electrical supplier
115 class FGElectricalSupplier : public FGElectricalComponent {
117 SGPropertyNode_ptr _rpm_node;
119 enum FGSupplierType {
132 FGElectricalSupplier ( SGPropertyNode *node );
133 ~FGElectricalSupplier () {}
139 // Electrical bus (can take multiple inputs and provide multiple
141 class FGElectricalBus : public FGElectricalComponent {
145 FGElectricalBus ( SGPropertyNode *node );
146 ~FGElectricalBus () {}
150 // A lot like an FGElectricalBus, but here for convenience and future
152 class FGElectricalOutput : public FGElectricalComponent {
156 // number of amps drawn by this output
161 FGElectricalOutput ( SGPropertyNode *node );
162 ~FGElectricalOutput () {}
164 inline float get_output_amps() const { return output_amps; }
165 inline void set_output_amps( float val ) { output_amps = val; }
169 // Model an electrical switch. If the rating_amps > 0 then this
170 // becomes a circuit breaker type switch that can trip
171 class FGElectricalSwitch {
175 SGPropertyNode *switch_node;
177 bool circuit_breaker;
181 FGElectricalSwitch( SGPropertyNode *node );
183 ~FGElectricalSwitch() { };
185 inline bool get_state() const { return switch_node->getBoolValue(); }
186 void set_state( bool val ) { switch_node->setBoolValue( val ); }
190 // Connects multiple sources to multiple destinations with optional
191 // switches/fuses/circuit breakers inline
192 class FGElectricalConnector : public FGElectricalComponent {
196 typedef vector< FGElectricalSwitch> switch_list;
197 switch_list switches;
201 FGElectricalConnector ( SGPropertyNode *node, FGElectricalSystem *es );
202 ~FGElectricalConnector () {}
204 void add_switch( FGElectricalSwitch s ) {
205 switches.push_back( s );
208 // set all switches to the specified state
209 void set_switches( bool state );
216 * Model an electrical system. This is a fairly simplistic system
220 class FGElectricalSystem : public SGSubsystem
225 FGElectricalSystem ();
226 virtual ~FGElectricalSystem ();
228 virtual void init ();
229 virtual void bind ();
230 virtual void unbind ();
231 virtual void update (double dt);
234 float propagate( FGElectricalComponent *node, double val, string s = "" );
235 FGElectricalComponent *find ( const string &name );
239 typedef vector<FGElectricalComponent *> comp_list;
243 SGPropertyNode *config_props;
250 comp_list connectors;
252 SGPropertyNode *_volts_out;
253 SGPropertyNode *_amps_out;
257 #endif // _SYSTEMS_ELECTRICAL_HXX