2002-09-24 15:24:04 +00:00
|
|
|
// electrical.hxx - a flexible, generic electrical system model.
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started September 2002.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2002 Curtis L. Olson - curt@flightgear.org
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _SYSTEMS_ELECTRICAL_HXX
|
|
|
|
#define _SYSTEMS_ELECTRICAL_HXX 1
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
# error This library requires C++
|
|
|
|
#endif
|
|
|
|
|
2002-09-24 19:57:11 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include STL_STRING
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
SG_USING_STD(string);
|
|
|
|
SG_USING_STD(vector);
|
|
|
|
|
2002-09-24 15:24:04 +00:00
|
|
|
#include <simgear/misc/props.hxx>
|
|
|
|
#include <Main/fgfs.hxx>
|
|
|
|
|
|
|
|
|
2002-09-26 04:51:23 +00:00
|
|
|
// Forward declaration
|
|
|
|
class FGElectricalSystem;
|
|
|
|
|
|
|
|
|
2002-09-24 19:57:11 +00:00
|
|
|
#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 {
|
|
|
|
|
2002-09-24 23:45:56 +00:00
|
|
|
protected:
|
|
|
|
|
2002-09-24 19:57:11 +00:00
|
|
|
typedef vector<FGElectricalComponent *> comp_list;
|
|
|
|
typedef vector<string> string_list;
|
|
|
|
|
2002-09-24 23:45:56 +00:00
|
|
|
int kind;
|
|
|
|
string name;
|
|
|
|
double value;
|
|
|
|
|
|
|
|
comp_list inputs;
|
|
|
|
comp_list outputs;
|
2002-09-26 04:51:23 +00:00
|
|
|
string_list props;
|
2002-09-24 23:45:56 +00:00
|
|
|
|
2002-09-24 19:57:11 +00:00
|
|
|
public:
|
|
|
|
|
2002-09-24 23:45:56 +00:00
|
|
|
FGElectricalComponent();
|
2002-09-24 19:57:11 +00:00
|
|
|
virtual ~FGElectricalComponent() {}
|
|
|
|
|
2002-09-24 23:45:56 +00:00
|
|
|
inline string get_name() { return name; }
|
2002-09-24 19:57:11 +00:00
|
|
|
|
2002-09-24 23:45:56 +00:00
|
|
|
inline int get_kind() const { return kind; }
|
|
|
|
inline double get_value() const { return value; }
|
|
|
|
inline void set_value( double val ) { value = val; }
|
|
|
|
|
2002-09-26 04:51:23 +00:00
|
|
|
inline int get_num_inputs() const { return outputs.size(); }
|
|
|
|
inline FGElectricalComponent *get_input( const int i ) {
|
|
|
|
return inputs[i];
|
|
|
|
}
|
|
|
|
inline void add_input( FGElectricalComponent *c ) {
|
|
|
|
inputs.push_back( c );
|
|
|
|
}
|
|
|
|
|
2002-09-24 23:45:56 +00:00
|
|
|
inline int get_num_outputs() const { return outputs.size(); }
|
|
|
|
inline FGElectricalComponent *get_output( const int i ) {
|
|
|
|
return outputs[i];
|
|
|
|
}
|
|
|
|
inline void add_output( FGElectricalComponent *c ) {
|
|
|
|
outputs.push_back( c );
|
|
|
|
}
|
|
|
|
|
2002-09-26 04:51:23 +00:00
|
|
|
inline int get_num_props() const { return props.size(); }
|
|
|
|
inline string get_prop( const int i ) {
|
|
|
|
return props[i];
|
2002-09-24 23:45:56 +00:00
|
|
|
}
|
2002-09-26 04:51:23 +00:00
|
|
|
inline void add_prop( const string &s ) {
|
|
|
|
props.push_back( s );
|
2002-09-24 23:45:56 +00:00
|
|
|
}
|
2002-09-26 04:51:23 +00:00
|
|
|
|
2002-09-24 19:57:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Electrical supplier
|
|
|
|
class FGElectricalSupplier : public FGElectricalComponent {
|
|
|
|
|
2002-09-24 23:45:56 +00:00
|
|
|
SGPropertyNode_ptr _rpm_node;
|
|
|
|
|
2002-09-24 19:57:11 +00:00
|
|
|
enum FGSupplierType {
|
|
|
|
FG_BATTERY = 0,
|
|
|
|
FG_ALTERNATOR = 1,
|
|
|
|
FG_EXTERNAL = 2
|
|
|
|
};
|
|
|
|
|
2003-02-03 22:35:24 +00:00
|
|
|
string rpm_src;
|
2002-09-24 19:57:11 +00:00
|
|
|
int model;
|
|
|
|
double volts;
|
|
|
|
double amps;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2002-09-26 04:51:23 +00:00
|
|
|
FGElectricalSupplier ( SGPropertyNode *node );
|
2002-09-24 19:57:11 +00:00
|
|
|
~FGElectricalSupplier () {}
|
|
|
|
|
2002-09-24 23:45:56 +00:00
|
|
|
double get_output();
|
2002-09-24 19:57:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Electrical bus (can take multiple inputs and provide multiple
|
|
|
|
// outputs)
|
|
|
|
class FGElectricalBus : public FGElectricalComponent {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2002-09-26 04:51:23 +00:00
|
|
|
FGElectricalBus ( SGPropertyNode *node );
|
2002-09-24 19:57:11 +00:00
|
|
|
~FGElectricalBus () {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A lot like an FGElectricalBus, but here for convenience and future
|
|
|
|
// flexibility
|
|
|
|
class FGElectricalOutput : public FGElectricalComponent {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2002-09-26 04:51:23 +00:00
|
|
|
FGElectricalOutput ( SGPropertyNode *node );
|
2002-09-24 19:57:11 +00:00
|
|
|
~FGElectricalOutput () {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Connects multiple sources to multiple destinations with optional
|
|
|
|
// switches/fuses/circuit breakers inline
|
|
|
|
class FGElectricalConnector : public FGElectricalComponent {
|
|
|
|
|
|
|
|
comp_list inputs;
|
|
|
|
comp_list outputs;
|
2002-09-24 23:45:56 +00:00
|
|
|
typedef vector<SGPropertyNode *> switch_list;
|
|
|
|
switch_list switches;
|
2002-09-24 19:57:11 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2002-09-26 04:51:23 +00:00
|
|
|
FGElectricalConnector ( SGPropertyNode *node, FGElectricalSystem *es );
|
2002-09-24 19:57:11 +00:00
|
|
|
~FGElectricalConnector () {}
|
|
|
|
|
2002-09-24 23:45:56 +00:00
|
|
|
void add_switch( SGPropertyNode *node ) {
|
|
|
|
switches.push_back( node );
|
2002-09-24 19:57:11 +00:00
|
|
|
}
|
|
|
|
|
2003-02-03 22:15:36 +00:00
|
|
|
// set all switches to the specified state
|
|
|
|
void set_switches( bool state );
|
|
|
|
|
2002-09-24 23:45:56 +00:00
|
|
|
bool get_state();
|
2002-09-24 19:57:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-09-24 15:24:04 +00:00
|
|
|
/**
|
2003-02-03 22:35:24 +00:00
|
|
|
* Model an electrical system. This is a fairly simplistic system
|
2002-09-24 15:24:04 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2002-09-24 19:57:11 +00:00
|
|
|
class FGElectricalSystem : public FGSubsystem
|
2002-09-24 15:24:04 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2002-09-24 19:57:11 +00:00
|
|
|
FGElectricalSystem ();
|
|
|
|
virtual ~FGElectricalSystem ();
|
2002-09-24 15:24:04 +00:00
|
|
|
|
|
|
|
virtual void init ();
|
|
|
|
virtual void bind ();
|
|
|
|
virtual void unbind ();
|
|
|
|
virtual void update (double dt);
|
|
|
|
|
2002-09-24 19:57:11 +00:00
|
|
|
bool build ();
|
2003-02-03 22:22:02 +00:00
|
|
|
void propagate( FGElectricalComponent *node, double val, string s = "" );
|
2002-09-24 19:57:11 +00:00
|
|
|
FGElectricalComponent *find ( const string &name );
|
|
|
|
|
2002-09-24 23:45:56 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
typedef vector<FGElectricalComponent *> comp_list;
|
|
|
|
|
2002-09-24 15:24:04 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
SGPropertyNode *config_props;
|
2002-09-24 19:57:11 +00:00
|
|
|
|
|
|
|
bool enabled;
|
|
|
|
|
|
|
|
comp_list suppliers;
|
|
|
|
comp_list buses;
|
|
|
|
comp_list outputs;
|
|
|
|
comp_list connectors;
|
2002-09-24 15:24:04 +00:00
|
|
|
};
|
|
|
|
|
2002-09-24 19:57:11 +00:00
|
|
|
|
2002-09-24 15:24:04 +00:00
|
|
|
#endif // _SYSTEMS_ELECTRICAL_HXX
|