Close

Follow Me, I Say!

A project log for Tote

Affordable spider robot

dehipudeʃhipu 07/30/2015 at 19:340 Comments

I didn't have much time to work on Tote this week, but since the sensors arrived, I will at least finish the "follow me" log.

This time the sensors I got GP2Y0A60SZLF Pololu modules, which are specified to work from 2.7V. Hacks like the previous two attempts will sometimes work, but as you can see, often not, and you shouldn't rely on them.

This sensor works beautifully though. Here's my testing rig:

And here are the results:

DistanceReading
5020
4568
40122
35174
30243
25317
20423
15597
10900
51020

As you can see, they don't repeat and use pretty much all the scale from 0 to 1023. Perfect.

Now, let's just modify our program a little, using the new values for the readings:

void sharp_loop() {
    int distance = 0;
    for (unsigned char i=0; i<10; ++i) {
        distance += analogRead(A4);
    }
    distance /= 10;
    if (distance > 700) {
        creep_dx = 0;
        creep_dy = -1;
        creep_rotation = 0;
        beep(352, 100);
    } else if (distance > 520) {
        creep_dx = 0;
        creep_dy = 0;
        creep_rotation = 0;
    } else if (distance > 260) {
        creep_dx = 0;
        creep_dy = 1;
        creep_rotation = 0;
        beep(704, 100);
    } else {
        creep_dx = 0;
        creep_dy = 0;
        creep_rotation = PI/45;
        beep(1408, 100);
    }
}
And here we go:

There still can be a lot of improvements. Instead of rotating in one direction, the robot could first just rotate its body left and right to see if the target is still there. I could use some timeouts between switching into the "search" mode, so that it doesn't switch back and forth constantly. The speed could be adjusted depending on the actual distance, etc. I will leave those as homework, though.

Discussions