# pointsim
Проект создан для симуляции материальной точки для тестирования ПИД регуляторов и их коэффициентов.
# Установка
```
pip install git+https://github.com/OnisOris/pointsim
```
# Примеры
## 2D симуляция
```python
import matplotlib
import numpy as np
from pointsim.cython_pid import PIDController
from pointsim import StabilizationSimulator2D, Point2D
matplotlib.use('Qt5Agg')
# Инициализируем PID-контроллер с коэффициентами
kp = [6.103582235784548, 6.103582235784548]
ki = [0, 0]
kd = [5.898832824054038, 5.898832824054038]
# pid_controller = PIDController(kp, ki, kd)
pid_controller = PIDController(np.array(kp, dtype=np.float64),
np.array(ki, dtype=np.float64),
np.array(kd, dtype=np.float64))
# Инициализируем точку
mass = 1.0
position = np.array([5.0, 5.0]) # Начальная позиция вдали от центра
speed = np.array([0.0, 0.0]) # Начальная скорость
point = Point2D(mass, position, speed)
# Создаем симулятор стабилизации с PID-регулятором
stabilization_simulator = StabilizationSimulator2D("PIDStabilizationSim", point, dt=0.1, pid_controller=pid_controller)
# Запускаем анимацию стабилизации с графиками
stabilization_simulator.animate()
```
![alt text](./img/Figure_1.png)
## 3D симуляция
```python
import matplotlib
from pointsim import StabilizationSimulator3D
matplotlib.use('Qt5Agg')
if __name__ == "__main__":
simulator = StabilizationSimulator3D(
name="PIDStabilizationSim",
mass=1.0,
position=[10.0, 10.0, 5.0], # Начальное смещение
speed=[0.0, 0.0, 0.0],
kp=[1, 1, 1], # Коэффициенты PID
ki=[0.0, 0.0, 0.0], # Интегральная часть отключена
kd=[1, 1, 1], # Дифференциальная часть
dt=0.05, # Шаг времени
show_trajectory=True, # Включаем отображение траектории
max_acceleration=5
)
simulator.run_simulation(steps=1000)
```
![alt text](./img/Figure_2.png)
## 3D симуляция в реальном времени
```python
import numpy as np
import matplotlib
from pointsim import StabilizationSimulator3DRealTime
matplotlib.use('Qt5Agg')
if __name__ == "__main__":
simulator = StabilizationSimulator3DRealTime(
name="PIDRealTimeSim",
mass=1.0,
position=[10.0, 10.0, 5.0],
speed=[0.0, 0.0, 0.0],
kp=[1, 1, 1],
ki=[0.0, 0.0, 0.0],
kd=[1, 1, 1],
dt=0.05,
show_trajectory=True,
max_acceleration=5
)
# Передаем внешний управляющий сигнал
simulator.receive_external_signal(np.array([0.1, -0.2, 0.3]))
# Запуск симуляции с анимацией
simulator.animate_real_time()
```
![alt text](./img/Figure_3.png)
Raw data
{
"_id": null,
"home_page": "https://github.com/OnisOris/pointsim",
"name": "pointsim",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "PID control point simulation",
"author": "OnisOris",
"author_email": "onisoris@yandex.ru",
"download_url": "https://files.pythonhosted.org/packages/bc/75/c95f4eea755fd4cd46b53fbc401cbcb97dca0bf34b87ddb1dff5b27afc93/pointsim-0.0.1.tar.gz",
"platform": null,
"description": "# pointsim\r\n\u041f\u0440\u043e\u0435\u043a\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u0434\u043b\u044f \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u041f\u0418\u0414 \u0440\u0435\u0433\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u0432 \u0438 \u0438\u0445 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u0432.\r\n\r\n# \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430\r\n```\r\npip install git+https://github.com/OnisOris/pointsim\r\n```\r\n# \u041f\u0440\u0438\u043c\u0435\u0440\u044b\r\n## 2D \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044f\r\n```python\r\nimport matplotlib\r\nimport numpy as np\r\nfrom pointsim.cython_pid import PIDController\r\nfrom pointsim import StabilizationSimulator2D, Point2D\r\nmatplotlib.use('Qt5Agg')\r\n\r\n# \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c PID-\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0441 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0430\u043c\u0438\r\nkp = [6.103582235784548, 6.103582235784548]\r\nki = [0, 0]\r\nkd = [5.898832824054038, 5.898832824054038]\r\n# pid_controller = PIDController(kp, ki, kd)\r\npid_controller = PIDController(np.array(kp, dtype=np.float64),\r\n np.array(ki, dtype=np.float64),\r\n np.array(kd, dtype=np.float64))\r\n\r\n# \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0442\u043e\u0447\u043a\u0443\r\nmass = 1.0\r\nposition = np.array([5.0, 5.0]) # \u041d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0432\u0434\u0430\u043b\u0438 \u043e\u0442 \u0446\u0435\u043d\u0442\u0440\u0430\r\nspeed = np.array([0.0, 0.0]) # \u041d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c\r\npoint = Point2D(mass, position, speed)\r\n\r\n# \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0438\u043c\u0443\u043b\u044f\u0442\u043e\u0440 \u0441\u0442\u0430\u0431\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 PID-\u0440\u0435\u0433\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u043c\r\nstabilization_simulator = StabilizationSimulator2D(\"PIDStabilizationSim\", point, dt=0.1, pid_controller=pid_controller)\r\n\r\n# \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u044e \u0441\u0442\u0430\u0431\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u0433\u0440\u0430\u0444\u0438\u043a\u0430\u043c\u0438\r\nstabilization_simulator.animate()\r\n```\r\n![alt text](./img/Figure_1.png)\r\n\r\n## 3D \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044f\r\n\r\n```python\r\nimport matplotlib\r\nfrom pointsim import StabilizationSimulator3D\r\n\r\nmatplotlib.use('Qt5Agg')\r\n\r\nif __name__ == \"__main__\":\r\n simulator = StabilizationSimulator3D(\r\n name=\"PIDStabilizationSim\",\r\n mass=1.0,\r\n position=[10.0, 10.0, 5.0], # \u041d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435\r\n speed=[0.0, 0.0, 0.0],\r\n kp=[1, 1, 1], # \u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b PID\r\n ki=[0.0, 0.0, 0.0], # \u0418\u043d\u0442\u0435\u0433\u0440\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0430\r\n kd=[1, 1, 1], # \u0414\u0438\u0444\u0444\u0435\u0440\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c\r\n dt=0.05, # \u0428\u0430\u0433 \u0432\u0440\u0435\u043c\u0435\u043d\u0438\r\n show_trajectory=True, # \u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0442\u0440\u0430\u0435\u043a\u0442\u043e\u0440\u0438\u0438\r\n max_acceleration=5\r\n )\r\n\r\n simulator.run_simulation(steps=1000)\r\n```\r\n![alt text](./img/Figure_2.png)\r\n\r\n## 3D \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044f \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438\r\n```python\r\nimport numpy as np\r\nimport matplotlib\r\nfrom pointsim import StabilizationSimulator3DRealTime\r\n\r\nmatplotlib.use('Qt5Agg')\r\n\r\n\r\nif __name__ == \"__main__\":\r\n simulator = StabilizationSimulator3DRealTime(\r\n name=\"PIDRealTimeSim\",\r\n mass=1.0,\r\n position=[10.0, 10.0, 5.0],\r\n speed=[0.0, 0.0, 0.0],\r\n kp=[1, 1, 1],\r\n ki=[0.0, 0.0, 0.0],\r\n kd=[1, 1, 1],\r\n dt=0.05,\r\n show_trajectory=True,\r\n max_acceleration=5\r\n\r\n )\r\n\r\n # \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u0441\u0438\u0433\u043d\u0430\u043b\r\n simulator.receive_external_signal(np.array([0.1, -0.2, 0.3]))\r\n\r\n # \u0417\u0430\u043f\u0443\u0441\u043a \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u0438 \u0441 \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0435\u0439\r\n simulator.animate_real_time()\r\n```\r\n![alt text](./img/Figure_3.png)\r\n\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A module for simulating a point and controlling points.",
"version": "0.0.1",
"project_urls": {
"GitHub": "https://github.com/OnisOris/pointsim",
"Homepage": "https://github.com/OnisOris/pointsim"
},
"split_keywords": [
"pid",
"control",
"point",
"simulation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d0e5c2496b691daabd02edf84f4e430678f9528e122dcb245bb0a3d166fcf10d",
"md5": "b3c18905077bcad443c3143f6694592b",
"sha256": "149cda9fdcc2827398aeac75bbec781a34f547833d773723deb344daf4a61756"
},
"downloads": -1,
"filename": "pointsim-0.0.1-cp313-cp313-win_amd64.whl",
"has_sig": false,
"md5_digest": "b3c18905077bcad443c3143f6694592b",
"packagetype": "bdist_wheel",
"python_version": "cp313",
"requires_python": ">=3.9",
"size": 53452,
"upload_time": "2024-10-27T00:36:51",
"upload_time_iso_8601": "2024-10-27T00:36:51.962966Z",
"url": "https://files.pythonhosted.org/packages/d0/e5/c2496b691daabd02edf84f4e430678f9528e122dcb245bb0a3d166fcf10d/pointsim-0.0.1-cp313-cp313-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "bc75c95f4eea755fd4cd46b53fbc401cbcb97dca0bf34b87ddb1dff5b27afc93",
"md5": "ad7ca5007f3672d94be6530bdf6a3c4e",
"sha256": "2266bbd7eb566a54d43e0d902cedebf9d31cda82d685597ef10702957c0cdc13"
},
"downloads": -1,
"filename": "pointsim-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "ad7ca5007f3672d94be6530bdf6a3c4e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 97295,
"upload_time": "2024-10-27T00:36:53",
"upload_time_iso_8601": "2024-10-27T00:36:53.496785Z",
"url": "https://files.pythonhosted.org/packages/bc/75/c95f4eea755fd4cd46b53fbc401cbcb97dca0bf34b87ddb1dff5b27afc93/pointsim-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-27 00:36:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "OnisOris",
"github_project": "pointsim",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pointsim"
}