summaryrefslogtreecommitdiff
path: root/tags/host/0.8.1/src/org/reprap/gui/steppertest/AxisRepeatabilityTest.java
blob: 9acb7801da2dafd3f535427121d83eccf0a5f4f4 (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
/**
 * 
 */
package org.reprap.gui.steppertest;

import org.reprap.Preferences;
import org.reprap.comms.snap.SNAPAddress;
import org.reprap.comms.Communicator;
import org.reprap.comms.snap.SNAPCommunicator;
import org.reprap.devices.GenericStepperMotor;
import java.io.*;

/**
 * @author eD Sells
 * 
 * Send the axis back and forth to check repeatability. 
 * Delay in between incorporated to allow for driver chip cooling.
 * To be used in conjunction with calipers.
 *
 */
public class AxisRepeatabilityTest {
	
	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		
		// Test parameters
		int motorId = 2;
		int motorSpeed = 200;
		int axisRepeatabilityRuns = 20;
		int axisRepeatabilityStepsPerStroke = 400;
		int axisRepeatabilityDelay = 3000; 
		
		
		final int localNodeNumber = 0;
		final int baudRate = 19200;


		int address;
		
		try
		{
			address = Preferences.loadGlobalInt("Axis" + motorId + "Address");
		}catch(Exception ex)
		{
			System.err.println("Argh 1!");
			return;
		}
			
		SNAPAddress myAddress = new SNAPAddress(localNodeNumber);
		Communicator communicator;
		try
		{		
			communicator = new SNAPCommunicator(Preferences.loadGlobalString("Port"),
				baudRate, myAddress);
		}catch(Exception ex)
		{
			System.err.println("Argh 2!");
			return;
		}
		GenericStepperMotor motor;
		try
		{			
			motor = new GenericStepperMotor(communicator, 
				new SNAPAddress(address), Preferences.getGlobalPreferences(), motorId);
		}catch(Exception ex)
		{
			System.err.println("Argh 3!");
			return;
		}
	
		// Console Reader
		BufferedReader console = new BufferedReader (new InputStreamReader(System.in));		
		
	
		
//		//Find home
//		try
//		{		
//			motor.homeReset(motorSpeed);
//		}catch(Exception ex)
//		{
//			System.err.println("Argh 4!");
//			return;
//		}
		
		System.out.println("Motor: " + motorId);
		System.out.println("Motor speed: " + motorSpeed);
		System.out.println("Runs: " + axisRepeatabilityRuns);
		System.out.println("Steps per stroke: " + axisRepeatabilityStepsPerStroke);
		System.out.println("Pause between strokes (s): " + (axisRepeatabilityDelay/1000));
		
		System.out.println("\nReset your calipers, and then push return to start...");
		try {
			String trigger = console.readLine();}
		catch(Exception ex)
		{
			System.err.println("Argh 5!");
			return;
		}
				
		for (int i = 1; i <= axisRepeatabilityRuns; i++)
		{
		
			try {		
				motor.seekBlocking(motorSpeed, axisRepeatabilityStepsPerStroke);
			}catch(Exception ex)
			{
				System.err.println("Argh 6!");
				return;
			}
			
			try { 
				Thread.sleep(axisRepeatabilityDelay);
			} catch (InterruptedException e) { System.out.println(e);
			}

			try {		
				motor.seekBlocking(motorSpeed, 0);
			}catch(Exception ex)
			{
				System.err.println("Argh 7!");
				return;
			}
			
			try {
				Thread.sleep(axisRepeatabilityDelay);
			} catch (InterruptedException e) {
			}
			
			System.out.println("Run complete: " + i);
						
		}
		System.out.println("All Done");
		communicator.close();
	}

}