public abstract class Motor extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Motor.Port
These represent the physical ports on the robot which Motors can be connected to
|
Modifier and Type | Method and Description |
---|---|
void |
backward()
Tells the motor to rotate backwards
The motor will continue rotating until
stop() is called. |
void |
forward()
Tells the motor to rotate forwards
The motor will continue rotating until
stop() is called. |
int |
getMaxSpeed()
Returns the maximum speed, this value is based off the Robots battery voltage (it decreases as the Robots battery drains).
|
int |
getSpeed()
Returns the speed of the Motor
|
int |
getTachoCount()
Returns the cumulative number of degrees the motor has turned since
resetTachoCount() was last called. |
boolean |
isMoving()
Returns whether the motor is currently moving.
|
boolean |
isStalled()
Returns whether the motor has stalled.
|
void |
resetTachoCount()
Resets the value returned by
getTachoCount() to 0 |
void |
rotate(int degrees)
Rotates the motor the specified number of degrees.
|
void |
rotate(int degrees,
boolean async)
Rotates the motor the specified number of degrees.
|
void |
rotateTo(int degrees)
Rotates the motor to the specified tacho count.
|
void |
rotateTo(int degrees,
boolean async)
Rotates the motor to the specified tacho count.
|
void |
run()
This method is for internal use, it exists due to Sensors and Motors both extending runnable.
|
void |
setSpeed(int newSpeed)
Sets the speed of the Motor.
|
void |
stop()
Tells the motor to stop moving
|
public void forward()
stop()
is called.public void backward()
stop()
is called.public void stop()
public void resetTachoCount()
getTachoCount()
to 0public int getTachoCount()
resetTachoCount()
was last called.public void setSpeed(int newSpeed)
forward()
or backward()
must be called after.
The lowest accepted value is 0
The motors maximum speed can be found using getMaxSpeed()
newSpeed
- The speed of the motor, this value must not be negativeIllegalArgumentException
- When newSpeed is negativepublic int getSpeed()
public int getMaxSpeed()
public boolean isMoving()
public boolean isStalled()
public void rotate(int degrees)
degrees
- The number of degrees that the motor should rotaterotate(int, boolean)
public void rotate(int degrees, boolean async)
async
is set to true, this method will return instantly,
this can be used if you need to call rotate multiple motors simultaneously.degrees
- The number of degrees that the motor should rotateasync
- When true this method will not wait for the action to complete before returning controlpublic void rotateTo(int degrees)
getTachoCount()
should return the specified value within 2 degrees.degrees
- The tacho count to rotate the motor untilrotateTo(int, boolean)
public void rotateTo(int degrees, boolean async)
getTachoCount()
should return the specified value within 2 degrees.
When async
is set to true, this method will return instantly,
this can be used if you need to call rotate multiple motors simultaneously.degrees
- The tacho count to rotate the motor untilasync
- When true this method will not wait for the action to complete before returning control