/lstm_pid_hardware

Hardware controlled PID using LSTM neural network

Primary LanguageJupyter Notebook

LSTM HARDWARE PID

Hardware controlled PID using LSTM neural network

What we need : we want to build a PID hardware controller, to control the burner of a Roasting machine.

This PID controller that takes in input a SET temperature ( desired temperature), and predict the Burner Value of .

Steps to achieve the desired result:

  • train a LSTM neural network used for predicting the Burner value of a Hardware Pid controlled roasted machine
  • Deploy the trained model to a ESP32 or similar device

Environment configuration

Linux server server

here you can find linux server base configuration instructions

If you have a Corsair liquid cooler look here: Corsair liquid cooler configuration

The server has installed two GPU, Nvidia Quadro P4000 8Gb and Nvidia quadro P6000 24Gb. Since we dont need for this training so huge amount of memory we can use without problems the P4000 or any other Nvidia GPU.

ANACONDA

Check here the last conda download https://www.anaconda.com/download/success

anaconda installation

wget https://repo.anaconda.com/archive/Anaconda3-2024.10-1-Linux-x86_64.sh
chmod +x ./Anaconda3-2024.10-1-Linux-x86_64.sh
./Anaconda3-2024.10-1-Linux-x86_64.sh

anaconda environment

conda create --name deeplearning python=3.9

If you'd prefer that conda's base environment not be activated on startup, run the following command when conda is activated:

conda config --set auto_activate_base false

if you get this error:

-bash: conda: command not found

then Activate Anaconda:

source ~/anaconda3/bin/activate

Add Anaconda to PATH

touch ~/.bashrc
echo "export PATH=~/anaconda3/bin:\$PATH" >> ~/.bashrc

if the conda is still not working probably ~/.profile is missing:

touch ~/.profile

echo "if [ -f ~/.bashrc ]; then" >> ~/.profile
echo "   source ~/.bashrc" >> ~/.profile
echo "fi" >> ~/.profile

initialize conda ( only once )

conda init

activate the new environment

conda activate deeplearning

GIT

install git

sudo dnf install git

generate ssh key, replacing the email used in the example with your GitHub email address.

ssh-keygen -t ed25519 -C "your_email@example.com"

create the config file

touch ~/.ssh/config

edit this file and past the following

Host github.com
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_ed25519

Add the SSH public key to your account on GitHub.

cat ~/.ssh/id_ed25519.pub

For more information, see "Adding a new SSH key to your GitHub account."

Important Python libraries

Installing numpy

conda install -c anaconda numpy

Installing matplotlib

conda install -c anaconda matplotlib

Installing Pandas

conda install -c anaconda pandas

Installing Scipy

conda install -c anaconda scipy

PYTORCH

conda activate deeplearning

conda install -c pytorch pytorch 

JUPYTER NOTEBOOK

Installation

conda install -c anaconda jupyter

then you can open it with

jupyter notebook

if you want Jupyter notebook to be accessible from the network instead of the local pc ( in this case its a Linux server so it doesnt have the desktop)

jupyter notebook --ip=0.0.0.0 --no-browser

Lets create the configuration for Jupyter

jupyter notebook --generate-config

set a password:

jupyter notebook password

edit the configuration file:

vi ~/.jupyter/jupyter_notebook_config.py

uncomment and set the following:

c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888

restart the notebook:

jupyter notebook

it maybe necessary to open the port in the firewall (Fedora ):

sudo firewall-cmd --zone=FedoraServer --add-port=8888/tcp --permanent
sudo firewall-cmd --reload

REFERENCES USED

Multi-Step LSTM Time Series Forecasting

Python notebook
training data

https://www.youtube.com/watch?v=kR4TzKZBaNs&t=91s
https://www.kaggle.com/datasets/rupakroy/lstmmultistep