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

Update

parent d88d798d
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,15 @@ add_subdirectory(libs/spdlog) ...@@ -8,6 +8,15 @@ add_subdirectory(libs/spdlog)
include_directories(src) include_directories(src)
# Test application to manually send commands to the Arduino # Test application to manually send commands to the Arduino
add_executable(manual_control src/ComTest.cpp) add_executable(manual_control src/manual_control/ComTest.cpp)
target_link_libraries(manual_control spdlog) target_link_libraries(manual_control spdlog)
# Smart Grid Simulation
include_directories(src/i2c)
add_executable(smart_grid.exe
src/main.cpp
src/SmartGridModell.cpp
src/i2c/Node.cpp)
target_link_libraries(smart_grid.exe spdlog)
\ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <linux/i2c-dev.h> #include <linux/i2c-dev.h>
#include <unistd.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
...@@ -69,23 +70,23 @@ bool Node::send(uint8_t reg, uint8_t val) ...@@ -69,23 +70,23 @@ bool Node::send(uint8_t reg, uint8_t val)
constexpr uint8_t i2c_smbus_max_block_size = 32; constexpr uint8_t i2c_smbus_max_block_size = 32;
struct i2c_smbus_data struct i2c_data
{ {
uint8_t block [i2c_smbus_max_block_size + 2]; uint8_t block [i2c_smbus_max_block_size + 2];
}; };
struct i2c_smbus_ioctl_data struct i2c_ioctl_data
{ {
char read_write; char read_write;
uint8_t command; uint8_t command;
int size; int size;
i2c_smbus_data* data; i2c_data* data;
}; };
int Node::read16(uint8_t reg_addr) int Node::read16(uint8_t reg_addr)
{ {
i2c_smbus_data data; i2c_data data;
i2c_smbus_ioctl_data args; i2c_ioctl_data args;
args.read_write = 1; // rw args.read_write = 1; // rw
args.command = reg_addr; args.command = reg_addr;
args.size = 3; // byte = 2; word = 3 (because of address); only byte: 1 -> command = 0; args.size = 3; // byte = 2; word = 3 (because of address); only byte: 1 -> command = 0;
......
...@@ -61,4 +61,4 @@ private: ...@@ -61,4 +61,4 @@ private:
} // i2c namespace } // i2c namespace
#endif I2C_NODE_HEADER #endif
\ No newline at end of file \ No newline at end of file
/// @file main.cpp /// @file main.cpp
/// ///
struct ModellState struct CleanPower
{ {
float solar = 0.0;
float wind = 0.0;
};
struct PowerProduction
{
float conventional = 0.0;
CleanPower renewable {0.0, 0.0};
}; };
struct CleanPower struct PowerUsage
{ {
float solar; float village = 0.0;
float wind; float industry = 0.0;
}; };
struct PowerProduction
struct ModellState
{ {
float conventional; PowerProduction production;
CleanPower renewable; PowerUsage usage;
}; };
struct PowerUsage class ModelState
{ {
float village; public:
float industry; 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
}; };
struct EnergyMix
/// @brief Peak Power consumption or production in MW
///
struct MaxPower
{ {
PowerUsage used; float conventional = 600;
PowerProduction available; 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() int main()
{ {
using namespace std::literals;
spdlog::info("start");
std::this_thread::sleep_for(3s);
spdlog::info("end");
// Intialisation
// put model into a base state
// Intialise environment data
// select operating mode
// manual control
// sim mode
// run loop
// i2c::Node arduino{0x14};
// SmartGridModell modell{arduino};
// ModelState state {};
// bool simulation_is_running {true};
// while (simulation_is_running)
// {
// state.next_step();
// }
return 0; return 0;
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
// select and interact with device // select and interact with device
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <unistd.h>
// Definition of I2C_SLAVE // Definition of I2C_SLAVE
#include <linux/i2c-dev.h> #include <linux/i2c-dev.h>
...@@ -14,6 +13,7 @@ ...@@ -14,6 +13,7 @@
// Nice and easy logging // Nice and easy logging
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <unistd.h>
#include<vector> #include<vector>
#include<array> #include<array>
...@@ -24,11 +24,8 @@ constexpr uint8_t arduino_address = 0x14; ...@@ -24,11 +24,8 @@ constexpr uint8_t arduino_address = 0x14;
void write_to_node(int fd, std::vector<uint8_t> data) void write_to_node(int fd, std::vector<uint8_t> data)
{ {
int buffer_size = data.size(); int buffer_size = data.size();
int bytes_written = write(fd, data.data(), buffer_size); int bytes_written = write(fd, data.data(), buffer_size);
if (bytes_written != buffer_size) if (bytes_written != buffer_size)
{ {
spdlog::error("Failed to write buffer over I2C"); spdlog::error("Failed to write buffer over I2C");
...@@ -45,14 +42,12 @@ int main(int argc, char* argv[]) ...@@ -45,14 +42,12 @@ int main(int argc, char* argv[])
spdlog::error("Unable to open I2C device"); spdlog::error("Unable to open I2C device");
return 1; return 1;
} }
int device_selected = ioctl(fd_i2c, I2C_SLAVE, arduino_address); int device_selected = ioctl(fd_i2c, I2C_SLAVE, arduino_address);
if (device_selected < 0) if (device_selected < 0)
{ {
spdlog::error("Unable to select I2C device"); spdlog::error("Unable to select I2C device");
return 1; return 1;
} }
if (argc == 3) if (argc == 3)
{ {
uint8_t arg1 = atoi(argv[1]); uint8_t arg1 = atoi(argv[1]);
...@@ -71,6 +66,5 @@ int main(int argc, char* argv[]) ...@@ -71,6 +66,5 @@ int main(int argc, char* argv[])
} }
} }
close(fd_i2c); close(fd_i2c);
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment