Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * RobotControl.java
- *
- * This is the control mechanism for the Robot arm - this is the part
- * of the program that you are required to implement.
- *
- * There are three separate methods which correspond to the the
- * three scenarios your control mechanism needs to be able to handle -
- * if you are going to start with scenario A and then move onto
- * scenarios B and C later then you can finish the control mechanism
- * for scenario first and then implement your control mechanism for
- * scenarios B and C in the corresponding empty control methods.
- *
- * You do not need to do anything for the Robot itself as it has
- * already been fully implemented - you just need to supply the control
- * mechanism(s) to make it move blocks from the source pile to their
- * corresponding target piles.
- */
- import javax.swing.*;
- import java.util.Scanner;
- class RobotControl
- {
- private Robot r;
- public RobotControl(Robot r)
- {
- this.r = r;
- }
- public void control(int[] barHeights, int[] blockHeights)
- {
- /*
- * This is the starting point for handling scenario A
- */
- //controlMechanismForStageA(barHeights, blockHeights);
- /*
- * comment out the method call above and uncomment the method call below
- * when you're ready to start working on Stage B
- */
- //controlMechanismForStageB(barHeights, blockHeights);
- /*
- * comment out the method call above and uncomment the method call below
- * when you're ready to start working on Stage C
- */
- controlMechanismForStageC(barHeights, blockHeights);
- }
- /*
- * If you are working through this assignment one scenario at a time then you
- * should start implementing the control mechanism for the basic
- * configuration in stage A here.
- */
- public void controlMechanismForStageA(int barHeights[],
- int blockHeights[])
- {
- r.slowDown(2);
- // variables representing the initial state of the robot arm -
- // you can update these as needed when performing the different
- // moves to keep track of the position of the robot arm
- int h = 1;
- int w = 1;
- int d = 1;
- // variable representing the height the robot arm needs to
- // move down to when picking up a block
- int sourceHeight = 9;
- // variable representing the column (bar) the current block
- // is to be dropped on
- int targetColumn = 4;
- // variable representing the safe clearance height
- int clearanceHeight = 13;
- // move first section of arm up initially to a safe position
- // loop which repeats sequence of moves for one block
- // to many bloody comments in this code
- /*it has come to my mind if we made 2 arrys one for down upo and pick and put it in order
- * then the other for ints could we get away with only one for loop ?
- */
- for (int i = 0; i<9;i++)
- r.up();
- for (int i = 0; i<9;i++)
- r.extend();
- for (int i = 0; i<1;i++)
- r.lower();
- r.pick();
- for (int i = 0; i<1;i++)
- r.raise();
- for (int i = 0; i<6;i++)
- r.contract();
- for (int i = 0; i<2;i++)
- r.down();
- r.drop();
- for (int i = 0; i<6;i++)
- r.extend();
- for (int i = 0; i<2;i++)
- r.lower();
- r.pick();
- for (int i = 0; i<3;i++)
- r.up();
- for (int i = 0; i<5;i++)
- r.contract();
- for (int i = 0; i<1;i++)
- r.lower();
- r.drop();
- for (int i = 0; i<5;i++)
- r.extend();
- for (int i = 0; i<5;i++)
- r.lower();
- r.pick();
- for (int i = 0; i<7;i++)
- r.raise();
- for (int i = 0; i<4;i++)
- r.contract();
- for (int i = 0; i<2;i++)
- r.lower();
- r.drop();
- for (int i = 0; i<5;i++)
- r.contract();
- for (int i = 0; i<3;i++)
- r.raise();
- for (int i = 0; i<9;i++)
- r.down();
- {
- // move second section of arm across to source pile
- {
- r.extend();
- }
- // what will the next move of the robot arm be?
- // ...
- }
- }
- /*
- * If you are working through this assignment one scenario at a time then you
- * should start implementing the control mechanism for configuration scenario
- * B here.
- */
- public void controlMechanismForStageB(int barHeights[],
- int blockHeights[])
- {
- for (int i = 0; i<12;i++)
- r.up();
- for (int i = 0; i<9;i++)
- r.extend();
- for (int i = 0; i<=0 + blockHeights[2];i++)
- r.lower();
- r.pick();
- for (int i = 0; i<4;i++)
- r.raise();
- for (int i = 0; i<6;i++)
- r.contract();
- for (int i = 0; i<=9 - barHeights[0];i++)
- r.lower();
- r.drop();
- for (int i = 0; i<=9 - barHeights[0];i++)
- r.raise();
- for (int i = 0; i<6;i++)
- r.extend();
- for (int i = 0; i<=0 + blockHeights[2]+ blockHeights[1];i++)
- r.lower();
- r.pick();
- for (int i = 0; i<13 - blockHeights[1]- blockHeights[2];i++)
- r.raise();
- for (int i = 0; i<5;i++)
- r.contract();
- for (int i = 0; i<=9 - barHeights[1];i++)
- r.lower();
- r.drop();
- for (int i = 0; i<=9 - barHeights[1];i++)
- r.raise();
- for (int i = 0; i<5;i++)
- r.extend();
- for (int i = 0; i<=0 + blockHeights[0]+ blockHeights[1]+ blockHeights[2];i++)
- r.lower();
- r.pick();
- for (int i = 0; i<13 - blockHeights[2];i++)
- r.raise();
- for (int i = 0; i<4;i++)
- r.contract();
- for (int i = 0; i<10 - barHeights[2];i++)
- r.lower();
- r.drop();
- for (int i = 0; i<10 - barHeights[2];i++)
- r.raise();
- for (int i = 0; i<5;i++)
- r.contract();
- for (int i = 0; i<12;i++)
- r.down();
- // You can copy and paste the code from the stage A mechanism here and
- // start adjusting itstart out writing a completely/*
- /* {
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter 6 numbers to adjust the bar heights ");
- int [] barHeights array = new int[6];
- for(int f = 0; f < 6; ++f);*/
- }
- /*
- * If you are working through this assignment one scenario at a time then you
- * should start implementing the control mechanism for configuration scenario
- * C here.
- */
- public void controlMechanismForStageC(int barHeights[],
- int blockHeights[])
- {
- for (int i = 0; i<12;i++)
- r.up();
- for (int i = 0; i<9;i++)
- r.extend();
- for (int i = 0; i<=12 - blockHeights[0]- blockHeights[1]- blockHeights[2];i++)
- r.lower();
- r.pick();
- for (int i = 0; i<=12 - blockHeights[0]- blockHeights[1]- blockHeights[2];i++)
- r.raise();
- if (blockHeights[0] <=3 (int i = 0i<=6;i++)){
- }else if (blockHeights[0] <=2 (int i = 0; i<=7;i++)){
- }else (int i = 0; i<=5;i++))
- r.contract();
- for (int i = 0; i<=12 - barHeights[0] - blockHeights[2];i++)
- r.lower();
- r.drop();
- for (int i = 0; i<=9 - barHeights[0];i++)
- r.raise();
- for (int i = 0; i<6;i++)
- r.extend();
- for (int i = 0; i<=12 - blockHeights[0]- blockHeights[1];i++)
- r.lower();
- r.pick();
- for (int i = 0; i<=12 - blockHeights[0]- blockHeights[1];i++)
- r.raise();
- for (int i = 0; i<5;i++)
- r.contract();
- for (int i = 0; i<=12 - barHeights[1] - blockHeights[1];i++)
- r.lower();
- r.drop();
- for (int i = 0; i<=9 - barHeights[1];i++)
- r.raise();
- for (int i = 0; i<5;i++)
- r.extend();
- for (int i = 0; i<=12 - blockHeights[0];i++)
- r.lower();
- r.pick();
- for (int i = 0; i<=12 - blockHeights[0];i++)
- r.raise();
- for (int i = 0; i<4;i++)
- r.contract();
- for (int i = 0; i<=12 - barHeights[2] - blockHeights[0];i++)
- r.lower();
- r.drop();
- for (int i = 0; i<10 - barHeights[2];i++)
- r.raise();
- for (int i = 0; i<5;i++)
- r.contract();
- for (int i = 0; i<12;i++)
- r.down();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement