Title: Walking the Grid: Robotics in CS 2
1Walking the Grid Robotics in CS 2
- LMICSE Workshop
- June 14 - 17, 2005
- Alma College
2Presentation Outline
- Overall Goals
- Occupancy Grids
- Project 1 Random Walk (and Back)
- Rotation sensors and the RotationNavigator Class
- Project 2 Path Planning using Wavefront
Propagation - Propagation using a modification of breadth-first
search - Traveling the path
3Overall Goals
- Create engaging projects that
- introduce AI themes in a CS 2
- robotic systems
- graph searching algorithms (without the graph)
- occupancy grids and path planning
- use basic user defined data structures like
stacks and queues - reinforce material learned in CS 1 such as
- classes and inheritance
- two dimensional arrays
- exceptions
4Occupancy Grid
- An occupancy grid is a discrete grid that
represents the environment. - Each cell in the grid is either
- occupied (part of an obstacle).
- empty (part of free space).
- If any part of an obstacle is in a grid cell,
then the cell is considered to be occupied. - Grids representing real world environments are
often fine grained (cells representing 4 to 6
square area).
5Occupancy Grid Example
A 14 by 8 grid Black figures are the
obstacles Gray areas are the occupied cells
6Limitations of Occupancy Grids
- If it is fine grained, an occupancy grid will use
large amounts of memory. - a problem on the RCX!
- If course grained, environmental features may be
lost. - e.g., narrow passageways.
- Despite these limitations, occupancy grids are
often used in mobile robot path planning
solutions.
7Project 1 Random Walk (and Back)
- The robot goes for a random walk on an occupancy
grid containing no obstacles. - Then retraces its steps back to the starting
point. - Basic strategy is to use a stack
- At each point the robot can move one cell north,
east, south, or west (if legal). - On the way out, push the directions traveled onto
the stack. - On the way back, pop the stack and travel in the
opposite direction.
8Project 1 Overall Architecture
9Project 1 The Grid Walker Class
- The heart of this project is the definition of
the GridWalker class. It contains - a constructor that specifies the grid size and
the starting point of the robot - a goto method that takes as a parameter a grid
location and causes the robot to move from its
current grid position to that location - convenience methods north, east, south, and west
that move the robot one cell in the respective
direction.
10Project 1 Grid Walker Implementation
- Three possibilities
- Implement the grid walker directly, using timing
for distances and turns - this is like our CS 1 lab 10 Navigation
- but timing depends on battery strength so is
inexact over time - Use one of the two LeJOS navigation classes
- Timed Navigator same problem as above
- Rotation Navigator this is the ticket!
- but requires two rotation sensors
11The Rotation Sensor
- Thread an axle through the sensor
- One revolution of the axle is 16 clicks of the
sensor - So it can measure a changes in angle of 22.5
degrees - Which is why it is also known as an angle sensor
A Rotation Sensor
12Mounting Rotation Sensors
- Here is a solution that is a simple modification
of the basic Roverbot
Rear View of Roverbot Chassis
13The LeJOS Rotation Navigator Class (1)
- Rotation Navigator implements the Navigator
interface - Important Navigator methods
- public void gotoPoint(float x, float y)
- Rotates the RCX robot towards the target point
and moves the required distance - public float getX()
- Returns the current x coordinate of the RCX.
- public float getY()
- Returns the current y coordinate of the RCX
- public float getAngle()
- Returns the current angle the RCX robot is facing
14The LeJOS Rotation Navigator Class (2)
- assumes differential drive, with rotation sensors
(encoders) for the left and right sides in sensor
ports 1 and 3. - the constructor
public RotationNavigator(float wheelDia, float
AxleWidth, float ratio)
the ratio of encoder revolutions to axle
revolutions
the distance from the center of the left wheel to
the center of the right wheel
the diameter of a wheel
15Project 1 Grid Walker Implementation (1)
- Define GridWalker to extend RotationNavigator
- Have instance variables for
- initial grid position (x and y)
- current grid position (x and y)
- the number of columns and rows in the grid
- the size of a grid cell (assume it is square)
- The constructor is passed this information, plus
the information the RotationNavigator class needs
16Project 1 Grid Walker Implementation (2)
import josx.robotics. public class GridWalker
extends RotationNavigator int currentH,
currentV, initialH, initialV int dimensionH,
dimensionV int cellSize public
GridWalker(int cH, int cV, int dimH, int dimV,
int cSize,
float wDia, float wBase, float ratio)
super(wDia, wBase, ratio) initialH
currentH cH initialV currentV cV
dimensionH dimH dimensionV
dimV cellSize cSize
The beginning of the class definition and the
constructor
17Project 1 Grid Walker Implementation (3)
- In implementing the the goto method
- need to check that the new location is legal
(i.e., in the grid) - if not, throw an exception (optional, but a good
opportunity to reinforce the use of programmer
defined exceptions) - need to convert grid locations to absolute
locations - RotationNavigator assumes the robot starts at 0,0
with an orientation of 0 degrees - GridWalker allows the programmer to specify any
cell as the starting location, but still assumes
orientation of 0 degrees
18Project 1 Grid Walker Implementation (4)
public void gotoCell(int h, int v) throws
OutOfBoundsException if (h gt 0 h lt
dimensionH v gt 0 v lt dimensionV)
gotoPoint(gridHToPoint(h), gridVToPoint(v))
currentH h currentV
v else throw new
OutOfBoundsException(h, v)
private float gridVToPoint(int n)
return (n - initialV) cellSize
private float gridHToPoint(int n)
return (n - initialH) cellSize
The goto method and helpers
19Project 1 Remaining Details
- Add the north, east, south, and west methods to
the GridWalker class - Implement a stack of ints (or Objects - Integers)
- Then in the main class
- First (random walk)
- Generate a series of random ints between 0 and 3
- Travel in that direction and push on stack
- Second (travel back)
- Pop the stack until empty, traveling in the
appropriate direction
20Project 2Path Planning using Wavefront
Propagation
- Design a program that will move the robot from a
starting point to a goal point - using the shortest possible path
- navigating around obstacles
- assume the robot can only move north, east,
south, or west (Manhattan movement). - Use the GridWalker class for movement
- So main problem is finding the path
21Wavefront Propagation (1)
- Image a wave moving out from the goal cell.
- When the wave first reaches each of the other
cells, it is labeled with the time it took to
reach it. - The wave moves Manhattan
22Wavefront Propagation (2)
- If there are occupied cells, the wavefront simply
flows around them.
23Wavefront Propagation (3)
- The path from any cell to the goal is implicit in
the grid labels - Until at the goal, move to an adjacent cell with
a smaller label - There may be many different equal length paths
24Wavefront Propagation Implementation (1)
- The basic approach for propagating the wave is
breath-first - Initialize the value of empty locations in the
grid to -1, occupied locations to high values - Implement a queue of points
- Initialize the queue with the goal point, and set
that points value to 0 - Then while the queue is not empty
- Dequeue a point (the current point)
- For each of its four neighbors
- If the neighbor value is -1
- Set its value to the value of the current point
1 - Enqueue that point
25Wavefront Propagation Implementation (2)
public void setValues (Queue q, int grid)
q.enqueue(new Point (goalX, goalY)) gridgoal
YgoalX 0 while ( !q.empty() ) Point
currentP (Point) q.dequeue() int x
currentP.x int y currentP.y int newX
x1 // go east if (newX lt gridy.length
gridynewX -1) gridynewX
gridyx 1 q.enqueue(new
Point(newX,y)) // also need cases
for the other three directions
The base method for setting the wavefront values
26Wavefront Propagation Implementation (3)
public void travel () int curX startX int
curY startY while (curtX ! goalX curY
! goalY) int curValue gridcurYcurX
if (curX1 lt grid0.length
gridcurYcurX1 curValue - 1) curX
curX 1 // move to the east else //
cases for the other three directions robot.goto
(curY, curX)
Making the robot move to the goal location
27Hands-on Activities
- Implement the GridWalker class and do a random
walk - Complete Project 1 - Random Walk and Back
- Complete Project 2 - Wavefront Propagation
- (well, maybe when you get back home!)