-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprinter.java
More file actions
195 lines (152 loc) · 6.14 KB
/
printer.java
File metadata and controls
195 lines (152 loc) · 6.14 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
//
// Printer With lejos
//
// 3 Motors
// - 2 Motors For X and Y : MotorPort A and MotorPort B
// - 1 Motor For Pen Up and Pen Down : MotorPort C
//
// 4 Touch Sensors
// - 2 on Each Movement Motor : S1, S2 for X and S3, S4 for Y
//
// Imports
import lejos.hardware.Button;
import lejos.hardware.Key;
import lejos.hardware.KeyListener;
import lejos.hardware.lcd.LCD;
import lejos.hardware.motor.BaseRegulatedMotor;
import lejos.hardware.motor.EV3LargeRegulatedMotor;
import lejos.hardware.port.MotorPort;
import lejos.hardware.port.SensorPort;
import lejos.hardware.sensor.EV3TouchSensor;
import lejos.robotics.navigation.Waypoint;
import lejos.robotics.pathfinding.Path;
public class printer{
// Constants
// Motors for Movement
final private static BaseRegulatedMotor MOVEMENT_MOTORS[] = new BaseRegulatedMotor[] {new EV3LargeRegulatedMotor(MotorPort.A), new EV3LargeRegulatedMotor(MotorPort.B) };
// Motor for the Pen
final private static BaseRegulatedMotor PEN_MOTOR = new EV3LargeRegulatedMotor(MotorPort.C);
// Touch Sensors for calibration on the X and Y Motors
final private static EV3TouchSensor MOVEMENT_SENSORS[] = new EV3TouchSensor[] {new EV3TouchSensor(SensorPort.S1), new EV3TouchSensor(SensorPort.S2),
new EV3TouchSensor(SensorPort.S3), new EV3TouchSensor(SensorPort.S4)};
// For Each Axis setting the Motors and Sensors for the axis Controllers
final private static axisController sideAxis = new axisController(MOVEMENT_MOTORS[0], new EV3TouchSensor[] {MOVEMENT_SENSORS[0], MOVEMENT_SENSORS[1]} );
final private static axisController topAxis = new axisController(MOVEMENT_MOTORS[1], new EV3TouchSensor[] {MOVEMENT_SENSORS[2], MOVEMENT_SENSORS[3]} );
final private static penController pen = new penController(PEN_MOTOR);
// Then Using a Overall Controller for the axis's, this will make it be able to move paths
// So another class need sto be made which controls both axisControllers which we can interface with here
public static void main(String args[]) {
LCD.clear();
// create the axisInterface
// gets the scale values from that for generating a circle later
System.out.println("Printer : v12");
System.out.println("-------------");
System.out.println("-- Authors --");
System.out.println("Joshua Barrass");
System.out.println("Lewis Hawkesford");
System.out.println("Iffet Aygun");
System.out.println("Press Left To Continue");
Button.LEFT.waitForPressAndRelease();
axisInterface printerController = new axisInterface(sideAxis, topAxis, pen);
while(true) {
int choice = 0;
while(Button.LEFT.isUp())
{
LCD.clear();
System.out.println(String.format("Choice: %s", choice));
System.out.println(choice == 1 ? "> Circle" : " Circle");
System.out.println(choice == 2 ? "> Square" : " Sqaure");
System.out.println(choice == 3 ? "> Boundries" : " Boundries");
System.out.println(choice == 4 ? "> Exit" : " Exit");
System.out.println("Press Left To Draw");
while(Button.LEFT.isUp()) {
if(Button.DOWN.isDown()) {
choice ++;
if(choice > 4 )
choice = 4;
break;
}
if(Button.UP.isDown()) {
choice--;
if(choice < 1) {
choice = 1;
}
break;
}
}
}
LCD.clear();
switch(choice) {
case 1:
System.out.println("Drawing Circle");
drawCircle(printerController);
break;
case 2:
System.out.println("Drawing Square");
drawSquare(printerController);
break;
case 3:
System.out.println("Drawing Boundaries");
drawBoundaries(printerController);
break;
case 4:
System.exit(0);
break;
default:
break;
}
}
}
private static void drawBoundaries(axisInterface printerController) {
Path newPath = new Path();
double xMax = printerController.getXLength();
double yMax = printerController.getYLength();
newPath.add(new Waypoint(0,0));
newPath.add(new Waypoint(xMax,0));
newPath.add(new Waypoint(xMax, yMax));
newPath.add(new Waypoint(0, yMax));
newPath.add(new Waypoint(0,0));
System.out.println("Made Path calling");
printerController.followPath(newPath, false);
}
private static void drawSquare(axisInterface printerController) {
Path newPath = new Path();
double xQuarter = printerController.getXLength()/4;
double yQuarter = printerController.getYLength()/4;
double xQuarterTo= printerController.getXLength()*(3/4);
double yQuarterTo = printerController.getYLength()*(3/4);
newPath.add(new Waypoint(xQuarter,yQuarter));
newPath.add(new Waypoint(xQuarter, yQuarterTo));
newPath.add(new Waypoint(xQuarterTo, yQuarterTo));
newPath.add(new Waypoint(xQuarterTo, yQuarter));
newPath.add(new Waypoint(xQuarter, yQuarter));
//+- -+
//| x---x | (.25, .25)
// (.25, .75)
// x---x (.75, .75)
// (.75, .25)
// (.25, .25)
System.out.println("Made Path calling");
printerController.followPath(newPath, false);
}
private static void drawCircle(axisInterface printerController) {
double xScalar = printerController.getXScalar();
double yScalar = printerController.getYScalar();
Path newPath = new Path();
// Everything we need to generate a circle and add it to a path for the robot
double pointAmount = 36;
double AngleChange = 360 / pointAmount ;
double CircleRadius = printerController.getXLength() / 4.0;
double circleOffset = printerController.getXLength() / 2.0;
double CurrentAngle = 0.0;
for(int i = 0; i < pointAmount; i++){
double LocalX = (CircleRadius * Math.cos(Math.toRadians(CurrentAngle)));
double LocalY = (CircleRadius * Math.sin(Math.toRadians(CurrentAngle)));
newPath.add(new Waypoint((LocalX + circleOffset) * xScalar, (LocalY + circleOffset) * yScalar));
CurrentAngle += AngleChange;
}
// Makes it follow a path
System.out.println("Made Path calling");
printerController.followPath(newPath, false);
}
}