aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Stubs Collection/Procedures/Winder Calibration.txt
blob: b73f25e1edec73dcfe5df957e1138b03a0e634f8 (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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using Google.Protobuf;
using Tango.BL.Enumerations;
using Tango.PMR.Stubs;
using Tango.PMR.Diagnostics;
using Tango.FSE.Common.Diagnostics;
using Tango.PMR.IO;
using Tango.FSE.Procedures;
using System.IO;
using System.Windows.Forms;



public class Program
{
    public void OnExecute(IProcedureContext context)
    {
		uint SCREW_MOTOR = 14;
		int offset = 200;
		int Calibration_Offset = 0;
		bool Located = false;
		string box_msg = "Keep your hands away from the winder";
		MessageBox.Show(box_msg);
		
		MotorHomingRequest motorHomingRequest = new MotorHomingRequest();
		motorHomingRequest.MotorType = Tango.PMR.Hardware.HardwareMotorType.MotoScrew;
		motorHomingRequest.Speed = 800;
		motorHomingRequest.Direction = Tango.PMR.Diagnostics.MotorDirection.Forward;

		ProgressRequest progressRequest = new ProgressRequest();
		progressRequest.Amount = 0xB21;
		progressRequest.Delay = 500;
		context.Send<ProgressResponse>(progressRequest);
		
       	offset = 200;//context.GetInput<int>("Initial Offset");

		StubMotorMovRequest stubMotorMovRequest = new StubMotorMovRequest();
		stubMotorMovRequest.MotorID = SCREW_MOTOR;
		stubMotorMovRequest.Direction = false;
		while (Located == false)
		{
			context.Send<MotorHomingResponse>(motorHomingRequest);
			Thread.Sleep(2000);
			stubMotorMovRequest.Position = (uint)((offset + Calibration_Offset)*16);
			//stubMotorMovRequest.Direction = 
			context.Send<StubMotorMovResponse>(stubMotorMovRequest);
			Thread.Sleep(1000);

        	Located =	context.RequestUserInputFor<bool>(Located,"Is Winder located well?","Please fill in the form");

			
			if (Located == false)
			{
				Calibration_Offset = context.RequestUserInputFor<int>(Calibration_Offset,"Enter new value for calibration offset"," (15 steps = 1mm. minus - toward the machine");
			}
		}
		
		progressRequest.Amount = 0xB20;
		progressRequest.Delay = Calibration_Offset;
		context.Send<ProgressResponse>(progressRequest);
		box_msg = "Writing new winder offset " + Calibration_Offset+ " to the main card EEPROM";
		
		progressRequest.Amount = 0xB21;
		progressRequest.Delay = 1000000;
		context.Send<ProgressResponse>(progressRequest);

		MessageBox.Show(box_msg);

    }
}