General Category > Machines Simulator

Help with analog inputs and outputs property.

(1/1)

KCP-KIMUEL:
Hi Master ,

Can you help me with regards to the functionalities of using Analog inputs/output in machine editor?
I think I have now the knowledge of using digital I/O's. Now, I want to learn how the analog I/O's works.
It will be a big help if you can provide me even a basic component that is run by Analog Input/Output.
Or see attached .cmp file. This is my code using digital I/O's. Can you create alternative code that uses Analog I/O's?

What I want to do is to control the speed of rotation of the pipe which is from 1.0f - 5.0f. Meaning I can change the Analog Output from 1.0f - 5.0f and display its values in Analog Input.

Thank you for always helping master.

[attachment deleted by admin]

EasyPLC_Master:
Is more easily than you think!!!!
Change your code as show:

float speed;
float rot;
bool mould_speed = false;

 
public void Init()
{
 //speed = IO.Parameter("Speed");
}

public void Main(GameTime gameTime)
{
   float fTimeScale = Compensation(gameTime);
   if (fTimeScale < 0.017f)
        fTimeScale = 0.017f;
       
    if(IO.GetOutput("Position1"))
   {
      mould_speed = true;
      rot -= speed * 50 * fTimeScale;
      if (rot < 0)
         rot = 360;
      Editor.RotateZ(1,rot);
      box[0].ApplyMovement(box[0].body.Orientation.Forward, speed * 15 * fTimeScale);
   }
   else
      box[0].StopMovement();
      
   /*if(IO.GetOutput("mould_speed"))
      speed = 5.5f;
   else
      speed = 1.0f;*/
      
   speed = IO.GetAnalogOut("Speed");
 
}

public void Draw(GameTime gameTime)
{
 
}

public void Finish()
{
 
}

Then change the Analog Output in the editor, press change button and you will see the effect!

KCP-KIMUEL:
Hi Master,
What if i want to display the values that I put in my  PLC Analog output, to Analog Input Value. What is the function to be used?

KCP-KIMUEL:
Please disregard my question above master I already make it. ;D ;D


float speed;
float rot;

public void Init()
{
}

public void Main(GameTime gameTime)
{
   speed = IO.GetAnalogOut("Speed");
   IO.SetAnalogInp("Value",speed);
   float fTimeScale = Compensation(gameTime);
   if (fTimeScale < 0.017f)
        fTimeScale = 0.017f;
       
    if(IO.GetOutput("Position1"))
   {
      rot -= speed * 50 * fTimeScale;
      if (rot < 0)
         rot = 360;
      Editor.RotateZ(1,rot);
      box[0].ApplyMovement(box[0].body.Orientation.Forward, speed * 15 * fTimeScale);
   }
   else
      box[0].StopMovement();
}

public void Draw(GameTime gameTime)
{
 
}

public void Finish()
{
 
}

Navigation

[0] Message Index

Go to full version