Indexing wraparound labeling - Tia Portal programı ve C# kodu
Video da bir sensör ile şişenin sapı algılanarak indeksleme yapılmış. Sensör, şişe sapını ilk gördüğünde değil ikinci kez gördüğünde etiketleme yapılmış. Çünkü ilk görme, şişe dönmeye başlamadan önce olabilir, bu da etiketin yanlış yere yapışarak kaymasına neden olur. Sensörün ikinci görüşünden sonra etiketi yapıştırmak mantıklı bir çözüm.. Bu tip etiketleme işlerinde şişeyi çok hızlı döndürmek de istenmeyen bir şeydir, hız arttıkça etiket konumundaki kaymalar da artacaktır.. Ben de aynı şekilde ikinci görmede etiketleme yaptım.
Tia da üst kısımda bulunan tırnağa tıklayarak aşağı inen pencerede Constant ları tanımlayarak programın daha okunur hale gelmesini sağlayabilirsiniz.. Program adımlarını constant olarak tanımlamış olduk.
Bir HMI ile bağlayabileceğiniz DB miz var :
Tia Portal S7-1200 programı..
Kullanılan kütüphanelerle ve PLCSIM ayarlarıyla ilgili önemli bilgilere, önceki post lardan bakabilirsiniz...
Bendeki timer1 interval 150ms.. Formun büyüklüğü 745;531.. panel1 in büyüklüğü 716;323
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Nakov.TurtleGraphics;
using S7.Net;
namespace wrapAround
{
public partial class MainForm : Form
{
Plc _S71200 = new Plc(CpuType.S71200, "127.0.0.1", 0, 1);
float x_pos=-350,y_pos=0,bottleAngle=0;
bool turning, cylinder_1, cylinder_2, cylinder_3, conveyor, s1, s2, cyl3_sensor;
bool barcodeScannerTrig, sGoodRead, labelStart, dispenseEnd, start, stop, tetik_var, movement;
float cyl1_pos=10,cyl2_pos=10,cyl3_pos=10;
public MainForm()
{
InitializeComponent();
_S71200.Open();
}
void Timer1Tick(object sender, EventArgs e)
{
//label1.Text=""+x_pos; //for debugging
//label2.Text=""+cyl3_pos;
//label10.Text=""+cyl2_pos;
ushort stepNo = (ushort)_S71200.Read("MW50"); // Adım numarası
lblAdim.Text = "Step No: " + stepNo;
cylinder_1 = (bool)_S71200.Read("Q0.4"); //
cylinder_2 = (bool)_S71200.Read("Q0.5");
cylinder_3 = (bool)_S71200.Read("Q0.6");
labelStart= (bool)_S71200.Read("Q0.7");
barcodeScannerTrig= (bool)_S71200.Read("Q1.0");
conveyor= (bool)_S71200.Read("Q1.1");
if(labelStart) lblEtiket.Text="Label printing...";
if(barcodeScannerTrig) tetik_var=true;
if(cylinder_1 && cyl1_pos<90) cyl1_pos += 10;
if(!cylinder_1 && cyl1_pos>10) cyl1_pos -= 10;
if(cylinder_2 && cyl2_pos<90) cyl2_pos += 10;
if(!cylinder_2 && cyl2_pos>10) cyl2_pos -= 10;
if(cylinder_3 && cyl3_pos<45) cyl3_pos += 5;
if(!cylinder_3 && cyl3_pos>10) cyl3_pos -= 5;
if(x_pos<-190 && x_pos>-210){
s1=true;
_S71200.Write("I0.0",1); // S1
}else{
s1=false;
_S71200.Write("I0.0",0);
}
if(x_pos>-100 && x_pos<-75){
s2=true;
_S71200.Write("I0.1",1);
}else{
s2=false;
_S71200.Write("I0.1",0);
}
if(bottleAngle>119 && bottleAngle<151){
sGoodRead=true;
_S71200.Write("I0.2",1);
tetik_var=false;
}else{
sGoodRead=false;
_S71200.Write("I0.2",0);
}
if(conveyor && x_pos<-200) {x_pos += 5; movement=true;}
if(!movement && conveyor && cyl1_pos==90 && cyl2_pos==10) {x_pos += 5;movement=true;}
if(!movement && conveyor && x_pos>-145 && x_pos<20){ x_pos += 5;movement=true;}
if(!movement && conveyor && stepNo==0 && cyl3_pos<40) x_pos += 5;
movement=false;
if(x_pos>350){ x_pos=-350; bottleAngle=0;y_pos=0;}
if(x_pos>300){ lblEtiket.Text=""; sGoodRead=false; }
if(cyl3_pos==45){
turning=true;
_S71200.Write("I0.6",1); //cyl3_sensor
txtCyl3_sensor.BackColor=Color.LightGreen;
cyl3_sensor=true;
}else{
turning=false;
_S71200.Write("I0.6",0);
txtCyl3_sensor.BackColor=Color.LightGray;
cyl3_sensor=false;}
Turtle.Init(panel1);
Turtle.ShowTurtle=false;
Turtle.PenUp();
Turtle.MoveTo(x_pos,y_pos);
Turtle.RotateTo(bottleAngle);
Turtle.PenDown();
for (int i = 0; i <= 23; i++) {
Turtle.Rotate(15);
Turtle.Forward(10.04f);
if(i==1 && turning == true) {
x_pos=Turtle.X;
y_pos=Turtle.Y;
bottleAngle=Turtle.Angle;
}
}
Turtle.Rotate(97);
Turtle.Forward(30);
//cylinder_1
Turtle.PenUp();
Turtle.MoveTo(-210,-95);
Turtle.RotateTo(0);
Turtle.PenColor = Color.Black;
Turtle.PenSize=20;
Turtle.PenDown();
Turtle.Forward(30);
Turtle.PenColor = Color.Green;
Turtle.PenSize=10;
Turtle.Forward(cyl1_pos);
//cylinder_2
Turtle.PenUp();
Turtle.MoveTo(-115,-95);
Turtle.RotateTo(0);
Turtle.PenColor = Color.Black;
Turtle.PenSize=20;
Turtle.PenDown();
Turtle.Forward(30);
Turtle.PenColor = Color.Green;
Turtle.PenSize=10;
Turtle.PenDown();
Turtle.Forward(cyl2_pos);
//turning roller on top
Turtle.PenUp();
Turtle.MoveTo(20,85);
Turtle.RotateTo(0);
Turtle.PenDown();
Turtle.PenColor = Color.Black;
Turtle.PenSize=10;
for (int i = 0; i <= 23; i++) {
Turtle.Rotate(15);
Turtle.Forward(10.04f);
}
//cylinder_3
Turtle.PenUp();
Turtle.MoveTo(60,-130);
Turtle.RotateTo(0);
Turtle.PenColor = Color.Black;
Turtle.PenSize=20;
Turtle.PenDown();
Turtle.Forward(30);
Turtle.PenColor = Color.Green;
Turtle.PenSize=10;
Turtle.Forward(cyl3_pos);
Turtle.PenColor = Color.Gray;
Turtle.PenSize=7;
Turtle.Rotate(90);
Turtle.Forward(30);
Turtle.PenColor = Color.Black;
for (int i = 0; i <= 23; i++) {
Turtle.Rotate(-15);
Turtle.Forward(2f);
}
Turtle.PenUp();
Turtle.Backward(30);
Turtle.PenDown();
Turtle.PenColor = Color.Gray;
Turtle.Backward(30);
Turtle.PenColor = Color.Black;
for (int i = 0; i <= 23; i++) {
Turtle.Rotate(-15);
Turtle.Forward(2f);
}
//S1
Turtle.PenUp();
Turtle.MoveTo(-160,50);
Turtle.RotateTo(0);
Turtle.PenDown();
if(s1) Turtle.PenColor = Color.Yellow; else Turtle.PenColor = Color.Black;
Turtle.PenSize=15;
Turtle.Forward(20);
//S2
Turtle.PenUp();
Turtle.MoveTo(-50,50);
Turtle.RotateTo(0);
Turtle.PenDown();
if(s2) Turtle.PenColor = Color.Yellow; else Turtle.PenColor = Color.Black;
Turtle.Forward(20);
//Barcode reader or scanner
Turtle.PenUp();
Turtle.MoveTo(120,50);
Turtle.RotateTo(45);
Turtle.PenDown();
if(sGoodRead && cyl3_pos==45 && stepNo!=60) Turtle.PenColor = Color.LightGreen; else Turtle.PenColor = Color.Black;
Turtle.Forward(20);
Turtle.Backward(20);
if(tetik_var){
Turtle.PenColor = Color.Red;
Turtle.PenSize=2;
Turtle.Backward(60);
}
//Label applicator or label printer applies a label to the bottle based on barcode position
Turtle.PenUp();
Turtle.MoveTo(26,42);
Turtle.RotateTo(-50);
Turtle.PenDown();
Turtle.PenSize=7;
if(labelStart) Turtle.PenColor = Color.Red; else Turtle.PenColor = Color.BlueViolet;
Turtle.Forward(70);
}
static int RandomAngle(int min, int max) {
Random random=new Random();
return random.Next(min,max);
}
void BtnStartMouseDown(object sender, MouseEventArgs e)
{
start=true;
_S71200.Write("I0.4",1);
}
void BtnStartMouseUp(object sender, MouseEventArgs e)
{
start=false;
_S71200.Write("I0.4",0);
}
void BtnStopMouseDown(object sender, MouseEventArgs e)
{
stop=true;
_S71200.Write("I0.5",1);
}
void BtnStopMouseUp(object sender, MouseEventArgs e)
{
stop=false;
_S71200.Write("I0.5",0);
}
void BtnPrintedMouseDown(object sender, MouseEventArgs e)
{
_S71200.Write("I0.3",1); // dispense end label printed
}
void BtnPrintedMouseUp(object sender, MouseEventArgs e)
{
_S71200.Write("I0.3",0);
lblEtiket.Text="PRINTED..";
}
}
}
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Nakov.TurtleGraphics;
using S7.Net;
namespace wrapAround
{
public partial class MainForm : Form
{
Plc _S71200 = new Plc(CpuType.S71200, "127.0.0.1", 0, 1);
float x_pos=-350,y_pos=0,bottleAngle=0;
bool turning, cylinder_1, cylinder_2, cylinder_3, conveyor, s1, s2, cyl3_sensor;
bool barcodeScannerTrig, sGoodRead, labelStart, dispenseEnd, start, stop, tetik_var, movement;
float cyl1_pos=10,cyl2_pos=10,cyl3_pos=10;
public MainForm()
{
InitializeComponent();
_S71200.Open();
}
void Timer1Tick(object sender, EventArgs e)
{
//label1.Text=""+x_pos; //for debugging
//label2.Text=""+cyl3_pos;
//label10.Text=""+cyl2_pos;
ushort stepNo = (ushort)_S71200.Read("MW50"); // Adım numarası
lblAdim.Text = "Step No: " + stepNo;
cylinder_1 = (bool)_S71200.Read("Q0.4"); //
cylinder_2 = (bool)_S71200.Read("Q0.5");
cylinder_3 = (bool)_S71200.Read("Q0.6");
labelStart= (bool)_S71200.Read("Q0.7");
barcodeScannerTrig= (bool)_S71200.Read("Q1.0");
conveyor= (bool)_S71200.Read("Q1.1");
if(labelStart) lblEtiket.Text="Label printing...";
if(barcodeScannerTrig) tetik_var=true;
if(cylinder_1 && cyl1_pos<90) cyl1_pos += 10;
if(!cylinder_1 && cyl1_pos>10) cyl1_pos -= 10;
if(cylinder_2 && cyl2_pos<90) cyl2_pos += 10;
if(!cylinder_2 && cyl2_pos>10) cyl2_pos -= 10;
if(cylinder_3 && cyl3_pos<45) cyl3_pos += 5;
if(!cylinder_3 && cyl3_pos>10) cyl3_pos -= 5;
if(x_pos<-190 && x_pos>-210){
s1=true;
_S71200.Write("I0.0",1); // S1
}else{
s1=false;
_S71200.Write("I0.0",0);
}
if(x_pos>-100 && x_pos<-75){
s2=true;
_S71200.Write("I0.1",1);
}else{
s2=false;
_S71200.Write("I0.1",0);
}
if(bottleAngle>119 && bottleAngle<151){
sGoodRead=true;
_S71200.Write("I0.2",1);
tetik_var=false;
}else{
sGoodRead=false;
_S71200.Write("I0.2",0);
}
if(conveyor && x_pos<-200) {x_pos += 5; movement=true;}
if(!movement && conveyor && cyl1_pos==90 && cyl2_pos==10) {x_pos += 5;movement=true;}
if(!movement && conveyor && x_pos>-145 && x_pos<20){ x_pos += 5;movement=true;}
if(!movement && conveyor && stepNo==0 && cyl3_pos<40) x_pos += 5;
movement=false;
if(x_pos>350){ x_pos=-350; bottleAngle=0;y_pos=0;}
if(x_pos>300){ lblEtiket.Text=""; sGoodRead=false; }
if(cyl3_pos==45){
turning=true;
_S71200.Write("I0.6",1); //cyl3_sensor
txtCyl3_sensor.BackColor=Color.LightGreen;
cyl3_sensor=true;
}else{
turning=false;
_S71200.Write("I0.6",0);
txtCyl3_sensor.BackColor=Color.LightGray;
cyl3_sensor=false;}
Turtle.Init(panel1);
Turtle.ShowTurtle=false;
Turtle.PenUp();
Turtle.MoveTo(x_pos,y_pos);
Turtle.RotateTo(bottleAngle);
Turtle.PenDown();
for (int i = 0; i <= 23; i++) {
Turtle.Rotate(15);
Turtle.Forward(10.04f);
if(i==1 && turning == true) {
x_pos=Turtle.X;
y_pos=Turtle.Y;
bottleAngle=Turtle.Angle;
}
}
Turtle.Rotate(97);
Turtle.Forward(30);
//cylinder_1
Turtle.PenUp();
Turtle.MoveTo(-210,-95);
Turtle.RotateTo(0);
Turtle.PenColor = Color.Black;
Turtle.PenSize=20;
Turtle.PenDown();
Turtle.Forward(30);
Turtle.PenColor = Color.Green;
Turtle.PenSize=10;
Turtle.Forward(cyl1_pos);
//cylinder_2
Turtle.PenUp();
Turtle.MoveTo(-115,-95);
Turtle.RotateTo(0);
Turtle.PenColor = Color.Black;
Turtle.PenSize=20;
Turtle.PenDown();
Turtle.Forward(30);
Turtle.PenColor = Color.Green;
Turtle.PenSize=10;
Turtle.PenDown();
Turtle.Forward(cyl2_pos);
//turning roller on top
Turtle.PenUp();
Turtle.MoveTo(20,85);
Turtle.RotateTo(0);
Turtle.PenDown();
Turtle.PenColor = Color.Black;
Turtle.PenSize=10;
for (int i = 0; i <= 23; i++) {
Turtle.Rotate(15);
Turtle.Forward(10.04f);
}
//cylinder_3
Turtle.PenUp();
Turtle.MoveTo(60,-130);
Turtle.RotateTo(0);
Turtle.PenColor = Color.Black;
Turtle.PenSize=20;
Turtle.PenDown();
Turtle.Forward(30);
Turtle.PenColor = Color.Green;
Turtle.PenSize=10;
Turtle.Forward(cyl3_pos);
Turtle.PenColor = Color.Gray;
Turtle.PenSize=7;
Turtle.Rotate(90);
Turtle.Forward(30);
Turtle.PenColor = Color.Black;
for (int i = 0; i <= 23; i++) {
Turtle.Rotate(-15);
Turtle.Forward(2f);
}
Turtle.PenUp();
Turtle.Backward(30);
Turtle.PenDown();
Turtle.PenColor = Color.Gray;
Turtle.Backward(30);
Turtle.PenColor = Color.Black;
for (int i = 0; i <= 23; i++) {
Turtle.Rotate(-15);
Turtle.Forward(2f);
}
//S1
Turtle.PenUp();
Turtle.MoveTo(-160,50);
Turtle.RotateTo(0);
Turtle.PenDown();
if(s1) Turtle.PenColor = Color.Yellow; else Turtle.PenColor = Color.Black;
Turtle.PenSize=15;
Turtle.Forward(20);
//S2
Turtle.PenUp();
Turtle.MoveTo(-50,50);
Turtle.RotateTo(0);
Turtle.PenDown();
if(s2) Turtle.PenColor = Color.Yellow; else Turtle.PenColor = Color.Black;
Turtle.Forward(20);
//Barcode reader or scanner
Turtle.PenUp();
Turtle.MoveTo(120,50);
Turtle.RotateTo(45);
Turtle.PenDown();
if(sGoodRead && cyl3_pos==45 && stepNo!=60) Turtle.PenColor = Color.LightGreen; else Turtle.PenColor = Color.Black;
Turtle.Forward(20);
Turtle.Backward(20);
if(tetik_var){
Turtle.PenColor = Color.Red;
Turtle.PenSize=2;
Turtle.Backward(60);
}
//Label applicator or label printer applies a label to the bottle based on barcode position
Turtle.PenUp();
Turtle.MoveTo(26,42);
Turtle.RotateTo(-50);
Turtle.PenDown();
Turtle.PenSize=7;
if(labelStart) Turtle.PenColor = Color.Red; else Turtle.PenColor = Color.BlueViolet;
Turtle.Forward(70);
}
static int RandomAngle(int min, int max) {
Random random=new Random();
return random.Next(min,max);
}
void BtnStartMouseDown(object sender, MouseEventArgs e)
{
start=true;
_S71200.Write("I0.4",1);
}
void BtnStartMouseUp(object sender, MouseEventArgs e)
{
start=false;
_S71200.Write("I0.4",0);
}
void BtnStopMouseDown(object sender, MouseEventArgs e)
{
stop=true;
_S71200.Write("I0.5",1);
}
void BtnStopMouseUp(object sender, MouseEventArgs e)
{
stop=false;
_S71200.Write("I0.5",0);
}
void BtnPrintedMouseDown(object sender, MouseEventArgs e)
{
_S71200.Write("I0.3",1); // dispense end label printed
}
void BtnPrintedMouseUp(object sender, MouseEventArgs e)
{
_S71200.Write("I0.3",0);
lblEtiket.Text="PRINTED..";
}
}
}
Yorumlar
Yorum Gönder