Pallet Labeller - Tia Portal programı ve C# kodu

 


Youtube ta izleyebilirsin..

Çift bobin sendromundan kurtulmuş biri olarak yazdım plc programını.. Aslında merker hafıza alanlarını (M110.0 gibi) kullanmadan, çıkışları sadece normal coil olarak değil de set veya reset ile kullanmak daha kolay bir yöntem.. Pick & Place serisinde simülasyonun nasıl yapıldığını detaylıca anlattığım için burada detayları yazmıyorum..

Bu şekilde simülasyon yapmak için ne bir pistona ne de plc ye ihtiyaç var.. Yani önce sanal olarak projeyi kafanızda canlandırıp, sonra gerçeğe dönüştürmek yolunu izlemek daha iyi olur diye düşünüyorum.. Tabi ki plc programını yazarken de sanki "makina önünüzde canlanmış" gibi durması da programcı için bulunmaz bir nimet..










Form ölçüsü (size) bende 570;460 olarak gözüküyor. Formumuz bu şekilde :





using Nakov.TurtleGraphics;
using S7.Net;


namespace palletLabeller
{
    
    public partial class MainForm : Form
    {
        Plc _S71200 = new Plc(CpuType.S71200, "127.0.0.1", 0, 1);
        float y_pos=30;
        bool Y;
        float x_pos=30;
        bool X;
        bool Turn; // false normal, true 90 derece
        bool Touch; // Touch sensor, etiketi tutan pad, palete temas edince gören sensör
        bool Lamp;  // error lamp, if it touch something in front labelling before pallet
        bool FrontLabel, SideLabel;
        
        public MainForm()
        {
            
            InitializeComponent();
            _S71200.Open();
        }
        
