项目所有资源
1.DllLibrary: S7通讯库 (所用PLC为西门子1517)
2.Font:字模,unity不支持中文,需要自行导入需要的字模:这里我导入的楷体
3.Models,实现项目所需要的模型:我这里用到焊枪、Kuka、ABB、抓手、辊床、转台
4.picture:一些需要展示的图片贴在对象上
5.Scripts:脚本,项目的灵魂,实现程序中机器人,辊床、转台的动作
最终实现的效果:
RSM
相关代码:
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class RobotMove : MonoBehaviour
{
private float oneAxisAngle;
private float twoAxisAngle;
private float threeAxisAngle;
private float fourAxisAngle;
private float fiveAxisAngle;
private float handAngle;
private Transform oneAxis;
private Transform twoAxis;
private Transform threeAxis;
private Transform fourAxis;
private Transform fiveAxis;
private Transform sixAxis;
private Transform Valve1;
private Transform Valve2;
private Transform Valve3;
private Transform Valve4;
private Vector3 OneCurrentPosition;
private Vector3 TwoCurrentPosition;
private Vector3 ThreeCurrentPosition;
private Vector3 FourCurrentPosition;
private Vector3 FiveCurrentPosition;
private Vector3 SixCurrentPosition;
public bool AllowSeg1 = false;
public bool AllowSeg2 = false;
public bool AllowSeg3 = false;
public bool AllowSeg4 = false;
public bool AllowSeg5 = false;
public bool AllowSeg6 = false;
public bool AllowSeg7 = false;
public bool AllowSeg8 = false;
public bool[] FinishSeg = new bool[8];
public bool[] OutSeg = new bool[8];
Vector3[,] Pos = new Vector3[9, 6] {
{new Vector3(0,0,0),new Vector3(0,0,0),new Vector3(0,0,0),new Vector3(0,0,0),new Vector3(0,0,0),new Vector3(0,0,0) }//初始化
,{new Vector3(0,0,0),new Vector3(0,0,21),new Vector3(0,0,321),new Vector3(0,0,0),new Vector3(0,0,0),new Vector3(0,0,0) }//等待抓件
,{new Vector3(0,0,0),new Vector3(0,0,43),new Vector3(0,0,0),new Vector3(0,0,0),new Vector3(0,0,24),new Vector3(0,0,-17.8f) }//去抓件
,{new Vector3(0,0,0),new Vector3(0,0,1),new Vector3(0,0,0),new Vector3(0,0,0),new Vector3(0,0,24),new Vector3(0,0,0) }//抓件離開
,{new Vector3(0,0,90),new Vector3(0,0,1),new Vector3(0,0,0),new Vector3(0,0,0),new Vector3(0,0,323),new Vector3(0,0,0) }//固定焊
,{new Vector3(0,0,180),new Vector3(0,0,21),new Vector3(0,0,321),new Vector3(0,0,0),new Vector3(0,0,0),new Vector3(0,0,0) }//放件等待
,{new Vector3(0,0,180),new Vector3(0,0,43),new Vector3(0,0,0),new Vector3(0,0,0),new Vector3(0,0,24),new Vector3(0,0,21.4f) }//去放件
,{new Vector3(0,0,180),new Vector3(0,0,1),new Vector3(0,0,0),new Vector3(0,0,0),new Vector3(0,0,24),new Vector3(0,0,0) }//放件離開
,{new Vector3(0,0,90),new Vector3(0,0,1),new Vector3(0,0,0),new Vector3(0,0,0),new Vector3(0,0,5),new Vector3(0,0,0) }//放件離開
};
private float WalkSpeed=20f;
private float BackSpeed = 15f;
private float OneAxisSpeed = 50;
private float TwoAxisSpeed = 30;
private float ThreeAxisSpeed = 30;
private float FourAxisSpeed = 20;
private float FiveAxisSpeed = 20;
private float SixAxisSpeed = 20;
private void Awake()
{
//==================获取轴=========================
oneAxis = this.GetComponentInParent<Transform>().Find("一轴轴心");
twoAxis = this.GetComponentInParent<Transform>().Find("一轴轴心/一轴/二轴父/二轴轴心");
threeAxis = this.GetComponentInParent<Transform>().Find("一轴轴心/一轴/二轴父/二轴轴心/二轴/三轴父/三轴轴心");
fourAxis = this.GetComponentInParent<Transform>().Find("一轴轴心/一轴/二轴父/二轴轴心/二轴/三轴父/三轴轴心/三轴/四轴父/四轴轴心");
fiveAxis = this.GetComponentInParent<Transform>().Find("一轴轴心/一轴/二轴父/二轴轴心/二轴/三轴父/三轴轴心/三轴/四轴父/四轴轴心/四轴/mesh16/五轴父/五轴轴心");
sixAxis = this.GetComponentInParent<Transform>().Find("一轴轴心/一轴/二轴父/二轴轴心/二轴/三轴父/三轴轴心/三轴/四轴父/四轴轴心/四轴/mesh16/五轴父/五轴轴心/五轴/六轴父/六轴");
Valve1 = this.GetComponentInParent<Transform>().Find("一轴轴心/一轴/二轴父/二轴轴心/二轴/三轴父/三轴轴心/三轴/四轴父/四轴轴心/四轴/mesh16/五轴父/五轴轴心/五轴/六轴父/六轴/抓手/气缸1/抓手气缸1压臂");
Valve2 = this.GetComponentInParent<Transform>().Find("一轴轴心/一轴/二轴父/二轴轴心/二轴/三轴父/三轴轴心/三轴/四轴父/四轴轴心/四轴/mesh16/五轴父/五轴轴心/五轴/六轴父/六轴/抓手/气缸2/抓手气缸2压臂");
Valve3 = this.GetComponentInParent<Transform>().Find("一轴轴心/一轴/二轴父/二轴轴心/二轴/三轴父/三轴轴心/三轴/四轴父/四轴轴心/四轴/mesh16/五轴父/五轴轴心/五轴/六轴父/六轴/抓手/气缸3/抓手气缸3压臂");
Valve4 = this.GetComponentInParent<Transform>().Find("一轴轴心/一轴/二轴父/二轴轴心/二轴/三轴父/三轴轴心/三轴/四轴父/四轴轴心/四轴/mesh16/五轴父/五轴轴心/五轴/六轴父/六轴/抓手/气缸4/抓手气缸4压臂");
//Debug.Log(oneAxis);
//Debug.Log(twoAxis.name);
//Debug.Log(threeAxis);
//Debug.Log(fourAxis);
//Debug.Log(fiveAxis);
//Debug.Log(hand);
// HomeHandAxis = sixAxis.transform.localEulerAngles;
}
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < 8; i++)
{
if (FinishSeg[i] == true && FinishSeg[i+1] == false)
{
oneAxis.transform.localEulerAngles = Pos[i, 0];
twoAxis.transform.localEulerAngles = Pos[i, 1];
threeAxis.transform.localEulerAngles = Pos[i, 2];
fourAxis.transform.localEulerAngles = Pos[i, 3];
fiveAxis.transform.localEulerAngles = Pos[i, 4];
this.transform.localPosition = Pos[i, 5];
}
}
}
// Update is called once per frame
void Update()
{
if (AllowSeg1 == true)
BackHome();
if (AllowSeg2 == true)
WaitGrapPart();
if (AllowSeg3 == true)
ToGrapPart();
if (AllowSeg4 == true)
LeaveGrapPart();
if (AllowSeg5 == true)
ToSolidWelding();
if (AllowSeg6 == true)
WaitPutPart();
if (AllowSeg7 == true)
ToPutPart();
if (AllowSeg8 == true)
LeavePutPart();
//if (AllowSeg1 == false && AllowSeg2 == false
// && AllowSeg3 == false && AllowSeg4 == false
// && AllowSeg5 == false && AllowSeg6 == false
// && AllowSeg7 == false && AllowSeg8 == false)
//{
// BackHome();
//}
if (FinishSeg[2] == true&& FinishSeg[6] == false)
ValveClose();
if (FinishSeg[6] == true)
ValveOpen();
}
public void BackHome()
{
ValveOpen();
GotoHome();
ToTargetPos(Pos, 0);
}
public void WaitGrapPart()
{
ToTargetPos(Pos,1);
}
public void ToGrapPart()
{
GoToForward();
ToTargetPos(Pos, 2);
}
public void LeaveGrapPart()
{
GotoHome();
ToTargetPos(Pos, 3);
}
public void ToSolidWelding()
{
ToTargetPos(Pos, 4);
}
public void WaitPutPart()
{
ToTargetPos(Pos, 5);
}
public void ToPutPart()
{
ToTargetPos(Pos, 6);
GoToBackward();
}
public void LeavePutPart()
{
GotoHome();
ToTargetPos(Pos, 7);
}
void CalculateCurrentPosition()
{
OneCurrentPosition = oneAxis.transform.localEulerAngles;
TwoCurrentPosition = twoAxis.transform.localEulerAngles;
ThreeCurrentPosition = threeAxis.transform.localEulerAngles;
FourCurrentPosition = fourAxis.transform.localEulerAngles;
FiveCurrentPosition = fiveAxis.transform.localEulerAngles;
SixCurrentPosition = sixAxis.transform.localEulerAngles;
}
//}
/// <summary>
/// 去给定的目标位置
/// </summary>
void ToTargetPos(Vector3[,] pos,int i)
{
CalculateCurrentPosition();
UInt16 OneCurrentPositionZ = (ushort)(OneCurrentPosition.z);
UInt16 TwoCurrentPositionZ = (ushort)(TwoCurrentPosition.z);
UInt16 ThreeCurrentPositionZ = (ushort)(ThreeCurrentPosition.z);
UInt16 FourCurrentPositionZ = (ushort)(FourCurrentPosition.x);
UInt16 FiveCurrentPositionZ = (ushort)(FiveCurrentPosition.z);
#region 一轴运动逻辑
if (OneCurrentPositionZ != pos[i, 0].z)
{
if (OneCurrentPositionZ < pos[i, 0].z)
{
oneAxis.localEulerAngles += new Vector3(0, 0, OneAxisSpeed * Time.deltaTime);
}
else
{
oneAxis.localEulerAngles -= new Vector3(0, 0, OneAxisSpeed * Time.deltaTime);
}
}
if (OneCurrentPositionZ > 350)
{
oneAxis.localEulerAngles += new Vector3(0, 0, OneAxisSpeed * Time.deltaTime);
}
#endregion
#region 二轴运动逻辑
//==========================我写的=======================
if (TwoCurrentPositionZ != pos[i, 1].z)
{
if (pos[i, 1].z > 0 && pos[i, 1].z <= 75)
{
if (TwoCurrentPositionZ >= 0 && TwoCurrentPositionZ < 75)
{
if (TwoCurrentPositionZ < pos[i, 1].z)
twoAxis.localEulerAngles += new Vector3(0, 0, TwoAxisSpeed * Time.deltaTime);
if (TwoCurrentPositionZ > pos[i, 1].z)
twoAxis.localEulerAngles -= new Vector3(0, 0, TwoAxisSpeed * Time.deltaTime);
}
if (TwoCurrentPositionZ >= 319 && TwoCurrentPositionZ <= 359)
{
if (TwoCurrentPositionZ >= pos[i, 1].z)
twoAxis.localEulerAngles += new Vector3(0, 0, TwoAxisSpeed * Time.deltaTime);
}
}
if (pos[i, 1].z > 319 && pos[i, 1].z < 360)
{
if (TwoCurrentPositionZ >= 0 && TwoCurrentPositionZ < 75)
{
if (TwoCurrentPositionZ < pos[i, 1].z)
twoAxis.localEulerAngles -= new Vector3(0, 0, TwoAxisSpeed * Time.deltaTime);
}
if (TwoCurrentPositionZ >= 319 && (TwoCurrentPositionZ <= 359 && pos[i, 1].z != 0))
{
if (TwoCurrentPositionZ < pos[i, 1].z)
twoAxis.localEulerAngles += new Vector3(0, 0, TwoAxisSpeed * Time.deltaTime);
if (TwoCurrentPositionZ > pos[i, 1].z)
twoAxis.localEulerAngles -= new Vector3(0, 0, TwoAxisSpeed * Time.deltaTime);
}
}
if (pos[i, 1].z == 0)
{
if (TwoCurrentPositionZ >= 0 && TwoCurrentPositionZ < 75)
twoAxis.localEulerAngles -= new Vector3(0, 0, TwoAxisSpeed * Time.deltaTime);
if (TwoCurrentPositionZ >= 319 && ThreeCurrentPositionZ < 359)
twoAxis.localEulerAngles += new Vector3(0, 0, TwoAxisSpeed * Time.deltaTime);
}
}
#endregion
#region 三轴运动逻辑
if (ThreeCurrentPositionZ != pos[i, 2].z)
{
if (pos[i, 2].z > 0 && pos[i, 2].z <= 55)
{
if (ThreeCurrentPositionZ >= 0 && ThreeCurrentPositionZ < 55)
{
if (ThreeCurrentPositionZ < pos[i, 2].z)
threeAxis.localEulerAngles += new Vector3(0, 0, ThreeAxisSpeed * Time.deltaTime);
if (ThreeCurrentPositionZ > pos[i, 2].z)
threeAxis.localEulerAngles -= new Vector3(0, 0, ThreeAxisSpeed * Time.deltaTime);
}
if (ThreeCurrentPositionZ >= 280 && ThreeCurrentPositionZ <= 359)
{
if (ThreeCurrentPositionZ >= pos[i, 2].z)
threeAxis.localEulerAngles += new Vector3(0, 0, ThreeAxisSpeed * Time.deltaTime);
}
}
if (pos[i, 2].z > 280 && pos[i, 2].z < 360)
{
if (ThreeCurrentPositionZ >= 0 && ThreeCurrentPositionZ < 55)
{
if(ThreeCurrentPositionZ< pos[i, 2].z)
threeAxis.localEulerAngles -= new Vector3(0, 0, ThreeAxisSpeed * Time.deltaTime);
}
if (ThreeCurrentPositionZ >= 270 && (ThreeCurrentPositionZ <= 360&& pos[i, 2].z != 0))
{
if (ThreeCurrentPositionZ < pos[i, 2].z)
threeAxis.localEulerAngles += new Vector3(0, 0, ThreeAxisSpeed * Time.deltaTime);
if(ThreeCurrentPositionZ > pos[i, 2].z)
threeAxis.localEulerAngles -= new Vector3(0, 0, ThreeAxisSpeed * Time.deltaTime);
}
}
if (pos[i, 2].z == 0)
{
if(ThreeCurrentPositionZ >= 0 && ThreeCurrentPositionZ < 55)
threeAxis.localEulerAngles -= new Vector3(0, 0, ThreeAxisSpeed * Time.deltaTime);
if(ThreeCurrentPositionZ >= 280 && ThreeCurrentPositionZ < 360)
threeAxis.localEulerAngles += new Vector3(0, 0, ThreeAxisSpeed * Time.deltaTime);
}
}
#endregion
#region 四轴运动逻辑
//if (FourCurrentPosition.x != pos[i, 3].x)
//{
// if (FourCurrentPosition.x < pos[i, 3].x)
// {
// fourAxis.localEulerAngles += new Vector3(Speed * Time.deltaTime, 0, 0);
// }
// else
// {
// fourAxis.localEulerAngles -= new Vector3(Speed * Time.deltaTime, 0, 0);
// }
//}
if (FourCurrentPositionZ != pos[i, 3].x)
{
if (pos[i, 3].x > 0 && pos[i, 3].x <= 80)
{
if (FourCurrentPositionZ >= 0 && FourCurrentPositionZ < 80)
{
if (FourCurrentPositionZ < pos[i, 3].x)
fourAxis.localEulerAngles += new Vector3(FourAxisSpeed * Time.deltaTime, 0, 0);
if (FourCurrentPositionZ > pos[i, 3].x)
fourAxis.localEulerAngles -= new Vector3(FourAxisSpeed * Time.deltaTime, 0, 0);
}
if (FourCurrentPositionZ >= 280 && FourCurrentPositionZ <= 359)
{
if (FourCurrentPositionZ >= pos[i, 3].x)
fourAxis.localEulerAngles += new Vector3(FourAxisSpeed * Time.deltaTime, 0, 0);
}
}
if (pos[i, 3].x > 280 && pos[i, 3].x < 360)
{
if (FourCurrentPositionZ >= 0 && FourCurrentPositionZ < 80)
{
if (FourCurrentPositionZ < pos[i, 3].x)
fourAxis.localEulerAngles -= new Vector3(FourAxisSpeed * Time.deltaTime, 0, 0);
}
if (FourCurrentPositionZ >= 280 && (FourCurrentPositionZ <= 360 && pos[i, 3].x != 0))
{
if (FourCurrentPositionZ < pos[i, 3].x)
fourAxis.localEulerAngles += new Vector3(FourAxisSpeed * Time.deltaTime, 0, 0);
if (FourCurrentPositionZ > pos[i, 3].x)
fourAxis.localEulerAngles -= new Vector3(FourAxisSpeed * Time.deltaTime, 0, 0);
}
}
if (pos[i, 3].x == 0)
{
if (FourCurrentPositionZ >= 0 && FourCurrentPositionZ < 80)
fourAxis.localEulerAngles -= new Vector3(FourAxisSpeed * Time.deltaTime, 0, 0);
if (FourCurrentPositionZ >= 280 && FourCurrentPositionZ < 360)
fourAxis.localEulerAngles += new Vector3(FourAxisSpeed * Time.deltaTime, 0, 0);
}
}
#endregion
#region 五轴运动逻辑
if (FiveCurrentPositionZ != pos[i, 4].z)
{
if (pos[i, 4].z > 0 && pos[i, 4].z <= 60)
{
if (FiveCurrentPositionZ >= 0 && FiveCurrentPositionZ < 60)
{
if (FiveCurrentPositionZ < pos[i, 4].z)
fiveAxis.localEulerAngles += new Vector3(0, 0, FiveAxisSpeed * Time.deltaTime);
if (FiveCurrentPositionZ > pos[i, 4].z)
fiveAxis.localEulerAngles -= new Vector3(0, 0, FiveAxisSpeed * Time.deltaTime);
}
if (FiveCurrentPositionZ >= 320 && FiveCurrentPositionZ <= 359)
{
if (FiveCurrentPositionZ >= pos[i, 4].z)
fiveAxis.localEulerAngles += new Vector3(0, 0, FiveAxisSpeed * Time.deltaTime);
}
}
if (pos[i, 4].z > 320 && pos[i, 4].z < 360)
{
if (FiveCurrentPositionZ >= 0 && FiveCurrentPositionZ < 60)
{
if (FiveCurrentPositionZ < pos[i, 4].z)
fiveAxis.localEulerAngles -= new Vector3(0, 0, FiveAxisSpeed * Time.deltaTime);
}
if (FiveCurrentPositionZ >= 320 && (FiveCurrentPositionZ <= 360 && pos[i, 4].z != 0))
{
if (FiveCurrentPositionZ < pos[i, 4].z)
fiveAxis.localEulerAngles += new Vector3(0, 0, FiveAxisSpeed * Time.deltaTime);
if (FiveCurrentPositionZ > pos[i, 4].z)
fiveAxis.localEulerAngles -= new Vector3(0, 0, FiveAxisSpeed * Time.deltaTime);
}
}
if (pos[i, 4].z == 0)
{
if (FiveCurrentPositionZ >= 0 && FiveCurrentPositionZ < 60)
fiveAxis.localEulerAngles -= new Vector3(0, 0, FiveAxisSpeed * Time.deltaTime);
if (FiveCurrentPositionZ >= 320 && FiveCurrentPositionZ < 360)
fiveAxis.localEulerAngles += new Vector3(0, 0, FiveAxisSpeed * Time.deltaTime);
}
}
#endregion
}
/// <summary>
/// 前进
/// </summary>
void GoToForward()
{
if (this.transform.localPosition.z >= -17.8)
{
this.transform.localPosition -= new Vector3(0,0, WalkSpeed*Time.deltaTime);
}
}
/// <summary>
/// 后退
/// </summary>
void GoToBackward()
{
if (this.transform.localPosition.z < 21.4)
{
this.transform.localPosition += new Vector3(0, 0, BackSpeed * Time.deltaTime);
}
}
/// <summary>
/// 回Home位
/// </summary>
void GotoHome()
{
if (this.transform.localPosition.z < 0)
{
this.transform.localPosition += new Vector3(0, 0, WalkSpeed * Time.deltaTime);
}
if (this.transform.localPosition.z > 0)
{
this.transform.localPosition -= new Vector3(0, 0, WalkSpeed * Time.deltaTime);
}
}
#region 抓手气缸压臂动作
public void ValveOpen()
{
Valve1.localEulerAngles = new Vector3(0, 0, 70);
Valve2.localEulerAngles = new Vector3(0, 0, 70);
Valve3.localEulerAngles = new Vector3(0, 0, 70);
Valve4.localEulerAngles = new Vector3(0, 0, -70);
}
public void ValveClose()
{
Valve1.localEulerAngles = new Vector3(0, 0, 0);
Valve2.localEulerAngles = new Vector3(0, 0, 0);
Valve3.localEulerAngles = new Vector3(0, 0, 0);
Valve4.localEulerAngles = new Vector3(0, 0, 0);
}
#endregion
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using S7.Net;
public class PLCData : MonoBehaviour
{
Plc RSM = new Plc(CpuType.S71500,"192.168.0.40",0,0);
public S7.Net.Types.DataItem initate = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 350, Count = 1, BitAdr = 0 }; //初始化
public S7.Net.Types.DataItem WaitGrapPart = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 350, Count = 1, BitAdr = 1 }; //抓件等待
public S7.Net.Types.DataItem ToGrapPart = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 350, Count = 1, BitAdr = 2 }; //去抓件
public S7.Net.Types.DataItem LeaveGrapPart = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 350, Count = 1, BitAdr = 3 }; //抓件离开
public S7.Net.Types.DataItem SolidWelding = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 350, Count = 1, BitAdr = 4 }; //固定焊
public S7.Net.Types.DataItem WaitPutPart = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 350, Count = 1, BitAdr = 5 }; //放件等待
public S7.Net.Types.DataItem ToPutPart = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 350, Count = 1, BitAdr = 6 }; //去放件
public S7.Net.Types.DataItem LeavePutPart = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 350, Count = 1, BitAdr = 7 }; //放件离开
public List<S7.Net.Types.DataItem> Seg = null;
public S7.Net.Types.DataItem FinishSeg0 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 360, Count = 1, BitAdr = 0 }; //抓件完成
public S7.Net.Types.DataItem FinishSeg1 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 360, Count = 1, BitAdr = 1 }; //抓件完成
public S7.Net.Types.DataItem FinishSeg2 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 360, Count = 1, BitAdr = 2 }; //抓件完成
public S7.Net.Types.DataItem FinishSeg3 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 360, Count = 1, BitAdr = 3 }; //抓件完成
public S7.Net.Types.DataItem FinishSeg4 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 360, Count = 1, BitAdr = 4 }; //抓件完成
public S7.Net.Types.DataItem FinishSeg5 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 360, Count = 1, BitAdr = 5 }; //抓件完成
public S7.Net.Types.DataItem FinishSeg6 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 360, Count = 1, BitAdr = 6 }; //抓件完成
public S7.Net.Types.DataItem FinishSeg7 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 360, Count = 1, BitAdr = 7 }; //抓件完成
public List<S7.Net.Types.DataItem> FinishSeg = null;
public S7.Net.Types.DataItem RunSeg0 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 358, Count = 1, BitAdr = 0 }; //抓件完成
public S7.Net.Types.DataItem RunSeg1 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 358, Count = 1, BitAdr = 1 }; //抓件完成
public S7.Net.Types.DataItem RunSeg2 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 358, Count = 1, BitAdr = 2 }; //抓件完成
public S7.Net.Types.DataItem RunSeg3 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 358, Count = 1, BitAdr = 3 }; //抓件完成
public S7.Net.Types.DataItem RunSeg4 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 358, Count = 1, BitAdr = 4 }; //抓件完成
public S7.Net.Types.DataItem RunSeg5 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 358, Count = 1, BitAdr = 5 }; //抓件完成
public S7.Net.Types.DataItem RunSeg6 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 358, Count = 1, BitAdr = 6 }; //抓件完成
public S7.Net.Types.DataItem RunSeg7 = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 358, Count = 1, BitAdr = 7 }; //抓件完成
public List<S7.Net.Types.DataItem> RunSeg = null;
public S7.Net.Types.DataItem SendPgNo = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Int, StartByteAdr = 346, Count = 1, BitAdr = 0 }; //发送任务号
public S7.Net.Types.DataItem ReceivePgNo = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Int, StartByteAdr = 338, Count = 1, BitAdr = 0 }; //接收任务号
public S7.Net.Types.DataItem Pointer = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 298, VarType = VarType.Int, StartByteAdr = 4472, Count = 1, BitAdr = 0 }; //指针
public S7.Net.Types.DataItem ExAuto = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 352, Count = 1, BitAdr = 6 }; //外部自动
public S7.Net.Types.DataItem Home = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 354, Count = 1, BitAdr = 0 }; //Home位
public S7.Net.Types.DataItem ReqChangeTip = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 354, Count = 1, BitAdr = 3 }; //请求换电极
public S7.Net.Types.DataItem Maintain = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 354, Count = 1, BitAdr = 6 }; //维护位
public S7.Net.Types.DataItem GunTipDress = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 305, VarType = VarType.Bit, StartByteAdr = 354, Count = 1, BitAdr = 7 }; //修模中
public S7.Net.Types.DataItem TurnTableActualPos = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 300, VarType = VarType.DInt, StartByteAdr = 5574, Count = 1, BitAdr = 0 }; //转台实际位置值
public S7.Net.Types.DataItem RSM20TurnTableActualPos = new S7.Net.Types.DataItem() { DataType = DataType.DataBlock, DB = 400, VarType = VarType.DInt, StartByteAdr = 5574, Count = 1, BitAdr = 0 };
public List<S7.Net.Types.DataItem> Number = null;
private void Awake()
{
Seg = new List<S7.Net.Types.DataItem>() { initate, WaitGrapPart, ToGrapPart
,LeaveGrapPart,SolidWelding,WaitPutPart
,ToPutPart,LeavePutPart};
FinishSeg = new List<S7.Net.Types.DataItem>() {FinishSeg0,FinishSeg1,FinishSeg2
,FinishSeg3,FinishSeg4,FinishSeg5
,FinishSeg6,FinishSeg7};
RunSeg = new List<S7.Net.Types.DataItem>() {RunSeg0,RunSeg1,RunSeg2
,RunSeg3,RunSeg4,RunSeg5
,RunSeg6,RunSeg7};
Number = new List<S7.Net.Types.DataItem>() { SendPgNo, ReceivePgNo, Pointer
,ExAuto,Home,ReqChangeTip,Maintain
,GunTipDress,TurnTableActualPos
,RSM20TurnTableActualPos};
}
// Start is called before the first frame update
void Start()
{
//RSM.Open();
if (RSM.IsConnected)
{
Debug.Log("PLC通讯成功");
}
}
// Update is called once per frame
void Update()
{
}
private void FixedUpdate()
{
// ReadData();
}
public void ReadData()
{
RSM.ReadMultipleVars(Seg);
RSM.ReadMultipleVars(FinishSeg);
RSM.ReadMultipleVars(RunSeg);
RSM.ReadMultipleVars(Number);
}
public void OpenPLC()
{
RSM.Open();
}
}