Java代写 | COSC 1073 Assignment Part A: Robot Simulation

本次Java代写是完成机器人模拟
Programming1 COSC 1073
Assignment Part A: Robot Simulation

4. Assessment details
To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm
movement loop which you will build upon to create the full solution.
NOTE: The primary requirements specifications are the supplied videos which show the EXACT behaviour you should reproduce.
However, some points worth noting about the displayed behaviour:
INITIALISATION:
After the init() method is called with valid array parameters the robot environment is AUTOMATICALLY configured as
follows by the supplied RobotImpl.jar
● Bars are placed in order from the supplied (hard coded) barHeights array from left to right (from
Control.FIRST_BAR_COLUMN to a maximum of Control.LAST_BAR_COLUMN).
● You can provide less bars than columns and the extra columns will be treated as a zero. You can also create gaps with zeros
in barHeights as with the default provided data.
● Blocks are placed in order from the supplied (hard coded) blockHeights array on top of bars (or at the bottom if no
bar) from left to right (from Control.FIRST_BAR_COLUMN to Control.LAST_BAR_COLUMN). Upon reaching
either column extreme the direction changes and blocks are stacked back in the other direction. This continues, including
further direction changes at the extremes, until all blocks have been placed.
● If less bars than columns are supplied or there are gaps due to zeros in barHeights then blocks are still be placed on the
empty column and are laid out as described above from Control.FIRST_BAR_COLUMN to
Control.LAST_BAR_COLUMN.
BLOCK PLACMENT:
You must reproduce this behaviour by calling methods on the Robot. Further hints are given in the section HOW TO PROCEED
below.
● Blocks are picked from the top of the bar/block stack in the same order they were placed during initialization, as described
above (left to right then changing direction at the extremes).
● Blocks are dropped in an alternating fashion on the two stacks (Control. STACK1_COLUMN and Control.
STACK2_COLUMN) starting with column 1.
● This continues until all blocks have been placed.
● Blocks are lowered to the drop position using the raise()/lower() methods to move Arm3.
HEIGHT OPTIMISATION (ARM1 movement):
Again, you must reproduce this behaviour by calling appropriate methods on the Robot.
● Arm 2 (the horizontal arm controlled by extend()/contract()) should always be at the lowest height to clear any
obstacles (i.e. the top of any column stack). This is achieved by using the up()/down() methods on Arm1.
● This is set before moving to make a pick (or after any drop) so that the arm can JUST clear any obstacles as it moves to the
target column.
● The height is then rechecked as soon as you make a pick taking into account the picked block and the additional clearance
it needs as it moves to the drop destination (the far left or right columns as marked in the Robot user interface).
HOW TO PROCEED
Your task is to write code using loops, selection/conditionals, arrays and methods to solve the problem, thereby writing an
algorithm. You will also need to create variables/data structures to keep track of the position of bars, blocks and the arm segments
so you can move and pick/drop as required. Arrays and primitive variables are sufficient for this purpose and you must not use any
other data structures such as Collections/Lists/Maps etc. since the purpose of this assignment is to test programming
fundamentals. This assignment does not require any of the more advanced Object-Oriented concepts such as
inheritance/polymorphism that will covered in assignment part B.
The simplest way to solve this is to build the behaviour with small methods, passing parameters as necessary to avoid code
repetition. If you try to do this with a single method, the loop nesting will get complex and you will lose marks! For example, rather
than nesting loops, place one loop in a method (as with the supplied extendToWidth()) and call that single method in a loop ..
much easier and cleaner!
The possible robot arm movement operations are specified and described by the supplied RobotMovement interface
(RobotMovement.java). Additionally, Control.java contains some constants you can use to avoid hard coding values and
ensure correct operation.
As previously mentioned, the supplied RobotControl.java provides the example method:
private void moveToWidth(int width)
This method uses the extend() method from RobotMovement.java and serves as an example you can follow to keep your
methods small, cohesive and useful.
Suggestions
In order to solve the problem in an incremental manner, it can be useful to start with a simple configuration such as the following (4
bars of height 6 with 2 blocks of height 1):
this.barHeights = new int[] { 6, 6, 6, 6 };
this.blockHeights = new int[] { 1, 1 };
This example is simple since you only have two blocks of a fixed size to pick from a known bar size. You can even start with one
bar/block if you are feeling cautious!
You can then increasingly add more and diverse block sizes and bars.
You can also start with the arm always at the maximum height which simplifies your calculations. The height optimisation can be
added separately once you have finished the block placement.
Description of the Supplied Videos
The supplied video RobotStartupA.mp4 shows the default behaviour of the robot with supplied code once it is correctly imported
and executed from eclipse.
The supplied video Robot24x1SolutionA.mp4 shows 24 x 1 blocks which clearly demonstrates the picking order and block
placement including multiple direction changes.
The supplied video RobotMixedSolutionA.mp4 uses the following data set from RobotControl.java which has a mix of
block and bar sizes. If you can solve this without hard coding you should be good to go 
this.barHeights = new int[] { 0, 6, 1, 3, 0, 5, 1 };
this.blockHeights = new int[] { 3, 3, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 2, 2 };
NOTE: Do NOT hardcode a solution to these exact data sets. A proper algorithm will work for ALL different (legal) combinations and
we WILL test with a different combination! If you are using “magic numbers” or constants other than those defined in
Control.java this is not a good sign so please seek help in class.
Summary
Write code using loops, conditionals, arrays and methods in RobotControl.java to reproduce the behaviour shown in the
supplied videos and described in this specification.
Manual Robot Control (Testing/Development Only No Marks)
For testing purposes you can control the robot arm manually using the following keys. This will help you determine when
collisions occur etc. before or while writing control code.
Robot Command Key(s)
up() Page Up .or [
down() Page Down or ]
extend() Right Arrow
contract() Left Arrow
raise() Up arrow
lower() Down arrow
pick() Home or P
drop() End or D
Speed up (1) NumPad +
Slow down (1) NumPad –
Speed up (5) NumPad *
Slow down (5) NumPad /
5. Referencing and third party code exclusion
 You are free to refer to textbooks and notes, and discuss the design issues (and associated general solutions) with your fellow
students or on Canvas; however, the assignment should be your OWN INDIVIDUAL WORK and is NOT a group assignment.
 You may also use other references, but since you will only be assessed on your own work you should NOT use any third-party
packages or code (i.e. not written by you) in your work.
 As described previously you must use primitives and Arrays for your data structures and should not use any of the Java
Collection Framework classes such as Collections/Lists/Maps etc. since this assignment is intended to test your application of
low-level data structures.