Friday 16 January 2009

End-project. PART VII



Date: 12 01 2009
Duration of activity: 3 hours + (3 hours of homework)
Group members participating: all group members + (Anders D. of homework)



1. The Goal



The goal of this session is to continue on making relevant adjustments with motor and calibration layers, and to test methods of the navigation layer.

2. The Plan




  • Make adjustments if needed to the motor layer.

  • Make adjustments if needed to the calibration layer.

  • Make tests with methods of navigation layer.



3. The Results



3.1. Motor layer




  • MotorSpeed() The constructor now creates two SensorListener which listen for sensor port events. The listener is implemented in the usual ``anonymous class'' way, with the method stateChanged(SensorPort aSource, int aOldValue, int aNewValue) being filled out. The two parameters denote the raw values before and after the event, but since what we would like two know is the answer to the binary question ``is the touch sensor pressed'', we will keep on using isPressed().

  • The MotorLayer implementation now effectively has the safety-break that will stop to motors whenever the corner are being pushed, but this does not stop the motors for starting again (see MotorSpeed() below).

  • setSpeed(MotorPort motor, int speed) The new thing is a condition made before setting the speed to the motor. First of all it is checked if the tacho count taken from the motor handling the x-axis is greater or equal to some predetermined x-tacho-threshold, and if the current speed is greater than or equal to zero. In this case, the movement is allowed, since it's a movement from close to the lower endpoint and towards less close to the lower endpoint. A symmetric argument arises about the top-point.


So far, the news with this layer is about touch sensors. To make things right, we use SensorPort listeners to be aware of when a touch sensor is pushed. Also, we decided to have two sensor ports: One for the lowermost layer (x-axis) and the other for the carriage (y-axis).


3.2. Navigation layer




  • gotoCoordinates(int x, int y, int z) defines actual driving to the given spot in the coordinate system.

  • gotoCoordinates(int[] coords) a wrapper of the prior.

  • getCoordinates() gets an array of coordinates. The array is of length 3.

  • getXCorrdinate(), ..Y.., ..Z.. gets a certain coordinate by calling a method from the calibration layer.


The navigation layer is on top of the calibration layer. This layer handles going to certain coordinates. What is more, it should be able to get current coordinates in an array, or get coordinates separately. For now, this layer needs a lot of testing.

3.3. Driver class, debugging the layers



So far, each test of different parts of the system has done through Driver.java. The driver class is primarily a main() method that allow us to run our code on the NXT brick, without making a main method for each layer. It has a button listener attached that allows us to exit that programs gracefully (i.e. without disconnecting the battery). Driver.java is that only class that breaks that strictly layer-based architecture.
Each testcase added to this blob of a driver is enclosed into a method with a reasonable name, and then called from the main loop.
A testcase could look like:

public static void testFindMinAndMax()
{
cal.setSpeed(MotorPort.A, -100);
while(Motor.A.getSpeed() != 0){};
LCD.drawString("min="+MotorPort.A.getTachoCount(),0,0);
cal.setSpeed(MotorPort.A, 100);
while(Motor.A.getSpeed() != 0){};
LCD.drawString("max="+MotorPort.A.getTachoCount(),0,0);
}

So far the class is for provoking the calibration and prints on the screen tacho count values.

This class is nothing more then a driver class for testing code being written during development. Having one class with the canonical name Driver.nxj also makes it a bit easier to debug unwanted behavior from the robot, by only needing to set the file as being the default program once, and then not bothering with menu interactions afterwards.

This driver should not be seen as the final driver-class for the program, showing off all the features of the robot. Later in this project, when actual final features can be shown, other driver classes should be constructed.

4. Conclusion



During this lab session, the motor layer was adjusted to better serve for our needs and the navigation layer methods were tested. The most significant change is that, in the motor layer, we use a SensorPort listener for touch sensors and we support two sensor ports.


No comments: