Prerequisite Knowledge
This lab requires that you have the knowledge of how to create a world
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.
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.
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.
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);
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.
|
![]() |
In this lab, you learned the following: