XYMoveControl.cs
6.4 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
namespace UserFromControl
{
public partial class XYMoveControl : UserControl
{
public XYMoveControl()
{
InitializeComponent();
}
public string GroupName
{
get { return group.Text; }
set
{
group.Text = value;
}
}
public string CurrPosition
{
get { return lblCurrPosition.Text; }
set
{
lblCurrPosition.Text = value;
}
}
public double XValue
{
set
{
txtRobotX.Text = value.ToString();
}
get
{
return FormUtil.getDoubleValue(txtRobotX);
}
}
public void DisMoveAndTestBtn()
{
btnMove.Visible = false;
btnUpdate.Visible = false;
}
public double YValue
{
set
{
txtRobotY.Text = value.ToString();
}
get
{
return FormUtil.getDoubleValue(txtRobotY);
}
}
private void btnUp_Click(object sender, EventArgs e)
{
TSAVBean.YStepMove(speedList[preValue] * yChangeValue);
}
private void btnDown_Click(object sender, EventArgs e)
{
TSAVBean.YStepMove(0 - speedList[preValue] * yChangeValue);
}
private void btnLeft_Click(object sender, EventArgs e)
{
TSAVBean.XStepMove(0 - speedList[preValue] * xChangeValue);
}
private void btnRight_Click(object sender, EventArgs e)
{
TSAVBean.XStepMove(speedList[preValue] * xChangeValue);
}
//private double stepValue =(double) ConfigAppSettings.GetNumValue(Setting_Init.XYStepValue);
private double xChangeValue = ConfigAppSettings.GetDoubleValue(Setting_Init.XAxis_Change);
private double yChangeValue = ConfigAppSettings.GetDoubleValue(Setting_Init.YAxis_Change);
//private double GetStepValue()
//{
// return stepValue / this.trackBar1.Maximum * trackBar1.Value;
//}
private static int preValue = 5;
private void trackBar1_ValueChanged(object sender, EventArgs e)
{
preValue = trackBar1.Value;
double value =speedList[preValue];
string stepStr = UserControlResource.GetString(UserControlResource.StepValue,"步进值");
lblSpeedText.Text = stepStr+ ":" +value+"mm";
//TSAVBean.XYStepValue = value;
}
public void UpdatePosition()
{
txtRobotX.Text = TSAVBean.Axis_X.LastVoltage.ToString();
txtRobotY.Text = TSAVBean.Axis_Y.LastVoltage.ToString();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
UpdatePosition();
}
private void btnMove_Click(object sender, EventArgs e)
{
//移动测试
double x = FormUtil.getDoubleValue(txtRobotX);
double y = FormUtil.getDoubleValue(txtRobotY);
//判断位置是否超出范围
if (!TSAVBean.IsValidPosition(x, y))
{
MessageBox.Show( "Position:" + x + "," + y + "Invalid,Please check the configuration ?", "", MessageBoxButtons.OK);
}
else
{
TSAVBean.Axis_X.SlowSetVoltage(x);
TSAVBean.Axis_Y.SlowSetVoltage(y);
}
}
public void MoveToPoint()
{
if (btnMove.Enabled)
{
btnMove_Click(null, null);
}
}
private Dictionary<int, double> speedList = new Dictionary<int, double>();
private void XYMoveControl_Load(object sender, EventArgs e)
{
speedList.Add(1, 0.5);
speedList.Add(2, 1);
speedList.Add(3, 2);
speedList.Add(4, 5);
speedList.Add(5, 10);
speedList.Add(6, 15);
speedList.Add(7, 20);
speedList.Add(8, 25);
speedList.Add(9, 30);
speedList.Add(10, 50);
List<double> valueList = new List<double>();
int index = valueList.IndexOf(preValue);
trackBar1.Value = preValue;
}
public bool ProcessKey(Keys keyData)
{
// 按快捷键Ctrl+S执行按钮的点击事件方法
if (btnUp.Enabled.Equals(true) && btnDown.Enabled.Equals(true) && btnLeft.Enabled.Equals(true) && btnRight.Enabled.Equals(true))
{
if (keyData.Equals(Keys.Up) || keyData.Equals(Keys.MButton | Keys.Space))
{
btnUp.PerformClick();
return true;
}
else if (keyData.Equals(Keys.Down) || keyData.Equals(Keys.Back | Keys.Space))
{
this.btnDown.PerformClick();
return true;
}
else if (keyData.Equals(Keys.Left) || keyData.Equals(Keys.LButton | Keys.MButton | Keys.Space))
{
this.btnLeft.PerformClick();
return true;
}
else if (keyData.Equals(Keys.Right) || keyData.Equals(Keys.LButton | Keys.RButton | Keys.MButton | Keys.Space))
{
this.btnRight.PerformClick();
return true;
}
}return false;
}
public void UpdateStatus()
{
if (TSAVBean.Axis_X.isRun)
{
btnLeft.Enabled = true;
btnRight.Enabled = true;
}
if (TSAVBean.Axis_Y.isRun)
{
btnUp.Enabled = true;
btnDown.Enabled = true;
}
if (TSAVBean.Axis_X.isRun && TSAVBean.Axis_Y.isRun)
{
double x = TSAVBean.Axis_X.LastVoltage;
double y = TSAVBean.Axis_Y.LastVoltage;
lblCurrPosition.Text = " X:" + x + ",Y:" + y;
}
}
}
}