Commit 31d33c0b LN

增加通用IO端口值判断,调宽电机原点返回时如果已在原点,先相对走-1000.

1 个父辈 d18889ef
......@@ -136,7 +136,7 @@ namespace TSA_V.DeviceLibrary
{
LogUtil.info(Name + "连接Can协议成功");
}
Thread.Sleep(100);
Thread.Sleep(PUSICANControl.SleepMS);
resetStep = ResetStep.OpenCan_0;
LastResetChangeTime = DateTime.Now;
}
......@@ -159,7 +159,7 @@ namespace TSA_V.DeviceLibrary
{
LogUtil.info(Name + "重置中:重置之前先停止所有运动");
StopMove();
Thread.Sleep(100);
Thread.Sleep(PUSICANControl.SleepMS);
}
......@@ -174,7 +174,7 @@ namespace TSA_V.DeviceLibrary
resetStep = ResetStep.AddNode_1;
Thread.Sleep(100);
Thread.Sleep(PUSICANControl.SleepMS);
foreach (Dictionary<int, NodeInfo> map in RotateMap.Values)
{
foreach (NodeInfo nodeid in map.Values)
......@@ -290,7 +290,7 @@ namespace TSA_V.DeviceLibrary
if (isAllOk.Equals(true))
{
Thread.Sleep(100);
Thread.Sleep(PUSICANControl.SleepMS);
//初始化所有旋转轴
foreach (Dictionary<int, NodeInfo> map in RotateMap.Values)
{
......@@ -349,10 +349,14 @@ namespace TSA_V.DeviceLibrary
public static void StopWork()
{
StopMove();
if (Status.Equals(TSAVStatus.Reset))
{
Status = TSAVStatus.Wait;
//Status = TSAVStatus.Wait;
}
else
{
StopMove();
}
}
private static bool IsProcess = false;
......@@ -508,13 +512,13 @@ namespace TSA_V.DeviceLibrary
if (PUSICANControl.IsDuZhuan(node.NodeId))
{
LogUtil.error(Name + " 发现旋转轴[" + node.NodeId + "]堵转,清除一下控制器状态,重新读取一下堵转状态");
Thread.Sleep(100);
Thread.Sleep(PUSICANControl.SleepMS);
//清除一下状态,在重新读一次
if (!TSAVBean.Status.Equals(TSAVStatus.Reset))
{
PUSICANControl.ClearStatus(node.NodeId);
}
Thread.Sleep(100);
Thread.Sleep(PUSICANControl.SleepMS);
if (PUSICANControl.IsDuZhuan(node.NodeId))
{
WarnMsg = GetTime() + ResourceControl.GetString(ResourceControl.DuZhuanMsg, " 旋转轴[{0}]堵转,需要重置", node.NodeId);
......@@ -572,15 +576,18 @@ namespace TSA_V.DeviceLibrary
IOManager.IOMove(IOManager.Line_FStart, IO_VALUE.LOW);
Thread.Sleep(100);
Thread.Sleep(PUSICANControl.SleepMS);
foreach (Dictionary<int, NodeInfo> map in RotateMap.Values)
{
foreach (NodeInfo nodeid in map.Values)
{
if (PUSICANControl.IsBusy(nodeid.NodeId))
{
PUSICANControl.StopMove(nodeid.NodeId);
}
}
}
}
private static void CheckWorkWait()
{
try
......
......@@ -47,6 +47,7 @@ namespace PUSICANLibrary
// sdoMap.Add(MoveDirection, new SDOAddrInfo(MoveDirection, DATA_TYPE.DT_UINT32, 0));
sdoMap.Add(CurrPosition, new SDOAddrInfo(CurrPosition, DATA_TYPE.DT_UINT32, 0));
sdoMap.Add(OutStop, new SDOAddrInfo(OutStopSingle, DATA_TYPE.DT_UINT8, 0));
sdoMap.Add(GPIO_Value, new SDOAddrInfo(GPIO_Value, DATA_TYPE.DT_INT16, 0));
}
return sdoMap;
}
......@@ -163,6 +164,10 @@ namespace PUSICANLibrary
/// 外部停止,0x600f ,2h 外部紧急停止触发
/// </summary>
public static uint OutStop_Type= 0x600F2;
/// <summary>
/// 通用IO端口值,0x6012 ,U16 0高电平,1低电平
/// </summary>
public static uint GPIO_Value = 0x6012;
}
......
......@@ -150,7 +150,7 @@ namespace PUSICANLibrary
#endregion
public static int SleepMS= 30;
public delegate void SetTcpClient_drvier(string ip, int nPort);
public delegate void SetSerial_drvier(int nPort, int nBaud);
public static bool ISOpen = false;
......@@ -355,7 +355,7 @@ namespace PUSICANLibrary
//相对运动
data = BitConverter.GetBytes(value);
result = PUSICANControl.PUSICO_WriteSDO(nodeid, addr.sdoAddr, 0x01, data, addr.dataType, addr.dataLength, addr.timeOut);
Thread.Sleep(100);
Thread.Sleep(SleepMS);
if (PUSIResult.RET_SUCCESS == result)
{
Console.WriteLine("write "+ nodeid + " CAN_Address.OutStop sdo ok.");
......@@ -369,7 +369,7 @@ namespace PUSICANLibrary
//相对运动
data = BitConverter.GetBytes(value);
result = PUSICANControl.PUSICO_WriteSDO(nodeid, addr.sdoAddr, 0x02, data, addr.dataType, addr.dataLength, addr.timeOut);
Thread.Sleep(100);
Thread.Sleep(SleepMS);
if (PUSIResult.RET_SUCCESS == result)
{
Console.WriteLine("write "+ nodeid + " CAN_Address.OutStop sdo ok.");
......@@ -571,10 +571,10 @@ namespace PUSICANLibrary
}
public static bool AbsMove(uint nodeid, int position)
{
if (PUSICANControl.CheckStop2IsHigh(nodeid))
if (PUSICANControl.IsStop2High(nodeid))
{
PUSICANControl.ClearStatus(nodeid);
Thread.Sleep(100);
Thread.Sleep(SleepMS);
}
//写模式
......@@ -592,10 +592,10 @@ namespace PUSICANLibrary
/// </summary>
public static bool RelMove(uint nodeId, int position)
{
if (PUSICANControl.CheckStop2IsHigh(nodeId))
if (PUSICANControl.IsStop2High(nodeId))
{
PUSICANControl.ClearStatus(nodeId);
Thread.Sleep(100);
Thread.Sleep(SleepMS);
}
//写模式
PUSIResult result;
......@@ -628,36 +628,69 @@ namespace PUSICANLibrary
result = PUSICANControl.WriteSDO(nodeid, CAN_Address.RelativeMove, (speed));
return CheckWriteResult(result, " node [" + nodeid + "] CAN_Address.RelativeMove");
}
///// <summary>
///// 原点返回
///// </summary>
//public static bool HomeMove(uint nodeid, int speed)
//{
// //写模式
// PUSIResult result;
// PUSICANControl.WriteSDO(nodeid, CAN_Address.MoveType, 1);
// if (speed < 0)
// {
// PUSICANControl.WriteSDO(nodeid, CAN_Address.MoveDirection, 1);
// }
// else
// {
// PUSICANControl.WriteSDO(nodeid, CAN_Address.MoveDirection, 0);
// }
// SetMaxSpeed(nodeid, speed);
// result = PUSICANControl.WriteSDO(nodeid, CAN_Address.RelativeMove, Math.Abs(speed));
// return CheckWriteResult(result, " node [" + nodeid + "] CAN_Address.RelativeMove");
//}
/// <summary>
/// 原点返回
/// 原点返回 ,旋转轴原点返回使用的方法
/// </summary>
public static bool HomeMove(uint nodeid, int speed)
public static bool HomeMove(uint nodeid,bool isLineSlv=false,int speed=0 )
{
//写模式
PUSIResult result;
PUSICANControl.WriteSDO(nodeid, CAN_Address.MoveType, 1);
if (speed < 0)
//如果是调宽电机回原点,已经回过原点,需要反向走2000
if (isLineSlv && IsEXT2High(nodeid))
{
PUSICANControl.WriteSDO(nodeid, CAN_Address.MoveDirection, 1);
LogUtil.info("HomeMove[" + nodeid + "],EXT2IsHigh,先相对走-1000");
RelMove(nodeid, -1000);
//相对走1000超时时间10秒
int count = 0;
while (true)
{
Thread.Sleep(200);
count++;
if (IsBusy(nodeid))
{
if (count >= 25)
{
LogUtil.info("HomeMove[" + nodeid + "],EXT2IsHigh,先相对走-1000,超时5秒结算");
StopMove(nodeid);
break;
}
}
else
{
PUSICANControl.WriteSDO(nodeid, CAN_Address.MoveDirection, 0);
LogUtil.info("HomeMove[" + nodeid + "],EXT2IsHigh,先相对走-1000,相对走-1000结束");
break;
}
SetMaxSpeed(nodeid, speed);
result = PUSICANControl.WriteSDO(nodeid, CAN_Address.RelativeMove, Math.Abs(speed));
return CheckWriteResult(result, " node [" + nodeid + "] CAN_Address.RelativeMove");
}
/// <summary>
/// 原点返回 ,旋转轴原点返回使用的方法
/// </summary>
public static bool HomeMove(uint nodeid,bool isLineSlv=false )
Thread.Sleep(SleepMS);
}
if (speed.Equals(0))
{
int speed = ConfigAppSettings.GetIntValue(Setting_Init.RotateNode_HomeSpeed, nodeid.ToString());
speed = ConfigAppSettings.GetIntValue(Setting_Init.RotateNode_HomeSpeed, nodeid.ToString());
if (isLineSlv)
{
speed = ConfigAppSettings.GetIntValue(Setting_Init.Line_HomeSpeed, nodeid.ToString());
}
}
//写模式
PUSIResult result;
PUSICANControl.WriteSDO(nodeid, CAN_Address.MoveType, 1);
......@@ -679,7 +712,7 @@ namespace PUSICANLibrary
/// </summary>
/// <param name="nodeId"></param>
/// <returns></returns>
public static bool CheckStop2IsHigh(uint nodeId)
public static bool IsStop2High(uint nodeId)
{
//判断 外部停止2=1
int value = 0;
......@@ -697,6 +730,25 @@ namespace PUSICANLibrary
}
} return false;
}
public static bool IsBusy(uint nodeId)
{
//判断 外部停止2=1
int value = 0;
//获取状态
if (PUSIResult.RET_SUCCESS == PUSICANControl.ReadSDO(nodeId, CAN_Address.ControlStatus, out value))
{
string stop2Str = Convert.ToString(value, 2).PadLeft(5, '0').Substring(1, 1);
if (stop2Str.Equals("1"))
{
return true;
}
else
{
return false;
}
}
return false;
}
public static void ClearStatus(uint nodeId)
{
//清理驱动器状态
......@@ -707,7 +759,7 @@ namespace PUSICANLibrary
//清理驱动器状态
PUSIResult result = PUSICANControl.WriteSDO(nodeId, CAN_Address.ControlStatus, 1);
Thread.Sleep(100);
Thread.Sleep(SleepMS);
//重置位置
SetPosition(nodeId, 0);
......@@ -838,7 +890,7 @@ namespace PUSICANLibrary
Thread.Sleep(10);
//设置为位置模式
PUSICANControl.WriteSDO(node, CAN_Address.MoveType, movetype);
Thread.Sleep(100);
Thread.Sleep(SleepMS);
PUSICANControl.SetSpeed(node,isLineSlv);
Thread.Sleep(10);
//所有轴走到待机点
......@@ -965,6 +1017,38 @@ namespace PUSICANLibrary
return list;
}
public static bool IsEXT2High(uint nodeId)
{
//判断 外部停止2=1
int value = 0;
//获取状态
if (PUSIResult.RET_SUCCESS == PUSICANControl.ReadSDO(nodeId, CAN_Address.GPIO_Value, out value))
{
string ext2 = Convert.ToString(value, 2).PadLeft(12, '0').Substring(4, 1);
if (ext2.Equals("0"))
{
return true;
}
else
{
return false;
}
}
return false;
}
public static string GetGPIO(uint nodeId)
{
//判断 外部停止2=1
int value = 0;
//获取状态
if (PUSIResult.RET_SUCCESS == PUSICANControl.ReadSDO(nodeId, CAN_Address.GPIO_Value, out value))
{
string ext2 = Convert.ToString(value, 2).PadLeft(12, '0').ToString();
string ext2v = Convert.ToString(value, 2).PadLeft(12, '0').Substring(4, 1);
return " [P8,ETC2,ETC1,EXT2,EXT1,P7,P6,P5,P4,P3,P2,P1]=[" + ext2+"],EXT2="+ ext2v;
}
return "";
}
}
}
......@@ -53,7 +53,7 @@ namespace TSA_V
//DatumPoint datumPoint = new DatumPoint("YR1", "1", 2, 61.309f, 133.04f, "CRD", 0, 0);
//LearningControl.TrainModel();
//datumPoint = LearningControl.TestData(datumPoint);
string ext2v = "111101111111".Substring(4, 1);
try
{
......
......@@ -98,18 +98,21 @@
//
// lblControlStatus
//
this.lblControlStatus.AutoSize = true;
this.lblControlStatus.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblControlStatus.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblControlStatus.ForeColor = System.Drawing.Color.Red;
this.lblControlStatus.Location = new System.Drawing.Point(33, 480);
this.lblControlStatus.Location = new System.Drawing.Point(6, 170);
this.lblControlStatus.Name = "lblControlStatus";
this.lblControlStatus.Size = new System.Drawing.Size(0, 20);
this.lblControlStatus.Size = new System.Drawing.Size(703, 52);
this.lblControlStatus.TabIndex = 52;
this.lblControlStatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.lblControlStatus.Click += new System.EventHandler(this.lblControlStatus_Click);
//
// btnBack
//
this.btnBack.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnBack.Location = new System.Drawing.Point(564, 526);
this.btnBack.Location = new System.Drawing.Point(564, 579);
this.btnBack.Name = "btnBack";
this.btnBack.Size = new System.Drawing.Size(136, 45);
this.btnBack.TabIndex = 6;
......@@ -138,7 +141,7 @@
this.groupBox2.Controls.Add(this.label18);
this.groupBox2.Controls.Add(this.nudDelSpeed);
this.groupBox2.Controls.Add(this.btnReadAll);
this.groupBox2.Location = new System.Drawing.Point(14, 154);
this.groupBox2.Location = new System.Drawing.Point(14, 155);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(716, 171);
this.groupBox2.TabIndex = 35;
......@@ -506,6 +509,7 @@
//
// groupBox5
//
this.groupBox5.Controls.Add(this.lblControlStatus);
this.groupBox5.Controls.Add(this.txtHomeMoveSpeed);
this.groupBox5.Controls.Add(this.label2);
this.groupBox5.Controls.Add(this.btnHomeMove);
......@@ -517,9 +521,9 @@
this.groupBox5.Controls.Add(this.btnGetStatus);
this.groupBox5.Controls.Add(this.btnClearStatus);
this.groupBox5.Controls.Add(this.label20);
this.groupBox5.Location = new System.Drawing.Point(14, 330);
this.groupBox5.Location = new System.Drawing.Point(14, 333);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(716, 178);
this.groupBox5.Size = new System.Drawing.Size(716, 232);
this.groupBox5.TabIndex = 33;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "运动测试";
......@@ -689,8 +693,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(752, 589);
this.Controls.Add(this.lblControlStatus);
this.ClientSize = new System.Drawing.Size(752, 636);
this.Controls.Add(this.btnBack);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
......@@ -720,7 +723,6 @@
this.groupBox5.ResumeLayout(false);
this.groupBox5.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
......
......@@ -164,6 +164,7 @@ namespace TSA_V
lblControlStatus.Text = ("status:stop 3:[" + str.Substring(0, 1) + "],busy:[" + str.Substring(1, 1) + "],Locked-rotor state:["
+ str.Substring(2, 1) + "],stop 2:[" + str.Substring(3, 1) + "],stop 1:[" + str.Substring(4, 1) + "]");
}
lblControlStatus.Text += PUSICANControl.GetGPIO(nodeid);
}
private void btnClearStatus_Click(object sender, EventArgs e)
......@@ -238,8 +239,16 @@ namespace TSA_V
private void btnHomeMove_Click(object sender, EventArgs e)
{
uint nodeid = GetSelectNode();
if (nodeid.Equals(LWidthManager.Line_NodeAddr))
{
int homeSpeed = FormUtil.GetIntValue(txtHomeMoveSpeed);
PUSICANControl.HomeMove(nodeid, true, homeSpeed);
}
else
{
int homeSpeed = FormUtil.GetIntValue(txtHomeMoveSpeed);
PUSICANControl.HomeMove(nodeid, homeSpeed);
PUSICANControl.HomeMove(nodeid,false, homeSpeed);
}
}
private void llblClearp_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
......@@ -247,6 +256,11 @@ namespace TSA_V
uint nodeid = GetSelectNode();
PUSICANControl.SetPosition(nodeid, 0);
}
private void lblControlStatus_Click(object sender, EventArgs e)
{
}
}
}
......@@ -308,7 +308,7 @@ namespace TSA_V
this.timer.Enabled = false;
this.timerShowForm.Enabled = false;
if (TSAVBean.Status > TSAVStatus.Wait)
if (TSAVBean.Status > TSAVStatus.Reset)
{
TSAVBean.StopWork();
}
......@@ -677,15 +677,15 @@ namespace TSA_V
private void btnStop_Click(object sender, EventArgs e)
{
Task.Factory.StartNew(delegate
{
if (TSAVBean.Status > TSAVStatus.Wait)
{
TSAVBean.StopWork();
}
//OpInfo op = OpInfo.GetOpInfo(BoardManager.CurrBoard);
//bool result = DB.db.AddHistory(op, out int id);
});
//Task.Factory.StartNew(delegate
//{
// if (TSAVBean.Status > TSAVStatus.Reset)
// {
// TSAVBean.StopWork();
// }
// //OpInfo op = OpInfo.GetOpInfo(BoardManager.CurrBoard);
// //bool result = DB.db.AddHistory(op, out int id);
//});
this.Close();
}
......
......@@ -83,3 +83,8 @@ SmartWorkstation.exe.config文件需要增加参数:
</dependentAssembly>
20210429 修改问题:
1.调宽电机速度混乱
2.增加通用IO端口值判断,调宽电机原点返回时如果已在原点,先相对走-1000.
3.原点返回过程中,工作界面点结束会卡死
4.主界面增加设备状态显示。
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!