Java代写:CS1073 Robot

实现控制一个机器人的小程序。

Project Overview

This is a single assignment topic in two parts (Part A and B)

This specification provides an overview of the problem and supplied code and also specifies the requirements for the Part A submission.

Make sure you CAREFULLY WATCH THE ASSIGNMENT RELATED DEMO VIDEOS which show the default startup behavior (when no code is added) as well as working solutions for two different data sets (arrays) for this assignment. See section Description of the Supplied Videos at the end of this document for more details.

The code to do the graphical drawing of the robot environment is provided and the use, and understanding of, the supplied interfaces is not required in detail until assignment B.

The possible operations on the robot are specified by the supplied Robot and RobotMovement interfaces(Robot.java and RobotMovement.java). Some additional CONSTANTS you should use in your code are specified in the Control.java interface.

IMPORTANT: DO NOT CHANGE ANY OF THESE INTERFACES!

PART A Requirements

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:

INITIALIZATION

After the init() method is called with valid array parameters:

  • Blocks are placed in order from the supplied (hardcoded) block Heights array alternating between the left source column (Control.SRC1_COLUMN) and the right source column (Control.SRC2_COLUMN).
  • Bars are placed in order from the supplied(hardcoded) bar Heights array from left to right(fromControl.FIRST_BAR_COLUMN to a maximum of Control.LAST_BAR_COLUMN).
  • This initialization is done AUTOMATICALLY by the supplied RobotImpl.jar

BLOCK PLACEMENT

You must reproduce this behavior by calling methods on the Robot.
Further hints are given in the section HOW TO PROCEED below.

  • Blocks are picked from the two source columns starting from the left column and alternating between the two columns. You will need to control the robot movement to do this.
  • Block are dropped on bars starting at the left most bar (Control.FIRST_BAR_COLUMN) and progressing to the right most bar (Control.LAST_BAR_COLUMN).
  • Once all bars have a block on them, the direction changes and blocks are placed from right to left (like a second row of “bricks”). This continues until all blocks have been placed.
  • Blocks are lowered to the drop position using the raise()/ lower()methods to move Arm3.
  • If less bars than columns are supplied then blocks can still be placed on the empty column and should still be laid out as described above from Control.FIRST_BAR_COLUMN to Control.LAST_BAR_COLUMN

HEIGHT OPTIMISATION (ARM1 movement):

Again, you must reproduce this behavior by calling appropriate methods on the Robot.

  • Arm2(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). 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.

HOW TO PROCEED

Write code using loops and 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. This assignment does not require any of the Object-Oriented concepts 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 Robot interface (Robot.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 Robot.java and serves as an example you can follow to keep your methods small, cohesive and useful. 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):

1
2
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 place on 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.

The supplied video RobotStartup.avi shows the default behavior of the robot with supplied code once it is correctly imported and executed from eclipse.

The supplied video Robot24x1Solution.avi shows 24 x 1 blocks which clearly demonstrates the picking order and block placement including multiple direction changes.

The supplied video RobotMixedSolution.avi uses the following data set which has a mix of block and bar sizes. If you can solve this without hard coding you should be good to go

1
2
this.barHeights = new int[] { 3, 4, 1, 5, 2, 3, 2, 6 };
this.blockHeights= new int[] {3,2,1,2,1,1,2,2,1,1,2,1,2,3};

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.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.

Think you should know!! This is important!!

As well as functional correctness (robot arm behaviour matches video requirements)

Avoid code repetition. (THIS IS THE MOST IMPORTANT ONE!)

  • you will also be assessed based on the following code quality requirements:
  • Use meaningful / descriptive identifiers (eg variable and method names).
  • You must demonstrate understanding of local variables versus class attributes.
  • Demonstrate the use of defined constants in Control.java Rather than using numbers.
  • Write small private methods to avoid code other than one or more method calls going intheRobotControl.control() method.
  • Appropriate use of comments (but remember that easily understandable code is better than a comment).
  • Include a comment at the top of RobotControl.java class