Class Ship

java.lang.Object
  |
  +--Ship

public class Ship
extends java.lang.Object

A Ship class to simulate a basic ship using the lego robot. The model assumes that the robot is driven with a differential drive system powered by Motors A and C. It is also assumed that there is a mechanism that measures the difference in rotation between the two wheels and drives the rotation sensor on input 2 of the RCX. The Ship class should probably be a singleton object because it only makes sense to instantiate a single Ship object. The behaviour of the robot is undefined if you try to control it from two ship objects.


Constructor Summary
Ship()
          Constructs the Ship object effectively setting its initial heading to 0 degrees.
 
Method Summary
 int getHeading()
          Returns the current heading of the robot in degrees.
static void main(java.lang.String[] args)
          A main method should you wish to test the class without writing your own code.
 void move()
          Moves the robot forwards by appying the same power to both motors.
 void moveStraight()
          Moves the robot forwards in a straight line.
static void pause(int millis)
          Lets the robot do nothing for the specified number of milli seconds.
 void setCourse(int course)
          Causes the robot to turn to point in the direction specified by course.
 void setSpeed(int speed)
          Sets the speed of the robot.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Ship

public Ship()
Constructs the Ship object effectively setting its initial heading to 0 degrees.
Method Detail

main

public static void main(java.lang.String[] args)
A main method should you wish to test the class without writing your own code. This should just move the robot round in a square. This may be useful for calibrating the turning sensor so that you can find a suitable value for rightAngle.

setSpeed

public void setSpeed(int speed)
Sets the speed of the robot. This method stops the robot if a zero speed is specified.

setCourse

public void setCourse(int course)
Causes the robot to turn to point in the direction specified by course. The robot is not made to turn if it's current heading is within two degrees of requested course as this is beyond the precision of the robot.

getHeading

public int getHeading()
Returns the current heading of the robot in degrees.

move

public void move()
Moves the robot forwards by appying the same power to both motors. Due to the nature of the robot this may not actually result in the robot moving in a straight line.

moveStraight

public void moveStraight()
Moves the robot forwards in a straight line. This method checks the robot's heading and steers appropriately if the robot moves off course.

pause

public static void pause(int millis)
Lets the robot do nothing for the specified number of milli seconds.