Putting robotics at your service™

Free shipping on orders over $200

BRAT Servo offset program

Print view Share :
Previous topicNext topic

Page 1 of 1 [ 3 posts ]

Novice ( offline )
Posts: 52
Posted: 2008-06-02 10:19 
I've been trying to use the program here:
http://www.lynxmotion.com/images/files/bratosf.bas
but as I do not have an ATOM pro but instead a BS2 i rewrote it in this way:
Code:
' {$STAMP BS2}
' {$PBASIC 2.5}
righthip   CON 10                '| Servo Offset Finder        |'
rightknee   CON 8               '|    Written by James Frye    |'
rightankle   CON 7                '|                  |'
lefthip      CON 6                '| Use this program TO find     |'
leftknee   CON 5                '| the servo offsets FOR your    |'
leftankle   CON 4                '| Lynxmotion BRAT using an Atom Pro|'
                        '| AND a Bot Board!          |'
righthip_start CON 0              '|                  |'
rightknee_start CON 0              '+----------------------------------+'
rightankle_start CON 0               '|        How TO use      |'
lefthip_start CON 0               '|                  |'
leftknee_start CON 0               '| Press A TO decrease the servo   |'
leftankle_start CON 0               '|  offset by 5us          |'
                         '|                  |'
rhip  VAR Word                '| Press C TO increase the servo  |'
rknee  VAR Word                '|  offset by 5us          |'
rankle  VAR Word                '|                  |'
lhip  VAR Word                '| Press B TO change which servo is |'
lknee  VAR Word                '|  being manipulated, AND TO send  |'
lankle  VAR Word                '|  DATA back TO the terminal    |'
                         '|                  |'
rhip  = ((righthip_start / 24) + 750)    '| The servos are changed in this   |'
rknee  = ((rightknee_start / 24) + 750)    '|  order              |'
rankle  = ((rightankle_start / 24) + 750)     '|                  |'
lhip  = ((lefthip_start / 24) + 750)      '| Right Hip -> Right Knee -> Right  |'
lknee  = ((leftknee_start / 24) + 750)    '|    ^            Ankle  |'
lankle  = ((leftankle_start / 24) + 750)    '|    |            |  |'
                        '|    |            v  |'
 currentServo VAR Byte              '|    Send <- Left <- Left <- Left|'
 currentServo = 1                '|    DATA  Ankle  Knee   Hip  |'
                        '+----------------------------------+'
'BUTTON init
buttonA VAR Bit
buttonB VAR Bit
buttonC VAR Bit

prevA VAR Bit
prevB VAR Bit
prevC VAR Bit
INPUT 12
INPUT 13
INPUT 14

main:

 GOSUB pulsemove

 prevA = buttonA
 prevB = buttonB
 prevC = buttonC

 buttonA = IN12
 buttonB = IN13
 buttonC = IN14

 IF (buttonA = 0) AND (prevA = 1) THEN      'A wasn't already pressed the last time

  GOSUB decreaseOffset

  GOTO main
 ENDIF

 IF (buttonB = 0) AND (prevB = 1) THEN


  currentServo = currentServo + 1
  IF(currentServo = 7) THEN

      LOW 13

  ENDIF
  GOTO main
 ENDIF


 IF (buttonC = 0) AND (prevC = 1)  THEN


  GOSUB increaseOffset

  GOTO main
 ENDIF

GOTO main
increaseOffset:

 IF(currentServo = 1) AND (rhip < 800) THEN
  rhip = rhip + 5


  ELSEIF(currentServo = 2) AND (rknee < 800) THEN
   rknee = rknee + 5

   ELSEIF(currentServo = 3) AND (rankle < 800)THEN
    rankle = rankle + 5

    ELSEIF(currentServo = 4) AND (lhip < 800) THEN
     lhip = lhip + 5

     ELSEIF(currentServo = 5) AND (lknee < 800)   THEN
      lknee = lknee + 5

      ELSEIF(currentServo = 6) AND (lankle < 800)     THEN
       lankle = lankle + 5

       ELSE

 ENDIF
RETURN
   decreaseOffset:

 IF(currentServo = 1) AND (rhip > 700) THEN
  rhip = rhip - 5

  ELSEIF(currentServo = 2) AND (rknee > 700) THEN
   rknee = rknee - 5

   ELSEIF(currentServo = 3) AND (rankle > 700)THEN
    rankle = rankle - 5

    ELSEIF(currentServo = 4) AND (lhip > 700)  THEN
     lhip = lhip - 5

     ELSEIF(currentServo = 5) AND (lknee > 700)    THEN
      lknee = lknee - 5

      ELSEIF(currentServo = 6) AND (lankle > 700)      THEN
       lankle = lankle - 5

       ELSE

 ENDIF
RETURN
pulsemove:
 PULSOUT leftankle, (lankle)
 PULSOUT leftknee, (lknee)
 PULSOUT lefthip, (lhip)

 PULSOUT rightankle, (rankle)
 PULSOUT rightknee, (rknee)
 PULSOUT righthip, (rhip)
 PAUSE 20

RETURN


waitloop:

 GOSUB pulsemove

 buttonB = IN13

 IF (buttonB = 0) AND (prevB = 1) THEN
   currentServo = 1

   GOTO main
 ENDIF

 prevB = buttonB

GOTO waitloop

I left out the sound and the final output for simplicity.

For some reason, when I run the code, it first calls pulsemove with each var=750 and the brat starts barely moving, as if the servo motors aren't strong enough to move it at all- it never can execute the other code because the first call to pulsemove is never completed. Also, there is a noticeable jerking. I have a 422, is this because the motor is too weak?


User avatar
Guru ( offline )
Posts: 9257
Posted: 2008-06-02 12:34 
This program was written for the Atom Pro to take advantage of it's HSERVO (hardware servo pulse generating system.) Although it also used the pulsout command for the Atom Pro. Problem is the BS2 doesn't have HSERVO, and even the pulsout command uses different values for the resolution. Not an easy conversion for me on a Monday. :(

_________________
Jim Frye, the Robot Guy
http://www.lynxmotion.com
I've always tried to do my best...


Novice ( offline )
Posts: 52
Posted: 2008-06-02 14:05 
I think I'm gonna get an ATOM, it'd save a lot of work.


 

All times are UTC - 5 hours [ DST ]. It is currently 2014-10-23 05:21
Feedback Form
Feedback Form