2002-09-24 15:24:04 +00:00
|
|
|
// electrical.hxx - a flexible, generic electrical system model.
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started September 2002.
|
|
|
|
//
|
2004-11-19 22:10:41 +00:00
|
|
|
// Copyright (C) 2002 Curtis L. Olson - http://www.flightgear.org/~curt
|
2002-09-24 15:24:04 +00:00
|
|
|
//
|
|
|
|
// 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
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-09-24 15:24:04 +00:00
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _SYSTEMS_ELECTRICAL_HXX
|
|
|
|
#define _SYSTEMS_ELECTRICAL_HXX 1
|
|
|
|
|
2002-09-24 19:57:11 +00:00
|
|
|
|
2008-07-25 18:38:29 +00:00
|
|
|
#include <string>
|
2002-09-24 19:57:11 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2003-05-06 23:54:17 +00:00
|
|
|
#include <simgear/props/props.hxx>
|
2003-09-24 17:20:55 +00:00
|
|
|
#include <simgear/structure/subsystem_mgr.hxx>
|
2002-09-24 15:24:04 +00:00
|
|
|
|
|
|
|
|
2002-09-26 04:51:23 +00:00
|
|
|
// Forward declaration
|
|
|
|
class FGElectricalSystem;
|
|
|
|
|
|
|
|
|
2002-09-24 19:57:11 +00:00
|
|
|
// Base class for other electrical components
|
|
|
|
class FGElectricalComponent {
|
|
|
|
|
2005-06-14 17:57:48 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
enum FGElectricalComponentType {
|
|
|
|
FG_UNKNOWN,
|
|
|
|
FG_SUPPLIER,
|
|
|
|
FG_BUS,
|
|
|
|
FG_OUTPUT,
|
|
|
|
FG_CONNECTOR
|
|
|
|
};
|
|
|
|
|
2002-09-24 23:45:56 +00:00
|
|
|
protected:
|
|
|
|
|
2018-09-10 10:45:58 +01:00
|
|
|
using comp_list = std::vector<FGElectricalComponent *> ;
|
2002-09-24 19:57:11 +00:00
|
|
|
|
2002-09-24 23:45:56 +00:00
|
|
|
int kind;
|
2018-09-10 10:45:58 +01:00
|
|
|
std::string name;
|
2003-11-15 05:18:55 +00:00
|
|
|
float volts;
|
2005-06-14 17:57:48 +00:00
|
|
|
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)
|
2002-09-24 23:45:56 +00:00
|
|
|
|
|
|
|
comp_list inputs;
|
|
|
|
comp_list outputs;
|
2018-09-10 10:45:58 +01:00
|
|
|
|
|
|
|
simgear::PropertyList 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() {}
|
|
|
|
|
2018-09-10 10:45:58 +01:00
|
|
|
inline const std::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; }
|
2003-11-15 05:18:55 +00:00
|
|
|
|
|
|
|
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; }
|
2002-09-24 23:45:56 +00:00
|
|
|
|
2005-06-14 17:57:48 +00:00
|
|
|
inline float get_available_amps() const { return available_amps; }
|
|
|
|
inline void set_available_amps( float val ) { available_amps = 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 );
|
|
|
|
}
|
|
|
|
|
2018-09-10 10:45:58 +01:00
|
|
|
void add_prop( const std::string &s );
|
|
|
|
|
|
|
|
void publishVoltageToProps() const;
|
2002-09-26 04:51:23 +00:00
|
|
|
|
2002-09-24 19:57:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Electrical supplier
|
|
|
|
class FGElectricalSupplier : public FGElectricalComponent {
|
|
|
|
|
2005-06-14 17:57:48 +00:00
|
|
|
public:
|
2002-09-24 23:45:56 +00:00
|
|
|
|
2002-09-24 19:57:11 +00:00
|
|
|
enum FGSupplierType {
|
2005-06-14 17:57:48 +00:00
|
|
|
FG_BATTERY,
|
|
|
|
FG_ALTERNATOR,
|
|
|
|
FG_EXTERNAL,
|
|
|
|
FG_UNKNOWN
|
2002-09-24 19:57:11 +00:00
|
|
|
};
|
|
|
|
|
2005-06-14 17:57:48 +00:00
|
|
|
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
|
2002-09-24 19:57:11 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2002-09-26 04:51:23 +00:00
|
|
|
FGElectricalSupplier ( SGPropertyNode *node );
|
2002-09-24 19:57:11 +00:00
|
|
|
~FGElectricalSupplier () {}
|
|
|
|
|
2005-06-14 17:57:48 +00:00
|
|
|
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; }
|
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 () {}
|
2003-11-15 05:18:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Model an electrical switch. If the rating_amps > 0 then this
|
|
|
|
// becomes a circuit breaker type switch that can trip
|
|
|
|
class FGElectricalSwitch {
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2006-06-11 10:21:10 +00:00
|
|
|
SGPropertyNode_ptr switch_node;
|
2003-11-15 05:18:55 +00:00
|
|
|
float rating_amps;
|
|
|
|
bool circuit_breaker;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2003-11-17 21:10:47 +00:00
|
|
|
FGElectricalSwitch( SGPropertyNode *node );
|
2003-11-15 05:18:55 +00:00
|
|
|
|
|
|
|
~FGElectricalSwitch() { };
|
|
|
|
|
|
|
|
inline bool get_state() const { return switch_node->getBoolValue(); }
|
|
|
|
void set_state( bool val ) { switch_node->setBoolValue( val ); }
|
2002-09-24 19:57:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Connects multiple sources to multiple destinations with optional
|
|
|
|
// switches/fuses/circuit breakers inline
|
|
|
|
class FGElectricalConnector : public FGElectricalComponent {
|
|
|
|
|
|
|
|
comp_list inputs;
|
|
|
|
comp_list outputs;
|
2003-11-15 05:18:55 +00:00
|
|
|
typedef vector< FGElectricalSwitch> switch_list;
|
2002-09-24 23:45:56 +00:00
|
|
|
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 () {}
|
|
|
|
|
2003-11-15 05:18:55 +00:00
|
|
|
void add_switch( FGElectricalSwitch s ) {
|
|
|
|
switches.push_back( s );
|
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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-09-24 17:20:55 +00:00
|
|
|
class FGElectricalSystem : public SGSubsystem
|
2002-09-24 15:24:04 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2005-06-14 17:57:48 +00:00
|
|
|
FGElectricalSystem ( SGPropertyNode *node );
|
2002-09-24 19:57:11 +00:00
|
|
|
virtual ~FGElectricalSystem ();
|
2002-09-24 15:24:04 +00:00
|
|
|
|
2018-09-10 10:45:58 +01:00
|
|
|
void init () override;
|
|
|
|
void bind () override;
|
|
|
|
void unbind () override;
|
|
|
|
void update (double dt) override;
|
2002-09-24 15:24:04 +00:00
|
|
|
|
2010-01-26 17:19:17 +01:00
|
|
|
bool build (SGPropertyNode* config_props);
|
2005-06-14 17:57:48 +00:00
|
|
|
float propagate( FGElectricalComponent *node, double dt,
|
|
|
|
float input_volts, float input_amps,
|
2018-09-10 10:45:58 +01:00
|
|
|
std::string s = "" );
|
|
|
|
FGElectricalComponent *find ( const std::string &name );
|
2002-09-24 19:57:11 +00:00
|
|
|
|
2002-09-24 23:45:56 +00:00
|
|
|
protected:
|
|
|
|
|
|
|
|
typedef vector<FGElectricalComponent *> comp_list;
|
|
|
|
|
2002-09-24 15:24:04 +00:00
|
|
|
private:
|
|
|
|
|
2018-09-10 10:45:58 +01:00
|
|
|
std::string name;
|
2005-06-14 17:57:48 +00:00
|
|
|
int num;
|
2018-09-10 10:45:58 +01:00
|
|
|
std::string path;
|
2002-09-24 19:57:11 +00:00
|
|
|
|
|
|
|
bool enabled;
|
2018-09-10 10:45:58 +01:00
|
|
|
|
2002-09-24 19:57:11 +00:00
|
|
|
comp_list suppliers;
|
|
|
|
comp_list buses;
|
|
|
|
comp_list outputs;
|
|
|
|
comp_list connectors;
|
2003-05-27 19:18:14 +00:00
|
|
|
|
2006-06-11 10:21:10 +00:00
|
|
|
SGPropertyNode_ptr _volts_out;
|
|
|
|
SGPropertyNode_ptr _amps_out;
|
2018-09-10 10:45:58 +01:00
|
|
|
SGPropertyNode_ptr _serviceable_node;
|
|
|
|
bool _serviceable = true;
|
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
|