SHOW:
|
|
- or go back to the newest paste.
1 | - | if (blockHeights[0] <=3 (int i = 0i<=6;i++){ |
1 | + | /* |
2 | - | }else if (blockHeights[0] <=2 (int i = 0; i<=7;i++){ |
2 | + | * RobotControl.java |
3 | - | }else (int i = 0; i<=5;i++) |
3 | + | * |
4 | - | r.contract(); |
4 | + | * This is the control mechanism for the Robot arm - this is the part |
5 | * of the program that you are required to implement. | |
6 | * | |
7 | * There are three separate methods which correspond to the the | |
8 | * three scenarios your control mechanism needs to be able to handle - | |
9 | * if you are going to start with scenario A and then move onto | |
10 | * scenarios B and C later then you can finish the control mechanism | |
11 | * for scenario first and then implement your control mechanism for | |
12 | * scenarios B and C in the corresponding empty control methods. | |
13 | * | |
14 | * You do not need to do anything for the Robot itself as it has | |
15 | * already been fully implemented - you just need to supply the control | |
16 | * mechanism(s) to make it move blocks from the source pile to their | |
17 | * corresponding target piles. | |
18 | */ | |
19 | ||
20 | import javax.swing.*; | |
21 | import java.util.Scanner; | |
22 | ||
23 | ||
24 | class RobotControl | |
25 | { | |
26 | private Robot r; | |
27 | ||
28 | public RobotControl(Robot r) | |
29 | { | |
30 | this.r = r; | |
31 | } | |
32 | ||
33 | public void control(int[] barHeights, int[] blockHeights) | |
34 | { | |
35 | ||
36 | ||
37 | ||
38 | ||
39 | ||
40 | ||
41 | ||
42 | ||
43 | /* | |
44 | * This is the starting point for handling scenario A | |
45 | */ | |
46 | ||
47 | //controlMechanismForStageA(barHeights, blockHeights); | |
48 | ||
49 | /* | |
50 | * comment out the method call above and uncomment the method call below | |
51 | * when you're ready to start working on Stage B | |
52 | */ | |
53 | ||
54 | //controlMechanismForStageB(barHeights, blockHeights); | |
55 | ||
56 | /* | |
57 | * comment out the method call above and uncomment the method call below | |
58 | * when you're ready to start working on Stage C | |
59 | */ | |
60 | ||
61 | controlMechanismForStageC(barHeights, blockHeights); | |
62 | } | |
63 | ||
64 | /* | |
65 | * If you are working through this assignment one scenario at a time then you | |
66 | * should start implementing the control mechanism for the basic | |
67 | * configuration in stage A here. | |
68 | */ | |
69 | ||
70 | public void controlMechanismForStageA(int barHeights[], | |
71 | int blockHeights[]) | |
72 | { | |
73 | r.slowDown(2); | |
74 | ||
75 | // variables representing the initial state of the robot arm - | |
76 | // you can update these as needed when performing the different | |
77 | // moves to keep track of the position of the robot arm | |
78 | ||
79 | int h = 1; | |
80 | int w = 1; | |
81 | int d = 1; | |
82 | ||
83 | // variable representing the height the robot arm needs to | |
84 | // move down to when picking up a block | |
85 | int sourceHeight = 9; | |
86 | ||
87 | // variable representing the column (bar) the current block | |
88 | // is to be dropped on | |
89 | int targetColumn = 4; | |
90 | ||
91 | // variable representing the safe clearance height | |
92 | int clearanceHeight = 13; | |
93 | ||
94 | ||
95 | // move first section of arm up initially to a safe position | |
96 | ||
97 | ||
98 | ||
99 | // loop which repeats sequence of moves for one block | |
100 | ||
101 | // to many bloody comments in this code | |
102 | ||
103 | /*it has come to my mind if we made 2 arrys one for down upo and pick and put it in order | |
104 | * then the other for ints could we get away with only one for loop ? | |
105 | */ | |
106 | for (int i = 0; i<9;i++) | |
107 | r.up(); | |
108 | for (int i = 0; i<9;i++) | |
109 | r.extend(); | |
110 | for (int i = 0; i<1;i++) | |
111 | r.lower(); | |
112 | r.pick(); | |
113 | for (int i = 0; i<1;i++) | |
114 | r.raise(); | |
115 | for (int i = 0; i<6;i++) | |
116 | r.contract(); | |
117 | for (int i = 0; i<2;i++) | |
118 | r.down(); | |
119 | r.drop(); | |
120 | for (int i = 0; i<6;i++) | |
121 | r.extend(); | |
122 | for (int i = 0; i<2;i++) | |
123 | r.lower(); | |
124 | r.pick(); | |
125 | for (int i = 0; i<3;i++) | |
126 | r.up(); | |
127 | for (int i = 0; i<5;i++) | |
128 | r.contract(); | |
129 | for (int i = 0; i<1;i++) | |
130 | r.lower(); | |
131 | r.drop(); | |
132 | for (int i = 0; i<5;i++) | |
133 | r.extend(); | |
134 | for (int i = 0; i<5;i++) | |
135 | r.lower(); | |
136 | r.pick(); | |
137 | for (int i = 0; i<7;i++) | |
138 | r.raise(); | |
139 | for (int i = 0; i<4;i++) | |
140 | r.contract(); | |
141 | for (int i = 0; i<2;i++) | |
142 | r.lower(); | |
143 | r.drop(); | |
144 | for (int i = 0; i<5;i++) | |
145 | r.contract(); | |
146 | for (int i = 0; i<3;i++) | |
147 | r.raise(); | |
148 | for (int i = 0; i<9;i++) | |
149 | r.down(); | |
150 | { | |
151 | // move second section of arm across to source pile | |
152 | ||
153 | { | |
154 | r.extend(); | |
155 | ||
156 | } | |
157 | ||
158 | // what will the next move of the robot arm be? | |
159 | // ... | |
160 | ||
161 | } | |
162 | ||
163 | ||
164 | } | |
165 | ||
166 | /* | |
167 | * If you are working through this assignment one scenario at a time then you | |
168 | * should start implementing the control mechanism for configuration scenario | |
169 | * B here. | |
170 | */ | |
171 | ||
172 | public void controlMechanismForStageB(int barHeights[], | |
173 | int blockHeights[]) | |
174 | { | |
175 | ||
176 | for (int i = 0; i<12;i++) | |
177 | r.up(); | |
178 | for (int i = 0; i<9;i++) | |
179 | r.extend(); | |
180 | for (int i = 0; i<=0 + blockHeights[2];i++) | |
181 | r.lower(); | |
182 | r.pick(); | |
183 | for (int i = 0; i<4;i++) | |
184 | r.raise(); | |
185 | for (int i = 0; i<6;i++) | |
186 | r.contract(); | |
187 | for (int i = 0; i<=9 - barHeights[0];i++) | |
188 | r.lower(); | |
189 | r.drop(); | |
190 | for (int i = 0; i<=9 - barHeights[0];i++) | |
191 | r.raise(); | |
192 | for (int i = 0; i<6;i++) | |
193 | r.extend(); | |
194 | for (int i = 0; i<=0 + blockHeights[2]+ blockHeights[1];i++) | |
195 | r.lower(); | |
196 | r.pick(); | |
197 | for (int i = 0; i<13 - blockHeights[1]- blockHeights[2];i++) | |
198 | r.raise(); | |
199 | for (int i = 0; i<5;i++) | |
200 | r.contract(); | |
201 | for (int i = 0; i<=9 - barHeights[1];i++) | |
202 | r.lower(); | |
203 | r.drop(); | |
204 | for (int i = 0; i<=9 - barHeights[1];i++) | |
205 | r.raise(); | |
206 | for (int i = 0; i<5;i++) | |
207 | r.extend(); | |
208 | for (int i = 0; i<=0 + blockHeights[0]+ blockHeights[1]+ blockHeights[2];i++) | |
209 | r.lower(); | |
210 | r.pick(); | |
211 | for (int i = 0; i<13 - blockHeights[2];i++) | |
212 | r.raise(); | |
213 | for (int i = 0; i<4;i++) | |
214 | r.contract(); | |
215 | for (int i = 0; i<10 - barHeights[2];i++) | |
216 | r.lower(); | |
217 | r.drop(); | |
218 | for (int i = 0; i<10 - barHeights[2];i++) | |
219 | r.raise(); | |
220 | for (int i = 0; i<5;i++) | |
221 | r.contract(); | |
222 | ||
223 | for (int i = 0; i<12;i++) | |
224 | r.down(); | |
225 | // You can copy and paste the code from the stage A mechanism here and | |
226 | // start adjusting itstart out writing a completely/* | |
227 | /* { | |
228 | Scanner scan = new Scanner(System.in); | |
229 | System.out.print("Enter 6 numbers to adjust the bar heights "); | |
230 | int [] barHeights array = new int[6]; | |
231 | for(int f = 0; f < 6; ++f);*/ | |
232 | } | |
233 | ||
234 | /* | |
235 | * If you are working through this assignment one scenario at a time then you | |
236 | * should start implementing the control mechanism for configuration scenario | |
237 | * C here. | |
238 | */ | |
239 | public void controlMechanismForStageC(int barHeights[], | |
240 | int blockHeights[]) | |
241 | { | |
242 | for (int i = 0; i<12;i++) | |
243 | r.up(); | |
244 | for (int i = 0; i<9;i++) | |
245 | r.extend(); | |
246 | for (int i = 0; i<=12 - blockHeights[0]- blockHeights[1]- blockHeights[2];i++) | |
247 | r.lower(); | |
248 | r.pick(); | |
249 | for (int i = 0; i<=12 - blockHeights[0]- blockHeights[1]- blockHeights[2];i++) | |
250 | r.raise(); | |
251 | ||
252 | if (blockHeights[0] <=3 (int i = 0i<=6;i++)){ | |
253 | }else if (blockHeights[0] <=2 (int i = 0; i<=7;i++)){ | |
254 | }else (int i = 0; i<=5;i++)) | |
255 | r.contract(); | |
256 | ||
257 | for (int i = 0; i<=12 - barHeights[0] - blockHeights[2];i++) | |
258 | r.lower(); | |
259 | r.drop(); | |
260 | for (int i = 0; i<=9 - barHeights[0];i++) | |
261 | r.raise(); | |
262 | for (int i = 0; i<6;i++) | |
263 | r.extend(); | |
264 | for (int i = 0; i<=12 - blockHeights[0]- blockHeights[1];i++) | |
265 | r.lower(); | |
266 | r.pick(); | |
267 | for (int i = 0; i<=12 - blockHeights[0]- blockHeights[1];i++) | |
268 | r.raise(); | |
269 | for (int i = 0; i<5;i++) | |
270 | r.contract(); | |
271 | for (int i = 0; i<=12 - barHeights[1] - blockHeights[1];i++) | |
272 | r.lower(); | |
273 | r.drop(); | |
274 | for (int i = 0; i<=9 - barHeights[1];i++) | |
275 | r.raise(); | |
276 | for (int i = 0; i<5;i++) | |
277 | r.extend(); | |
278 | for (int i = 0; i<=12 - blockHeights[0];i++) | |
279 | r.lower(); | |
280 | r.pick(); | |
281 | for (int i = 0; i<=12 - blockHeights[0];i++) | |
282 | r.raise(); | |
283 | for (int i = 0; i<4;i++) | |
284 | r.contract(); | |
285 | for (int i = 0; i<=12 - barHeights[2] - blockHeights[0];i++) | |
286 | r.lower(); | |
287 | r.drop(); | |
288 | for (int i = 0; i<10 - barHeights[2];i++) | |
289 | r.raise(); | |
290 | for (int i = 0; i<5;i++) | |
291 | r.contract(); | |
292 | ||
293 | for (int i = 0; i<12;i++) | |
294 | r.down(); | |
295 | ||
296 | } | |
297 | } |