Hey there I am trying to control the pinch valve using pid , The setup I have is like this
I have a cylinder which is connect through a pipe and the pipe is pinch valve ( it's a rubber pipe) and then after that there is flow sensor .
I want to control the user to specify the flow rate he want's and the pinch valve should open and close accordingly
Here is my approach for trying that Now i don't know how to implement PID into it .
void run_tmc_stepper(int setflow)
{
flowsensorvalue = flow_sensor(); //this will give the value of flow sensor
stepper_Y.setCurrentPosition(0);
if(setflow>flowsensorvalue)
{
if(diff > 5 )
{
stepper_Y.runToNewPosition(-highincrease);
}
else if ( diff > 3 && diff <=5)
{
stepper_Y.runToNewPosition(-mediumincrease);
}
else if (diff <=3 )
{
stepper_Y.runToNewPosition(-lowincrease);
}
return run_tmc_stepper(setflow);
}
else if(setflow<flowsensorvalue)
{
diff= diff*(-1);
if(diff > 5 )
{
stepper_Y.runToNewPosition(highincrease);
}
else if ( diff > 3 && diff <=5)
{
stepper_Y.runToNewPosition(mediumincrease);
}
else if (diff <=3 )
{
stepper_Y.runToNewPosition(lowincrease);
}
return run_tmc_stepper(setflow);
}
else if(setflow == flowsensorvalue)
{
return 0;
}
}