This repository has been archived by the owner on Dec 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
191 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
File renamed without changes
This file contains 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,101 @@ | ||
<p style="text-align: center;">Министерство образования Республики Беларусь</p> | ||
<p style="text-align: center;">Учреждение образования</p> | ||
<p style="text-align: center;">“Брестский Государственный технический университет”</p> | ||
<p style="text-align: center;">Кафедра ИИТ</p> | ||
<div style="margin-bottom: 10em;"></div> | ||
<p style="text-align: center;">Лабораторная работа №2</p> | ||
<p style="text-align: center;">По дисциплине “Общая теория интеллектуальных систем”</p> | ||
<p style="text-align: center;">Тема: “ПИД-регуляторы”</p> | ||
<div style="margin-bottom: 10em;"></div> | ||
<p style="text-align: right;">Выполнил:</p> | ||
<p style="text-align: right;">Студент 2 курса</p> | ||
<p style="text-align: right;">Группы ИИ-23</p> | ||
<p style="text-align: right;">Новицкая В.Д.</p> | ||
<p style="text-align: right;">Проверил:</p> | ||
<p style="text-align: right;">Иванюк Д. С.</p> | ||
<div style="margin-bottom: 10em;"></div> | ||
<p style="text-align: center;">Брест 2023</p> | ||
|
||
--- | ||
|
||
# Общее задание # | ||
1. Написать отчет по выполненной лабораторной работе №1 в .md формате (readme.md) и с помощью запроса на внесение изменений (**pull request**) разместить его в следующем каталоге: trunk\ii0xxyy\task_01\doc (где xx - номер группы, yy - номер студента, например **ii02102**). | ||
2. Исходный код написанной программы разместить в каталоге: **trunk\ii0xxyy\task_01\src**. | ||
|
||
|
||
# Выполнение задания # | ||
|
||
Код программы: | ||
|
||
#include <iostream> | ||
#include <cmath> | ||
#include <vector> | ||
#include <fstream> | ||
|
||
using namespace std; | ||
|
||
class PidRegulator { | ||
private: | ||
double K = 0.001; | ||
double T = 100; | ||
double Td = 100; | ||
double h = 1; | ||
|
||
double q0 = K * (1 + Td / h); | ||
double q1 = -K * (1 + 2 * Td / h - h / T); | ||
double q2 = (K * Td) / h; | ||
|
||
vector<double> q = {q0, q1, q2}; | ||
vector<double> e = {0, 0, 0}; | ||
vector<double> y = {0, 0, 0}; | ||
vector<double> u = {1, 1}; | ||
public: | ||
double sum() { | ||
double sum = 0; | ||
for (int i = 0; i < 3; i++) { | ||
sum += q[i] * e[i]; | ||
} | ||
return sum; | ||
} | ||
void nline(int time, double setpoint, double a = 0.5, double b = 0.3, double c = 0.9, double d = 0.7) { | ||
for (int i = 0; i < time; i++) { | ||
e[0] = setpoint - y[y.size() - 1]; | ||
e[1] = setpoint - y[y.size() - 2]; | ||
e[2] = setpoint - y[y.size() - 3]; | ||
u[0] = u[1] + sum(); | ||
y.push_back(a * y[y.size() - 1] - b * y[y.size() - 2] * y[y.size() - 2] + c * u[0] + d * sin(u[1])); | ||
u[1] = u[0]; | ||
} | ||
} | ||
|
||
vector<double> getY() const{ | ||
return y; | ||
} | ||
}; | ||
int main() { | ||
double value; | ||
ofstream out("output.txt"); | ||
PidRegulator f; | ||
if (out.is_open()) { | ||
cout << "Enter the value: "; | ||
cin >> value; | ||
f.nline(100, value); | ||
vector<double> y_value = f.getY(); | ||
|
||
for (int i = 0; i < y_value.size(); i++) { | ||
double repValue = y_value[i] * value / y_value[y_value.size() - 1]; | ||
cout << i << " " << repValue << endl; | ||
out << i << " " << value << endl; | ||
} | ||
|
||
out.close(); | ||
} else { | ||
cerr << "Error: Cannot open the output file." << std::endl; | ||
} | ||
return 0; | ||
} | ||
|
||
|
||
Линейный график и нелинейный графики: | ||
|
||
![линейный график](graph.png) |
This file contains 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,21 @@ | ||
# CMakeList.txt : CMake project for task_02, include source and define | ||
# project specific logic here. | ||
# | ||
cmake_minimum_required (VERSION 3.8) | ||
|
||
# Enable Hot Reload for MSVC compilers if supported. | ||
if (POLICY CMP0141) | ||
cmake_policy(SET CMP0141 NEW) | ||
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>") | ||
endif() | ||
|
||
project ("otis2") | ||
|
||
# Add source to this project's executable. | ||
add_executable (otis2 "otis2.cpp" ) | ||
|
||
if (CMAKE_VERSION VERSION_GREATER 3.12) | ||
set_property(TARGET otis2 PROPERTY CXX_STANDARD 20) | ||
endif() | ||
|
||
# TODO: Add tests and install targets if needed. |
This file contains 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,68 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
#include <vector> | ||
#include <fstream> | ||
|
||
using namespace std; | ||
|
||
class PidRegulator { | ||
private: | ||
double K = 0.001; | ||
double T = 100; | ||
double Td = 100; | ||
double h = 1; | ||
|
||
double q0 = K * (1 + Td / h); | ||
double q1 = -K * (1 + 2 * Td / h - h / T); | ||
double q2 = (K * Td) / h; | ||
|
||
vector<double> q = {q0, q1, q2}; | ||
vector<double> E = {0, 0, 0}; | ||
vector<double> y = {0, 0, 0}; | ||
vector<double> U = {1, 1}; | ||
public: | ||
double sum() { | ||
double sum = 0; | ||
for (int i = 0; i < 3; i++) { | ||
sum += q[i] * E[i]; | ||
} | ||
return sum; | ||
} | ||
void nline(int Time, double Point, double a = 0.5, double b = 0.3, double c = 0.9, double d = 0.7) { | ||
for (int i = 0; i < Time; i++) { | ||
E[0] = Point - y[y.size() - 1]; //count E0 | ||
E[1] = Point - y[y.size() - 2]; //count E1 | ||
E[2] = Point - y[y.size() - 3]; //count E2 | ||
U[0] = U[1] + sum(); //count U | ||
y.push_back(a * y[y.size() - 1] - b * y[y.size() - 2] * y[y.size() - 2] + c * U[0] + d * sin(U[1])); | ||
U[1] = U[0]; | ||
} | ||
} | ||
vector<double> getY() const{ | ||
return y; | ||
} | ||
}; | ||
int main() { | ||
double value; | ||
ofstream out("output.txt"); | ||
PidRegulator f; | ||
if (out.is_open()) { | ||
cout << "Enter the value: "; | ||
cin >> value; | ||
f.nline(100, value); | ||
vector<double> y_value = f.getY(); | ||
|
||
for (int i = 0; i < y_value.size(); i++) { | ||
double repValue = y_value[i] * value / y_value[y_value.size() - 1]; | ||
cout << i << " " << repValue << endl; | ||
out << i << " " << value << endl; | ||
} | ||
|
||
out.close(); | ||
} else { | ||
cerr << "Error: Cannot open the output file." << std::endl; | ||
} | ||
return 0; | ||
} | ||
|
||
|