November 24, 2024, 01:26:12 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.


Servo Control

Started by mbg_print, October 04, 2011, 12:00:43 PM

Previous topic - Next topic

mbg_print

Hi,
I am trying to use a Prop-1 Micro-controller to control two different props that are driven by a continuous rotation servo and I do not understand how to program the micro-controller, could you please help?

Prop #1

Triggered by a parallex PIC sensor module. On the sensor module parkage it reads Single-bit output, Passive infrared, Detects motion up to 20 feet away. This sensor is tripped when the guests walk past it. It triggers a servo that is attached to a 3/8th inch dowel that is mounted up in the rafters. From the dowel we have a fishing line attached and at the end of the fishing line is a spider. The spider hangs from the dowel in the rafters in the down position until the guests trigger the sensor and then the spider needs to be pulled up into the rafters via the servo attached to the dowel. The 3/8 inch dowel needs to rotate 360 degrees 18 times pause for 60 seconds and then in a reverse direction rotate 360 degrees 18 times to wind up back in it's down starting position awaiting the next set of guests to trigger it all over again.




Prop #2

Again this one is triggered by a PIC Sensor Module. It is a servo that is attached to a 3/8th inch dowel and when it is triggered it will rotate 360 degrees 18 times and then pause 60 seconds and then rotate 360 degrees in the opposite direction 18 times and then stop and wait to be triggered again.

JonnyMac

Are these two different items connected to the Prop-1 controller (via servos), or two Prop-1 controllers running separate tasks?
Jon McPhalen
EFX-TEK Hollywood Office

mbg_print

Hi,
   One prop-1 controller and two different servos functioning independent of each other based on their trigger which is the PIR Sensor. One is a spider which goes up into his hole when triggered and the other is a curtain (lightweight) which when triggered will roll up as specified in my first post. Now if this second prop (the curtain) makes things more complicated I would settle for eliminating the curtain prop and just dealing with the spider. Thanks Melanie

JackMan

mbg_print,
   If my calculations are correct it's gonna take about 21 seconds for a CR servo to do 18 revolutions at full speed. This may not be what you had in mind.

mbg_print

Hi Jack,
   Every little bit helps but my main problem is the overall programming. Jon Williams from the EFX team said he could help with that. Still I never turn down advice. Thanks. Melanie

JackMan

I hear ya, but whoever writes a program for you needs all the details first. If 21 seconds isn't gonna work for what you had in mind then you need to rethink your setup. CR servos max out at about 50 RPM's, (.833 RPS). You may need a larger diameter spool attached to the servo so less than 18 revolutions will do what you're looking for.

mbg_print

Right off the bat, just sitting watching the clock tick away seconds and imagining the prop functioning, 21 seconds sounds long. My gut says half that time, but my way of thinking is once my son gets the programming from Jon we can adjust from there. Widening the dowel has been taken into consideration, as well as shortening the line the spider hangs on starting him up higher. The spider has a buffer zone of a foot for any kind of variances or errors. When we get the servo programmed we will run the spider, see where he ends up and adjust from there. Again, thanks for your input I really do appreciate.

                                                                                      Melanie

JackMan

October 04, 2011, 09:46:29 PM #7 Last Edit: October 04, 2011, 11:00:59 PM by JackMan
I'm sure Jon will have a much better way but give this a try. This wasn't tested but I think  :-\ it will work. The timing is about 10s to get the spider down, 30s hold, 10s back up.

 
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  PIR2            = PIN7                  ' SETUP = DN
SYMBOL  PIR1            = PIN6                  ' SETUP = DN
SYMBOL  Servo2          = 1                     ' servo 2
SYMBOL  Servo1          = 0                     ' servo 1


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

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


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

SYMBOL   timer          = B2
SYMBOL   counter        = W2

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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00111111                              ' set P0-P5 as outputs
FOR counter = 1 TO 1500                       ' about 30s pause for PIR warm-up
  GOSUB Update_Servos
NEXT                                     

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

Main:
   timer = 0                                    ' reset timer


Check_PIR1:
  GOSUB Update_Servos
  IF PIR1 = IsOff THEN Check_PIR2              ' check trigger input
    timer = timer + 20                         ' update timer
  IF timer < 200 THEN Check_PIR1               ' check timer

FOR counter = 1 TO 350
  PULSOUT Servo1, 130                          ' rotate servo 1 CW for about 10s
  PULSOUT Servo2, 150                          ' hold servo 2
  PAUSE 20
NEXT
FOR counter = 1 TO 1500                       ' about 30s pause
  GOSUB Update_Servos
NEXT
FOR counter = 1 TO 350
  PULSOUT Servo1, 170                          ' rotate servo 1 CCW for about 10s
  PULSOUT Servo2, 150                          ' hold servo 2
  PAUSE 20
NEXT
  timer = 0                                    ' reset timer

Check_PIR2:
  GOSUB Update_Servos
  IF PIR2 = IsOff THEN Main                    ' check trigger input
    timer = timer + 20                         ' update timer
  IF timer < 200 THEN Check_PIR2               ' check timer

FOR counter = 1 TO 350
  PULSOUT Servo2, 130                          ' rotate servo 2 CW for about 10s
  PULSOUT Servo1, 150                          ' hold servo 1
  PAUSE 20
NEXT
FOR counter = 1 TO 1500                       ' about 30s pause
  GOSUB Update_Servos
NEXT
FOR counter = 1 TO 350
  PULSOUT Servo2, 170                          ' rotate servo 2 CCW for about 10s
  PULSOUT Servo1, 150                          ' hold servo 1
  PAUSE 20
NEXT

  GOTO Main



Update_Servos:
  PULSOUT Servo1, 150
  PULSOUT Servo2, 150
  PAUSE 20
  RETURN

mbg_print

Wow, thank you very much! We will try to get it into action by tonight or tomorrow. Things work a little on the slow side over here with my work force in school full time and their personal jobs part time.  That is probably why I started back in June. When you work on a new prop for about two weeks and begin to see it come together it is very exciting. Again, thanks so much and I will let you know the outcome as soon as we get it together.

                                                                 Melanie

JackMan

Keep in mind this will only activate one prop at a time. The BS1 code executes line by line so if one of the props has been triggered, that action must complete before the other PIR can be checked. If you need the ability to trigger each prop with a possible overlap then you will need another Prop-1 controller.

JonnyMac

October 04, 2011, 11:13:57 PM #10 Last Edit: October 04, 2011, 11:16:32 PM by JonnyMac
Congratulations! Your first Prop-1, you are new to programming, and you want to do the most difficult thing possible! ;)

So... here it is.  I would suggest that given your newness you will have less frustration buying second Prop-1 and power supply for it but, if you're willing, here's the code that turns the Prop-1 into a dual controller.

The two sections of the code are identical, setup as state machines.  Each servo has a "state": it can be waiting for a trigger (state 0), it can be moving one direction (state 1), it can be idle at the midpoint position (state 2), it can be returning to its starting position (state 3) and, finally, it can be in a hold-off period that prevents re-triggering (state 4).

Everything is time based; you will have to do a bunch of empirical testing to determine the timing for each state.  Not easy, but certainly possible.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger2        = PIN7                  ' SETUP = DN
SYMBOL  Trigger1        = PIN6                  ' SETUP = DN

SYMBOL  Servo2          = 1
SYMBOL  Servo1          = 0


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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0


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

SYMBOL  s1state         = B2                    ' servo 1 program state
SYMBOL  speed1          = B3                    ' servo 1 speed

SYMBOL  s2state         = B4                    ' servo 2 program state
SYMBOL  speed2          = B5                    ' servo 2 speed

SYMBOL  delay           = W3                    ' loop pad (~20ms loop)

SYMBOL  timer1          = W4                    ' servo 1 state timer
SYMBOL  timer2          = W5                    ' servo 2 state timer


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

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00000011                              ' P1..P0 are outputs

  speed1 = 150                                  ' stopped
  speed2 = 150

  s1state = 4                                   ' hold for 30s
  s2state = 4


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

Main:
  PULSOUT Servo1, speed1                        ' refresh servos
  PULSOUT Servo2, speed2
  delay = speed1 + speed2                       ' convert to 0.01ms
  delay = 2000 - delay / 100                    ' back to ms
  PAUSE delay                                   ' finish servo frame

  timer1 = timer1 + 20                          ' update timers
  timer2 = timer2 + 20


Program_1:
  BRANCH s1state, (S1_State0, S1_State1, S1_State2, S1_State3, S1_State4)
  s1state = 0

S1_State0:                                      ' debounce sensor in
  speed1 = 150                                  ' stop motor
  timer1 = timer1 * Trigger1                    ' scan trigger
  IF timer1 < 200 THEN Program_2                ' new input?
    timer1 = 0                                  ' reset timer
    s1state = 1                                 ' set new state
    GOTO Program_2

S1_State1:
  speed1 = 100                                  ' set speed
  IF timer1 < 10000 THEN Program_2              ' run for 10s
    timer1 = 0
    s1state = 2
    GOTO Program_2

S1_State2:
  speed1 = 150                                  ' stop
  IF timer1 < 10000 THEN Program_2              ' hold for 10s
    timer1 = 0
    s1state = 3
    GOTO Program_2

S1_State3:
  speed1 = 200                                  ' set speed
  IF timer1 < 10000 THEN Program_2              ' run for 10s
    timer1 = 0
    s1state = 4
    GOTO Program_2

S1_State4:
  speed1 = 150                                  ' stop
  IF timer1 < 30000 THEN Program_2              ' no re-trigger for 30s
    timer1 = 0
    s1state = 0
    GOTO Program_2


Program_2:
  BRANCH s2state, (S2_State0, S2_State1, S2_State2, S2_State3, S2_State4)
  s2state = 0

S2_State0:
  speed2 = 150
  timer2 = timer2 * Trigger2
  IF timer2 < 200 THEN Main
    timer2 = 0
    s2state = 1
    GOTO Main

S2_State1:
  speed2 = 100
  IF timer2 < 10000 THEN Main
    timer2 = 0
    s2state = 2
    GOTO Main

S2_State2:
  speed2 = 150
  IF timer2 < 10000 THEN Main
    timer2 = 0
    s2state = 3
    GOTO Main

S2_State3:
  speed2 = 200
  IF timer2 < 10000 THEN Main
    timer2 = 0
    s2state = 4
    GOTO Main

S2_State4:
  speed2 = 150
  IF timer2 < 30000 THEN Main
    timer2 = 0
    s2state = 0
    GOTO Main


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


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


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