Package lejos.robotics.pathfinding
Class FourWayGridMesh
- java.lang.Object
-
- lejos.robotics.pathfinding.FourWayGridMesh
-
- All Implemented Interfaces:
NavigationMesh
public class FourWayGridMesh extends java.lang.Object implements NavigationMesh
Generates a grid of nodes. Spacing between the grid nodes and clearance around map geometry can be specified. This set can be generated once at the beginning of a user program, and the same node set can be used for all subsequent navigation.- Author:
- BB
-
-
Constructor Summary
Constructors Constructor Description FourWayGridMesh(LineMap map, float gridSpace, float clearance)Instantiates a grid mesh of nodes which won't interconnect between any map geometry.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intaddNode(Node node, int neighbors)Adds a node to this set and connects it with a number of neighboring nodes.booleanconnect(Node node1, Node node2)Attempts to connect two nodes together by adding them as neighbors.booleandisconnect(Node node1, Node node2)Disconnects two nodes by removing them as neighbors.java.util.Collection<Node>getMesh()Returns a collection of all nodes within this navigation mesh.voidregenerate()Throws away the previous set of nodes and recalculates them all.booleanremoveNode(Node node)Removes a node from the set and removes any existing connections with its neighbors.voidsetClearance(float clearance)Changes the safety zone between all nodes/connections and map geometry.voidsetGridSpacing(float gridSpace)Change the size of each grid square.voidsetMap(LineMap map)Feeds this class a new map.
-
-
-
Constructor Detail
-
FourWayGridMesh
public FourWayGridMesh(LineMap map, float gridSpace, float clearance)
Instantiates a grid mesh of nodes which won't interconnect between any map geometry. Will also keep away the set parameter from map geometry. Grid spacing is adjustable via the constructor.- Parameters:
map- The map containing geometry.gridSpace- The size of each grid square.clearance- The safety zone between all nodes/connections and the map geometry.
-
-
Method Detail
-
getMesh
public java.util.Collection<Node> getMesh()
Description copied from interface:NavigationMeshReturns a collection of all nodes within this navigation mesh.- Specified by:
getMeshin interfaceNavigationMesh- Returns:
- A Collection of Nodes.
-
setGridSpacing
public void setGridSpacing(float gridSpace)
Change the size of each grid square. NOTE: When grid space value is changed, this class does not regenerate the navigation mesh until regenerate() is explicitly called.- Parameters:
gridSpace- The unit size of each grid square.
-
setClearance
public void setClearance(float clearance)
Changes the safety zone between all nodes/connections and map geometry. This leaves a margin of error between potential object collisions and the robot. NOTE: When clearance value is changed, this class does not regenerate the navigation mesh until regenerate() is explicitly called.- Parameters:
clearance- The safety clearance between nodes/connections and map geometry.
-
setMap
public void setMap(LineMap map)
Feeds this class a new map. NOTE: When Map is changed, this class does not regenerate the navigation mesh until regenerate() is explicitly called.- Parameters:
map- The new map data.
-
regenerate
public void regenerate()
Description copied from interface:NavigationMeshThrows away the previous set of nodes and recalculates them all. If any setting were changed, such as the spacing between nodes, then it will recalculate them with the new settings.- Specified by:
regeneratein interfaceNavigationMesh
-
connect
public boolean connect(Node node1, Node node2)
Description copied from interface:NavigationMeshAttempts to connect two nodes together by adding them as neighbors. If map data exists for this NavigationMesh, it will check the map data to see if the connection intersects or comes too close to map geometry. If it does they will not be connected and this method returns false.- Specified by:
connectin interfaceNavigationMesh- Returns:
- Boolean value, true if the nodes were connected successfully, false if they could not connect.
-
disconnect
public boolean disconnect(Node node1, Node node2)
Description copied from interface:NavigationMeshDisconnects two nodes by removing them as neighbors. If they were not previously connected it returns false.- Specified by:
disconnectin interfaceNavigationMesh- Returns:
- Returns false if they were not previously connected.
-
addNode
public int addNode(Node node, int neighbors)
Adds a node to this set and connects it with a number of neighboring nodes. If it is unable to find any neighbors it will return 0. This might occur because the node is outside of the bounded area of the map. Note: The most FourWayGridMesh can connect a node to is four. If you select a number larger than four, a maximum of four neighbors will be connected with the node.- Specified by:
addNodein interfaceNavigationMesh- Parameters:
node- The unconnected node to add to this mesh. Will be connected with others in the set.neighbors- The maximum number of neighbors to attempt to connect with.- Returns:
- the number of neighboring nodes it was able to connect with
-
removeNode
public boolean removeNode(Node node)
Description copied from interface:NavigationMeshRemoves a node from the set and removes any existing connections with its neighbors. Note: There is no guarantee it is disconnecting from only nodes in this mesh. This method will disconnect the node from all the nodes registered as neighbors.- Specified by:
removeNodein interfaceNavigationMesh- Parameters:
node- The node to remove.- Returns:
- Returns true if the node was removed, false if it did not exist in this set.
-
-