UCURRobot.cs
4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using DeviceLibrary;
using Robot.UR;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace URRobot
{
public partial class UCURRobot : UserControl
{
public URRobotControl robotControl;
public UCURRobot()
{
InitializeComponent();
for (int i = 0; i <= 100; i++)
{
cmbRate.Items.Add(i);
}
}
public void Init(URRobotControl rRobotControl)
{
this.robotControl = rRobotControl;
this.robotControl.Register(RobotClient_RobotModeFun, RobotClient_SafetModeFun, RobotClient_URPointValue);
cmbRate.SelectedIndex = robotControl.SpeedRate;
timer1.Start();
}
public bool MoveOk()
{
return robotControl.MoveCmdOk();
}
private void RobotClient_URPointValue(URPointValue value)
{
if (!this.IsHandleCreated) return;
this.Invoke(new Action(() =>
{
ShowPoint(value);
}));
}
private void RobotClient_SafetModeFun(string mode)
{
if (!this.IsHandleCreated) return;
this.Invoke(new Action(() => { lblSafeMode.Text = $"{mode}"; }));
}
private void RobotClient_RobotModeFun(string mode)
{
if (!this.IsHandleCreated) return;
this.Invoke(new Action(() => { lblRobotMode.Text = $"{mode}"; }));
}
void ShowPoint(URPointValue point)
{
txtRobotX.Text = point.X.ToString();
txtRobotY.Text = point.Y.ToString();
txtRobotZ.Text = point.Z.ToString();
lblRX.Text = point.RX.ToString();
lblRY.Text = point.RY.ToString();
lblRZ.Text = point.RZ.ToString();
}
public URPointValue GetPoint()
{
double x = getValue(txtRobotX);
double y = getValue(txtRobotY);
double z = getValue(txtRobotZ);
double rx = getValue(lblRX);
double ry = getValue(lblRY);
double rz = getValue(lblRZ);
return new URPointValue(x, y, z, rx, ry, rz);
}
public double getValue(Label textBox)
{
double.TryParse(textBox.Text, out double value);
return value;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (!this.IsHandleCreated) return;
try
{
this.Invoke(new Action(() =>
{
ShowPoint(robotControl.GetLastPosition());
lbl29999.BackColor = robotControl.IsRun ? Color.Green : Color.Red;
lbl30003.BackColor = robotControl.Port3003Connected ? Color.Green : Color.Red;
lblCurCmd.Text = $"Cmd:{robotControl.CurCmd}";
lblCmdResponse.Text = $"Response:{robotControl.CurCmdReponse}";
lblRobot.BackColor = robotControl.ClientIsConnected ? Color.Green : Color.Red;
lblRobot.Text = robotControl.ClientIp;
}));
}
catch { }
}
public bool IsConnected()
{
return robotControl.ClientIsConnected;
}
private void 启动机器人ToolStripMenuItem_Click(object sender, EventArgs e)
{
robotControl?.StartRobot();
}
private void 重置机器人ToolStripMenuItem_Click(object sender, EventArgs e)
{
robotControl?.Reset();
}
private void 关闭机器人ToolStripMenuItem_Click(object sender, EventArgs e)
{
robotControl?.StopRobot();
}
private void cmbRate_SelectedIndexChanged(object sender, EventArgs e)
{
robotControl?.SetSpeedRate(cmbRate.SelectedIndex);
}
public void SendMoveCmd(int CmdIdx,int rate=50)
{
robotControl?.SendMoveCmd(CmdIdx, rate, true,RobotHelper.LoadRateParam[0]);
}
public bool IsSendCmdOk(int cmdIdx)
{
return robotControl?.IsSendCmdOk(cmdIdx)??false;
}
private void 启动程序ToolStripMenuItem_Click(object sender, EventArgs e)
{
robotControl?.PlayProgram();
}
private void 暂停程序ToolStripMenuItem_Click(object sender, EventArgs e)
{
robotControl?.PauseProgram();
}
private void 停止程序ToolStripMenuItem_Click(object sender, EventArgs e)
{
robotControl?.StopProgram();
}
}
}