aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Stubs Collection/stubs/Scripts/Assemblies/Dryer/Load_Dryer_Arm.cs
blob: 1ce0a515f609ad8cecbd04ad608b475cbb132aad (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
//-------------------------------------------
using System;
using System.Text;
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;

include "..\..\Defines\Tango_Defines_Basic.cs"
include "..\Defines\Tango_Defines_Motors.cs"

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

//--------------------------------------------------------------------------------
Int32	last_14bit_position;
Int32	position_32bit;

	
public void OnExecute(StubManager stubManager)
{
	

	stubManager.Run<StubFpgaWriteRegResponse>("StubFpgaWriteRegRequest" ,0x6000019e, 0x0000);		//triggers a TX transmission
	var response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,0x60000190);
	var response1 = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,0x60000192);		 
	last_14bit_position =  Convert.ToInt32 (((((response1.Value <<16) + 	response.Value)>>10 ) & 0x3fff));
	position_32bit=0;

	
//Create form
		Form form1 = new Form();

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

// Create buttons to use as the accept and cancel buttons.
 		Button button1 = new Button () 
	{
		Width = 100,
   	  	Height = 100,
  	};
   
 		Button button2 = new Button ()
    {
		Width = 100,
	   	Height = 100,
	 };
//--------------------------------------------------------------------------------		
// Set the text of button
		   
		button1.Text = "ARM HOME";
		
		button2.Text = "ARM STRART";
   
//--------------------------------------------------------------------------------
// Set the position of the button on the form.
		
		button1.Location = new Point (40, 100);

	    button2.Location
      		= new Point (button1.Left  + button1.Width + 10, 100);

//--------------------------------------------------------------------------------
   // Add button to the form.
 
	    form1.Controls.Add(button1);

	    form1.Controls.Add(button2);
  
//--------------------------------------------------------------------------------

// Set the caption bar text of the form.
   
		form1.Text = "Load Dryer Arm";
		
//--------------------------------------------------------------------------------
   
   // Define the border style of the form to a dialog box.
   
  		form1.FormBorderStyle = FormBorderStyle.FixedDialog;
   
	// Set the MaximizeBox to false to remove the maximize box.

		form1.MaximizeBox = false;
   
	// Set the MinimizeBox to false to remove the minimize box.
   	
		form1.MinimizeBox = false;
   	
	// Set the start position of the form to the center of the screen.

		form1.StartPosition = FormStartPosition.CenterScreen;

   
	    form1.AutoSize = true;
	    form1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
//--------------------------------------------------------------------------------
	   
	TextBox TextBox1 = new TextBox () 
	{
		Width = 100,
   	  	Height = 10,
   	  	Text ="20"
  	};
TextBox1.Location = new Point (40, 40);
 form1.Controls.Add(TextBox1);
Label Label1 = new Label () 
	{
		Width = 150,
   	  	Height = 100,
   	  	Text ="Number round"
  	};
Label1.Location = new Point (20, 10);
 form1.Controls.Add(Label1);
 
 
 
//--------------------------------------------------------------------------------
    

   
	    button2.Click += (_,__) => 
	    	
   {
			position_32bit=0;
	    	stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,5, true, 40);
		    Thread.Sleep(200);

			while (Math.Abs(ReadEncoder())< (UInt32.Parse(TextBox1.Text)*0x4000)) 

			{
	   			Thread.Sleep(200);
	    										
			}
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,5, 3);
		
   };

   

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

	    button1.Click += (_,__) =>
   {
			Int32 temp3=0;
	    	Int32 j=0;
	    	position_32bit=0;
	    	Int32 temp=position_32bit;
		    stubManager.Run<StubMotorRunResponse>("StubMotorRunRequest" ,5, false, 40);
		    Thread.Sleep(200);

			while (temp3==0) 

			{
	   			Thread.Sleep(200);
	    		ReadEncoder();	
	   			stubManager.Write("position_32bit " + position_32bit  +"\t");

	    		if (Math.Abs(position_32bit)> (UInt32.Parse(TextBox1.Text)*0x4000))
	    		    temp3=1;
				if (Math.Abs(position_32bit-temp)<0x40)
					j=j+1;	
				else
					j=0;					
	   			temp=position_32bit;
				if (j>3)
					temp3=2;
				
				stubManager.Write("Temp3 " + temp3  +"\n");

										
			}
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,5, 3);
		
   };

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

// Display the form as a modal dialog box.
	    form1.ShowDialog();
	    
			stubManager.Run<StubMotorStopResponse>("StubMotorStopRequest" ,5, 3);
		
	
	return;
}

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

	var response = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,0x60000190);
	var response1 = stubManager.Run<StubFpgaReadRegResponse>("StubFpgaReadRegRequest" ,0x60000192);		 

	temp =  Convert.ToInt32 (((((response1.Value <<16) + 	response.Value)>>10 ) & 0x3fff));
	if (temp>last_14bit_position)
		{
		temp1=temp-last_14bit_position;
		position_32bit=position_32bit+temp1;
		if (temp1>0x2000)
			position_32bit=position_32bit-0x4000;
		}
	else if (temp<last_14bit_position)
		
		{
			temp1=last_14bit_position-temp;
			position_32bit=position_32bit-temp1;
		if (temp1>0x2000)
			position_32bit=position_32bit+0x4000;
		}
	
	last_14bit_position=temp;

	return position_32bit;
}