1 /* 2 Copyright (C) 1998,1999,2000,2001 T. Scott Dattalo 3 4 This file is part of the libgpsim_modules library of gpsim 5 6 This library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public 8 License as published by the Free Software Foundation; either 9 version 2.1 of the License, or (at your option) any later version. 10 11 This library is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public 17 License along with this library; if not, see 18 <http://www.gnu.org/licenses/lgpl-2.1.html>. 19 */ 20 21 22 #ifndef MODULES_SOLAR_SOLAR_H_ 23 #define MODULES_SOLAR_SOLAR_H_ 24 25 /* IN_MODULE should be defined for modules */ 26 #define IN_MODULE 27 28 #ifdef HAVE_GUI 29 #include <gtk/gtk.h> 30 #endif 31 32 #include <config.h> 33 34 #include <glib.h> 35 36 #include "src/modules.h" 37 #include "src/stimuli.h" 38 39 class VSscaleAttribute; 40 class VBscaleAttribute; 41 class AscaleAttribute; 42 class AoffAttribute; 43 class inductorAttribute; 44 class DOCAttribute; 45 class PCM; 46 class PCM_ENABLE; 47 48 class SolarModule : public Module , public TriggerObject { 49 public: 50 IO_bi_directional_pu *Vsol; 51 IO_bi_directional_pu *Vbat; 52 IO_bi_directional_pu *Asol; 53 PCM *pwm; 54 PCM_ENABLE *pwm_enable; 55 56 #ifdef MANAGING_GUI 57 58 GtkWidget *pu_window; 59 60 #endif 61 62 SolarModule(const char *init_name = nullptr, const char *desc = nullptr); 63 ~SolarModule(); 64 65 // Inheritances from the Package class 66 virtual void create_iopin_map(); 67 void setPcm(bool); 68 void setPcmEnable(bool); 69 double battery_voltage(double soc); 70 void Solar_panel(double Ton); 71 void callback(); 72 void set_BDOC(double); 73 double pvi(double); 74 double piv(double); 75 void pvi_init(); 76 77 static Module *construct(const char *new_name = nullptr); 78 79 double Voc; // Solar panel open circuit voltage 80 double Isc; // Solar panel short circuit current 81 double Vmp; // Solar panel Voltage of max power point 82 double Imp; // Solar panel Current at max power point 83 double VbatOC; // OC Battery voltage 84 double Rbat; // Internal battery resistance 85 double Vscale; // Voltage scale factor 86 double VSscale; // Panel Voltage scale factor 87 double VBscale; // Battery Voltage scale factor 88 double Ascale; // Current scale factor V/A 89 double Aoffset; // Zero current offset voltage 90 double BcapMax; // Max battery capacity amp-hours 91 double BDOC; // Battery Degree of charge 92 double cap_mah; // Battery capacity mAH 93 double cur_mah; // Battery current charge 94 double delta_mah; // accumulate charge added to battery 95 bool enabled; 96 bool active; 97 double Nvt; 98 double Isat; 99 double Vsp; // Present solar panel output voltage 100 double Isp; // Present solar panel output current 101 double inductor; // controler inductor 102 103 #ifdef MANAGING_GUI 104 void build_window(); 105 #endif 106 107 private: 108 VSscaleAttribute *VSattr; 109 VBscaleAttribute *VBattr; 110 AscaleAttribute *AVattr; 111 AoffAttribute *Aoffattr; 112 inductorAttribute *indattr; 113 DOCAttribute *docattr; 114 guint64 future_cycle; 115 116 double r0, r1, r2, r3; 117 double v1, v2, v3; 118 double i1, i2, i3; 119 // Variables 120 double Vsolar; // Present panel output voltage 121 double Asolar; // Present panel output current 122 double VBterm; // Present Baterry terminal voltage 123 gint64 Tperiod; // cycles PWM period 124 gint64 Thigh; // cycles PWM high 125 guint64 start_cycle; 126 }; 127 128 129 #endif // MODULES_SOLAR_SOLAR_H_ 130