battery.cc

Go to the documentation of this file.
00001 
00008 #include "battery.h"
00009 #include <string.h>
00010 
00011 
00012 battery :: battery(dsim_model_setup *setup) : dsim_model(setup)
00013 {
00014 }
00015 
00016 void battery :: initialize_data()
00017 {
00018         dsim_model::initialize_data();
00019     
00020     double charge_rate      = 2000;
00021     double battery_charge   = 0;
00022     double max_charge       = 20000000;
00023     
00024     max_charge_dsim         = create_parameter("max_charge",            sd_type_double, &max_charge,        1,1,    "J",    "Maximum charge");
00025     charge_rate_dsim        = create_input("charge_rate",               sd_type_double, &charge_rate,       1,1,    "W",    "Charge rate");     
00026     battery_charge_dsim     = create_integrated_state("battery_charge", sd_type_double, &battery_charge,    1,1,    "J",    "Battery charge");
00027     
00028     create_outlet( power_dsim, "power", sd_type_double,  "W",    "Power flow.");
00029 
00030     
00031     battery_charge_dsim.mark_telemetry();
00032     max_charge_dsim.mark_command_and_telemetry();
00033     power_dsim.mark_telemetry();
00034     charge_rate_dsim.mark_command_and_telemetry();
00035                 
00036 }
00037 
00038 void battery :: initialization_complete()
00039 {
00040     dsim_model::initialization_complete();
00041 }
00042 
00043 void battery :: rhs( double t, double jd )
00044 {    
00045         dsim_model::rhs(t,jd);
00046     
00047     double power        = power_dsim.value_as_double();
00048     double charge       = battery_charge_dsim.value_as_double();
00049     double charge_rate  = charge_rate_dsim.value_as_int();
00050     
00051     double charge_dot   = 0;
00052     
00053     if( (charge < 0 && power < 0) || (charge >= max_charge_dsim.value_as_double() && power > 0) )
00054     {
00055         charge_dot = 0;
00056     }
00057     else
00058     {
00059         if( power < charge_rate )
00060         {
00061             charge_dot = power;
00062         }
00063         else
00064         {
00065             charge_dot = charge_rate;
00066         }
00067     }
00068     
00069         battery_charge_dsim.set_derivative(charge_dot);
00070 }
00071 
00072 void battery :: post_calculate()
00073 {
00074     dsim_model::post_calculate();
00075 }
00076 
00077 extern "C"
00078 {
00079     dsim_model *Battery(void *setup);
00080 
00081         dsim_model *Battery(void *setup)
00082         {
00083                 return new battery((dsim_model_setup *)setup);
00084         }
00085 }
 All Classes Files Functions Variables