Write a program to move the stack of blocks from source to specific targets based on the size of blocks. Movement of Robot arms, picking and dropping can be controlled using the Robot methods described below.
up(), down(), extend(), contract(), raise(), lower(), pick(), drop(),speedUp(), slowDown()
There can only be one block placed on top of a bar and the blocks must be placed in order starting with the bar in column 3. For scenarios (a) and (b) you are required to deal with blocks of height 3 only.
Algorithms for moving the blocks must avoid collisions with others blocks and bars.
The height of bars are preset for scenario A at 7 each but will be specified as a command line argument for scenarios B and C. Similarly the heights of blocks at the source are preset to 3 each for scenarios A and B, but can be specified as a command line argument for scenario C, where the height of blocks may vary from 1 to 3. The number of blocks for Scenario C may vary between 1 and 12, but the total sum of the block heights cannot exceed 12.
It is your job to implement the control mechanism for the robot arm so that it can safely move the blocks from the source pile on the left to their destination without colliding with any bars or other blocks that have already been moved.
The control mechanism is implemented in the control() method of the RobotControl class – this is where your implementation of an algorithm for moving the robot must be placed.
Initially you may assume that the bars and blocks will be of a fixed size – the four blocks are all of sizes 3 (the first block is always at the bottom of the source pile) and all bars are of size 7.
The robot will start off with code in the control() method which demonstrates how the different movements can be combined to transport the first block from the source pile to the its target bar.
You will need to update the control method that it picks up each block and moves it to one of the bars, starting from the last bar and working backwards.
You can do this by repeating the code segment for moving the first block for each new block and making the necessary adjustments to the degree the arm moves in each direction to reflect the location of the top of the next block in the source pile and the next vacant bar the block is to be dropped upon (if you can do it more efficiently then that’s ok too).
Example: java Robot See image.
In this scenario the heights of the bars will be specified by the user on the command line when running the robot and thus their heights could be anything from 1 to 7.
You need to factor these variable bar heights when moving the arm into position to drop off each block (hint: the barHeights array contains the heights of each bar).
It is also a requirement that you implement the control method in an efficient manner, which means you should not repeat the code required for moving a block from the source pile to its destination and moving the arm back to the starting position more than once.
In order to do this you will need to nest the code for moving one block inside a loop which repeats that series of robot arm movements for each block in the source pile – you may find using variables to keep track of where the arm is, height of the source pile and target bar position and updating them appropriately whenever something happens helpful.
Note that marks will only be awarded for scenario B if you have implemented the control() method in an efficient manner as described above.
Note that the blocks at source are all of size 3 as for scenario A, but bar sizes can be specified in the range 1 to 7.
Example: java Robot 734561 See image.
In this scenario the heights of both the blocks and the bars will be specified by the user on the command line when running the robot and thus the block heights can be anything between 1 and 3 units and the bar heights can be anything between 1 and 7 units.
You need to factor these variable block and bar heights when moving the arm into position to pick up and drop off each block (hint: the blockHeights array contains the heights of each block with the last element in the array reflecting the height of the top block in the source pile and the barHeights array contains the heights of each bar).
It is also a requirement that you implement the control method in an efficient manner as was the case for scenario B, which means you should not repeat the code required for moving a block from the source pile to its destination and moving the arm back to the starting position more than once.
In order to do this you will need to nest the code for moving one block inside a loop which repeats that series of robot arm movements for each block in the source pile – you may find using variables to keep track of where the arm is, height of the source pile and target bar position and updating them appropriately whenever something happens helpful.
Note that marks will only be awarded for scenario C if you have implemented the control() method in an efficient manner as described for scenarios A and B above. Also note that your robot must work for any possible combination of block and bar heights (you may assume there will always be 6 bars that need to be cleared safely).
Note block sizes can be specified in the range 1-3 and bar sizes can be specified in the range 1 to 7. Example: java Robot 734561 231231 See image.
For all three sections below you are required to complete the control() method of the RobotControl class shown below. The control() method will be automatically called when the program is run. RobotControl class has a reference r set to refer to the Robot object. Hence to move the first arm of the Robot upwards call r.up(). See image.
This method is also passed two arrays containing the heights of (up to six) bars and blocks based on user input. If the instructions you specify for the Robot result in hitting an bar or going beyond the limits, program will terminate immediately with an appropriate Error Message.