aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Stubs Collection/stubs/Scripts/Jig_Tester/RTFU_Jig.cs
blob: 4f47a1cd0452cce68b6476ad331fe6309a43b23a (plain)
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
using System;
using System.Text;
using System.IO;
using System.Linq;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using Tango.PMR.Stubs;
using Tango.Stubs;
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------

const  int RTFU_UNDER_TEST=9;

string [,] Units_status_RTFU = new string[RTFU_UNDER_TEST,2]	{ 
												{"LS_RLOADMOTOR_Up","Not Test"},	//0
												{"LS_RLOADMOTOR_DOWN","Not Test"},	//1
												{"RLOADING_Motor","Not Test"},		//2
												{"DRIVING_Motor","Not Test"},		//3
												{"LS_RDANCER_DOWN","Not Test"},		//4
												{"LS_RDANCER_UP","Not Test"},		//5
												{"LS_RLOADRAM_DOWN","Not Test"},	//6
												{"RDANCER_Motor","Not Test"},		//7
												{"RDANCER_ROTENC","Not Test"},		//8
											};



//-----------------------------------------------------

public Task<decimal> RTFU_test( Action<string> settext, CancellationToken cancellationToken, string SN, string Location)
{
    Task<decimal> task = null;
    // Start a task and return it
    task = Task.Run(() =>
    {

	stubManager.Write("S/N:" +SN+ "\n");
	stubManager.Write("Location:" +Location+ "\n");

	copy_table (RTFU_UNDER_TEST,Units_status_RTFU);
		
	settext("Test RLOADING RTFU");
	Test_RLOADING_RTFU();
	stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,RLOADING_Motor, 3);					//hold Rloading high z

	delay(100);
//	Motor_SetParam(F1_MOTO_RLOADING_TX1,F1_MOTO_RLOADING_TX0,0x0a,0x14000000);							//set kval ran to 0x14,0.65A
	
	settext("Test RDRIVING RTFU");
	Test_RDRIVING_RTFU();

	settext("Test DANCER RTFU");

	Test_DANCER_RTFU();
	
	stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,RDANCER_Motor, 3);					//hold Rloading high z

	Status=write_to_file(SN,Location,RTFU_UNDER_TEST,"RTFU");

    settext("End Test");
	decimal result = 0;

    return result;
    });
    return task;
}
  

 //------------------------------------  
int Test_RLOADING_RTFU()
{
	int	temp=1; 
	int counter;
	
//	Motor_SetParam(F1_MOTO_RLOADING_TX1,F1_MOTO_RLOADING_TX0,0x0a,0x2c000000);							//set kval ran to 0x40- 1.9A
	delay(100);
	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,RLOADING_Motor, true,200);				//move Rloading down
	delay(3000);
	stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,RLOADING_Motor, 3);					//hold Rloading high z
	delay(1000);
//------------------------------------------ check  F1_LS_RLOADMOTOR_up------------------------------------------------

	var response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F1_LS_03_Direct);	//read LS
	if ((response.Value & F1_LS_RLOADMOTOR_UP) !=F1_LS_RLOADMOTOR_UP )									//if LS_RLOADMOTOR_UP is up then error
	{	
		DialogResult result = MessageBox.Show("Did RLOADIN MOTOR Move?", "Warning",MessageBoxButtons.YesNo);
	if(result == DialogResult.Yes)
		{
		Units_status[0,1]="Fail";
		stubManager.Write("LS_RLOADMOTOR_UP\tFail\n");	
		return 0;
		}
	else 
		{
			Units_status[2,1]="Fail";
			stubManager.Write("RLOADMOTOR\tFail\n");
			return 0;
		}
	}
	
//----------------------------------------- mov RLOADING up -------------------------------------------------
	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,RLOADING_Motor,false,300);				//move Rloading up
	counter =0;
	while ( counter < 200)
	{
		counter = counter + 1;
		response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F1_LS_03_Direct);	//if LS_RLOADMOTOR_UP is up then move down
		if ((response.Value & F1_LS_RLOADMOTOR_UP) != F1_LS_RLOADMOTOR_UP  )
			counter=250;
		
			delay(100);	
	}
		stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,RLOADING_Motor, 3);					//hold Rloading high z

	if (counter == 200) 								
	{	
		Units_status[0,1]="Fail";
		stubManager.Write("LS_RLOADMOTOR_UP\tFail\n");	
		return 0;
	}
	DialogResult result1 = MessageBox.Show("Limit Switch calibrate ?", "Warning",MessageBoxButtons.YesNo);
	if(result1 == DialogResult.No)
		{
			Units_status[0,1]="Fail";
			stubManager.Write("LS_RLOADMOTOR_UP Not calibrate\n");
			return 0;
		}
	Units_status[0,1]="Pass";
	Units_status[2,1]="Pass";
	
