Wall Follower Project

I purchased my 3pi with two Pololu Forum.docx (428 KB)GP2Y0A21YKOF sensors. I followed the instructions on this link: pololu.com/docs/pdf/0J26/3p … llower.pdf very thoroughly, but when I try to run the 3Pi it just goes around in circles. The program to download in on the link also. I have a few pictures I would to show you of what I have going on. Could someone give me a few pointers on how to get my 3pi working correctly. The sensors are reading as if it were against the wall trying to get away.

Hello.

It looks like you also emailed us, and the email contained more pictures. In those pictures, it looks like you forgot to remove the ADC7 and PC5 jumpers as noted in “Construction” section of the wall follower sample project document. Could you try running your robot again after removing those jumpers? If removing those jumpers does not solve the problem, could you post a video showing what the sensors are reading when you run the 3pi?

By the way, it looks like the pins on your sensor cables do not have housings. You should add housings or insulate them so they do not accidentally short and cause problems.

- Grant

I removed the jumper and I continue to have the same problems. Also, I realized I had one of the white wires in the wrong position. I corrected that, but it still does not work. What kind of housing do you recommend. I thought the plug ins would work fine. Sorry I am new at this kind of stuff. I really want to learn though. Is the analog distance sensors fine, I don’t need to use a different kind of sensor do I?

I see what you saying. I removed all of the jumpers and it works. You are awesome. I may have more questions about the program later. I need to do a little more research though.

I am glad that you were able to get the sample project working for you. It looks like you are using the3-pin female JST PH-style cable with male pins for 0.1" Housings. If that is the case, you can simply insert the male crimp pins into our 0.1" crimp connector housings to insulate them.

- Grant

Ok I have the sensors reading at least, however the 3pi does not follow the wall properly. I let it go and seems to go away from the wall. It will stop and turn when it sees an obstacle like it should. How can I get it to follow the wall properly. I know the sensors are reading or at least I see numbers jumping around . When I put my hand close to either sensor It seems work. Keep in mind I am using Sharp GP2Y0A21YK0 Analog distance sensor 10-80cm. Do I need to adjust anything since I am using a different sensor.Really these sensors just read from a further distance. The code is shown below:

[code]/*

*/

// The 3pi include file must be at the beginning of any program that
// uses the Pololu AVR library and 3pi.
#include <pololu/3pi.h>

// This include file allows data to be stored in program space. The
// ATmegaxx8 has 16x more flash than RAM, so large
// pieces of static data should be stored in program space.
#include <avr/pgmspace.h>

// Introductory messages. The “PROGMEM” identifier causes the data to
// go into program space.
const char welcome_line1[] PROGMEM = " Pololu";
const char welcome_line2[] PROGMEM = “3\xf7 Robot”;
const char name_line1[] PROGMEM = “Wall”;
const char name_line2[] PROGMEM = “Follower”;

// A couple of simple tunes, stored in program space.
const char welcome[] PROGMEM = “>g32>>c32”;
const char go[] PROGMEM = “L16 cdegreg4”;

// Refresh the LCD display every tenth of a second.
const int display_interval_ms = 100;

#define MS_ELAPSED_IS(n) (get_ms() % n == 0)
#define TIME_TO_DISPLAY (MS_ELAPSED_IS(display_interval_ms))

void initialize()
{
// Set PC5 as an input with internal pull-up disabled
DDRC &= ~(1<< PORTC5);
PORTC &= ~(1<< PORTC5);

    // Play welcome music and display a message
    print_from_program_space(welcome_line1);
    lcd_goto_xy(0,1);
    print_from_program_space(welcome_line2);
    play_from_program_space(welcome);
    delay_ms(1000);

    clear();
    print_from_program_space(name_line1);
    lcd_goto_xy(0,1);
    print_from_program_space(name_line2);
    delay_ms(1000);

    // Display battery voltage and wait for button press
    while(!button_is_pressed(BUTTON_B))
    {
            clear();
            print_long(read_battery_millivolts());
            print("mV");
            lcd_goto_xy(0,1);
            print("Press B");
            delay_ms(100);
    }

    // Always wait for the button to be released so that 3pi doesn't
    // start moving until your hand is away from it.
    wait_for_button_release(BUTTON_B);
    clear();
    print("Go!");

    // Play music and wait for it to finish before we start driving.
    play_from_program_space(go);
    while(is_playing());

}

