Finch ArrayList Lab

Lab #1: Goals: ArrayLists of Strings and Commands; File Reading; Finch movement

1) First, create a program that does not use the finch. It should create an creates an ArrayList filled with a commands, and then print those commands in order.

Commands can be held in the form of direction followed by time in milliseconds. The directions are F for forward, R for right, L for Left, B for backwards. A sample ArrayList would be:

It should print the name of the direction and the milliseconds to the screen. For example:

2) Change that program to connect to one finch, create an ArrayList filled with a commands, and then makes the finch run those commands in order, and continue to print the commands to the screen.

Here are good parameters to send to the setWheelVelocities for each direction:

When you are done with this step, the Finch will move in the pattern specified in the ArrayList.

3) Change that program to read its steps from a file. Create a file with the finch commands. Read the commands from that file into the program's arraylist. Make the finch run those commands in order, and continue to print the commands to the screen.

4) Change the program to read into a Command object. Create a Commands class that contains a direction character and time integer instance variables. Create a toString method to print a string like "move forward 1000 milliseconds". Create a constructor that takes in a single command string such as "F1000". Create getter methods for both instance variables. Adjust your program to make an Arraylist of the Commands class. This is an internal only change. The robot movement and screen will not change.

probably day 2:

5) Change your file to be comma separated and add an order field. Then sort by the order field before running the command. This means adding an order field to the Commands class, and making your Commands class implement comparable.

Sample file:

This should run Right, then backwards and then forwards.


Lab #2:

1) Explore the finch's accelerations. The finch will give you its orientation at any time. Capture its accelerations 6 times, telling the user when the capture will occur and spacing 10 seconds apart. Then print out all the accelerations when you are done recording, and then write those accelerations to a file.

The getAccelerations() method will return a primitive array of 3 doubles, representing x, y and z orientations. X is the forward / backward tilt of the beak to back line moving. Y is the right / left tilt of the wheel to wheel line moving. Z is the up/down orientation of a line that is in the middle of the finch. It reads in g's, multiple of standard gravity. Values for acceleration range from -1.5 to +1.5g (though I have only seen it reach 1). .

Create an Accel class that holds the x, y and z and use getAccelerations to fill it. Make an ArrayList of your Accel class.

Print the ArrayList after it is done recording.

Then print the list in sorted order, first by x, then y then z.

Can you figure out what values indicate tilted right, left, forward and backwards?

2) Extension: Teach the Accel class to know whether the beack is forwards or backwards, or left or right tilted. :

Then print the list again with the orientations labeled.