]> git.mxchange.org Git - flightgear.git/blob - src/Systems/electrical.hxx
04c71f3e7c318ced2f9b1d6a330c4cca154fae3f
[flightgear.git] / src / Systems / electrical.hxx
1 // electrical.hxx - a flexible, generic electrical system model.
2 //
3 // Written by Curtis Olson, started September 2002.
4 //
5 // Copyright (C) 2002  Curtis L. Olson  - curt@flightgear.org
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23
24 #ifndef _SYSTEMS_ELECTRICAL_HXX
25 #define _SYSTEMS_ELECTRICAL_HXX 1
26
27 #ifndef __cplusplus
28 # error This library requires C++
29 #endif
30
31 #ifdef HAVE_CONFIG_H
32 #  include <config.h>
33 #endif
34
35 #include STL_STRING
36 #include <vector>
37
38 SG_USING_STD(string);
39 SG_USING_STD(vector);
40
41 #include <simgear/misc/props.hxx>
42 #include <Main/fgfs.hxx>
43
44
45 #define FG_UNKNOWN  -1
46 #define FG_SUPPLIER  0
47 #define FG_BUS       1
48 #define FG_OUTPUT    2
49 #define FG_CONNECTOR 3
50
51 // Base class for other electrical components
52 class FGElectricalComponent {
53
54     typedef vector<FGElectricalComponent *> comp_list;
55     typedef vector<string> string_list;
56
57 public:
58
59     FGElectricalComponent() {}
60     virtual ~FGElectricalComponent() {}
61
62     virtual string get_name() { return ""; }
63
64     int kind;
65     inline int get_kind() { return kind; }
66 };
67
68
69 // Electrical supplier
70 class FGElectricalSupplier : public FGElectricalComponent {
71
72     enum FGSupplierType {
73         FG_BATTERY = 0,
74         FG_ALTERNATOR = 1,
75         FG_EXTERNAL = 2
76     };
77
78     string name;
79     int model;
80     double volts;
81     double amps;
82
83     comp_list outputs;
84
85 public:
86
87     FGElectricalSupplier ( string _name, string _model,
88                            double _volts, double _amps );
89     ~FGElectricalSupplier () {}
90
91     void add_output( FGElectricalComponent *c ) {
92         outputs.push_back( c );
93     }
94
95     string get_name() const { return name; }
96 };
97
98
99 // Electrical bus (can take multiple inputs and provide multiple
100 // outputs)
101 class FGElectricalBus : public FGElectricalComponent {
102
103     string name;
104     comp_list inputs;
105     comp_list outputs;
106
107 public:
108
109     FGElectricalBus ( string _name );
110     ~FGElectricalBus () {}
111
112     void add_input( FGElectricalComponent *c ) {
113         inputs.push_back( c );
114     }
115
116     void add_output( FGElectricalComponent *c ) {
117         outputs.push_back( c );
118     }
119
120     string get_name() const { return name; }
121 };
122
123
124 // A lot like an FGElectricalBus, but here for convenience and future
125 // flexibility
126 class FGElectricalOutput : public FGElectricalComponent {
127
128     string name;
129     comp_list inputs;
130
131 public:
132
133     FGElectricalOutput ( string _name );
134     ~FGElectricalOutput () {}
135
136     void add_input( FGElectricalComponent *c ) {
137         inputs.push_back( c );
138     }
139
140     string get_name() const { return name; }
141 };
142
143
144 // Connects multiple sources to multiple destinations with optional
145 // switches/fuses/circuit breakers inline
146 class FGElectricalConnector : public FGElectricalComponent {
147
148     comp_list inputs;
149     comp_list outputs;
150     string_list switches;
151
152 public:
153
154     FGElectricalConnector ();
155     ~FGElectricalConnector () {}
156
157     void add_input( FGElectricalComponent *c ) {
158         inputs.push_back( c );
159     }
160
161     void add_output( FGElectricalComponent *c ) {
162         outputs.push_back( c );
163     }
164
165     void add_switch( const string &s ) {
166         switches.push_back( s );
167     }
168
169     string get_name() const { return ""; }
170 };
171
172
173 /**
174  * Model an electrical system.  This is a simple system with the
175  * alternator hardwired to engine[0]/rpm
176  *
177  * Input properties:
178  *
179  * /engines/engine[0]/rpm
180  *
181  * Output properties:
182  *
183  * 
184  */
185
186 class FGElectricalSystem : public FGSubsystem
187 {
188
189 public:
190
191     FGElectricalSystem ();
192     virtual ~FGElectricalSystem ();
193
194     virtual void init ();
195     virtual void bind ();
196     virtual void unbind ();
197     virtual void update (double dt);
198
199     bool build ();
200     FGElectricalComponent *find ( const string &name );
201
202 private:
203
204     SGPropertyNode *config_props;
205     // SGPropertyNode_ptr _serviceable_node;
206
207     bool enabled;
208
209     typedef vector<FGElectricalComponent *> comp_list;
210
211     comp_list suppliers;
212     comp_list buses;
213     comp_list outputs;
214     comp_list connectors;
215 };
216
217
218 #endif // _SYSTEMS_ELECTRICAL_HXX