        void Timer1Tick(object sender, EventArgs e)
        {
            ushort stepNo = (ushort)_S71200.Read("MW50"); // Adım numarası
            lblStep.Text = "Step: " + stepNo;
                
            Y = (bool)_S71200.Read("Q0.0");  // Y cylinder, vertical one
            X = (bool)_S71200.Read("Q0.1");  // X cylinder
            Turn = (bool)_S71200.Read("Q0.2"); // Turn cylinder
            Lamp = (bool)_S71200.Read("Q0.3");  // error lamp
            FrontLabel = (bool)_S71200.Read("M100.1");
            SideLabel = (bool)_S71200.Read("M100.2");
            
            
            if(Y && y_pos<100) y_pos += 2;
            if(!Y && y_pos>20) y_pos -= 2;
            if(X && x_pos<100) x_pos += 2;
            if(!X && x_pos>14) x_pos -= 2;
            
            label2.Text = " "+x_pos;
            label1.Text = " "+y_pos;
            
            if(y_pos==20) {
                txbYmin.BackColor=Color.LightGreen;
                _S71200.Write("I0.1",1);}
                  else {
                  txbYmin.BackColor=Color.White;
                _S71200.Write("I0.1",0);}
                  
            if(y_pos==100) {
                txbYmax.BackColor=Color.LightGreen;
                _S71200.Write("I0.2",1);}
                  else {
                  txbYmax.BackColor=Color.White;
                _S71200.Write("I0.2",0);}
                  
            if(x_pos==14) {
                txbXmin.BackColor=Color.LightGreen;
                _S71200.Write("I0.3",1);}
                  else {
                  txbXmin.BackColor=Color.White;
                _S71200.Write("I0.3",0);}
            
            if(x_pos==100) {
                txbXmax.BackColor=Color.LightGreen;
                _S71200.Write("I0.4",1);}
                  else {
                  txbXmax.BackColor=Color.White;
                _S71200.Write("I0.4",0);}
            
            if(Turn) {
                txbTurn90.BackColor=Color.LightGreen;
                _S71200.Write("I0.5",1);}  //Turn 90 degree sensor
                  else {
                  txbTurn90.BackColor=Color.White;
                _S71200.Write("I0.5",0);}
            
            if(!Turn) {
                txbTurn0.BackColor=Color.LightGreen;
                _S71200.Write("I0.6",1);}  //Turn 0 degree sensor, normal position
                  else {
                  txbTurn0.BackColor=Color.White;
                _S71200.Write("I0.6",0);}
            
            
            
            if(Touch) {
                btnTouch.BackColor=Color.LightGreen;
                _S71200.Write("I0.7",1);}
                  else {
                  btnTouch.BackColor=Color.White;
                _S71200.Write("I0.7",0);}
            
            if(Lamp) {
                txbLamp.BackColor=Color.LightPink;}
                  else {
                  txbLamp.BackColor=Color.White;}
            
            if(FrontLabel && y_pos<73 && Turn) Touch=true;
            if(FrontLabel && y_pos>78 && Turn) Touch=false;
            if(SideLabel && x_pos>42 && !Turn) Touch=true;
            if(SideLabel && x_pos<38 && !Turn) Touch=false;
            
            
            Turtle.Dispose();
            Turtle.Init(panel1);
            Turtle.PenUp();
            Turtle.MoveTo(40,100); 
            Turtle.PenDown();
            Turtle.ShowTurtle = false;
            Turtle.PenColor = Color.Black;
            Turtle.PenSize=20;
            Turtle.Rotate(180);
            Turtle.Forward(80);
            Turtle.PenColor = Color.Green;
            Turtle.PenSize=7;
            Turtle.Forward(y_pos);    //  y_pos
            Turtle.RotateTo(270);
            Turtle.PenColor = Color.Black;
            Turtle.PenSize=15;
            Turtle.Backward(80);
            Turtle.PenUp();
            
            Turtle.PenColor = Color.Green;
            Turtle.PenSize=7;
            Turtle.Forward(80);
            Turtle.PenDown();
            Turtle.Forward(x_pos);    // x_pos
            
            // 90 derece dönebilen pad
            if (!Turn) {
            Turtle.PenColor = Color.Aqua;
            Turtle.PenSize=5;
            Turtle.Rotate(-30);
            Turtle.Forward(30);
            Turtle.Rotate(120);
            Turtle.Forward(30);
            Turtle.Rotate(120);
            Turtle.Forward(30);
            }
            if (Turn) {
            Turtle.PenColor = Color.Aqua;
            Turtle.PenSize=5;
            Turtle.Rotate(60);
            Turtle.Forward(30);
            Turtle.Rotate(120);
            Turtle.Forward(30);
            Turtle.Rotate(120);
            Turtle.Forward(30);
            }
            
            // palet
            Turtle.PenUp();
            Turtle.MoveTo(-120,-15);
            Turtle.RotateTo(0);
            Turtle.PenDown();
            Turtle.PenColor = Color.SandyBrown;
            Turtle.PenSize=10;
            Turtle.Forward(120);
            Turtle.Rotate(90);
            Turtle.Forward(80);
            Turtle.Rotate(90);
            Turtle.Forward(120);
            Turtle.Rotate(90);
            Turtle.Forward(80);
            
            
        }
        void MainFormFormClosed(object sender, FormClosedEventArgs e)
        {
            _S71200.Close();
        }
        void BtnStartMouseDown(object sender, MouseEventArgs e)
        {
            _S71200.Write("I0.0",1);   // START button
        }
        void BtnStartMouseUp(object sender, MouseEventArgs e)
        {
            _S71200.Write("I0.0",0);
        }
        void BtnResetMouseDown(object sender, MouseEventArgs e)
        {
            _S71200.Write("I1.0",1);  // RESET button
        }
        void BtnResetMouseUp(object sender, MouseEventArgs e)
        {
            _S71200.Write("I1.0",0);
        }
        void BtnTouchClick(object sender, EventArgs e)
        {
            if(Touch) Touch=false; else Touch=true;
        }
    }
}

Yorumlar

Bu blogdaki popüler yayınlar

VBA - Mscomm (seri port) ile veri loglama

RJ45 2 - Novexx barkod yazıcıya, S7-1200 plc ile etiket yazdırma

Uzak I/O modülü olarak PLC kullanmak