lejos.robotics.mapping
Class PCNavigationModel

java.lang.Object
  extended by lejos.robotics.mapping.NavigationModel
      extended by lejos.robotics.mapping.PCNavigationModel

public class PCNavigationModel
extends NavigationModel

The PCNavigationModel holds all the navigation data that is transmitted as events, to and from a NXT brick. It has methods to generate events, and a Receiver thread to receive events from the NXT. There is a NavigationPanel associated with the model. Whenever data in the model is updated, the NavigationPanel is repainted with the new data.

Author:
Lawrie Griffiths

Nested Class Summary
 
Nested classes/interfaces inherited from class lejos.robotics.mapping.NavigationModel
NavigationModel.NavEvent
 
Field Summary
protected  AstarSearchAlgorithm alg
           
protected  int clearance
           
protected  int closest
           
protected  boolean connected
           
protected  Node destination
           
protected  java.util.ArrayList<Point> features
           
protected  int gridSpace
           
protected  FourWayGridMesh mesh
           
protected  java.util.ArrayList<Move> moves
           
protected  java.util.Collection<Node> nodes
           
protected  NXTCommand nxtCommand
           
protected  MapApplicationUI panel
           
protected  RangeReadings particleReadings
           
protected  PathFinder pf
           
protected  java.util.ArrayList<Pose> poses
           
protected  Waypoint reached
           
protected  Node start
           
protected  float voltage
           
protected  java.util.ArrayList<Waypoint> waypoints
           
protected  float weight
           
 
Fields inherited from class lejos.robotics.mapping.NavigationModel
currentPose, debug, dis, dos, feature, lastMove, lastPlannedMove, map, mcl, numReadings, nxtName, particles, path, readings, target
 
Constructor Summary
PCNavigationModel(MapApplicationUI panel)
          Create the model and associate the navigation panel with it
 
Method Summary
 void addWaypoint(Waypoint wp)
          Add a waypoint and send it to the NXT
 void arc(float radius, float angle)
          Send an ARC event to the NXT
 void calculatePath()
          Calculate the path with the Node path finder
protected  boolean checkFile(java.io.File f)
          Check that the file exists on the NXT with the right size
 void clear()
          Clear all variable data
 void clearPath()
          Send a CLEAR_PATH event to the NXT
 void connect(java.lang.String nxtName)
          Connect to the NXT
 void connectAndUpload(java.lang.String nxtName, java.io.File file)
          Connect to the NXT, upload a program, and run it
 void findClosest(float x, float y)
          Send a FIND_CLOSEST event to the NXT
 void findPath(Waypoint wp)
          Send a FIND_PATH event to the NXT
 void followPath()
          Send a route to the NXT and follow it
 void generateParticles()
          Generate particles for the MCLPoseProvider and send them to the NXT
 void getEstimatedPose()
          Send a GET_ESTIMATED_POSE event to the NXT
 java.util.ArrayList<Point> getFeatures()
          Get the list of features
 Move getLastMove()
          Get the last move made by the robot
 MCLPoseProvider getMCL()
          Get the MCLPoseProvider associated with this model
 java.util.ArrayList<Move> getMoves()
          Get the moves made since the last setPose
 java.util.Collection<Node> getNodes()
          Get the generated node
 void getPose()
          Send a GET_POSE event to the NXT
 java.util.ArrayList<Pose> getPoses()
          Get the sequence of poses of the robot from moves sent from the NXT, since the last call of setPose
 void getRemoteBattery()
          Get the remote battery voltage
 void getRemoteParticles()
          Send a GET_PARTICLES event to the NXT
 void getRemoteReadings()
          Send a GET_READINGS event to the NXT
