Shop OBEX P1 Docs P2 Docs Learn Events
digital encoder — Parallax Forums

digital encoder

Ben DamonBen Damon Posts: 42
edited 2005-01-21 21:47 in BASIC Stamp
hey to all.· I've got encoders on my boe-bot and can't get them to work.· The boe-bot just goes straight forward.· So like the booklet said that came with it, i guess the left encoder is messed up.· Because i'm new and haven't even finished the book that came with the robot, (Robotics with the Boe-Bot) i'm at a lost confused.gif to know what to do to figure out what's wrong.·

Here is the program that I tried:
' Star_Pattern.bs2
·
' {$STAMP BS2}
' {$PBASIC 2.5}
·
'Program to traverse a 5-pointed star.· Straight sections are about 25" long.
'Angle of each turn is 144-degrees.· Use it to test the encoders.· If the left on
'fails to funtion, the Boe-Bot will just contnue going in a straight line
'without stopping.· If the right one fails, it will continue to curcle in the turn.
'Ideally, it will come to rest at the point and direction in which it started.
'But it's uncalibrated, so that's somewhat unlikely!
·
'
[noparse][[/noparse]Constants]

·
RIGHT····CON 0·············· 'Constants defining direction subscripts.
LEFT······ CON 1
·
SenseR·· PIN 7················· 'Righthand encoder·input.
SenseL·· PIN 11················'Lefthand encoder input.· (MUST be SenseR = 1.)
·
MotorR·· PIN 12··············· 'Righthand motor outpt.
MotorL·· PIN 13················'Lefthand motor output.· (must be MotorR = 1.)
·
Sense···· CON SenseR··· ·'Base address for encoders.
Motor···· CON MotorR·· ·'Base address for motors.
·
'
Variables

·
Prev····· VAR Bit(2)············· ·'Previous readings from encoders.
New····· VAR Bit(2)············· 'Current readings from encoders.
Side····· VAR Bit·················· 'Side index (LEFT or RIGHT)
·
Counter· VAR Word(2)····· 'Pulse counters for encoders.
i······· VAR Byte··················· 'FOR/NEXT index
·
'
Program begins here

·
PAUSE 1000
FREQOUT 4, 2000, 2000
FOR i = 1 TO 5
· Counter(LEFT) = 0
· DO WHILE (Counter(LEFT) < 50)
··· PULSOUT MotorL, 810
··· PULSOUT MotorR, 650
··· GOSUB Update
··· PAUSE 20
· LOOP
· PAUSE 500
· Counter(RIGHT) = 0
· DO WHILE (Counter(RIGHT) < 20)
··· PULSOUT MotorR, 650
··· GOSUB Update
··· PAUSE 20
· LOOP
· PAUSE 500
NEXT
END
·
'
Subroutines

·
Update:························ ··'Update pulse counts from the encoders.
································· 'Just call it often enought to catch all the
································· 'changes.
· FOR Side = RIGHT TO LEFT······································ 'For both encoders...
··· New(Side) = INS.LOWBIT(Sense + Side)·············· ·'Read new encoder calue.
··· IF (New(Side) ^ Prev(Side)) THEN·························· ·'Different from last value?
····· Prev(Side) = New(Side)·········································· · '· Yes: Update with new value.
····· Counter(Side) = Counter(Side) + 1························· '······ Update counter.
··· ENDIF
· NEXT
· RETURN


The highlighted parts are prgraming i'm not familiar with.· If someone is willing I could do with a commentary on the whole thing.
(in blue is Pin 7 origanly pin 10.· my right encoder is conected to pin 7 though)

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ben Damon


And may God Bless America!
·

Comments

  • edited 2005-01-20 16:39
    To make the program work correctly, the right encoder needs to be connectec to P10, and that pin directive for Pin 7 needs to be changed back to Pin 10.· Look up DO WHILE in the index of Robotics with the Boe-Bot. To figure out what's going on in that subroutine, click Help in the BASIC Stamp Editor, and look up VAR. Read the section on "multipart variables called arrays" and try the programs. Then, go back and take a second look at the code.

    Post Edited (Andy Lindsay (Parallax)) : 1/20/2005 4:54:30 PM GMT
  • Ben DamonBen Damon Posts: 42
    edited 2005-01-21 21:47
    thanks. what i'm most confused about in the programing is the double variables, such as:

    Counter(side)
    New(side)
    Counter(left)
    Counter(right)

    thanks again

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ben Damon


    And may God Bless America!
    ·
Sign In or Register to comment.