Tunnels and mazes
Invent Logo

You've discovered an underground system of tunnels under the planet surface, but they are too dangerous to explore! Let's get our robot to explore instead.

Tunnels and mazes
The start of the tunnel

Rather than build physical barriers, we've created a printed mat that looks like the tunnels, where the black lines represent the tunnels, so you'll be using the line sensor module ...

The start of the tunnel
The first challenge

Place your robot where the red arrow is at 'C'. Because your robot turns around the point in between the two wheels, you'll want to start with the center of the wheels aligned with the start of this line, and the robot pointed up in the direction of the arrow shown.

Your code should go forward until it 'sees' the first turn, and then turn around until it finds the track. It should then go forward again until the next turn and repeat the process. The challenge is to reach point 'B'! We've then gone into the middle of the tunnel network.

If you think you can do this with no help, go for it! If not, read on for a couple of helpful tips ...

The first challenge
Tips 1

To help you with this challenge, you might like to know that the distance between junctions in the maze is about 6cm.

Also, the distance between the center of the robot wheels (where it turns) and the line sensor module is less than this (about 5cm). So this means if you move about 1cm forward, your line sensor should be about at where the turn is but it will still be over the black line.

To find out if the tunnel continues beyond the junction, you have to move about another 1cm forward (so 2cm forward in total) ...

Tips 1
Tips 2

We've now only moved 2cm forward in total, but we can now check the line sensor which will tell us if the tunnel continues or not ...

... but to turn around, we want to keep going another 4cm (so we've travelled the full 6cm length of the first part of the tunnel), before the wheels are centered on the next position for the turn ...

Tips 2
Tips 3

We've now travelled a full 6cm - but we've already determined that there's no tunnel ahead. so if we spin around clockwise 90 degrees now, we should be exactly at the right place to be pointing down the next part of the tunnel ...

Tips 3
Tips 4

We've now spun around 90 degrees.

If we repeat this process again (moving forward 2cm, checking for a track, and then going another 4cm forward and spinning whatever direction we want if we need to), then we can navigate the whole maze!

To do this challenge (going from 'C' to 'B'), you should just need to do clockwise turns when you reach the end of a tunnel.

Tips 4
The second challenge

Your next challenge is to go from 'A' to 'C' to escape the tunnels. As before, if you know how you might do it, go for it!

If you need some tips, read on ...

The second challenge
Tips 1

A good algorithm for a simple maze is to:

  • Go forward if you can
  • If you can't, turn in the same direction every time (left, for example)

This is sometimes called the 'wall hugger' algorithm and will always get you to another exit or return you to the one that you entered.

Read on if you want one more tip ...

Tips 1
Tips 2

It should be quite easy for our robot to know what options it has available at each junction ...

  • First we'll go forward 2cm and see if the tunnel continues forward as we've done previously
  • Then we'll go forward another 4cm so our wheels are positioned at the junction to turn around
  • Then we can spin around 90 degrees one way to see if there's a tunnel in that direction
  • Then we spin back 90 degrees, and continue going an additional 90 degrees back to check the other way

Hint: if your robot starts going a bit wonky and doesn't go straight up/down/left/right, rather than instead of always turning a fixed 90 degrees, you might want to turn until you detect a line. If you're clever you can still work out where the tunnels are and adjust for previous turns that might not have been perfect.

Tips 2
Mega Maze

You now have to navigate the Mega Maze! Your challenge is to always escape from the maze, wherever your robot starts from.

Hint: You should be able to use a similar 'wall hugging' algorithm from the last challenge for this one as well. Test it out but see if you can speed up your robot so that it exits from the maze more quickly!

Mega Maze