PowerPort added to store current independent from DC bus type
The DC bus type caused issues because current limits could not be defined individually for each connection to a junction, as described in issue #50. With this commit, also some structs were converted to C++ classes to improve readibility of the code and make sure that pointers (e.g. to PowerPort objects) are always assigned during initialization.
This commit is contained in:
+12
-25
@@ -3,29 +3,16 @@
|
||||
#include "adc_dma_stub.h"
|
||||
#include "adc_dma.h"
|
||||
|
||||
#include "bat_charger.h"
|
||||
#include "dc_bus.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
extern Dcdc dcdc;
|
||||
extern DcBus hv_terminal;
|
||||
extern DcBus lv_terminal;
|
||||
extern DcBus lv_bus_int;
|
||||
extern DcBus load_terminal;
|
||||
extern Charger charger;
|
||||
extern BatConf bat_conf;
|
||||
extern LoadOutput load;
|
||||
extern LogData log_data;
|
||||
#include "main.h"
|
||||
|
||||
static void init_structs()
|
||||
{
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_FLOODED, 6, 100);
|
||||
charger_init(&charger);
|
||||
battery_init_dc_bus(&lv_terminal, &bat_conf, 1);
|
||||
battery_init_dc_bus(&lv_bus, &lv_terminal, &bat_conf, 1);
|
||||
charger.state = CHG_STATE_IDLE;
|
||||
}
|
||||
|
||||
@@ -61,9 +48,9 @@ void energy_calculation_init()
|
||||
update_measurements();
|
||||
|
||||
for (int i = 0; i < 60*60*sun_hours; i++) {
|
||||
dc_bus_energy_balance(&hv_terminal);
|
||||
dc_bus_energy_balance(&lv_terminal);
|
||||
dc_bus_energy_balance(&load_terminal);
|
||||
hv_terminal.energy_balance();
|
||||
lv_terminal.energy_balance();
|
||||
load_terminal.energy_balance();
|
||||
}
|
||||
|
||||
// disable DC/DC = solar charging
|
||||
@@ -72,9 +59,9 @@ void energy_calculation_init()
|
||||
update_measurements();
|
||||
|
||||
for (int i = 0; i < 60*60*night_hours; i++) {
|
||||
dc_bus_energy_balance(&hv_terminal);
|
||||
dc_bus_energy_balance(&lv_terminal);
|
||||
dc_bus_energy_balance(&load_terminal);
|
||||
hv_terminal.energy_balance();
|
||||
lv_terminal.energy_balance();
|
||||
load_terminal.energy_balance();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,26 +69,26 @@ void charging_energy_calculation_valid()
|
||||
{
|
||||
energy_calculation_init();
|
||||
// charging only during sun hours
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(sun_hours * lv_terminal.voltage * (dcdc_current_sun - load_current)), round(lv_terminal.chg_energy_Wh));
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(sun_hours * lv_terminal.bus->voltage * (dcdc_current_sun - load_current)), round(lv_terminal.chg_energy_Wh));
|
||||
}
|
||||
|
||||
void discharging_energy_calculation_valid()
|
||||
{
|
||||
energy_calculation_init();
|
||||
// discharging (sum of current) only during dis hours
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(night_hours * lv_terminal.voltage * adcval.load_current), round(lv_terminal.dis_energy_Wh));
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(night_hours * lv_terminal.bus->voltage * adcval.load_current), round(lv_terminal.dis_energy_Wh));
|
||||
}
|
||||
|
||||
void solar_input_energy_calculation_valid()
|
||||
{
|
||||
energy_calculation_init();
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(sun_hours * lv_terminal.voltage * dcdc_current_sun), round(hv_terminal.dis_energy_Wh));
|
||||
TEST_ASSERT_EQUAL_FLOAT(round(sun_hours * lv_terminal.bus->voltage * dcdc_current_sun), round(hv_terminal.dis_energy_Wh));
|
||||
}
|
||||
|
||||
void load_output_energy_calculation_valid()
|
||||
{
|
||||
energy_calculation_init();
|
||||
TEST_ASSERT_EQUAL_FLOAT(round((sun_hours + night_hours) * lv_terminal.voltage * adcval.load_current), round(load_terminal.chg_energy_Wh));
|
||||
TEST_ASSERT_EQUAL_FLOAT(round((sun_hours + night_hours) * lv_terminal.bus->voltage * adcval.load_current), round(load_terminal.chg_energy_Wh));
|
||||
}
|
||||
|
||||
void dc_bus_tests()
|
||||
|
||||
Reference in New Issue
Block a user