News:

SMF - Just Installed!

Main Menu

Mixer - PID

Started by fredz0003, October 08, 2015, 12:32:24 AM

Previous topic - Next topic

fredz0003

Hi,

I am trying to learn a bit more about PID's controllers. The mixer machine seems like a good candidate. I wonder if there's a built in component to measure liquid level on the tank, not just two prox switches. And also if is possible to make the top water valve 0-100%, and not just on/off.

I plan to use PID functions in step7. Any ideas are welcome on how to implement this into the mixer machine.

Thank you!  :D

EasyPLC_Master

The aim of Easy PLC Software Suite is to be an open platform to automation simulation, for this reason provides a lot of tools that allows to develop custom needs.
As you can image, it is impossible to create a software containing all the electronic/mechanical/pneumatic/hydraulic/... components used in the industry, for this, I recommend you to use the User Defined Components in Machines Editor in order to create your own PID.
Once created, you can add it in the Mixer machine, changing the behaviour for your convenience.

fredz0003

Thanks for the reply. I wasn't trying to create a PID controller as a component, I am doing the PID portion within Step7 Siemens. I was trying to find out if there was a component already in the machines editor, that could read the liquid level in the mixer machine, and also change the water percentage going in with the top valve.

I added this to the world script, to read the water level based on the waterPos.Y, it works quite well:

IO.SetAnalogInp(0, waterPos.Y);

I also made a modification to change the water Speed based on an analog output:

