November 22, 2024, 07:01:02 PM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


BOE Question

Started by chsom, April 14, 2008, 08:17:53 PM

Previous topic - Next topic

chsom

We are using a BOE trying to make a monster with a tongue that goes out, picks up an item and comes back. I am using the following coding. The problem is that it goes out just fine. Coming back the servos that are sliding the tongue back start jumping rather than coming back smoothly. Thus the back motion takes a long period of time.

Can anyone look at the coding and tell me if there is a mistake in it?

Thanks
DFly

' {$STAMP BS2}
' {$PBASIC 2.5}

counter VAR Byte
BACKCOUNTER VAR Byte
TOP CON 650
BOTTOM CON 850
DO
DEBUG ? IN3
IF IN3 = 1 THEN
FOR counter = 1 TO 255
  PULSOUT 12,850
  PULSOUT 13,650
  PULSOUT 14,725
  DEBUG ? counter
  PAUSE 15
NEXT
FOR counter = 255 TO 1
  PULSOUT 12,850
  PULSOUT 13,650
  PULSOUT 14,725
  DEBUG ? counter
  PAUSE 20
NEXT
FOR counter = 1 TO 112
  PULSOUT 12,850
  PULSOUT 13,650
  PULSOUT 14,725
  DEBUG ? counter
  PAUSE 20
NEXT
FOR BACKCOUNTER = 1 TO 255
  PULSOUT 12,TOP
  PULSOUT 13,BOTTOM
  PULSOUT 14,850
  DEBUG ? BACKCOUNTER
  PAUSE 20
NEXT
FOR BACKCOUNTER = 255 TO 1
  PULSOUT 12,TOP
  PULSOUT 13,BOTTOM
  PULSOUT 14,850
  DEBUG ? BACKCOUNTER
  PAUSE 20
NEXT
FOR BACKCOUNTER = 1 TO 255
  PULSOUT 12,TOP
  PULSOUT 13,BOTTOM
  PULSOUT 14,850
  DEBUG ? BACKCOUNTER
  PAUSE 20
NEXT
FOR BACKCOUNTER = 255 TO 1
  PULSOUT 12,TOP
  PULSOUT 13,BOTTOM
  PULSOUT 14,850
  DEBUG ? BACKCOUNTER
  PAUSE 20
NEXT
FOR BACKCOUNTER = 1 TO 200
  PULSOUT 12,TOP
  PULSOUT 13,BOTTOM
  PULSOUT 14,850
  DEBUG ? BACKCOUNTER
  PAUSE 20
NEXT
END
ELSEIF  IN3 = 0 THEN
  PULSOUT 12,750
  PULSOUT 13,750
  PULSOUT 14,750
  PAUSE 20
ENDIF
LOOP

JonnyMac

April 15, 2008, 10:48:24 AM #1 Last Edit: April 15, 2008, 10:52:23 AM by JonnyMac
As a reminder, the BoE is a Parallax product and you really should give them a crack at support....

Things that can create issues:
-- enormous DO-LOOP constructs (for more than a few lines, use a Label at the top and a GOTO at the bottom)
-- using internal pin names and numbers (e.g. IN1) in the body of your code is not a good idea; use the PIN definition
-- DEBUG is a form of serial transmission and will consume time in your loops -- don't use it in your servo refresh loops.
    * especially when you want the values to change every 20 ms (you can't keep up with that on your PC)
-- you should call a subroutine to refresh your servos; this will save code space

You might want to download my book, StampWorks, from Parallax as it will teach you professional programming skills for the BS2.
Jon McPhalen
EFX-TEK Hollywood Office