Lego wire guided robot in PBP


Closed Thread
Results 1 to 4 of 4
  1. #1

    Default Lego wire guided robot in PBP

    Hi

    I build the following wire guidance sensor succesfully

    http://www.philohome.com/sensors/fil...uide-schem.gif

    I removed the D4,D5,D6 part and put a pullup to +5V on the collector of Q1

    This is giving me a fine DC voltage according to the position of the wire to the 2 coils

    So far so good

    Can anyone help me to convert the following LEGO NQC code to PBP ?

    I use HPWM 1 for the left motor, HPWM 2 for the right motor on a 16F877
    ADCin 0 has the wire guidance sensor as input (which is the wire sensor)
    Portd.0 is the fwd/rev Hbridge control for motor 1 (Left)
    Portd.1 is the fwd/rev Hbridge control for motor 2 (Right)
    Here is the NQC code


    #define Wireguide SENSOR_1
    #define Left OUT_A
    #define Right OUT_C
    #define Threshold1 10
    #define Threshold2 25
    #define HysterVal 8

    task main ()
    {
    int Offset;
    int Hyster=0;
    int Diff;

    // The wire guidance sensor is used
    // the same way as a Light sensor
    SetSensor (Wireguide, SENSOR_LIGHT);

    // Reads the "no-signal" response. The sensor must
    // be centered on the wire, or generator be off
    Offset = Wireguide;
    Wait(200);

    // Starts driving

    OnFwd (Left+Right);
    while (true)
    {
    // Reads error signal
    Diff = Wireguide - Offset - Hyster;
    if (Diff >= -Threshold1 && Diff <= Threshold1)
    // We are centered - drive straight
    {
    OnFwd (Left+Right);
    Hyster = 0;
    }
    else
    {
    if (Diff > 0)
    {
    if(Diff > Threshold2)
    // Very off center: turn in place
    {
    OnRev (Left);
    OnFwd (Right);
    }
    else
    {
    // Slightly off center: shallow turn
    Off (Left);
    OnFwd (Right);
    }
    // sets hysteresis to avoid over-turning
    Hyster = HysterVal;
    }
    else
    {
    if(Diff < -Threshold2)
    {
    OnRev (Right);
    OnFwd (Left);
    }
    else
    {
    Off (Right);
    OnFwd (Left);
    }
    Hyster = -HysterVal;
    }
    }
    }
    }
    Attached Images Attached Images  

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: Lego wire guided robot in PBP

    This page might be of help to someone:

    http://www.philohome.com/sensors/filoguide.htm

    Robert

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: Lego wire guided robot in PBP

    Hi Robert, yess this is the side where the sensor and lego code is comming from

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: Lego wire guided robot in PBP

    ADCin 0 has the wire guidance sensor as input (which is the wire sensor)
    There are 2 sensor signals on the schematic, but the code only checks one ADC signal?

    Does defining it as a sensor light do something special?

    Why not just ignore that code, use a PBP ADC sample program and use 2 channels (left and right sensor). Check the level of the signals and react accordingly?

    Robert

Similar Threads

  1. Line following robot
    By samsoltats in forum mel PIC BASIC
    Replies: 2
    Last Post: - 3rd September 2010, 16:01
  2. Line following robot
    By azmax100 in forum Schematics
    Replies: 0
    Last Post: - 1st July 2009, 15:55
  3. robot program
    By ajak in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th January 2008, 16:36
  4. how? 2 wire lcd with pbp?
    By nimonia in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 20th October 2005, 07:41
  5. IR for robot on 16F877A
    By Samuel in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 9th April 2005, 20:57

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts