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

wheel encoder

B.ASHISHB.ASHISH Posts: 28
edited 2012-08-21 21:20 in General Discussion
This is my wheel encoder code in Spin language to display the readings of the Left and Right wheels of the Stingray Robot of Parallax with Propeller Microcontroller .But I'm receiving only zeros for both the wheels.Please suggest me the correct code for me to get the count value of the wheel encoders for both the wheels.
[CODE/]
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
clock = 80_000_000
ms1= clock/1_000
XBEE_RX = 16
XBEE_TX = 17
XBEE_Baud =115200




OBJ
sr :"SRMotorcontrol"
CTR :"MyEncoder"
XB :"FullDuplexSerial"
'pst:"Parallax Serial Terminal"
PUB main |RCount,LCount
sr.Start
CTR.Start
XB.Start(XBEE_RX,XBEE_TX,%0000,XBEE_Baud)
'pst.Start(115200)
CTR.Start
sr.SetRamp(10)
repeat
sr.MoveForward(30)
waitcnt(clkfreq+cnt)
RCount:=RCount-CTR.RCount
LCount:=LCount-CTR.LCount
XB.Dec(RCount)
'pst.Dec(RCount)
XB.tx(9)
'pst.NewLine
XB.Dec(LCount)
'pst.Dec(LCount)
XB.tx(13)
'pst.NewLine

[/code]
[CODE/] for "MY ENCODER"
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000


'===========< IO Pin assignments >==========
EncdrLA = 16 'Left Wheel Encoder Phase A
EncdrLB = 19 'Left Wheel Encoder Phase B
EncdrRA = 2 'Right Wheel Encoder Phase A
EncdrRB = 3 'Right Wheel Encoder Phase B
Mask = |<EncdrLA + |<EncdrLB + |<EncdrRA + |<EncdrRB


'========< Counter mode values >=========
ModeNegEdge = %01110 << 26 'Negative Edge Detector for wheel encoders
ModeNCO = %00100 << 26 'Bit 31 overflow goes to pin for servo drives


PUB Start
' Left wheel counter
Frqa := 1
Phsa := 0
Ctra := ModeNegEdge + EncdrLA
' Right Wheel counter
Frqb := 1
Phsb := 0
Ctrb := ModeNegEdge + EncdrRA


PUB CZero
Phsa := 0
Phsb := 0


PUB RCount
return Phsb

PUB LCount

Return Ctrb
[/code]

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-20 10:07
    Your leading code tags needs to be [noparse][code], not [code/][/noparse].

    -Phil
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2012-08-20 10:14
    - What encoders are you using for the robot? Are they the US-Digital encoders that stick on the back or are you using something else?

    - How do you have the encoders connected to the Stringray?

    - What Propeller board are you using? Is it an MRS1 that came with the original full kit?

    If you search for Stingray in the robotics forum you will turn up some examples of people using encoders with the robot and example code. Most people are using pins 8,9,10,11 for the encoders.
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2012-08-21 13:26
    Here is a link to a thread with code samples with the encoders on pins 8,9,10, and 11. I followed that on my Stingray robot and it works great so far.

    http://forums.parallax.com/showthrea...ingray+encoder

    Robert
  • B.ASHISHB.ASHISH Posts: 28
    edited 2012-08-21 21:20
    Thank You Sir,the code is running well.It was only a mistake of the pin connections.
    The values displayed in the Parallax Serial Terminal for the Left and right wheels are somewhat like
    RIGHT LEFT
    24678 254367
    32145 349766
    33679 32146
    45673 46789
    and so on ,and the values continue in this manner as long as the wheels rotate.
    Sir ,can you please tell us exactly what these Count values exactly are,so that we can proceed further.
Sign In or Register to comment.