protected  java.util.ArrayList<Waypoint> getWaypoints()
          Get the list of waypoints
 void goTo(Waypoint wp)
          Send a GOTO event to the NXT
 boolean isConnected()
          Test if a NXT brick is currently connected
 void lcpClose()
          Close the LCP connection to the NXT
 boolean lcpConnect(java.lang.String nxtName)
          Make an LCP connection to the NXT
 LineMap loadMap(java.lang.String mapFileName)
           
 LineMap loadMap(java.lang.String mapFileName, int finder)
          Load a line map and send it to the PC
 void localize()
          Tell the NXT to keep making random moves until the robot is localized
 void randomMove()
          Send a RANDOM_MOVE event to the NXT
 void rotate(float angle)
          Send a ROTATE event to the NXT
 void rotateTo(float angle)
          Send a ROTATE_TO event to the NXT
 void sendExit()
          Send an EXITevent to the NXT
 void sendMap()
          Send the map to the NXT
 void sendRandomMoveParams(float maxDistance, float clearance)
          Send Random Move parameters to the NXT
 void sendSound(int code)
          Send a system sound
 void setDifferentialPilotParams(float wheelDiameter, float trackWidth, int leftMotor, int rightMotor, boolean reverse)
          Set the parameters for a DifferentialPilot, send them to the NXT, and write them to the pilot.props file.
 void setMCL(MCLPoseProvider mcl)
          Set an MCLPOseProvider for this model
 void setMeshParams(int gridSpace, int clearance)
          Set the parameter for the 4-way mesh
 void setPathFinder(int finder)
           
 void setPose(Pose p)
          Send a SET_POSE event to the NXT
 void setRangeFeatureParams(float maxDistance, int delay)
          Set the parameter for a Range Feature Detector
 void setRotateSpeed(float speed)
          Set the rotate speed for a pilot
 void setRotatingRangeScannerParams(int gearRatio, int headMotor)
          Set the patameters for a Rotating Range Scanner
 void setTarget(Waypoint target)
          Set the target for a path finder
 void setTravelSpeed(float speed)
          Set the travel speed for the pilot.
 void shutDown()
          Shut down the receiver thread
 void startNavigator()
          Start the navigator following a path
 void stop()
          Send a STOP event to the NXT
 void takeReadings()
          Send a TAKE_READINGS event to the NXT
 void travel(float distance)
          Send a travel event to the NXT
 
Methods inherited from class lejos.robotics.mapping.NavigationModel
getMap, getParticles, getPath, getReadings, getRobotPose, getTarget, hasMap, setDebug, setNumReadings, setParticleSet, setRobotPose
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

panel

protected MapApplicationUI panel

closest

protected int closest

connected

protected boolean connected

particleReadings

protected RangeReadings particleReadings

weight

protected float weight

mesh

protected FourWayGridMesh mesh

gridSpace

protected int gridSpace

clearance

protected int clearance

alg

protected AstarSearchAlgorithm alg

nodes

protected java.util.Collection<Node> nodes

start

protected Node start

destination

protected Node destination

pf

protected PathFinder pf

moves

protected java.util.ArrayList<Move> moves

poses

protected java.util.ArrayList<Pose> poses

features

protected java.util.ArrayList<Point> features

waypoints

protected java.util.ArrayList<Waypoint> waypoints

reached

protected Waypoint reached

nxtCommand

protected NXTCommand nxtCommand

voltage

protected float voltage
Constructor Detail

PCNavigationModel

public PCNavigationModel(MapApplicationUI panel)
Create the model and associate the navigation panel with it

Parameters:
panel - the NavigationPanel
Method Detail

setMeshParams

public void setMeshParams(int gridSpace,
                          int clearance)
Set the parameter for the 4-way mesh

Parameters:
gridSpace - the spacing of the mesh
clearance - the clearance from the walls

getMCL

public MCLPoseProvider getMCL()
Get the MCLPoseProvider associated with this model

Returns:
the MCLPoseProvider

setMCL

public void setMCL(MCLPoseProvider mcl)
Set an MCLPOseProvider for this model

Parameters:
mcl - the MCLPoseProvider

getLastMove

public Move getLastMove()
Get the last move made by the robot

Returns:
the Move object

getMoves

public java.util.ArrayList<Move> getMoves()
Get the moves made since the last setPose

Returns:
an ArrayList of Move objects

getFeatures

public java.util.ArrayList<Point> getFeatures()
Get the list of features

Returns:
the features as an array of points

getWaypoints

protected java.util.ArrayList<Waypoint> getWaypoints()
Get the list of waypoints

Returns:
the list of waypoints

getPoses

public java.util.ArrayList<Pose> getPoses()
Get the sequence of poses of the robot from moves sent from the NXT, since the last call of setPose

Returns:
an ArrayList of Pose objects

lcpConnect

public boolean lcpConnect(java.lang.String nxtName)
Make an LCP connection to the NXT

Parameters:
nxtName - the name of the NXT
Returns:
true iff the connection was successful

lcpClose

public void lcpClose()
Close the LCP connection to the NXT


connectAndUpload

public void connectAndUpload(java.lang.String nxtName,
                             java.io.File file)
                      throws java.io.FileNotFoundException
Connect to the NXT, upload a program, and run it

Parameters:
nxtName - the name of the NXT
file - the name of the program file
Throws:
java.io.FileNotFoundException

checkFile

protected boolean checkFile(java.io.File f)
Check that the file exists on the NXT with the right size


setDifferentialPilotParams

public void setDifferentialPilotParams(float wheelDiameter,
                                       float trackWidth,
                                       int leftMotor,
                                       int rightMotor,
                                       boolean reverse)