//------------------------------------------ check  F1_LS_RLOADMOTOR_DN------------------------------------------------
		
		response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F1_LS_03_Direct);		//read LS
	
	if ((response.Value & F1_LS_RLOADMOTOR_DN) !=F1_LS_RLOADMOTOR_DN )										//if LS_RLOADMOTOR_DN is up then error
	{	
		Units_status[1,1]="Fail";
		stubManager.Write("LS_RLOADMOTOR_DN\tFail\n");
		return 0;
	}
//------------------------------------------ mov RLOADING dn ------------------------------------------------

	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,RLOADING_Motor, true,300);				//move Rloading down
	counter =0;
	while ( counter < 200)
	{
		counter = counter + 1;
		response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F1_LS_03_Direct);	//if LS_RLOADMOTOR_UP is up then move down
		if ((response.Value & F1_LS_RLOADMOTOR_DN) != F1_LS_RLOADMOTOR_DN  )
			counter=250;	
			
			delay(100);	
	}
	
		if (counter == 150) 								
	{	
		Units_status[1,1]="Fail";
		stubManager.Write("LS_RLOADMOTOR_DN\tFail\n");	
		return 0;
	}
		stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,RLOADING_Motor, 3);					//hold Rloading high z
		
	DialogResult result2 = MessageBox.Show("Limit Switch calibrate ?", "Warning",MessageBoxButtons.YesNo);
	if(result2 == DialogResult.No)
		{
			Units_status[1,1]="Fail";
			stubManager.Write("LS_RLOADMOTOR_DN Not calibrate\n");
			return 0;
		}
	Units_status[1,1]="Pass";
		stubManager.Write("RLOADMOTOR\tPass\n");
	
		stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,RLOADING_Motor, true,200);				//move Rloading down
			delay(2000);	
		stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,RLOADING_Motor, 3);					//hold Rloading high z

	return 1 ;

}	

//----------------------------------

Int32 ReadEncoder()
{
	Int32 temp;
	stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,F1_RDANCER_ROTENC_DATA_p_TX, 0x0000);		//triggers a TX transmission

	var response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F1_RDANCER_ROTENC_DATA_p_RX_lsb);
	var response1 = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F1_RDANCER_ROTENC_DATA_p_RX_msb);		 

	temp =  Convert.ToInt32 (((((response1.Value <<16) + 	response.Value)>>10 ) & 0x3fff));
	

	return temp;
}
//--------------------------------------------------------------------------------
int Test_DANCER_RTFU()
{
	int counter;
	Int32 temp;
	Int32 temp1;
	
//------------------------------------------ check  F1_LS_RDANCER_DOWN  ------------------------------------------------

	MessageBox.Show("Make sure RDANCER Down");
	var response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F1_LS_03_Direct);	//read LS
	if ((response.Value & F1_LS_RDANCER_DOWN) !=F1_LS_RDANCER_DOWN )								//if F1_LS_RDANCER_DOWN is up then error
	{	
		Units_status[4,1]="Fail";
		stubManager.Write("LS_RDANCER_DOWN\tFail\n");	
		return 0;
	}
//----------------------------------------- mov RDANCER_Motor up and check F1_LS_RDANCER_DOWN -------------------------------------------------
	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,RDANCER_Motor,true,10);				//move Rloading up
	counter =0;
	while ( counter < 150)
	{
		counter = counter + 1;
		response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F1_LS_03_Direct);	//if LS_RLOADMOTOR_UP is up then move down
		if ((response.Value & F1_LS_RDANCER_DOWN) != F1_LS_RDANCER_DOWN  )
			counter=250;
		
			delay(100);	
	}
		if (counter == 150) 								
	{	
		Units_status[4,1]="Fail";
		stubManager.Write("LS_RDANCER_DOWN\tFail\n");	
		return 0;
	}
		Units_status[4,1]="Pass";
		stubManager.Write("LS_RDANCER_DOWN\tPass\n");	
	
