November 22, 2024, 02:47:58 PM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Another cake help program

Started by Nannuu, October 13, 2008, 10:00:42 AM

Previous topic - Next topic

Nannuu

I'm working on another cake for my daughter, Super Mario Galaxy.  I have a simple program but don't know if this will work.  Here is the gist of it:

1. Goomba moves toward Luigi (standard servo)
2. Luigi spins (continuous servo), Luigi spins while the Goomba is "hit" away
3. Goomba moves away from Luigi fast as if he is hit
4. Repeat

It will just be a little Goomba guy on the end of a servo arm (long arm) and Luigi attached to the center of a cont rotating servo.  I can mess around with the speeds and distance movement once I have the base of the code, just don't know how to start.  It's been so long since I looked at this I can't remember what code does what.

I'm not at home so I can't test what I have so far.  If I don't do this stuff during lunch I tend to not get it done at all.


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Luigi          = 0                     ' Servo1 Pin #
SYMBOL  Goomba         = 1                     ' Servo2 Pin #

' -----[ Constants ]-------------------------------------------------------

SYMBOL  Spin          = 300                    ' Speed of Luigis spin.

' -----[ Variables ]-------------------------------------------------------

SYMBOL  pos            = B2                    ' Goomba servo position

' -----[ Program Code ]----------------------------------------------------

Main:
  PAUSE 10

MoveIn:
  FOR pos = 100 to 200 step 2                    ' Move Goomba in
     PULSOUT Goomba, pos
     PAUSE 20
  NEXT

MoveOutSpin:
  FOR pos = 200 to 100 step 6                    ' Jump Goomba away
     PULSOUT Luigi, Spin                         ' Spin Luigi
     PAUSE 10
     PULSOUT Goomba, pos
  NEXT

  GOTO Main                                      ' Start again

  END

' -----[ Subroutines ]-----------------------------------------------------

JonnyMac

Servos are never as easy as we wish the were; they require constant refreshing (ever 20ms).  That means we have to construct a program that is constantly sending updates to both servos -- like this program. 

' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 13 OCT 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Servo2          = 1
SYMBOL  Servo1          = 0


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0


' -----[ Variables ]-------------------------------------------------------

SYMBOL  state           = B2

SYMBOL  pos             = B3                    ' Luigi position
SYMBOL  speed           = B4                    ' Gumba speed

SYMBOL  timer           = W5


' -----[ Initialization ]--------------------------------------------------

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000011                              ' set outputs

  pos = 100
  speed = 125


' -----[ Program Code ]----------------------------------------------------

Main:
  PULSOUT Servo1, pos
  PULSOUT Servo2, speed
  PAUSE 17
  timer = timer + 1                             ' timer is 20ms units

  BRANCH state, (Luigi_Home, Advance, Retreat)
  state = 0

Luigi_Home:
  IF timer < 100 THEN Main                      ' hold 2 seconds
    state = 1
    GOTO Main

Advance:
  pos = pos + 1                                 ' creep forward
  IF pos < 200 THEN Main
    state = 2
    GOTO Main

Retreat:
  pos = pos - 4                                 ' pull back fast
  IF pos > 100 THEN Main
    pos = 100
    state = 0
    timer = 0
    GOTO Main


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

Nannuu

Thank you for the effort, though I still can't get it to do what I want.  The regular servo is great.  The continuous servo never stops.  I played around with it a lot now (so much that it looks nothing like your original) but all I can do is get the cont servo to slightly slow down for what seems like .01" second or the opposite and move for .01" second.  I'm trying to get Servo2 to spin only while Servo1 retreats and stop while it advances.  Maybe I'm just using the wrong equipment for this problem?

JonnyMac

Get a continuous rotation servo from Parallax; it has an adjustment screw so that you can set the stop point (should be at 150).  You can change the spinners speed from 150 (stopped) to spinning at the end of the loop that causes Luigi to move in -- I think this will give you the affect you want.
Jon McPhalen
EFX-TEK Hollywood Office

Nannuu

I do have a Parallax, it actually stops at 154.  But I think my issue is that I have a short movement on the servo back and forth so it doesn't leave enough time for the other to spin.  I don't think you can really control the speed of the servo right?  Just the position.  If I can slow the back and forth servo way down I think I'd have more time.  My new plan is to work up a mechanical version of this somehow.

JonnyMac

Continuous rotation servos have a degree of speed control but they draw a lot of current on the slow speed end so be careful. Experiment with different values to see if you can find something that works -- the value will probably be pretty close to your stop point.
Jon McPhalen
EFX-TEK Hollywood Office