November 23, 2024, 09:25:32 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


newbi three axis skull question

Started by screamingskull, May 13, 2009, 02:57:25 PM

Previous topic - Next topic

screamingskull

Hey everyone.  I've finally got around to using my prop 1 that I've had sitting around here for three or four years but now I've run into some problems.  I saw a couple other threads on here with the code for a skull but it didn't really work for me.  This will eventually be part or a zomby prop so I want it to move slowly.  I did find one code that worked great for the head tilt left and right but I have no idea how to basically duplicate this code for the other two servos.  I tried but then the speed got all wacky.  Any help would be greatly appreciated.  Here's the code I used for the head tilt left and right and basically want to duplicate it for the other two nice small movements

' =========================================================================
'
'   File...... Servo_Move.BS1
'   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...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  Servo           = 0


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

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

SYMBOL  Baud            = OT2400


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

SYMBOL  pos             = B2                    ' position, 100 to 200
SYMBOL  tix             = B3                    ' for servo timing


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00000001                              ' make servo an output


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

Main:
  pos = 100
  tix = 50                                      ' hold one second
  GOSUB Servo_Hold

  FOR pos = 100 TO 200 STEP 1
    tix = 1                                     ' increase to slow movement
    GOSUB Servo_Hold
  NEXT

  pos = 200
  tix = 50
  GOSUB Servo_Hold

  FOR pos = 200 TO 100 STEP -1                  ' rotate back
    tix = 0                                     ' increase to slow movement
    GOSUB Servo_Hold
  NEXT

  GOTO Main


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

' Refresh servo and hold for "tix" units
' -- 1 tix = 0.02 seconds; 50 tix = 1 second

Servo_Hold:
  PULSOUT Servo, pos
  PAUSE 19
  IF tix = 0 THEN Hold_Done
    tix = tix - 1
    GOTO Servo_Hold

Hold_Done:
  RETURN


JonnyMac

3-Axis skull programming is probably not the best place for a "newbie" (God, I hate that moniker....) to start -- fair warning.  The nature of the Prop-1 and the way servos needs to be refreshed dictates a somewhat sophisticated programming style.  The program below illustrates this by putting servo moves into a table.  Run the program as-is and then experiment with it.

' =========================================================================
'
'   File...... Servo_Blender_x3.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 25 MAR 2007
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Starts an external audio player and then controls the simultaneous
' movement of three servos.  Servo movement is stored in a EEPROM table
' with a "repeats" value for timing at the positions specified in the
' record (last byte).  The timing is approximately:
'
' 20 milliseconds x (repeats + 1)
'
' Mimimum: ~0.02 seconds
' Maximum: ~5.12 seconds
'
' Note that servos are mechanical and move slowly, so very small "repeats"
' values may expire before the servos reaches their target positions.


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


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

SYMBOL  Audio           = 7
SYMBOL  Trigger         = PIN6

SYMBOL  Servo3          = 2
SYMBOL  Servo2          = 1
SYMBOL  Servo1          = 0


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  RecLen          = 4                     ' record length (servos + 1)


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

SYMBOL  record          = B0                    ' movement record
SYMBOL  pntr            = B1                    ' table byte pointer
SYMBOL  s1Pos           = B2                    ' servo 1 position
SYMBOL  s2Pos           = B3                    ' servo 2 position
SYMBOL  s3Pos           = B4                    ' servo 3 position
SYMBOL  repeats         = B5                    ' repeats for record data


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

Reset:
  DIRS = %10000111                              ' make servo pins outputs

  record = 0
  GOSUB Get_Servo_Pos                           ' get "home" positions


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

Main:
  GOSUB Refresh_Servos
  IF Trigger = IsOff THEN Main                  ' wait for trigger

Start_Audio:
  PULSOUT Audio, 2500                           ' 25 ms blip on audio pin

Reset_Moves:
  record = 1                                    ' point to start of moves

Move_Engine:
  GOSUB Get_Servo_Pos                           ' get servo positions
  IF s1Pos = 255 THEN Reset                     ' abort if at end

Servo_Hold:
  GOSUB Refresh_Servos
  IF repeats = 0 THEN New_Record                ' time left at this pos?
    repeats = repeats - 1                       ' yes, decrement timing
    GOTO Servo_Hold

New_Record:
  record = record + 1
  GOTO Move_Engine


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

' Call with "record" set to table line to read

Get_Servo_Pos:
  pntr = record * RecLen                        ' point into table
  READ pntr, s1Pos                              ' read servo 1 value
  pntr = pntr + 1                               ' point to servo 2
  READ pntr, s2Pos
  pntr = pntr + 1
  READ pntr, s3Pos
  pntr = pntr + 1                               ' point to repeats
  READ pntr, repeats                            ' read repeats
  RETURN

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

' Update servos -- time consumed is 18 to 21 ms

Refresh_Servos:
  PULSOUT Servo1, s1Pos
  PULSOUT Servo2, s2Pos
  PULSOUT Servo3, s3Pos
  PAUSE 15                                      ' pad for loop timing
  RETURN


' -----[ EEPROM Data ]-----------------------------------------------------

' Note on servo movement timing:
'
' Time spent on each record is 20 ms x (repeats + 1) so a repeats value
' of 0 is ~20 ms and a repeats value of 255 (max) is ~5.1 sseconds at that
' position.
'
'         s1   s2   s3   rpts

Move_Table:
  EEPROM (150, 150, 150, 255)                   ' home position
  EEPROM (100, 100, 150,  50)                   ' start of movements
  EEPROM (100, 200, 150,  50)
  EEPROM (200, 200, 150,  50)
  EEPROM (200, 100, 150,  50)
  EEPROM (255, 150, 150, 255)                   ' end here

  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)
  EEPROM (150, 150, 150, 255)                   ' last possible move
  EEPROM (255, 255, 255, 255)                   ' define end of table
Jon McPhalen
EFX-TEK Hollywood Office

screamingskull

Thanks,  I actually got that other code working the way I wanted it to... now to just build and add a trigger to it.... sometime