This repository was archived by the owner on Dec 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
[task_01] Лаба 1 Малич #269
Open
peacewxrld
wants to merge
17
commits into
brstu:main
Choose a base branch
from
peacewxrld:ivan
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e954044
fix yanchuk
peacewxrld 583f416
Merge branch 'brstu:main' into main
peacewxrld f896075
Merge branch 'brstu:main' into main
peacewxrld e22dea2
Merge branch 'brstu:main' into ivan
peacewxrld 0c91599
lab1
peacewxrld cb2133d
ayo bro
peacewxrld 4bf51ad
Merge branch 'main' into ivan
peacewxrld c4751e2
ayo bro
peacewxrld f99365b
Merge branch 'main' into ivan
peacewxrld 9fe5e58
ayo bro
peacewxrld 67b2332
Merge branch 'main' into ivan
peacewxrld a33ead9
ayo bro
peacewxrld 75b3283
Merge branch 'brstu:main' into ivan
peacewxrld 87a342a
ayo bro
peacewxrld 01b523b
Merge branch 'main' into ivan
peacewxrld cc319e0
Merge branch 'main' into ivan
Lictwin 7e58614
Merge branch 'main' into ivan
Lictwin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| <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 | ||
|
peacewxrld marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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} | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
peacewxrld marked this conversation as resolved.
peacewxrld marked this conversation as resolved.
|
||
| double y_prev = 0; | ||
| double y_prev2 = 0; | ||
| double u_prev = 0; | ||
|
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 { | ||
|
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) : | ||
|
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; | ||
| } | ||
| }; | ||
|
peacewxrld marked this conversation as resolved.
|
||
|
|
||
|
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; | ||
|
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))); | ||
|
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; | ||
|
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 }; | ||
|
peacewxrld marked this conversation as resolved.
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; | ||
|
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; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.