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

Update

parent c106fb14
Branches
No related tags found
No related merge requests found
...@@ -11,12 +11,23 @@ include_directories(src) ...@@ -11,12 +11,23 @@ include_directories(src)
add_executable(manual_control src/manual_control/ComTest.cpp) add_executable(manual_control src/manual_control/ComTest.cpp)
target_link_libraries(manual_control spdlog) target_link_libraries(manual_control spdlog)
add_executable(sample_client
src/manual_control/sample_client.cpp
src/com/Socket.cpp
src/com/Protocol.cpp
)
target_link_libraries(sample_client spdlog)
# Smart Grid Simulation # Smart Grid Simulation
include_directories(src/i2c) include_directories(src/i2c)
include_directories(src/com)
add_executable(smart_grid.exe add_executable(smart_grid.exe
src/main.cpp src/smg_server.cpp
src/SmartGridModell.cpp src/SmartGridModell.cpp
src/i2c/Node.cpp) src/i2c/Node.cpp
src/com/Socket.cpp
src/com/Protocol.cpp
)
target_link_libraries(smart_grid.exe spdlog) target_link_libraries(smart_grid.exe spdlog)
...@@ -9,13 +9,22 @@ Darin werden die Bibliotheken [spdlog](https://github.com/gabime/spdlog) für da ...@@ -9,13 +9,22 @@ Darin werden die Bibliotheken [spdlog](https://github.com/gabime/spdlog) für da
[freeopcua](https://github.com/FreeOpcUa/freeopcua) für OPC-UA Server und Client. [freeopcua](https://github.com/FreeOpcUa/freeopcua) für OPC-UA Server und Client.
Für freeopcua werden zusätzliche Pakete benötigt. Für Debian sind diese in der Datei 'debain.soft' aufgelistet. Für freeopcua werden zusätzliche Pakete benötigt. Für Debian sind diese in der Datei 'debain.soft' aufgelistet.
Weitere: Die Git-Submodules müssen vor dem kompilieren mit
'git submodule init && git submodule update' heruntergeladen werden.
Die derzeitig auf dem Pi installierte Version von Raspbian hat nur Zugriff auf die alte CMake Version 3.6.2
für 'spdlog' wird jedoch 3.10 erwartet.
Weitere, wernn diese Pakete auf Raspbian nicht zur Verfügung stehen, dann kann TLS deaktiviert werden:
- libmbedx509-0 - libmbedx509-0
- libmbedcrypto1 - libmbedcrypto1
- libmbedtls-dev - libmbedtls-dev
# Durchgeführte Arbeiten # Durchgeführte Arbeiten
* Systemupdate des Raspberry Pi * Systemupdate des Raspberry Pi
......
/// /// @file SmartGridModell.cpp
/// @
#include <SmartGridModell.hpp> #include <SmartGridModell.hpp>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
......
...@@ -77,7 +77,7 @@ public: ...@@ -77,7 +77,7 @@ public:
/// ///
/// @param red Brightness of the red LEDs. /// @param red Brightness of the red LEDs.
/// @param green Brightness of the green LEDs. /// @param green Brightness of the green LEDs.
/// //
void set_village_color(uint8_t red, uint8_t green); void set_village_color(uint8_t red, uint8_t green);
/// @brief Set brightness of the power plant (only red LEDs) /// @brief Set brightness of the power plant (only red LEDs)
...@@ -102,6 +102,7 @@ public: ...@@ -102,6 +102,7 @@ public:
/// energy net. /// energy net.
/// ///
/// @param brightness Brightness off the LEDs. /// @param brightness Brightness off the LEDs.
///
void set_renewable_net(uint8_t brightness); void set_renewable_net(uint8_t brightness);
private: private:
......
/// @file main.cpp
///
struct CleanPower
{
float solar = 0.0;
float wind = 0.0;
};
struct PowerProduction
{
float conventional;
CleanPower renewable;
};
struct PowerUsage
{
float village = 0.0;
float industry = 0.0;
};
struct ModellState
{
PowerProduction production;
PowerUsage usage;
};
class ModelState
{
public:
unsigned get_time();
void next_step();
private:
void update_model_states();
void calc_wind();
void calc_soalr();
PowerProduction m_power_production;
PowerUsage m_pwer_usage;
unsigned m_time = 0; //< 0-24h
};
/// @brief Peak Power consumption or production in MW
///
struct MaxPower
{
float conventional = 600;
float village = 600;
float industry = 200;
float wind = 250;
float solar = 110;
};
constexpr float village_consumption_at[] {
98, 95, 93, 94, 95, 101, 115,
127, 132, 134, 136, 139, 138,
136, 134, 132, 130, 132, 132,
131, 125, 119, 114, 105, 98
};
constexpr float sunnshine_percentage[] {
0, 0, 0, 0, 0, 0, 3,
12, 30, 52, 73, 88, 97,
100, 98, 91, 81, 66, 46,
25, 10, 2, 0, 0, 0
};
constexpr float power_wind[] {
0, 3, 25, 82, 174,
321, 532, 815, 1180,
1612, 1890, 2000, 2100
};
#include <i2c/Node.hpp>
#include <SmartGridModell.hpp>
#include <spdlog/spdlog.h>
#include <thread>
int main()
{
spdlog::set_level(spdlog::level::debug);
spdlog::info("Starting - Smart Grid Modell");
// Intialisation
// put model into a base state
// Intialise environment data
// select operating mode
// manual control
// sim mode
// run loop
i2c::Node i2c_device {0x14};
if (false == i2c_device.open_device("/dev/i2c-1"))
{
spdlog::error("Failed to open device. Exiting...");
exit(1);
}
spdlog::debug("Node created");
SmartGridModell modell{i2c_device, SmartGridModell::DefaultState::Fancy};
spdlog::debug("Modell created");
// ModelState state {};
// bool simulation_is_running {true};
// while (simulation_is_running)
// {
// state.next_step();
// }
modell.put_modell_into_state(SmartGridModell::DefaultState::Off);
spdlog::info("End");
return 0;
}
\ No newline at end of file
/// @file main.cpp
///
#include <i2c/Node.hpp>
#include <SmartGridModell.hpp>
#include <spdlog/spdlog.h>
#include <thread>
#include <cstdlib>
#include <ctime>
#include <Socket.hpp>
#include <Protocol.hpp>
struct CleanPower
{
double solar = 0.0;
double wind = 0.0;
};
struct PowerProduction
{
double conventional;
CleanPower renewable;
};
struct PowerUsage
{
double village = 0.0;
double industry = 0.0;
};
/// @brief Peak Power consumption or production in MW
///
struct MaxPower
{
static constexpr double conventional = 600;
static constexpr double village = 600;
static constexpr double industry = 200;
static constexpr double wind = 250;
static constexpr double solar = 110;
};
constexpr double village_consumption_at[] {
98, 95, 93, 94, 95, 101, 115,
127, 132, 134, 136, 139, 138,
136, 134, 132, 130, 132, 132,
131, 125, 119, 114, 105, 98
};
constexpr double sunnshine_percentage[] {
0, 0, 0, 0, 0, 0, 3,
12, 30, 52, 73, 88, 97,
100, 98, 91, 81, 66, 46,
25, 10, 2, 0, 0, 0
};
constexpr double power_wind[] {
0, 3, 25, 82, 174,
321, 532, 815, 1180,
1612, 1890, 2000, 2100
};
class Day
{
public:
Day()
{
std::srand(std::time(nullptr));
}
void next_hour()
{
update_time();
update_sun();
update_wind();
update_power_production();
update_power_consumption();
print_states();
}
private:
void update_time()
{
if (m_time < 23)
{
++m_time;
}
else
{
m_time = 0;
}
}
void update_sun()
{
m_sun = sunnshine_percentage[m_time];
}
void update_wind()
{
double wind_by_sun = m_sun * 5.0 / 100.0; // wind by sun should by 5 max.
auto random_wind = ((std::rand() * 1.0) / RAND_MAX) * 7.0;
m_wind = power_wind[static_cast<int>(wind_by_sun + random_wind)];
spdlog::debug("wind: {} {} {}", random_wind, wind_by_sun, m_wind);
}
void update_power_production()
{
m_production.renewable.solar = m_sun * solar_size;
spdlog::debug("wind power {} {}", m_production.renewable.wind, m_wind);
m_production.renewable.wind = m_wind * windpark_size;
m_production.conventional = MaxPower::conventional;
spdlog::debug("wind power {} {}", m_production.renewable.wind, m_wind);
}
void update_power_consumption()
{
m_usage.village = village_consumption_at[m_time] * village_size;
if (m_producing == true)
{
m_usage.industry = MaxPower::industry;
}
else
{
m_usage.industry = 0.0;
}
}
static constexpr double solar_size {10};
static constexpr double windpark_size {1.0};
static constexpr double village_size {10};
int m_time {0};
double m_sun {0};
double m_wind {0};
PowerProduction m_production;
PowerUsage m_usage;
bool m_producing {false};
void print_states()
{
spdlog::debug("Time<{}> Sun<{}> Wind<{}>", m_time, m_sun, m_wind);
spdlog::debug("Power Conv<{}> Solar<{}> Wind<{}>", m_production.conventional, m_production.renewable.solar, m_production.renewable.wind);
spdlog::debug("Usage Village<{}> Industry<{}>", m_usage.village, m_usage.industry);
}
};
void run_sim()
{
i2c::Node i2c_device {0x14};
if (false == i2c_device.open_device("/dev/i2c-1"))
{
exit(1);
}
else
{
spdlog::debug("Node created");
}
SmartGridModell modell{i2c_device, SmartGridModell::DefaultState::Fancy};
spdlog::debug("Modell created");
modell.put_modell_into_state(SmartGridModell::DefaultState::Off);
Day day{};
bool active {true};
while (active)
{
day.next_hour();
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
void test_x64()
{
i2c::Node i2c_device {0x14};
bool done = i2c_device.open_device("/dev/i2c-1");
if (done == false)
{
spdlog::debug("You could try running as root");
}
ServerSocket server(8080);
bool finished {false};
Day day{};
while (!finished)
{
DataSocket accept = server.accept();
ProtocolSimple accept_simple(accept);
std::string message;
accept_simple.recv_message(message);
spdlog::info("RECV: {}", message);
accept_simple.send_message("", "OK");
day.next_hour();
}
}
int main(int argc, char** argv)
{
spdlog::set_level(spdlog::level::debug);
spdlog::info("Starting - Smart Grid Modell");
if (argc > 1)
{
test_x64();
}
else
{
run_sim();
}
spdlog::info("End");
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment