November 23, 2024, 07:14:29 AM

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.


Inconsistent servo movement

Started by james, March 31, 2009, 01:13:55 PM

Previous topic - Next topic

james

I have used VB6 and the SSCII servo controller to run my props over the past few years.  I am now converting to the Prop-1 and I'm having some problems with controlling the servo.

The program controls two props. The first "jumper" is activate by a switch and controls a pneumatic valve, which works just fine.

The second "werewolf" is a 180 degree servo that I would like to have a starting position of about 20 degrees and upon a switch being activated move the servo position to 180 degrees for about 5 seconds then return to the starting position.

In running the attach code the servo moves to different starting and ending positions each time it is activated.

Can someone help me?  Thanks


'-----I/O------------------------------------------------------------------

SYMBOL  WerewolfSw     = PIN6
SYMBOL  JumperSw         = PIN7
SYMBOL  Jumper              = 0
SYMBOL  Werewolf         = 1

'-----Constants------------------------------------------------------------

SYMBOL  IsOn       = 1
SYMBOL  IsOff                = 0

SYMBOL  Yes               = 1
SYMBOL  No               = 0

SYMBOL  startPos        = 110
SYMBOL  endPos         = 200


'-----Variables------------------------------------------------------------

SYMBOL  wereFlag       = BIT0
SYMBOL  jumperFlag   = BIT1
SYMBOL  wereTmr       = B0
SYMBOL  jumperTmr     = B1


'-----Initialzation--------------------------------------------------------

Setup:
  DIRS                   = %00000011
  wereTmr             = 0
  wereFlag              = No
  jumperTmr           = 0
  jumperFlag             = No
  PULSOUT Werewolf, startPos


'-----Program--------------------------------------------------------------

Main:
  PAUSE 20
  IF JumperSw = IsOff THEN JCont1
  HIGH Jumper
  jumperFlag = Yes

JCont1:
  IF jumperFlag = No THEN JCont2
  jumperTmr = jumperTmr + 1

JCont2:
  IF jumperTmr <> 150 THEN WCont1
  LOW Jumper
  jumperTmr = 0
  jumperFlag = No

WCont1:
  IF WerewolfSw = IsOff THEN WCont2
  PULSOUT Werewolf, endPos
  wereFlag = Yes

WCont2:
  IF wereFlag = No THEN WCont3
  wereTmr = wereTmr + 1

WCont3:
  IF wereFlag = No THEN Main
  IF wereTmr < 240 THEN Main
  PULSOUT Werewolf, startPos
  wereTmr = 0
  wereFlag = No
  GOSUB Main

JonnyMac

You might consider using the SSCII with the Prop-1; servos require updating every 20ms which the SSCII is doing for you and the Prop-1 is not -- not the way you have it programmed, anyway.   Managing servos can be very tricky with a small, single-threaded controller like the Prop-1 which is why I tend to favor the Prop-SX with a servo VP (virtual peripherial -- like a software version of the SSCII running in the same board).

I'm exhausted from TransWorld and my brain is not quite rested -- let me look at your code a while and show you how you might approach it using just the Prop-1; it probably won't be too hard since you're only running two servos.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Okay, give this a try.  Since you're clearly an experienced programmer you'll appreciate the use of the BRANCH instruction for managing the states of your two outputs.

' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2009 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  JumperSw        = PIN7                  ' SETUP = DN
SYMBOL  WolfSw          = PIN6                  ' SETUP = DN
SYMBOL  Werewolf        = 1
SYMBOL  Jumper          = PIN0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  StartPos        = 110
SYMBOL  EndPos          = 200


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

SYMBOL  flags           = B0
SYMBOL   wolfStart      =  BIT6
SYMBOL   jumpStart      =  BIT7

SYMBOL  wolfState       = B1                    ' werewolf state
SYMBOL  jumpState       = B2                    ' jumper state
SYMBOL  pos             = B3                    ' servo position
SYMBOL  idx             = B4                    ' loop controller

SYMBOL  wolfTmr         = W4
SYMBOL  jumpTmr         = W5


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

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

  pos = StartPos

  wolfState = 0                                 ' at rest
  jumpState = 0                                 ' at rest


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

Main:
  PULSOUT Werewolf, pos                         ' update servo


Debounce:
  flags = %11000000                             ' assume pressed
  FOR idx = 1 TO 19                             ' debounce, ~18ms delay
    flags = flags & PINS                        ' scan inputs
    PAUSE 2
  NEXT

  wolfTmr = wolfTmr + 20                        ' update timers
  jumpTmr = jumpTmr + 20


Run_Jumper:
  BRANCH jumpState, (Jump_0, Jump_1, Jump_2)
  jumpState = 0                                 ' fix busted state

Jump_0:                                         ' rest state
  IF jumpStart = No THEN Jumper_Exit            ' abort if no input
    Jumper = IsOn
    jumpState = 1                               ' switch to on state
    jumpTmr = 0                                 ' start timer
    GOTO Jumper_Exit

Jump_1:                                         ' on timing (3s)
  IF jumpTmr < 3000 THEN Jumper_Exit
    Jumper = IsOff
    jumpState = 2                               ' switch to delay state
    jumpTmr = 0                                 ' restart timer
    GOTO Jumper_Exit

Jump_2:                                         ' re-trigger delay (10s)
  IF jumpTmr < 10000 THEN Jumper_Exit
    jumpState = 0                               ' back to rest state


Jumper_Exit:
  ' exit point for modular code


Run_Wolf:
  BRANCH wolfState, (Wolf_0, Wolf_1, Wolf_2)
  wolfState = 0

Wolf_0:
  IF wolfStart = No THEN Wolf_Exit
    pos = EndPos
    wolfState = 1
    wolfTmr = 0
    GOTO Wolf_Exit

Wolf_1:
  IF wolfTmr < 5000 THEN Wolf_Exit
    pos = StartPos
    wolfState = 2
    wolfTmr = 0
    GOTO Wolf_Exit

Wolf_2:
  IF wolfTmr < 10000 THEN Wolf_Exit
    wolfState = 0

Wolf_Exit:
  ' exit point for modular code


  GOTO Main


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


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


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

james

Thanks Jon.  That solved the problem.