Skip to content
Snippets Groups Projects
Commit 630fd566 authored by Armin Co's avatar Armin Co
Browse files

Update modell state.

parent dfea1452
Branches
No related tags found
No related merge requests found
/// @file ControlMessages.hpp
///
#ifndef CONTROL_MESSAGES_HPP
#define CONTROL_MESSAGES_HPP
#include <string>
enum class CtrlMsgs
{
};
#endif
\ No newline at end of file
...@@ -22,12 +22,15 @@ struct PowerProduction ...@@ -22,12 +22,15 @@ struct PowerProduction
{ {
double conventional; double conventional;
CleanPower renewable; CleanPower renewable;
double clean(){return renewable.solar + renewable.wind;}
double sum(){return conventional + clean();}
}; };
struct PowerUsage struct PowerUsage
{ {
double village = 0.0; double village = 0.0;
double industry = 0.0; double industry = 0.0;
double sum() {return village + industry;}
}; };
...@@ -35,7 +38,6 @@ struct PowerUsage ...@@ -35,7 +38,6 @@ struct PowerUsage
/// ///
struct MaxPower struct MaxPower
{ {
static constexpr double conventional = 600;
static constexpr double village = 600; static constexpr double village = 600;
static constexpr double industry = 200; static constexpr double industry = 200;
static constexpr double wind = 250; static constexpr double wind = 250;
...@@ -65,7 +67,8 @@ constexpr double power_wind[] { ...@@ -65,7 +67,8 @@ constexpr double power_wind[] {
class ModelState class ModelState
{ {
public: public:
ModelState() ModelState(SmartGridModell &modell)
: m_modell{modell}
{ {
std::srand(std::time(nullptr)); std::srand(std::time(nullptr));
} }
...@@ -75,8 +78,9 @@ public: ...@@ -75,8 +78,9 @@ public:
update_time(); update_time();
update_sun(); update_sun();
update_wind(); update_wind();
update_power_production();
update_power_consumption(); update_power_consumption();
update_power_production();
update_modell();
print_states(); print_states();
} }
...@@ -109,12 +113,6 @@ private: ...@@ -109,12 +113,6 @@ private:
auto random_wind = ((std::rand() * 1.0) / RAND_MAX) * 7.0; auto random_wind = ((std::rand() * 1.0) / RAND_MAX) * 7.0;
m_wind = power_wind[static_cast<int>(wind_by_sun + random_wind)]; m_wind = power_wind[static_cast<int>(wind_by_sun + random_wind)];
} }
void update_power_production()
{
m_production.renewable.solar = m_sun * solar_size;
m_production.renewable.wind = m_wind * windpark_size;
m_production.conventional = MaxPower::conventional;
}
void update_power_consumption() void update_power_consumption()
{ {
m_usage.village = village_consumption_at[m_time] * village_size; m_usage.village = village_consumption_at[m_time] * village_size;
...@@ -127,6 +125,40 @@ private: ...@@ -127,6 +125,40 @@ private:
m_usage.industry = 0.0; m_usage.industry = 0.0;
} }
} }
void update_power_production()
{
m_production.renewable.solar = m_sun * solar_size;
m_production.renewable.wind = m_wind * windpark_size;
if (m_usage.sum() > m_production.clean())
{
m_excess_power = 0.0;
m_production.conventional = m_usage.sum() - m_production.clean();
}
else
{
m_excess_power = m_production.clean() - m_usage.sum();
m_production.conventional = 0;
}
}
void update_modell()
{
auto sun = m_sun * 2.5;
auto wind = m_wind / 8.3;
auto renewable = (sun + wind) / 2;
m_modell.set_solar_plant(sun);
m_modell.set_windmill_net(wind);
m_modell.set_renewable_net(renewable);
if (m_production.conventional > 0)
{
m_modell.set_power_plant(200);
m_modell.set_village_color(200, renewable);
}
else
{
m_modell.set_power_plant(0);
m_modell.set_village_color(0, renewable);
}
}
static constexpr double solar_size {10}; static constexpr double solar_size {10};
...@@ -136,9 +168,11 @@ private: ...@@ -136,9 +168,11 @@ private:
int m_time {0}; int m_time {0};
double m_sun {0}; double m_sun {0};
double m_wind {0}; double m_wind {0};
double m_excess_power {0.0};
PowerProduction m_production; PowerProduction m_production;
PowerUsage m_usage; PowerUsage m_usage;
bool m_producing {false}; bool m_producing {false};
SmartGridModell &m_modell;
void print_states() void print_states()
{ {
...@@ -168,7 +202,7 @@ void run_sim() ...@@ -168,7 +202,7 @@ void run_sim()
modell.put_modell_into_state(SmartGridModell::DefaultState::Off); modell.put_modell_into_state(SmartGridModell::DefaultState::Off);
ModelState day{}; ModelState day{modell};
bool active {true}; bool active {true};
while (active) while (active)
...@@ -190,7 +224,8 @@ void test_x64() ...@@ -190,7 +224,8 @@ void test_x64()
ServerSocket server(8080); ServerSocket server(8080);
bool finished {false}; bool finished {false};
ModelState day{}; SmartGridModell modell{i2c_device, SmartGridModell::DefaultState::Fancy};
ModelState day{modell};
while (!finished) while (!finished)
{ {
DataSocket accept = server.accept(); DataSocket accept = server.accept();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment