public class Navigator extends java.lang.Object implements WaypointListener
Waypoint
s.
It's default mode for a new path is continuous movement (no stopping at waypoints) but see also singleStep(boolean)
. To interrupt the path traversal, call stop().
It uses an inner class running its own thread to issue movement commands to its
MoveController
,
which can be either a DifferentialPilot
or SteeringPilot
.
It also uses a PoseProvider
Calls its NavigationListener
s
when a Waypoint is reached or the robot stops.
This class has only one blocking method: waitForStop()
.Constructor and Description |
---|
Navigator(MoveController pilot)
Allocates a Navigator object, using pilot that implements the ArcMoveController interface.
|
Navigator(MoveController pilot,
PoseProvider poseProvider)
Allocates a Navigator object using a pilot and a custom poseProvider, rather than the default
OdometryPoseProvider.
|
Modifier and Type | Method and Description |
---|---|
void |
addNavigationListener(NavigationListener listener)
Adds a NavigationListener that is informed when a the robot stops or
reaches a WayPoint.
|
void |
addWaypoint(float x,
float y)
Constructs an new Waypoint from the parameters and adds it to the end of the path.
|
void |
addWaypoint(float x,
float y,
float heading)
Constructs an new Waypoint from the parameters and adds it to the end of the path.
|
void |
addWaypoint(Waypoint aWaypoint)
Adds a Waypoint to the end of the path.
|
void |
clearPath()
Clears the current path.
|
void |
followPath()
Starts the robot traversing the current path.
|
void |
followPath(Path path)
Starts the robot traversing the path.
|
MoveController |
getMoveController()
Returns the MoveController belonging to this object.
|
Path |
getPath()
Gets the current path
|
PoseProvider |
getPoseProvider()
Returns the PoseProvider
|
Waypoint |
getWaypoint()
Returns the waypoint to which the robot is presently moving.
|
void |
goTo(float x,
float y)
Starts the moving toward the destination Waypoint created from
the parameters.
|
void |
goTo(float x,
float y,
float heading)
Starts the moving toward the destination Waypoint created from
the parameters.
|
void |
goTo(Waypoint destination)
Starts the robot moving toward the destination.
|
boolean |
isMoving()
Returns
true |
boolean |
pathCompleted()
Returns
true if the the final waypoint has been reached |
void |
pathGenerated()
Called when generation of the path is complete
|
boolean |
rotateTo(double angle)
Rotates the robot to a new absolute heading.
|
void |
setPath(Path path)
Sets the path that the Navigator will traverse.
|
void |
setPoseProvider(PoseProvider aProvider)
Sets the PoseProvider after construction of the Navigator
|
void |
singleStep(boolean yes)
Controls whether the robot stops at each Waypoint; applies to the current path only.
|
void |
stop()
Stops the robot.
|
boolean |
waitForStop()
Waits for the robot to stop for any reason ;
returns
true if the robot stopped at the final Waypoint of
the path. |
public Navigator(MoveController pilot)
pilot
- public Navigator(MoveController pilot, PoseProvider poseProvider)
pilot
- the pilotposeProvider
- the custom PoseProviderpublic void setPoseProvider(PoseProvider aProvider)
aProvider
- the PoseProviderpublic void addNavigationListener(NavigationListener listener)
listener
- the NavitationListenerpublic PoseProvider getPoseProvider()
public MoveController getMoveController()
public void setPath(Path path)
path
- to be followed.public void clearPath()
public Path getPath()
public void followPath(Path path)
path
- to be followed.public void followPath()
public void singleStep(boolean yes)
followPath()
.yes
- if true
, the robot stops at each Waypoint.public void goTo(Waypoint destination)
addWaypoint(destination);
followPath();
destination
- the waypoint to be reachedpublic void goTo(float x, float y)
add(float x, float y); followPath();
x
- coordinate of the destinationy
- coordinate of the destinationpublic void goTo(float x, float y, float heading)
add(float x, float y); followPath();
x
- coordinate of the destinationy
- coordinate of th destinationheading
- desired robot heading at arrivalpublic boolean rotateTo(double angle)
angle
- The absolute heading to rotate the robot to. Value is 0 to 360.public void addWaypoint(Waypoint aWaypoint)
followPath()
to start moving the along the current path.addWaypoint
in interface WaypointListener
aWaypoint
- to be addedpublic void addWaypoint(float x, float y)
followPath()
to start moving the along the current path.x
- coordinate of the waypointy
- coordinate of the waypointpublic void addWaypoint(float x, float y, float heading)
followPath()
to start moving the along the current path.x
- coordinate of the waypointy
- coordinate of the waypointheading
- the heading of the robot when it reaches the waypointpublic void stop()
followPath()
.public Waypoint getWaypoint()
public boolean pathCompleted()
true
if the the final waypoint has been reached true
if the path is completedpublic boolean waitForStop()
true
if the robot stopped at the final Waypoint of
the path. true
if the path is completedpublic boolean isMoving()
true if the robot is moving toward a waypoint.
true
if moving.public void pathGenerated()
WaypointListener
pathGenerated
in interface WaypointListener