4 * An abstraction for a motor without a tachometer,
5 * such as an RCX motor.
7 * @author Lawrie Griffiths
10 public abstract class BasicMotor
20 * @param power power setting: 0 - 100
22 public void setPower(int power)
25 _port.controlMotor(_power, _mode);
29 * Returns the current power setting.
31 * @return power value 0-100
39 * Causes motor to rotate forward.
48 * Return true if motor is forward.
50 public boolean isForward()
56 * Causes motor to rotate backwards.
58 public void backward()
65 * Return true if motor is backward.
67 public boolean isBackward()
73 * Reverses direction of the motor. It only has
74 * effect if the motor is moving.
76 public void reverseDirection()
78 if (_mode == 1 || _mode == 2)
86 * Returns true iff the motor is in motion.
88 * @return true iff the motor is currently in motion.
90 public boolean isMoving()
92 return (_mode == 1 || _mode == 2);
96 * Causes motor to float. The motor will lose all power,
97 * but this is not the same as stopping. Use this
98 * method if you don't want your robot to trip in
108 * Returns true iff the motor is in float mode.
110 * @return true iff the motor is currently in float mode.
112 public boolean isFloating()
118 * Causes motor to stop, pretty much
119 * instantaneously. In other words, the
120 * motor doesn't just stop; it will resist
121 * any further motion.
122 * Cancels any rotate() orders in progress
131 * Return true if motor is stopped.
133 public boolean isStopped()
140 _port.controlMotor(_power, _mode);
146 * @return mode 1=forward, 2=backward, 3=stopped, 4=floating