public void Main(GameTime gameTime)
{

speedIn = IO.GetAnalogOut(1);

float fTimeScale = (float)gameTime.ElapsedGameTime.Milliseconds/10;
if(IO.GetOutput(1))
{
if(waterPos.Y < 4.3)
waterPos.Y += speedIn * fTimeScale;
else
OverFlow();

waterPIn.Start();   
water.Position = waterPos;
machine[2].PlaySound("fillwater");
}
else
machine[2].StopSound();


Lastly I made a small fix, as the water animation was going way below the tank. Probably someone else had already fixed this.

if(IO.GetOutput(2))
{
// Water should be removed if tank is already empty
// On initial test the water animation goes down even below the tank
// making it look strange. 1.88 fixes this problem. 1 was a bit below the tank.
if(waterPos.Y > 1.88)
{
waterPos.Y -= speedOut * fTimeScale;
waterPOut.Start();   
water.Position = waterPos;
machine[1].PlaySound("fillwater");
}
else
machine[1].StopSound();


The only question remains, Analog Output 1, and Analog Input 0 are still usable? I don't see them on the I/O report?

fredz0003

Hi,

I made a few more code changes. I couldn't find documentation on how to use analog signals with step7 driver. On the pdf for the step7 driver all I could see is digital I/O which I already done before. If you can see the machine script, I want to use analog input 0, and analog output 0, 1.

I see information for DB data on the step7 driver pdf tutorial, does this mean I need to write a script on main connecting the analog I/O to a DB address so my step7 program could use that data?

But not sure how to configure the device drivers for step7 driver, and machine simulator driver.
I have attached my easyPLC file, I added a DB1 with one byte, but when testing simaticsPLCSim driver I get a "Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'

Thanks for the help!  :)

fredz0003

Quote from: fredz0003 on October 12, 2015, 09:23:57 AM

But not sure how to configure the device drivers for step7 driver, and machine simulator driver.
I have attached my easyPLC file, I added a DB1 with one byte, but when testing simaticsPLCSim driver I get a "Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'


I meant to say DB1 with one word.

EasyPLC_Master

Hi fredz0003!

Good work!.
About Simatic S7 driver, is like you say, you must to use the DB to process analogic signals.
In the EasyPLC Simatic S7 driver configuration window, when you declare new DB words to read or write, automatically, the EasyPLC driver creates new analogic I/O signals, in order to be used as you convenience, this is, if the DB is for read, you must use analogic input in the script code, if are DB for write, you must use the analog output.

fredz0003

Thanks for the response.

What can you say about this error.Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'?

Is this error because the DB is not ready on step7. Or because the easyPLC script is not yet wired for the DB?

EasyPLC_Master

When this error appears? when compiling or in run time?

I have not seen analogic signals in your plc posted program.

You have to write something like this:

for(int i=0; i<8; i++)
{
//Digital I/O
WriteOutput(0, i, ReadInput (1, i));

WriteOutput(1, i, ReadInput (0, i));
}

WriteAOutput(0, 0, ReadAInput(1, 0)); // here you send the analogic input number 0 from Machines Simulator to DB1 word 1

fredz0003

Neither runtime nor compile. I have PLCSim running, then I go to easyPLC Hardware, IO Devices, #0 SimaticsS7_PLCSIM I clicked on test button, and I can see Inputs and Outputs on and off in both easyPLc and PLCSim. However when I add a DB1.DBW1, and click test, I get the error mentioned in my previous post.

I am able to test Digital I/O without any code in main, so I figure I should be able to do the same with analog I/O. Or maybe not?

I will test again with writing the script in easyPLC for analog signals.

fredz0003

Quote from: fredz0003 on October 13, 2015, 06:26:09 PM
Neither runtime nor compile. I have PLCSim running, then I go to easyPLC Hardware, IO Devices, #0 SimaticsS7_PLCSIM I clicked on test button, and I can see Inputs and Outputs on and off in both easyPLc and PLCSim. However when I add a DB1.DBW1, and click test, I get the error mentioned in my previous post.

I am able to test Digital I/O without any code in main, so I figure I should be able to do the same with analog I/O. Or maybe not?

I will test again with writing the script in easyPLC for analog signals.

So I had added the analog signal on the script as you suggested. I hit test again, and nothing same error as before. I decided to take some screenshots to show you.

Strange  I didn't change anything at all. I hit test button again, and this time it worked! Now I am reading the analog signal on PLCSim.

fredz0003

I am not sure what's happening in regards with analog input 0 from machines simulator.

When I modified the mixer world in the machine editor, and I filled the water.  Analog input 0, goes up and down correspoding with water level.
But when I do a test of I/O in easyPLC for machinesSimulator analog input 0 is zero all the way, I made a video link of those two test I did.

https://youtu.be/3wnTHsom6Ko

Now I tried adding code for analog output 0, 1 for machine simulator but I just keep getting array index out of range, so my numbers are probably wrong, but maybe also the function I am using.

// Main Sequence: Main_Sequence_1
//  speedIn = IO.GetAnalogOut(0); from machine script
// speedOut = IO.GetAnalogOut(1); from machine script
//  IO.SetAnalogInp(0, waterPos.Y); from machine script
//  DB1.DBW0 -- Water level
//  DB1.DBW2 -- SpeedIn
//  DB1.DBW4 -- SpeedOut

for(int i=0; i<8; i++)
{
//Digital I/O
WriteOutput(0, i, ReadInput (1, i));

WriteOutput(1, i, ReadInput (0, i));
}

// Water level analog input
//WriteAOutput(device, number, value)
WriteAOutput(0, 0, ReadAInput(1, 0)); // here you send the analogic input number 0 from Machines Simulator to DB1 word 1

//Read DB data from PLC, and pass to mach simulator analog output
// speedIn analog output
// Read DB1.DBW2 and pass to Machine Simulator Analog output 0
WriteAOutput(1, 0, ReadAInput(0, 1));

// speedOut analog output
// Read DB1.DB4 and pass to Machine Simulator Analog output 1
WriteAOutput(1, 1, ReadAInput(0, 2));


This analog signals got me spinning around  :D, I don't remember having much trouble with digital signal setup between mach sim and step7 plcsim.
Any insights in what I am doing wrong?

EasyPLC_Master

OK! I think I know the cause of your problem!!!
You have to configure the same number of analogic I/O in Machines Simulator Editor and in EasyPLC Machines Simulator Driver, otherwise the analogic signal communication don't work!. :)

fredz0003

Ok, I already have 3 analog signals in the world script. What else do I have to do to configure 3 signals.

In easyPLC I did have the same 8 digital inputs, 8 digital outputs, 3 analog signals. For some reason it goes back to 0 sometimes, but I always make sure is the right amount of signals when compiling.

EasyPLC_Master

See the following screen captures, and configure your system in the same way

fredz0003

Thanks I did put 8, 8, 8, 8 in all devices in easyPLC for whatever reason everytime you disconnect from the virtualPLC, the machineSim configuration always reverts to 0, 0, 0, 0 for the signals that was triggering the array range error.

Ok Finally got the machine sim working with step7 PLCSim. It was driving me crazy. I was taking some screen recordings, and suddenly something clicked in my mind.

I was testing PLCSim in easyPLC, and I noticed that the analog inputs never changed, and then only some of them changed. The issue was that I was using DBD instead of DBW. Once modified my DB back to INT, and tested in easyPLC I was receving all data, on the input sides.

Next problem was that in my script in easyPLC. I was using ReadAOuput instead of ReadAInput, once I changed it I was able to notice water trickling in the machine.

//Read DB data from PLC, and pass to mach simulator analog output
// speedIn analog output
WriteAOutput(1, 0,ReadAInput(0, 1));

// speedOut analog output
WriteAOutput(1, 1,ReadAInput(0, 2));


Now because the value coming for the speed from the PLC are INT, I had to go in the machine script and divide by 10,000 or the value would be to big for the machine to use. Once I made this change then I was good to go. Lastly in the machine script I multiplied the analog input for water level by 10 to get a nice whole number in the PLC. That way I can get nice values for my PID controller.

   if(IO.GetOutput(1))
{
if(speedIn > 0.0f){
if(waterPos.Y < 4.3)
waterPos.Y += (speedIn / 10000) * fTimeScale;
else
OverFlow();

waterPIn.Start();   
water.Position = waterPos;
machine[2].PlaySound("fillwater");
}
}

IO.SetAnalogInp(0, waterPos.Y * 10);


I made a small recording of the simulation working with different water speeds, and also reading the water level. I could probably do something else with the particles, but as long as the water speed is controlled from the PLC that is all I care about. Once I get the PID controller working, I will post my work in my github. Thanks for all the help! PLCMaster  :D

https://youtu.be/xadpsixEa1E