Feiyu/ViewModel/Robots/FanucRobotVM.cs
2025-12-10 17:55:48 +08:00

1238 lines
39 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Community;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using MahApps.Metro.Controls.Dialogs;
using FRRJIf;
using Model;
using Views;
using System.Windows;
using System.Threading;
using System.IO;
using System.Runtime.ExceptionServices;
namespace ViewModel.Robots
{
/// <summary>
/// 发那科机械手
/// </summary>
public class FanucRobotVM : FeiYuRobotVM
{
/// <summary>
/// 上报异常回调函数
/// </summary>
public override event delegeateExcep eventExcepReport;
/// <summary>
/// 刷新阵列点位
/// </summary>
public override event ShuaxinPoint ShuaxinPointing;
System.Text.Encoding encode = System.Text.Encoding.GetEncoding("shift_jis");
//发那科机器人接口对象
FRRJIf.Core mobjCore;
FRRJIf.DataTable mobjDataTable;
FRRJIf.DataNumReg mobjDataNumReg_INT;
FRRJIf.DataNumReg mobjDataNumReg_REAL;
FRRJIf.DataString mobjDataString_NUMREG_COMMENT;
FRRJIf.DataPosReg mobjDataPosReg;
FRRJIf.DataCurPos mobjCurPos; //当前坐标对象
FRRJIf.DataAlarm mobjAlarm; //机器人错误报警
FRRJIf.DataAlarm mobjAlarmCurrent; //机器人错误报警
///// <summary>
///// 保存镭射值
///// </summary>
//public DelegateCommand SaveLaserCommand { get; set; }
#region 解除调试限制
private bool liftingRestr;
/// <summary>
/// 解除调试限制
/// </summary>
public bool LiftingRestr
{
get { return liftingRestr; }
set
{
liftingRestr = value;
this.RaisePropertyChanged("LiftingRestr");
}
}
#endregion
#region 构造函数
/// <summary>
/// 构造函数
/// </summary>
public FanucRobotVM(MachineModel machine)
{
MyWindow = new Robot();
MyWindow.DataContext = this;
MachineObj = machine;
ResetCommand = new DelegateCommand();
ResetCommand.ExecuteAction = new Action<object>(Reset);
RunSelectedRobotPointCommand = new DelegateCommand();
RunSelectedRobotPointCommand.ExecuteAction = new Action<object>(RunSelectedRobotPointPoint);
EditorRobotPointCommand = new DelegateCommand();
EditorRobotPointCommand.ExecuteAction = new Action<object>(EditorRobotPoint);
SaveRobotPointCommand = new DelegateCommand();
SaveRobotPointCommand.ExecuteAction = new Action<object>(SaveRobotPoint);
UpToolCoordinateCommand = new DelegateCommand();
UpToolCoordinateCommand.ExecuteAction = new Action<object>(UpToolCoordinate);
RobotPGMoveCommand = new DelegateCommand();
RobotPGMoveCommand.ExecuteAction = new Action<object>(RobotPGMove);
GoHomeCommand = new DelegateCommand();
GoHomeCommand.ExecuteAction = new Action<object>(GoHome);
RobotPer = dal.GetRobot()[0];
ControllerConn = new RobotSocket(RobotPer.IpStr, RobotPer.Port);
CommandInteraction = new RobotSocket(RobotPer.IpStr, RobotPer.Port1);
SaveLaserCommand = new DelegateCommand();
SaveLaserCommand.ExecuteAction = new Action<object>(SaveLaser);
SpeedS = RobotPer.SpeedS;
RobotCurPos = new RobotPoint();
RobotConn = false;
EditingEnabled = false;
TeachShow = new ShowInfo();
AutoShow = new ShowInfo();
WarningShow = new ShowInfo();
SErrorShow = new ShowInfo();
SafeDoorShow = new ShowInfo();
EStopShow = new ShowInfo();
ErrorShow = new ShowInfo();
PausedShow = new ShowInfo();
RunningShow = new ShowInfo();
ReadyShow = new ShowInfo();
HomeStep = GengralProcessEnum.Start;
MyThread = new Thread(ReceivesRunState);
MyThread.IsBackground = true;
MyThread.Start();
ControllerConn.ConnStatu = new ShowInfo();
ControllerConn.ConnStatu.StatuInfo = "等待连接";
CommonList = new List<CommonClass>() {
new CommonClass() { ID=0,CommonName="视觉点位"},
new CommonClass() { ID=1,CommonName="吸嘴1"},
new CommonClass() { ID=2,CommonName="吸嘴2"},
new CommonClass() { ID=3,CommonName="吸嘴3"}};
}
public override void SaveLaser(object obj)
{
if (dal.UpdateRobotPointSpareField(SelectedRobotPoint) > 0)
{
MyMessageBox.Show("保存成功");
}
else
{
MyMessageBox.Show("保存失败");
}
}
#endregion
#region 机器人连接
private bool robotConn;
/// <summary>
/// 机器人连接
/// </summary>
public bool RobotConn
{
get { return robotConn; }
set
{
robotConn = value;
if (value)
{
YunxingPointPG = false;
YunxingPoint = false;
RobotConnRun();
}
else
{
YunxingPointPG = false;
YunxingPoint = false;
RobotDisconnect();
}
this.RaisePropertyChanged("RobotConn");
}
}
#endregion
#region 机器人连接运行
/// <summary>
/// 机器人连接运行
/// </summary>
private void RobotConnRun()
{
try
{
//init fanuc robot interface object
mobjCore = new FRRJIf.Core();
mobjCore.set_TimeOutValue(1000);
mobjDataTable = mobjCore.get_DataTable();
mobjDataNumReg_INT = mobjDataTable.AddNumReg(FRIF_DATA_TYPE.NUMREG_INT, 1, 200);
mobjDataNumReg_REAL = mobjDataTable.AddNumReg(FRIF_DATA_TYPE.NUMREG_REAL, 1, 200);
mobjDataString_NUMREG_COMMENT = mobjDataTable.AddString(FRIF_DATA_TYPE.NUMREG_COMMENT, 1, 200);
mobjDataPosReg = mobjDataTable.AddPosReg(FRIF_DATA_TYPE.POSREG, 1, 1, 100);
mobjCurPos = mobjDataTable.AddCurPosUF(FRRJIf.FRIF_DATA_TYPE.CURPOS, 1, 15);
mobjAlarm = mobjDataTable.AddAlarm(FRRJIf.FRIF_DATA_TYPE.ALARM_LIST, 5, 0);
mobjAlarmCurrent = mobjDataTable.AddAlarm(FRRJIf.FRIF_DATA_TYPE.ALARM_CURRENT, 1, 0);
RobotPer = dal.GetRobot()[0]; //获取机器人参数对象
if (mobjCore.Connect(RobotPer.IpStr))
{
ControllerConn.ConnStatu.StatusBackground = ColorStr.Green;
ControllerConn.ConnStatu.StatusForeground = ColorStr.White;
ControllerConn.ConnStatu.StatuInfo = "连接成功";
CommandInteraction = ControllerConn;
nuo1 = true;
}
else
{
ControllerConn.ConnStatu.StatusBackground = ColorStr.Red;
ControllerConn.ConnStatu.StatusForeground = ColorStr.White;
ControllerConn.ConnStatu.StatuInfo = "连接失败";
CommandInteraction = ControllerConn;
eventExcepReport("机器人连接失败");
}
}
catch (Exception ex)
{
ControllerConn.ConnStatu.StatusBackground = ColorStr.Red;
ControllerConn.ConnStatu.StatusForeground = ColorStr.White;
ControllerConn.ConnStatu.StatuInfo = "连接异常";
CommandInteraction = ControllerConn;
eventExcepReport("机器人连接失败" + ex.Message);
}
}
#endregion
#region 断开机器人
/// <summary>
/// 断开机器人
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RobotDisconnect()
{
try
{
mobjCore.Disconnect();
mobjCore = null;
mobjDataTable = null;
mobjDataNumReg_INT = null;
mobjDataNumReg_REAL = null;
mobjDataString_NUMREG_COMMENT = null;
ControllerConn.ConnStatu.StatusBackground = ColorStr.Yellow;
ControllerConn.ConnStatu.StatuInfo = "连接断开";
CommandInteraction = ControllerConn;
}
catch (Exception ex)
{
ControllerConn.ConnStatu.StatusBackground = ColorStr.Red;
ControllerConn.ConnStatu.StatuInfo = "连接断开异常" + ex.Message;
CommandInteraction = ControllerConn;
}
}
#endregion
#region 重置机械手
/// <summary>
/// 清空报警
/// </summary>
bool ResetClose { get; set; }
/// <summary>
/// 重置机械手
/// </summary>
/// <param name="obj"></param>
public override void Reset(object obj)
{
YunxingPointPG = false;
YunxingPoint = false;
//mobjCore.ClearAlarm(0);
ResetClose = true;
}
#endregion
#region 获取机器人当前点位
/// <summary>
/// 获取机器人当前点位
/// </summary>
/// <returns></returns>
public bool GetCurrPoint()
{
try
{
Array xyzwpr = new float[9];
Array config = new short[7];
Array joint = new float[9];
short intUF = 0;
short intUT = 0;
short intValidC = 0;
short intValidJ = 0;
//刷新数据表
//bool blnDT = mobjDataTable.Refresh();
if (mobjCurPos.GetValue(ref xyzwpr, ref config, ref joint, ref intUF, ref intUT, ref intValidC, ref intValidJ))
{
return mstrPos(ref xyzwpr, ref config, ref joint, intValidC, intValidJ, intUF, intUT);
}
else
{
eventExcepReport("获取机器人坐标失败");
return false;
}
}
catch (Exception)
{
eventExcepReport("获取机器人坐标失败");
return false;
}
}
private bool mstrPos(ref Array xyzwpr, ref Array config, ref Array joint, short intValidC, short intValidJ, short UF, short UT)
{
bool bl = true;
try
{
if (intValidC != 0)
{
RobotCurPos.UF = UF;
RobotCurPos.UT = UT;
RobotCurPos.XyzwprStr = "";
foreach (var item in xyzwpr)
{
RobotCurPos.XyzwprStr += item.ToString() + ",";
}
RobotCurPos.ConfigStr = "";
foreach (var item in config)
{
RobotCurPos.ConfigStr += item.ToString() + ",";
}
}
else
{
bl = false;
}
}
catch (Exception)
{
bl = false;
}
return bl;
}
#endregion
#region 获取机器人报错信息
/// <summary>
/// 获取机器人报错信息
/// </summary>
public void GetAlarm()
{
for (int i = 1; i <= 5; i++)
{
string strTmp = mstrAlarm(ref mobjAlarm, i);
if (!string.IsNullOrEmpty(strTmp) && strTmp != "ヨリヨテ")
{
//eventExcepReport("机器人异常" + strTmp);
break;
}
}
}
private string mstrAlarm(ref FRRJIf.DataAlarm objAlarm, int Count)
{
string tmp = null;
short intID = 0;
short intNumber = 0;
short intCID = 0;
short intCNumber = 0;
short intSeverity = 0;
short intY = 0;
short intM = 0;
short intD = 0;
short intH = 0;
short intMn = 0;
short intS = 0;
string strM1 = "";
string strM2 = "";
string strM3 = "";
bool blnRes = false;
blnRes = objAlarm.GetValue(Count, ref intID, ref intNumber, ref intCID, ref intCNumber, ref intSeverity, ref intY, ref intM, ref intD, ref intH,
ref intMn, ref intS, ref strM1, ref strM2, ref strM3, encode);
if (blnRes == false)
{
return tmp;
}
if (!string.IsNullOrEmpty(strM1))
tmp = tmp + strM1;
if (!string.IsNullOrEmpty(strM2))
tmp = tmp + strM2;
if (!string.IsNullOrEmpty(strM3))
tmp = tmp + strM3;
return tmp;
}
#endregion
#region 机器人点位编辑相关
#region 机器人PG移动
/// <summary>
/// PG移动
/// </summary>
bool PgRun { get; set; }
/// <summary>
/// 机器人PG移动方法
/// </summary>
/// <param name="direction"></param>
public override void RobotMove(string direction)
{
CommandModel = ShareHelp.FeiyuCoper(RobotCurPos);
if (!LiftingRestr && RobotTuningDis > 20)
{
RobotTuningDis = 20;
}
float zhi;
switch (direction)
{
case "+X":
zhi = (float)CommandModel.Xyzwpr.GetValue(0) + (float)RobotTuningDis;
CommandModel.Xyzwpr.SetValue(zhi, 0);
if (SelectedRobotPoint.SpeedGear <= 10)
{
CommandModel.SpeedGear = 10;
}
else
{
CommandModel.SpeedGear = SelectedRobotPoint.SpeedGear;
}
PgRun = true;
break;
case "-X":
zhi = (float)CommandModel.Xyzwpr.GetValue(0) - (float)RobotTuningDis;
CommandModel.Xyzwpr.SetValue(zhi, 0);
if (SelectedRobotPoint.SpeedGear <= 10)
{
CommandModel.SpeedGear = 10;
}
else
{
CommandModel.SpeedGear = SelectedRobotPoint.SpeedGear;
}
PgRun = true;
break;
case "+Y":
zhi = (float)CommandModel.Xyzwpr.GetValue(1) + (float)RobotTuningDis;
CommandModel.Xyzwpr.SetValue(zhi, 1);
if (SelectedRobotPoint.SpeedGear <= 10)
{
CommandModel.SpeedGear = 10;
}
else
{
CommandModel.SpeedGear = SelectedRobotPoint.SpeedGear;
}
PgRun = true;
break;
case "-Y":
zhi = (float)CommandModel.Xyzwpr.GetValue(1) - (float)RobotTuningDis;
CommandModel.Xyzwpr.SetValue(zhi, 1);
if (SelectedRobotPoint.SpeedGear <= 10)
{
CommandModel.SpeedGear = 10;
}
else
{
CommandModel.SpeedGear = SelectedRobotPoint.SpeedGear;
}
PgRun = true;
break;
case "+Z":
zhi = (float)CommandModel.Xyzwpr.GetValue(2) + (float)RobotTuningDis;
CommandModel.Xyzwpr.SetValue(zhi, 2);
if (SelectedRobotPoint.SpeedGear <= 10)
{
CommandModel.SpeedGear = 10;
}
else
{
CommandModel.SpeedGear = SelectedRobotPoint.SpeedGear;
}
PgRun = true;
break;
case "-Z":
zhi = (float)CommandModel.Xyzwpr.GetValue(2) - (float)RobotTuningDis;
CommandModel.Xyzwpr.SetValue(zhi, 2);
if (SelectedRobotPoint.SpeedGear <= 10)
{
CommandModel.SpeedGear = 10;
}
else
{
CommandModel.SpeedGear = SelectedRobotPoint.SpeedGear;
}
PgRun = true;
break;
case "+U":
zhi = (float)CommandModel.Xyzwpr.GetValue(5) + (float)RobotTuningDis;
CommandModel.Xyzwpr.SetValue(zhi, 5);
if (SelectedRobotPoint.SpeedGear <= 10)
{
CommandModel.SpeedGear = 10;
}
else
{
CommandModel.SpeedGear = SelectedRobotPoint.SpeedGear;
}
PgRun = true;
break;
case "-U":
zhi = (float)CommandModel.Xyzwpr.GetValue(5) - (float)RobotTuningDis;
CommandModel.Xyzwpr.SetValue(zhi, 5);
if (SelectedRobotPoint.SpeedGear <= 10)
{
CommandModel.SpeedGear = 10;
}
else
{
CommandModel.SpeedGear = SelectedRobotPoint.SpeedGear;
}
PgRun = true;
break;
case "+V":
case "-V":
case "+W":
case "-W":
break;
}
}
/// <summary>
/// 鼠标点击PG移动
/// </summary>
/// <param name="obj"></param>
public override void RobotPGMove(object obj)
{
try
{
Button btn = obj as Button;
RobotTuningDis = Convert.ToDouble(btn.ToolTip);
RobotMove(btn.Tag.ToString());
}
catch (Exception)
{
}
}
#endregion
DateTime swwTime { get; set; }
/// <summary>
/// 编辑点位
/// </summary>
/// <param name="obj"></param>
public override void EditorRobotPoint(object obj)
{
if (SelectedRobotPoint != null && SelectedRobotPoint.ID > 0)
{
EditingEnabled = true;
ShareHelp.UserLog("编辑机器人点位:" + SelectedRobotPoint.PointNumber + SelectedRobotPoint.PointName);
}
else
{
MyMessageBox.Show("请选择要编辑的点位");
}
}
/// <summary>
/// 保存机器人点位
/// </summary>
/// <param name="obj"></param>
public override void SaveRobotPoint(object obj)
{
if (MyMessageBox.Show("请确定要保存当前点位吗?", "提示", MessageDialogStyle.AffirmativeAndNegative) == MessageDialogResult.Affirmative)
{
try
{
if (Math.Abs(SelectedRobotPoint.PointX - RobotCurPos.PointX) >= 5)
{
MyMessageBox.Show("坐标X超限", "提示");
return;
}
if (Math.Abs(SelectedRobotPoint.PointY - RobotCurPos.PointY) >= 5)
{
MyMessageBox.Show("坐标Y超限", "提示");
return;
}
if (Math.Abs(SelectedRobotPoint.PointU - RobotCurPos.PointU) >= 2)
{
MyMessageBox.Show("坐标U超限", "提示");
return;
}
SelectedRobotPoint.XyzwprStr = RobotCurPos.XyzwprStr;
SelectedRobotPoint.ConfigStr = RobotCurPos.ConfigStr;
if (dal.UpdateRobotPoint(SelectedRobotPoint) > 0)
{
MyMessageBox.Show("保存成功");
}
else
{
MyMessageBox.Show("保存失败");
}
}
catch (Exception ex)
{
MyMessageBox.Show("保存失败\r\n" + ex.Message);
}
}
}
/// <summary>
/// 运行到选中点位
/// </summary>
/// <param name="obj"></param>
public override void RunSelectedRobotPointPoint(object obj)
{
if (SelectedRobotPoint != null && SelectedRobotPoint.ID > 0)
{
RunRobotPoint(SelectedRobotPoint);
}
else
{
MyMessageBox.Show("请选择要运行的点位");
}
}
#endregion
#region 获取机器人状态
/// <summary>
/// 机器人状态码 10:空闲 100:运行中
/// </summary>
public int StatusCode { get; set; }
/// <summary>
/// 运行点位
/// </summary>
bool YunxingPoint = false;
bool nuo1 { get; set; }
[HandleProcessCorruptedStateExceptions]
[System.Security.SecurityCritical]
/// <summary>
/// 获取机器人状态
/// </summary>
private void ReceivesRunState()
{
while (true)
{
Thread.Sleep(10);
try
{
if (RobotConn && mobjDataTable != null)
{
object buf = new short();
#region 获取状态
//刷新数据表
bool blnDT = mobjDataTable.Refresh();
if (blnDT)
{
bool ret = mobjDataNumReg_INT.GetValue(1, ref buf);
if (ret)
{
StatusCode = Convert.ToInt32(buf);
switch (StatusCode)
{
//101:机器人执行任务完毕
case 101:
if (Bijiao(RP))
{
if (!YunxingPoint && !PgRun && !YunxingPointPG)
{
if (string.IsNullOrEmpty(RcvShowInfo))
{
RecordLog("(Robot→PC)" + "运行点位完毕,返回代码【" + 101 + "】");
}
RcvShowInfo = "runpointok";
}
}
break;
default:
RcvShowInfo = "";
break;
}
}
#endregion
#region 运动动作相关
if (YunxingPoint && !PgRun && !YunxingPointPG)
{
RcvShowInfo = "";
YunxingPoint = !runPoint();
}
if (PgRun && !YunxingPoint && !YunxingPointPG)
{
RcvShowInfo = "";
PgRun = !PGrunPoint();
}
if (YunxingPointPG && !YunxingPoint && !PgRun)
{
RcvShowInfo = "";
YunxingPointPG = !runPointPG();
}
#endregion
GetAlarm(); //获取机器人报错信息
GetCurrPoint();//获取机器人点位
RobotSwhit();//机器人开关控制
}
}
}
catch
{
eventExcepReport("机器人连接异常,无法获取机器人状态");
}
}
}
#endregion
#region 机器人开关操作
#region 启动机器人
private bool robotStart;
/// <summary>
/// 启动机器人
/// </summary>
public bool RobotStart
{
get { return robotStart; }
set
{
robotStart = value;
this.RaisePropertyChanged("RobotStart");
}
}
#endregion
#region 机器人使能开关
private bool servoOn;
/// <summary>
/// 机器人使能开关
/// </summary>
public bool ServoOn
{
get { return servoOn; }
set
{
servoOn = value;
this.RaisePropertyChanged("ServoOn");
}
}
#endregion
/// <summary>
/// 机器人启动中
/// </summary>
bool robotEnableing { get; set; }
/// <summary>
/// 清空报警开启中
/// </summary>
bool resetCloseing { get; set; }
/// <summary>
/// 伺服NO开启中
/// </summary>
bool servoOning { get; set; }
/// <summary>
/// 机器人开关操作
/// </summary>
private void RobotSwhit()
{
if (mobjCore != null)
{
if (RobotStart)
{
robotEnableing = true;
Array buf1 = new short[1];
buf1.SetValue((short)1, 0);
mobjCore.WriteSDI(209, buf1, 1);
//终止程序
buf1 = new short[1];
buf1.SetValue((short)0, 0);
mobjCore.WriteSDI(204, buf1, 1);
}
else
{
robotEnableing = false;
Array buf1 = new short[1];
buf1.SetValue((short)0, 0);
mobjCore.WriteSDI(209, buf1, 1);
//终止程序
buf1 = new short[1];
buf1.SetValue((short)1, 0);
mobjCore.WriteSDI(204, buf1, 1);
}
//清空报警
if (ResetClose)
{
Array buf1 = new short[1];
buf1.SetValue((short)1, 0);
mobjCore.WriteSDI(205, buf1, 1);
ResetClose = false;
}
else
{
Array buf1 = new short[1];
buf1.SetValue((short)0, 0);
mobjCore.WriteSDI(205, buf1, 1);
}
if (ServoOn)
{
Array buf1 = new short[1];
buf1.SetValue((short)1, 0);
mobjCore.WriteSDI(201, buf1, 1);
mobjCore.WriteSDI(202, buf1, 1);
mobjCore.WriteSDI(203, buf1, 1);
mobjCore.WriteSDI(208, buf1, 1);
}
else
{
Array buf1 = new short[1];
buf1.SetValue((short)0, 0);
mobjCore.WriteSDI(201, buf1, 1);
mobjCore.WriteSDI(202, buf1, 1);
mobjCore.WriteSDI(203, buf1, 1);
mobjCore.WriteSDI(208, buf1, 1);
}
}
}
#endregion
#region 运行机械手点位 10:不执行任何动作 11:执行任务完成 100:执行运行指令
/// <summary>
/// 运行机械手点位 0:不执行任何动作 100:执行运行指令
/// </summary>
/// <returns></returns>
public override bool RunRobotPoint(RobotPoint point, bool runType = false)
{
bool bl = false;
try
{
if (point == null)
{
return bl;
}
if (runType)
{
if (!YunxingPointPG)
{
RecordLog("(PC→Robot)" + point.PointName + "【" + point.XyzwprStr + "】");
RcvShowInfo = "";
RP = new RobotPoint();
RP.Xyzwpr = point.Xyzwpr;
RP.Config = point.Config;
RP.SpeedGear = point.SpeedGear;
YunxingPointPG = true;
}
}
else
{
if (!YunxingPoint)
{
RecordLog("(PC→Robot)" + point.PointName + "【" + point.XyzwprStr + "】");
RcvShowInfo = "";
RP = new RobotPoint() { PointName = point.PointName };
RP.Xyzwpr = point.Xyzwpr;
RP.Config = point.Config;
RP.SpeedGear = point.SpeedGear;
YunxingPoint = true;
}
}
}
catch (Exception)
{
}
return bl;
}
/// <summary>
/// 当前运行的点位
/// </summary>
RobotPoint RP { get; set; }
/// <summary>
/// 运行点位
/// </summary>
private bool runPoint()
{
bool bl = false;
//修改机械手执行点位坐标
Array xyzwper = RP.Xyzwpr;
Array config = RP.Config;
if (mobjDataPosReg.SetValueXyzwpr(20, ref xyzwper, ref config, RP.UF, RP.UT))
{
Array sudu = new int[1];
//int a = Convert.ToInt32(RP.SpeedGear);//获取速度单位
int a = Convert.ToInt32(RP.SpeedGear * RobotPer.SpeedS / 100); //获取速度档位
sudu.SetValue(a, 0);
if (mobjDataNumReg_INT.SetValuesInt(99, sudu, 1))//把第99个R值改为速度挡位对应的值 执行运行指令
{
Array buf = new int[1];
buf.SetValue(100, 0);
bl = mobjDataNumReg_INT.SetValuesInt(1, buf, 1); //把第一个R值改为100 执行运行指令
if (!bl)
{
eventExcepReport("机械手运行异常");
}
}
else
{
eventExcepReport("机械手运行异常");
}
}
else
{
eventExcepReport("机械手运行异常");
}
return bl;
}
/// <summary>
/// PG移动
/// </summary>
private bool PGrunPoint()
{
bool bl = false;
//修改机械手执行点位坐标
Array xyzwper = CommandModel.Xyzwpr;
Array config = CommandModel.Config;
if (mobjDataPosReg.SetValueXyzwpr(20, ref xyzwper, ref config, RP.UF, RP.UT))
{
Array sudu = new int[1];
//int a = Convert.ToInt32(CommandModel.SpeedGear);//获取速度单位
int a = Convert.ToInt32(RP.SpeedGear * RobotPer.SpeedS / 100); //获取速度档位
sudu.SetValue(a, 0);
if (mobjDataNumReg_INT.SetValuesInt(99, sudu, 1))//把第99个R值改为速度挡位对应的值 执行运行指令
{
Array buf = new int[1];
buf.SetValue(10, 0);
bl = mobjDataNumReg_INT.SetValuesInt(1, buf, 1); //把第一个R值改为10 执行PG移动
if (!bl)
{
eventExcepReport("机械手运行异常");
}
}
else
{
eventExcepReport("机械手运行异常");
}
}
else
{
eventExcepReport("机械手运行异常");
}
return bl;
}
#endregion
#region 手动回原点
/// <summary>
/// 手动回原点
/// </summary>
/// <param name="obj"></param>
public override void GoHome(object obj)
{
RP = RobotPointList.Where(w => w.PointType == 1 && w.PointClass == 0).FirstOrDefault();
RunRobotPoint(RP);
ShareHelp.UserLog("手动回原点");
}
#endregion
#region 回原点运行
/// <summary>
/// 回原点运行
/// </summary>
public override void RobotOrgin()
{
switch (HomeStep)
{
case GengralProcessEnum.Start:
try
{
RP = RobotPointList.Where(w => w.PointType == 1 && w.PointClass == 0).FirstOrDefault();
RunRobotPoint(RP);
HomeTime = DateTime.Now;
HomeStep++;
}
catch (Exception)
{
}
break;
case GengralProcessEnum.Step1:
if (RcvShowInfo == "runpointok")
{
HomeStep = GengralProcessEnum.End;
}
else if (HomeTime.AddMilliseconds(10000) < DateTime.Now)
{
HomeTime = DateTime.Now;
HomeStep++;
}
break;
}
}
#endregion
#region 外部PG运行
//是否外部PG点位运行
bool YunxingPointPG { get; set; }
private bool runPointPG()
{
bool bl = false;
//修改机械手执行点位坐标
Array xyzwper = RP.Xyzwpr;
Array config = RP.Config;
if (mobjDataPosReg.SetValueXyzwpr(20, ref xyzwper, ref config, RP.UF, RP.UT))
{
Array sudu = new int[1];
int a = Convert.ToInt32(RP.SpeedGear);//获取速度单位
sudu.SetValue(a, 0);
if (mobjDataNumReg_INT.SetValuesInt(99, sudu, 1))//把第99个R值改为速度挡位对应的值 执行运行指令
{
Array buf = new int[1];
buf.SetValue(10, 0);
bl = mobjDataNumReg_INT.SetValuesInt(1, buf, 1); //把第一个R值改为10 执行运行指令
if (!bl)
{
eventExcepReport("机械手运行异常");
}
}
else
{
eventExcepReport("机械手运行异常");
}
}
else
{
eventExcepReport("机械手运行异常");
}
return bl;
}
#endregion
#region 机器人移动日志
byte[] data { get; set; }
/// <summary>
/// 文件夹路径
/// </summary>
string path { get; set; }
/// <summary>
/// 文件路径
/// </summary>
string paths { get; set; }
/// <summary>
/// 打开的文件流对象
/// </summary>
FileStream FS { get; set; }
/// <summary>
/// 记录日志信息到文件
/// </summary>
/// <param name="info"></param>
private void RecordLog(string showMag)
{
try
{
lock (this)
{
path = @"D:\\LAGLog\RobotLog"; //文件夹路径
paths = @"D:\\LAGLog\RobotLog\" + DateTime.Now.ToString("D") + ".txt"; //文件路径 以年月日为名称
//创建文件夹
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//打开或创建文件
FS = File.Open(paths, FileMode.Append);
//获得字节数组
data = System.Text.Encoding.Default.GetBytes(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff") + showMag + "\r\n");
//开始写入
FS.Write(data, 0, data.Length);
//清空缓冲区、关闭流
FS.Flush();
FS.Close();
}
}
catch
{
}
}
#endregion
/// <summary>
/// 比较做标点位是否一致
/// </summary>
/// <param name="a1"></param>
/// <param name="a2"></param>
/// <returns></returns>
public override bool Bijiao(RobotPoint point)
{
Array a1 = point.Xyzwpr;
bool bl = false;
try
{
List<double> list1 = new List<double>();
List<double> list2 = new List<double>();
Array a2 = RobotCurPos.Xyzwpr;
if (a1 != null && a2 != null)
{
foreach (float item in a1)
{
list1.Add(Math.Round((double)item, 1));
}
foreach (float item in a2)
{
list2.Add(Math.Round((double)item, 1));
}
bl = true;
for (int i = 0; i < list1.Count; i++)
{
double aa = Math.Abs(list1[i] - list2[i]);
if (aa >= 0.15)
{
bl = false;
}
}
}
}
catch
{
}
return bl;
}
/// <summary>
/// 更新工具坐标
/// </summary>
/// <param name="obj"></param>
public override void UpToolCoordinate(object obj)
{
}
}
}