Motor class



The Motor class defines an interface that allows access to both motors on the robot. Each motor has two pieces of data associated with it: a speed and a wheel position. Unlike the Sensor class that defines one of the eight sensors, the Motor class encapsulates both motors. Motor speeds for each motor can range from -9 to 9. Setting speeds to initiate certain forms of movement is fairly intuitive; setting both motors to equal, positve values causes the robot to go straight forward, setting both motors to equal, negative values causes the robot to go straight backward, setting both motors to equal absolute values, where one is positive and the other negative, causes the robot to pivot turn, etc. The wheel position is incremented for each wheel when the it rotates forward (i.e. its motor speed is greater than zero), and the rate of incrementation is proportional to the actual speed. For negative speeds, the wheel position is decremented. The only time a wheel position is not updated is when the motor speed is zero or the robot is running into an immovable object.


Methods

void setMotorSpeeds(int lSpeed, int rSpeed) - accepts two integers that are within the legal speed range; illegal speed values are ignored. The arguments need to be in the following order: left speed, right speed.
long getLeftPosition() - returns a long int that refers to the current left wheel position.
long getRightPosition() - returns a long int that refers to the current right wheel position.

Back Home