OT: My first python package - pytunelogix

Join Date
Jun 2010
Location
Ireland
Posts
118
I posted this elsewhere, but this is my first attempt at a python package:
A PID tuning suite for Logix
https://github.com/Destination2Unknown/pytunelogix

Anyone with Python experience feel free to recommend any improvements...
Contributions are welcome

Notes:

First foray into the world of Python

Python to PLC communication is based on pylogix (which is excellent)

This is still very much a Work in Progress

Also works with Logix Emulator (V32+)

It's based on a First Order Plus Dead Time system model and uses general tuning rules, which may not be suitable for all systems

Code:
The Method:

Step 1 -> Record a step response using the logger (or save logix trend as csv)
Step 2 -> Open the step response CSV in the tuner
Step 3 -> Test the tune using the Python Simulator
Step 4 -> Test and fine tune the ControlLogix PID with the process simulator


Logger:

A.png


Tuner:

D.PNG


Simulator:

C.PNG


Logix Simulator:

b.png
 
This is awesome! Thank you for the contribution!

Question: Does the PID gains calculation change as a function of the pid form (dependent or independent) that is selected? If so, would it be beneficial to offer a check box and calculate the gains based on that?
 
This is awesome! Thank you for the contribution!

Question: Does the PID gains calculation change as a function of the pid form (dependent or independent) that is selected? If so, would it be beneficial to offer a check box and calculate the gains based on that?

The independent and dependent PID are equatable:
Code:
Independent -> Kp*E + Ki*Σe + Kd*Δe
Dependent -> Kc(1 + 1/Ti*Σe + Td*Δe)

Code:
To convert:

Kc=Kp
Ti=Kp/Ki
Td=Kp*Kd

and conversely

Kp=Kc
Ki=Kc/Ti
Kd=Kc*Kd

The tune is calculated for independent gains and optionally these are converted to dependent form.
The form of the PID doesn't impact the tune, same same but different
 
@destination unknown: what environment to you use for Python? I usually run WSL/PuTTY/Xwindows, which is solid enough; it's a bit of a dogs's breakfast to setup the first time, but still preferable for me as I am more comfortable in the Linux command-line world.

I know there are native Win10 Python environments, and I assume they can handle TK and plotting; can you recommend one?
 
@destination unknown: what environment to you use for Python? I usually run WSL/PuTTY/Xwindows, which is solid enough; it's a bit of a dogs's breakfast to setup the first time, but still preferable for me as I am more comfortable in the Linux command-line world.

I know there are native Win10 Python environments, and I assume they can handle TK and plotting; can you recommend one?

vscode will run on Linux and Mac. I have it installed on all my computers. It even runs on my ARM based Raspberry PI but it is a little slow. A lot of software people at work use vscode.
vscode will work well enough for most people and applications. vscode does take some setting up. The configuration files are .json files so they are easy to modify.

I used pyinstaller from
https://pypi.org/project/pyinstaller/

I have a python app that uses Tkinter and Matplotlib that I have used pyinstaller on. pyinstaller also requires some fussing with to get working optimally.
 
Off topic but somewhat related.

I use Jupyter Lab for learning and trying out new things. Jupyter lab makes it easy to follow along with examples on the internet. If you use python I highly recommend installing jupyter lab. BTW, forum member rwatson was the one that goaded me in to installing jupyter lab and jupyter hub.

At work we have Jupyter Hub installed. Jupyter Hub is like Jupyter Lab but unlike Jupyter Lab, Jupyter Hub runs on a remove server. In our case the remote server is at Delta and we can VPN in to access. The cool thing about Jupyter Hub is that I can share my work with others at the business and even if I am using a Raspberry PI, it still runs at the speed of our server.

I still use IDLE a lot. Mostly because I can have many windows open at a time for cutting and pasting between windows.

For serious work/debugging VSCode is good but many of the python gurus on YouTube use pycharm or sublime. VSCode has many pluggins. drbitboy mentioned VIM but pylint is good too. And then there is Kite that will try to finish the line for you.
VSCode works with many languages.
 
The independent and dependent PID are equatable:
Code:
Independent -> Kp*E + Ki*Σe + Kd*Δe
Dependent -> Kc(1 + 1/Ti*Σe + Td*Δe)

Code:
To convert:

Kc=Kp
Ti=Kp/Ki
Td=[COLOR="red"]Kp*Kd[/COLOR]

and conversely

Kp=Kc
Ki=Kc/Ti
Kd=Kc*[COLOR="Red"]Kd[/COLOR]

The tune is calculated for independent gains and optionally these are converted to dependent form.
The form of the PID doesn't impact the tune, same same but different

TYPO
The correct conversions:

Code:
Kc=Kp
Ti=Kp/Ki
Td=Kd/Kp

and 

Kp=Kc
Ki=Kc/Ti
Kd=Kc*Td
 

Similar Topics

Hello Guys, I want to establish profinet communication between siemens plc and my system using python programming. Which python lib can i use to...
Replies
12
Views
392
Hi! I'm trying to communicate with an old Kinetix 300 drive that is fully functioning. Is there any library I can use to monitor this drive with...
Replies
0
Views
430
Hi! I'm trying to communicate with an old Kinetix 300 drive that is fully functioning. Is there any library I can use to monitor this drive with...
Replies
0
Views
484
I have previously shared this elsewhere, so I apologize if you have already seen it. Here is a basic and quick introduction to Python for PLCs...
Replies
10
Views
2,251
Read and write the Tags direct using pycomm3 and LogixDriver. Just in case anybody wanted to know. Here's a sample: from pycomm3 import...
Replies
0
Views
801
Back
Top Bottom