//----------------------------------------- check F1_LS_RDANCER_UP -------------------------------------------------

	if ((response.Value & F1_LS_RDANCER_UP) !=F1_LS_RDANCER_UP )								//if F1_LS_RDANCER_UP is up then error
	{	
		Units_status[5,1]="Fail";
		stubManager.Write("LS_RDANCER_UP\tFail\n");	
		return 0;
	}
	counter =0;
	while ( counter < 150)
	{
		counter = counter + 1;
		response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F1_LS_03_Direct);	//if F1_LS_RDANCER_UP is up then move down
		if ((response.Value & F1_LS_RDANCER_UP) != F1_LS_RDANCER_UP  )
			counter=250;
		
			delay(100);	
	}
		if (counter == 150) 								
	{	
		Units_status[5,1]="Fail";
		stubManager.Write("LS_RDANCER_UP\tFail\n");	
		return 0;
	}
		Units_status[5,1]="Pass";
		stubManager.Write("LS_RDANCER_UP\tPass\n");	

//----------------------------------------- check F1_LS_RLOADRAM_DOWN -------------------------------------------------

	if ((response.Value & F1_LS_RLOADRAM_DOWN) !=F1_LS_RLOADRAM_DOWN )								//if F1_LS_RLOADRAM_DOWN is up then error
	{	
		Units_status[6,1]="Fail";
		stubManager.Write("LS_RLOADRAM_DOWN\tFail\n");	
		return 0;
	}
	counter =0;
	while ( counter < 150)
	{
		counter = counter + 1;
		response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F1_LS_03_Direct);	//if F1_LS_RLOADRAM_DOWN is up then move down
		if ((response.Value & F1_LS_RLOADRAM_DOWN) != F1_LS_RLOADRAM_DOWN  )
			counter=250;
		
			delay(100);	
	}
		if (counter == 150) 								
	{	
		Units_status[6,1]="Fail";
		stubManager.Write("LS_RLOADRAM_DOWN\tFail\n");	
		return 0;
	}
	Units_status[6,1]="Pass";
	stubManager.Write("LS_RLOADRAM_DOWN\tPass\n");	

//----------------------------------------- mov RDANCER_Motor down and check rdancer encoder -------------------------------------------------
	temp= ReadEncoder();
	
	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,RDANCER_Motor,false,10);				//move Rloading down
	counter =0;
	while ( counter < 150)
	{
		counter = counter + 1;
		response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,F1_LS_03_Direct);	//if LS_RLOADMOTOR_UP is up then move down
		if ((response.Value & F1_LS_RDANCER_DOWN) != F1_LS_RDANCER_DOWN  )
			counter=250;
		
			delay(100);	
	}
		if (counter == 150) 								
	{	
		Units_status[4,1]="Fail";
		stubManager.Write("LS_RDANCER_DOWN\tFail\n");	
		return 0;
	}
	Units_status[7,1]="Pass";
	stubManager.Write("RDANCER_Motor\tPass\n");	

	temp1= ReadEncoder();
	stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,RDANCER_Motor, 3);					//hold Rloading high z

	stubManager.Write("temp="+temp + "\temp1="+temp1 +"\n");
		
	DialogResult result = MessageBox.Show("SSI Dancer led is Green(Not blinking)?", "Warning",MessageBoxButtons.YesNo);
	if(result == DialogResult.No)
		{
			Units_status[8,1]="Fail";
			stubManager.Write("RDANCER_SSI\tFail\n");	
			return 0;
		}

	if (temp>temp1)
		temp1=temp1+0x4000;

	temp1=temp1-temp;			
	if ((temp1> 15000) || (temp1 <1000))
		{
			Units_status[8,1]="Fail";
			stubManager.Write("RDANCER_SSI\tFail\n");	
			return 0;
		}
	Units_status[8,1]="Pass";
		stubManager.Write("RDANCER_SSI\tPass\n");	
	
	return 1;
}


//-------------------------------------------------------------
int Test_RDRIVING_RTFU()
{	
	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,RDRIVING_Motor, true,200);				//move Rdriving clockwise 
	stubManager.Write("RDRIVING_Motor Motor rotate \n ");
	
	DialogResult result = MessageBox.Show("Are RDRIVING Motor rotate?", "Warning",MessageBoxButtons.YesNo);
	if(result == DialogResult.No)
		{
			Units_status[3,1]="Fail";
			stubManager.Write("RDRIVING Motor not rotate\n");
		}
	else 
		{
			Units_status[3,1]="Pass";
			stubManager.Write("RDRIVING Motor rotate\n");
		}
		stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,RDRIVING_Motor,3);		//stop motor

	return 0;
}