Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions trunk/as06613/task_01/doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<p align="center"> Министерство образования Республики Беларусь</p>
<p align="center">Учреждение образования</p>
<p align="center">“Брестский Государственный Технический университет”</p>
<p align="center">Кафедра ИИТ</p>
<br><br><br><br><br><br><br>
<p align="center">Лабораторная работа №1</p>
<p align="center">По дисциплине “Теория и методы автоматического управления”</p>
<p align="center">Тема: “Моделирование управляемого объекта”</p>
<br><br><br><br><br>
<p align="right">Выполнил:</p>
<p align="right">Студент 3 курса</p>
<p align="right">Группы АС-66</p>
Comment thread
peacewxrld marked this conversation as resolved.
<p align="right">Малич И.С.</p>
<p align="right">Проверил:</p>
<p align="right">Иванюк Д.С.</p>
<br><br><br><br><br><br><br><br>
<p align="center">Брест 2025</p>

---
## Task 1. Modeling controlled object

В результате выполнения программы получаем вывод линейного и нелинейного изменения температуры по соответствующим входным данным.
ЛИНЕЙНАЯ МОДЕЛЬ
0 - 20.0
1 10.0 18.0
2 15.0 17.4
3 20.0 17.9
4 25.0 19.3
5 30.0 21.5
6 25.0 22.2
7 20.0 21.7
8 15.0 20.4
9 10.0 18.3
10 5.0 15.7
НЕЛИНЕЙНАЯ МОДЕЛЬ
0 5.0 20.0
1 10.000 13.102
2 15.000 9.617
3 20.000 11.080
4 25.000 14.423
5 30.000 17.855
6 25.000 17.820
7 20.000 15.272
8 15.000 12.107
9 10.000 9.207
10 5.000 6.425
Comment thread
peacewxrld marked this conversation as resolved.
12 changes: 12 additions & 0 deletions trunk/as06613/task_01/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.10)

project(TemperatureModelWithInterface LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_executable(TemperatureModelWithInterface main.cpp)

set_target_properties(TemperatureModelWithInterface PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)
92 changes: 92 additions & 0 deletions trunk/as06613/task_01/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <chrono>
#include <thread>

class ITemperatureModel {
public:
virtual void setInitialConditions(double y0, double y1 = 0, double u0 = 0) = 0;
virtual double calculateNext(double u_current) = 0;
virtual double getCurrentTemperature() const = 0;
virtual ~ITemperatureModel() = default;
};

class TemperatureModel : public ITemperatureModel {
private:
double a;
double b;
double c;
double d;
Comment thread
peacewxrld marked this conversation as resolved.
Comment thread
peacewxrld marked this conversation as resolved.
double y_prev = 0;
double y_prev2 = 0;
double u_prev = 0;
Comment thread
peacewxrld marked this conversation as resolved.
bool is_nonlinear;

public:
TemperatureModel(double a_val, double b_val, double c_val = 0, double d_val = 0)
: a(a_val), b(b_val), c(c_val), d(d_val), is_nonlinear(c_val != 0 || d_val != 0) {
}

void setInitialConditions(double y0, double y1 = 0, double u0 = 0) override {
Comment thread
peacewxrld marked this conversation as resolved.
y_prev = y0;
y_prev2 = y1;
u_prev = u0;
}

double calculateNext(double u_current) override {
double y_next = is_nonlinear ?
a * y_prev - b * y_prev2 * y_prev2 + c * u_current + d * sin(u_prev) :
Comment thread
peacewxrld marked this conversation as resolved.
a * y_prev + b * u_current;

y_prev2 = y_prev;
y_prev = y_next;
u_prev = u_current;

return y_next;
}

double getCurrentTemperature() const override {
return y_prev;
}
};
Comment thread
peacewxrld marked this conversation as resolved.

Comment thread
peacewxrld marked this conversation as resolved.
void runSimulation(ITemperatureModel& model, const std::vector<double>& control_inputs, std::size_t steps, double timestep) {
std::cout << std::setw(4) << "Time" << std::setw(8) << "Control" << std::setw(12) << "Temperature" << std::endl;
Comment thread
peacewxrld marked this conversation as resolved.

for (std::size_t t = 0; t < steps; ++t) {
double u = (t < control_inputs.size()) ? control_inputs[t] : 0;
double y = model.calculateNext(u);
std::cout << std::fixed << std::setprecision(1) << std::setw(4) << t << std::setw(8) << u << std::setw(12) << y << std::endl;

std::this_thread::sleep_for(std::chrono::milliseconds(int(timestep * 1000)));
Comment thread
peacewxrld marked this conversation as resolved.
}
}

int main() {
double a_linear = 0.8;
double b_linear = 0.2;
double a_nonlinear = 0.7;
double b_nonlinear = 0.01;
double c = 0.3;
Comment thread
peacewxrld marked this conversation as resolved.
double d = 0.1;

// Линейная модель
TemperatureModel linear_model(a_linear, b_linear);
linear_model.setInitialConditions(20.0);

std::vector<double> control_inputs_linear = { 10, 15, 20, 25, 30, 25, 20, 15, 10, 5 };
Comment thread
peacewxrld marked this conversation as resolved.
Comment thread
peacewxrld marked this conversation as resolved.
runSimulation(linear_model, control_inputs_linear, control_inputs_linear.size(), 1.0);

std::cout << "\n=== NONLINEAR MODEL TEST ===" << std::endl;
Comment thread
peacewxrld marked this conversation as resolved.

// Нелинейная модель
TemperatureModel nonlinear_model(a_nonlinear, b_nonlinear, c, d);
nonlinear_model.setInitialConditions(20.0, 19.5, 5.0);

std::vector<double> control_inputs_nonlinear = { 10, 15, 20, 25, 30, 25, 20, 15, 10, 5 };
runSimulation(nonlinear_model, control_inputs_nonlinear, control_inputs_nonlinear.size(), 1.0);

return 0;
}
Loading