void back_up()
{
if (TIME_TO_DISPLAY)
{
clear();
lcd_goto_xy(0,0);
print(“Backing”);
lcd_goto_xy(0,1);
print(“Up”);
}

    // Back up slightly to the left
    set_motors(-50,-90);

}

void turn_in_place() {
if (TIME_TO_DISPLAY) {
clear();
lcd_goto_xy(0,0);
print(“Front”);
lcd_goto_xy(0,1);
print(“Obstacle”);
}

    // Turn to the right in place
    set_motors(50, -50);

}

int main()
{
// set up the 3pi
initialize();

    int last_proximity    = 0;
    const int base_speed  = 200;
    const int set_point   = 100;

    // This is the "main loop" - it will run forever.
    while(1)
    {
            // In case it gets stuck: for 1 second every 15 seconds back up
            if (get_ms() % 15000 > 14000) {
                    back_up();
                    continue;
            }

            // If something is directly in front turn to the right in place
            int front_proximity = analog_read(5);
            if (front_proximity > 200) {
                    turn_in_place();
                    continue;
            }

            int proximity = analog_read(7); // 0 (far away) - 650 (close)
            int proportional = proximity - set_point;
            int derivative = proximity - last_proximity;

            // Proportional-Derivative Control Signal
            int pd = proportional / 3 + derivative * 20;

            int left_set  = base_speed + pd;
            int right_set = base_speed - pd;

            set_motors(left_set, right_set);

            if (TIME_TO_DISPLAY) {
                    clear();
                    lcd_goto_xy(0,0);
                    print_long(proximity);

                    lcd_goto_xy(5,0);
                    print_long(pd);

                    lcd_goto_xy(0,1);
                    print_long(left_set);
                    lcd_goto_xy(4,1);
                    print_long(right_set);
            }

            last_proximity = proximity; // remember last proximity for derivative
    }

    // This part of the code is never reached.  A robot should
    // never reach the end of its program, or unpredictable behavior
    // will result as random code starts getting executed.  If you
    // really want to stop all actions at some point, set your motors
    // to 0,0 and run the following command to loop forever:
    //
    // while(1);

}[/code]

Hi.

What do you mean by “the 3pi does not follow the wall properly”? Could you post a video of how your robot behaves?

Also, you mentioned that you are using a “GP2Y0A21YK0 Analog distance sensor 10-80cm”, which you said is different from the sensors in the tutorial, but it seems like they might be the same Sharp GP2Y0A21YK0F Analog Distance Sensor 10-80cm used in the tutorial.

-Claire

I posted the video- youtu.be/ShV02JPY16o It does not follow the wall at all; you will see. The obstacle sensor works. The following sensor works (or reads numbers when I put my hand up to it), but the robot doesn’t follow the wall properly. The robot seems to go to fast. I’m sure you will be able to help me out with my problems.

I figured out what I was doing wrong. I had a weight on the back to keep the 3pi from tilting forward. This was causing one of the wheels to not have the correct traction. I have it working I think. Now I am trying to download a different program on the 3pi and I keep getting an error that shows (Failed to open \.\COM4. Error 0x2.) Could you tell me how to correct this. It seems to be one thing after another. I know this is simple to fix I just don’t know how to choose COM1.

I figured out the error too. It is amazing what restarting your computer can do.

I am glad you got the wall follower program working and figured out your COM port error. Thanks for letting us know what you did.

-Claire