# Line Tracing robot when sensors are behind the robot

I am trying to design a robot, a line tracer basically, but the catch is that, instead of the sensors being placed on the front, they are going to be placed on the back.
So I am trying to develop an algorithm, but I haven't had any success so far. The best I can think of is, when a curve comes and the it is sensed by the sensors, then the robot will move back and take the turn.
That is what I can think of.
I tried googling it, but it seems as if no one has thought of this before. So can I get an efficient algorithm?
I use an ATmega 128 microcontroller.

• Drive backwards. Commented Aug 22, 2012 at 2:29
• As a long-time LEGO Mindstorms user and with many line following competitions on my "career" I have just a question: WHY? :-) Commented Aug 22, 2012 at 10:26
• @Ignacio - back wheel steering is inherently unstable. Commented Aug 22, 2012 at 12:15
• @Axeman I am participating in the ROBOCON competition, to be held in Vienam, and my seniors gave me this project to complete. They think this is helpful. Commented Aug 22, 2012 at 15:44
• @Axeman - I love problems like this. Normal line following is pretty boring now. Giving hard constraints like this makes you think outside the box, and find clever solutions for hard problems. Commented Aug 22, 2012 at 16:20

It is certainly possible to do this, but as David Kessner pointed out, it's very difficult to do this with a traditional 2-wheeled robot.

Imagine what happens when the sensor realises that the line is slightly off to one side. Which way should the robot turn? Turn one way, and the sensor is now above the line, but the robot is actually steering away from the line! Turn the other way, and the robot steers towards the line, but the sensor is further from the line. Whatever you do, you lose.

However, if you are building this robot from scratch, then there is a solution. Use omnidirectional wheels!

Using these wheels, and some clever mathematics, you can actually make your robot drive as if the whole of the robot was actually behind the sensor! You'll have to spend some time studying the behaviour of the wheels, and working out the maths, as this is too much to explain here.

To get you started, here is a some cool video of the wheels in action:

• I will be using 4 wheels for this robot and I will be using a PWM also to count the rotations of the front wheels. So I guess this might be easier approach for me. Commented Aug 22, 2012 at 15:47

You haven't seen an algorithm for this before because it's silly! :) That's why dogs have their sensor package up front!

The problem is that by the time you have detected leaving the line, it is too late to correct for it. Further, if your robot is anything like other line-following robots, when you rotate to get back on course the sensors will actually move in the wrong direction-- causing further confusion and sensing issues.

Your "back up and try again" method is on the right track, but not perfect. Let me suggest a couple of things. Keep in mind that what follows is pure speculation. While I have written autonomous vehicle navigation software this might not be 100% right, or even be possible with your hardware.

What your robot needs is a map. Basically, an internal model of the playing field (a.k.a. the floor with a line). It also needs good enough dead-reckoning accuracy to be able to create this map and navigate within it.

Initially the map is empty and as the robot moves around it fills in the map with where it finds the line and where it doesn't. If the robot drives off of the line it will have to back up to get back on it. This maneuver might be a little more than a simple reverse. It could include some spinning or whatever to help relocate the line easier and fill more of the map in.

At some point the map is complete enough to contain the entire line. I assume that the line is one giant loop. The robot can switch modes where it tries to navigate around the course based mostly on the map. It uses the sensors to determine when it deviates from what was expected, and then corrects itself. In this way it can compensate for some slippage of the wheels or inaccuracy in its dead-reckoning.

This type of software is non-trivial, but not impossible. You will need a good amount of RAM to store the map, and your motors/wheels will need some rotary encoders on them. But it can be a fun and rewarding project!

• It will be almost impossible to achieve the level of dead-reckoning accuracy you need for this solution. Commented Aug 22, 2012 at 16:11
• @Rocketmagnet I disagree. Put good quadrature encoders on the wheels. Make the wheels and "floor" nice and non-slip. Drive slowly so you reduce slip further. Of course there are many ways that you can rig it so it is impossible but we're already stacking the deck by making a nice line on the floor-- so we might as well stack the deck further.
– user3624
Commented Aug 22, 2012 at 16:19
• Using a nice camera-based computer-mouse sensor (or two) might improve accuracy even more.
– user3624
Commented Aug 22, 2012 at 16:21
• Having good wheels and floor will help (if he's even allowed to choose the floor), but it won't be enough to maintain accuracy over the whole loop of a track. Computer-mouse sensors are also pretty bad for dead reckoning. I have tried them for exactly this purpose before, and they suck. They're only made to be accurate enough for constant visual feedback. Commented Aug 22, 2012 at 16:26

Another way to approach this problem is to make the sensor move.

As I mentioned above, if the robot steers in the right direction, then the sensor will obviously get moved off the line. OK, so why not mount the sensor on a moving tail and move it back onto the line!

Actually, the best way to do this is to concentrate on the tail. Servo the tail so that the sensor is always held above the line.

Now couple the steering and the tail together. As the tail moves, so do the steering wheels. The robot will steer in the right direction, and the robot won't lose the line.

• I was just about to write an answer based on this idea but instead of the sensor moving, just use more than one sensor in a line (e.g 4 or more) Commented Aug 22, 2012 at 16:30
• To get good response, I think one will need to be able to determine with fairly good linearity the position of the line relative to the back of the vehicle. It might be possible to do that with a fixed optical camera, but I think it might be easier to have a sensor which moves to keep itself centered on the line, and then track the sensor's position. The lag between the actual line position and the sensor's motion may be a little tricky to deal with, but the sensor could probably report reasonably accurately how far off the line it is. Commented Aug 22, 2012 at 17:31
• Note that if the vehicle is supposed to travel only forward, it will be unable to follow very sharp turns, no matter how slowly it's traveling, unless the sensor track extends far enough that when the vehicle is making a very sharp turn the sensor could actually be moving backward. I think given a sufficiently long sensor arm, it should be possible to follow practically any curve, at least at sufficiently slow speed. Commented Aug 22, 2012 at 17:44