Shop OBEX P1 Docs P2 Docs Learn Events
Wheel Encoder Calibration trouble — Parallax Forums

Wheel Encoder Calibration trouble

Jo B.Jo B. Posts: 5
edited 2009-10-15 14:58 in BASIC Stamp
Hi, I'm trying to use the calibration program for the digital encoder kit from Parallax as found here: www.parallax.com/StoreSearchResults/tabid/768/txtSearch/encoder/List/0/SortField/4/ProductID/80/Default.aspx The first three stages of the program work fine but once I try to use the fourth stage it doesn't move the motors. I put in debug commands in the code to determine where it gets caught up and it gets caught up just after it enters the "DoMove" function. Actually... it won't let me even put a debug command in that function because the BASIC Stamp program doesn't let me and instead throws up an error saying "Data occupies same location as program"

I'm not sure what this means or how to fix it. Has anybody else had this problem or have suggestions on how to fix it? Here's the .bs2 file.

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-10-13 16:36
    "...but once I try to use the fourth stage it doesn't move the motors."

    There's a five-second delay built into the start so that you can stand back and stand still during the process. Also, you need to have a photoresistor wired into your circuit, per the instructions, so that the program can "see" light as the Boe-Bot rotates. Without that, you may experience further delays.

    Actually... it won't let me even put a debug command in that function because the BASIC Stamp program doesn't let me and instead throws up an error saying "Data occupies same location as program"

    That's because the program is near capacity, as-is. By adding the DEBUG instruction, you're forcing the program (which builds from the end of memory backwards) into the DATA area. If you remove your other DEBUG statements, you will make more room for the one you want to add.

    -Phil
  • Jo B.Jo B. Posts: 5
    edited 2009-10-13 17:59
    Hi Phil, thanks for your quick response. I'm rather new to the BASIC Stamp and was unaware exactly what the size capacity of these programs are. Thanks for pointing that out.

    As for the fourth stage of the calibration program, I've tried the photoresistor circuit with both the 0.1uF and 0.01uF capacitors and ensured that all the ports are the same as those specified in the program and waited over 30 seconds for the bot to move but it doesn't move. I've tried it under varying lighting conditions as well and still nothing. When I go back to the 1 stage of the calibration where it dumps the data collected the calibration data corresponding to the photoresistors, it outputs something like 221, 232, 8307, 0, 0, 0, 0, 0 for the first line and then everything line after that is all 65558 values or something like that ((which I think is the max value for Word) not at home w/ my bot so I can't check atm)

    I'm not sure, but I think it might be getting the first 2 values fine and then getting stuck in on the last one, hence the larger value, and it doesn't get any new ones because it doesn't move.

    Not quite sure why it'd stop, I've checked all the circuits to ensure they're the same as in the diagrams provided and that the ports all sync up with those in the program.

    I'm gonna put some debug stuff in the DoMove code and also where the program takes the photoresistor readings to see if there's an issue there as well, but other than that I'm out of ideas.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-10-13 19:19
    You might want to double check your photoresistor circuit for a loose connection. When you see zeroes or 65535, it means that it's waiting a very long time for the phototransistor to drain the cap.

    -Phil
  • Jo B.Jo B. Posts: 5
    edited 2009-10-14 02:48
    Okay, so I'm back at home now and I've been moving the debug statements and I've found that the program gets stuck in the "do while" loop and repeats it over and over again.

    DO WHILE (Counts(RIGHT) OR Counts(LEFT))
        DEBUG "ONE LOOP RUN", CR
        'Get new encoder state for each wheel.
        'If it's changed, decrement that wheel's Count.
    
        FOR Side = RIGHT TO LEFT
          New(Side) = INS.LOWBIT(Sense + Side)
          IF (New(Side) <> Prev(Side) AND Counts(Side)) THEN
            Prev(Side) = New(Side)
            Counts(Side) = Counts(Side) - 1
          ENDIF
        NEXT
    
        'For each wheel decide whether and how much to pulse its servo.
    
        FOR Side = RIGHT TO LEFT
          Opp = ~ Side
          IF (Counts(Side) AND Counts(Side) * Dist(Opp) + (Dist(Side)) >= Counts(Opp) * Dist(Side) + (Dist(Opp) >> 1)) THEN
            Pulse = (Veloc MIN 3) MAX ((Counts(Side) MIN Counts(Opp)) MAX ((Dist(Side) - Counts(Side)) MIN (Dist(Opp) - Counts(Opp))) << 1 MIN 3)
            READ Side << 1 + (Dir(Side) ^ Side) << 4 + (Pulse * Dist(Side) / (Dist(Side) MIN Dist(Opp)) + 1 MAX 15), Pulse
            PULSOUT Motor + Side, NULL - ((Dir(Side) ^ Opp << 1 - 1) * Pulse)
          ENDIF
        NEXT
    
        'Pause between pulses.
    
        PAUSE 5
      LOOP
    



    I've also determined that it always sends the motors to pulse out at 750 and so that's why the motors don't move (this is due to the Pulse variable being = to 0). If I manually move the motors it exits the "do while" loop and takes the next photoresistor readings.

    After deconstruction the values of the arguments that go into the declaration of Pulse, it looks like the first part seems to be causing the error because the value of it is zero and thus makes the rest of it zero all the time. (Veloc was declared immediately before entering the DoMove function to = 1) However, changing the MIN 3 to MIN 1 changed the value of that argument but Pulse is still = 0.

    Pulse = (Veloc MIN 3) MAX ((Counts(Side) MIN Counts(Opp)) MAX ((Dist(Side) - Counts(Side)) MIN (Dist(Opp) - Counts(Opp))) << 1 MIN 3)
    



    Gonna deconstruct it further once I finish some assignment.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-10-14 03:01
    Did you do the velocity calibration first? If the EEPROM velocity calibration values are zero, this is the kind of behavior one would expect.

    -Phil
  • Jo B.Jo B. Posts: 5
    edited 2009-10-14 03:58
    Yes, I did the velocity calibration first. I don't see the data from it referenced at any point in the code for the stage involving the photoresistors though. As far as I can tell, the stage 4 (photoresistor stuff) code is completely independent of the velocity calibration data.

    I'm actually not sure how I'm supposed to use the calibration data once I've got it anyway. The guide just says to copy/paste the output into programs later on. The data outputted looks like this:

    Copy and paste these DATA statements into your BASIC Stamp programs:
    DATA @0, 7,9,11,13,16,17,19,21
    DATA 24,26,28,31,36,40,48,61
    DATA 3,5,7,9,11,13,15,17
    DATA 20,22,25,28,31,35,40,49
    DATA 7,9,11,13,15,17,19,21
    DATA 23,26,28,30,33,37,41,49
    DATA 3,5,7,9,11,13,15,17
    DATA 20,23,25,28,31,36,42,53
    



    Then the photoresistor data comes after that.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-10-14 06:50
    The calibration data is used in DoMove here:

    ...
        FOR Side = RIGHT TO LEFT
          Opp = ~ Side
          IF (Counts(Side) AND Counts(Side) * Dist(Opp) + (Dist(Side)) >= Counts(Opp) * Dist(Side) + (Dist(Opp) >> 1)) THEN
            Pulse = (Veloc MIN 3) MAX ((Counts(Side) MIN Counts(Opp)) MAX ((Dist(Side) - Counts(Side)) MIN (Dist(Opp) - Counts(Opp))) << 1 MIN 3)
            [b]READ Side << 1 + (Dir(Side) ^ Side) << 4 + (Pulse * Dist(Side) / (Dist(Side) MIN Dist(Opp)) + 1 MAX 15), Pulse[/b]
            PULSOUT Motor + Side, NULL - ((Dir(Side) ^ Opp << 1 - 1) * Pulse)
          ENDIF
        NEXT
    ...
    
    
    


    -Phil
  • Jo B.Jo B. Posts: 5
    edited 2009-10-15 03:56
    Dang, totally missed that.

    So after looking through the code extensively it turns out that the data that I collected during the velocity calibration was actually telling it not to move. After using the provided example calibration output data I was able to use the fourth stage to get proper angle calibration data.

    After that I fine tuned the constants outputted by Calibrate_All.exe and the Wheel_Motion.bs2 ran pretty nicely.

    I'm currently looking for ways to increase the value for the pulses sent to the motor that don't compromise the accuracy. (one way I tried was just to multiply the amount that's subtracted from NULL by 9 (because then the final value sent to the motor is below 650 and just at 850 for the other, thus making both go at max speed and having no variance between the two)) I did it that way because I'm not really sure why/what is going on in the determination of a motor pulse value.

    Anyway, I've got it running, I just need to make it run at a decent speed now. Thanks for your help Phil.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-10-15 14:58
    Hey Jo,

    'Glad you got it running!

    -Phil
Sign In or Register to comment.