public class Gear extends Part
Constructor and Description |
---|
Gear()
Creates a gear instance with right motor plugged into port A, left motor plugged into port B.
|
Modifier and Type | Method and Description |
---|---|
void |
backward()
Starts the backward movement.
|
void |
backward(int duration)
Starts the backward movement for the given duration (in ms) and stops.
|
void |
forward()
Starts the forward movement.
|
void |
forward(int duration)
Starts the forward movement for the given duration (in ms) and stops.
|
Location |
getLocation()
Returns the current location.
|
int |
getSpeed()
Returns the current speed (arbitrary units).
|
int |
getX()
Returns the x-coordinate of the current location.
|
int |
getY()
Returns the y-coordinate of the current location.
|
boolean |
isMoving()
Checks if one or both motors are rotating
Calls Thread.sleep(1) to prevent CPU overload in close polling loops.
|
void |
left()
Starts to rotate left (center of rotation at middle of the wheel axes).
|
void |
left(int duration)
Starts to rotate left (center of rotation at middle of the wheel axes)
for the given duration (in ms) and stops.
|
void |
leftArc(double radius)
Starts to move to the left on an arc with given radius.
|
void |
leftArc(double radius,
int duration)
Starts to move left on an arc with given radius
for the given duration (in ms) and stops.
|
void |
right()
Starts to rotate right (center of rotation at middle of the wheel axes).
|
void |
right(int duration)
Starts to rotate right (center of rotation at middle of the wheel axes)
for the given duration (in ms) and stops.
|
void |
rightArc(double radius)
Starts to move to the right on an arc with given radius.
|
void |
rightArc(double radius,
int duration)
Starts to move right on an arc with given radius
for the given duration (in ms) and stops.
|
void |
setSpeed(int speed)
Sets the speed to the given value (arbitrary units).
|
void |
stop()
Stops the movement.
|
public Gear()
public void forward()
public void forward(int duration)
duration
- the duration (in ms)public void backward()
public void backward(int duration)
duration
- the duration (in ms)public void stop()
public void left()
public void left(int duration)
duration
- the duration (in ms)public void right()
public void right(int duration)
duration
- the duration (in ms)public void leftArc(double radius)
radius
- the radius of the arc; if negative, moves backwardpublic void leftArc(double radius, int duration)
radius
- the radius of the arc; if negative, moves backwardduration
- the duration (in ms)public void rightArc(double radius)
radius
- the radius of the arc; if negative, moves backwardpublic void rightArc(double radius, int duration)
radius
- the radius of the arc; if negative, moves backwardduration
- the duration (in ms)public void setSpeed(int speed)
speed
- 0..100public int getSpeed()
public boolean isMoving()
public int getX()
public int getY()
public Location getLocation()