LMICSE: Lego Mindstorms in Computer Science Education

Site Map | Contact Us
Project Overview | Staff | Grant Information
Short Workshops | Primary Workshops
CS 1 | Data Str. & Algo. | Prog. Languages | Architecture | Intelligent Sys. | Operating Sys. | Net-centric
Ada | C | C++ | Java | Lisp

Turtle Navigation with Non-Perfect World Knowledge

small logo

Part 2: Seeing What is Around Us and then Making Decisions on Where to Move

In this lab, we will modify our code from Part 1, so that they bot cannot see the entire world. Instead, the bot will only be able to see the cells surrounding the current cell, as well as cells that the bot has already seen.

Prerequisite Knowledge

This lab requires that you have the knowledge of how to create a world

Materials

To complete this lab, you will need the basic Turtle robot without any bumpers or sensors.

Possible structure with a 'home' for the sentry tasks.

Looking Around Us

Now that we've gotten the bot to move around in a world where it knows the location of all the obstacles, lets get it to navigate through a world where it doesn't know the world it's in, except for the 8 cells around it, and the path that it has already taken. To do this, we'll need to declare another world object, and initialize the same goal cell and starting cell as the perfect-knowledge world (the world we created in the previous part). We don't want to declare any obstacles in this new world (lets call it realworld) because we assume (or for what the bot can see) the world is empty. So now that we've got realworld declared with a goal, we need to start deciding where to move the bot. This requires that we write a method that looks at all the cells around our current cell to check for walls.

Building Obstacles

Next, we'll need to build obstacles in our realworld according to the cell checks that our bot has made and re-populate to adjust for all of the obstacles that we may have found in the legoworld. If there is a wall, we should call the build obstacle method in our realworld .

realworld.buildObstacle(x,y,x,y);

Moving Accordingly

Once we've updated all of the cells around our current cell and repopulated the world, it's time to decide which cell we should move to next. This can be done very simply by calling the nextcell method that we wrote in Part 1 from our realworld object. Remember that once we tell our bot to move to the next cell, we not only need to update our current position in the realworld, but also in the legoworld so that the next time we look at the cells around our current cell, we are looking at the current cell.

The animation to the right shows how one might move through the world. The top half is our realworld, a world where we can only see the cells immediately around our current cell. The bottom half is our legoworld, the perfect-knowledge world.

  • yellow cells = the cells around our current cell that we can see
  • dark blue cells = our current cell
  • light blue cells = cells that we've previously visited
  • black cells = obstacle cells
  • green cell = our goal cell once we've reached it
Notice how the values in the cells get updated every time the realworld finds an obstacle.

Conclusion

In this lab, you learned the following:

  • How to write a method and call it from another method.
  • How to generate random numbers.
  • How to manipulate those numbers to fit specifications.
  • How to make the Turtle play beeps.