Set the parameters for a DifferentialPilot, send them to the NXT, and write them to the pilot.props file.

Parameters:
wheelDiameter - the wheel diameter
trackWidth - the track width
leftMotor - the left motor
rightMotor - the right motor
reverse - true iff the driving the motors in reverse drives the pilot forward

setRangeFeatureParams

public void setRangeFeatureParams(float maxDistance,
                                  int delay)
Set the parameter for a Range Feature Detector

Parameters:
maxDistance - the distance from a feature that trifggers detection
delay - the delay between readings in microseconds

setRotatingRangeScannerParams

public void setRotatingRangeScannerParams(int gearRatio,
                                          int headMotor)
Set the patameters for a Rotating Range Scanner

Parameters:
gearRatio - the ratio between motor rotation and head rotation
headMotor - the motor that drives the read (0 = A, 1 =B, 2 = C)

setTravelSpeed

public void setTravelSpeed(float speed)
Set the travel speed for the pilot.

Parameters:
speed - the travel speed

setRotateSpeed

public void setRotateSpeed(float speed)
Set the rotate speed for a pilot

Parameters:
speed - the rotate speed

getRemoteParticles

public void getRemoteParticles()
Send a GET_PARTICLES event to the NXT


findClosest

public void findClosest(float x,
                        float y)
Send a FIND_CLOSEST event to the NXT


addWaypoint

public void addWaypoint(Waypoint wp)
Add a waypoint and send it to the NXT

Parameters:
wp - the waypoint

generateParticles

public void generateParticles()
Generate particles for the MCLPoseProvider and send them to the NXT


connect

public void connect(java.lang.String nxtName)
Connect to the NXT


getNodes

public java.util.Collection<Node> getNodes()
Get the generated node

Returns:
the collection of nodes

isConnected

public boolean isConnected()
Test if a NXT brick is currently connected

Returns:
true iff a NXT brick is connected

loadMap

public LineMap loadMap(java.lang.String mapFileName)

loadMap

public LineMap loadMap(java.lang.String mapFileName,
                       int finder)
Load a line map and send it to the PC

Parameters:
mapFileName - the SVG map file
Returns:
the LineMap

sendMap

public void sendMap()
Send the map to the NXT


setPathFinder

public void setPathFinder(int finder)

goTo

public void goTo(Waypoint wp)
Send a GOTO event to the NXT

Parameters:
wp - the Waypoint to go to

travel

public void travel(float distance)
Send a travel event to the NXT

Parameters:
distance - the distance to travel

rotate

public void rotate(float angle)
Send a ROTATE event to the NXT

Parameters:
angle - the angle to rotate

arc

public void arc(float radius,
                float angle)
Send an ARC event to the NXT

Parameters:
radius - the radius of the arc
angle - the angle to rotate

rotateTo

public void rotateTo(float angle)
Send a ROTATE_TO event to the NXT

Parameters:
angle - the angle to rotate

getPose

public void getPose()
Send a GET_POSE event to the NXT


getEstimatedPose

public void getEstimatedPose()
Send a GET_ESTIMATED_POSE event to the NXT


getRemoteReadings

public void getRemoteReadings()
Send a GET_READINGS event to the NXT


setPose

public void setPose(Pose p)
Send a SET_POSE event to the NXT

Parameters:
p - the robot pose

setTarget

public void setTarget(Waypoint target)
Set the target for a path finder

Overrides:
setTarget in class NavigationModel
Parameters:
target - the target waypoint

stop

public void stop()
Send a STOP event to the NXT


randomMove

public void randomMove()
Send a RANDOM_MOVE event to the NXT


localize

public void localize()
Tell the NXT to keep making random moves until the robot is localized


takeReadings

public void takeReadings()
Send a TAKE_READINGS event to the NXT


sendRandomMoveParams

public void sendRandomMoveParams(float maxDistance,
                                 float clearance)
Send Random Move parameters to the NXT


followPath

public void followPath()
Send a route to the NXT and follow it


startNavigator

public void startNavigator()
Start the navigator following a path


findPath

public void findPath(Waypoint wp)
Send a FIND_PATH event to the NXT


clearPath

public void clearPath()
Send a CLEAR_PATH event to the NXT


sendExit

public void sendExit()
Send an EXITevent to the NXT


calculatePath

public void calculatePath()
Calculate the path with the Node path finder


sendSound

public void sendSound(int code)
Send a system sound


getRemoteBattery

public void getRemoteBattery()
Get the remote battery voltage


shutDown

public void shutDown()
Shut down the receiver thread


clear

public void clear()
Clear all variable data