November 22, 2024, 01:31:15 AM

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.


My elevator simulator

Started by GOT, July 07, 2008, 09:46:04 PM

Previous topic - Next topic

GOT

You replied to my post in a Halloween forum with the following:

If you'll explain (in detail) what you want your program to do, we'll write the code for you to get started. Please post in the Prop-2 section of our forums: forums.efx-tek.com
I've been programming BASIC Stamps a long time and have a few tricks up my sleeve....

Jon Williams
EFX-TEK

Remember, you offered...

Here is part of what I want to do.  Actually, if you could get me started, I think I could take the ball and run with it.

THE RESULT:  This is a light panel for my elevator simulator.  The kids will see the diamond-shaped lighted panel through some frosted glass so it will be out of focus.  This panel will be about three feet above the frosted glass but I want it to appear about twenty feet up.  I will use two servos moving sliding panels to make the diamond grow larger then lower the entire assembly down just a few inches from the frosted glass.  This will give the appearance of the elevator rising up to the light panel.  When the elevator drops (in simulation only), I will raise the panel up about three feet, then use the servos to make the diamond grow smaller (turning off the LED rings as they are covered up) until just the center LED is visible.  I will then slowly dim the LED to finish the decent into darkness.  There will be a light tree inside the elevator counting off the floors.  The elevator goes up for 12 seconds, pauses for 4 seconds, then goes down for 40 seconds.

Connections (My suggestions only):
p18: 1st floor indicator light which is originally on.  I would like to use this as a trigger.  I flip a physical switch to turn off the light and start the program.
p1: light tree (a 555 timer and decade counter used to light the floor indicators)
p2: center LED light
p3: inner ring of 4 LED lights
p4: outer ring of 4 LED lights
p5: runs both servos (branch with a Y-connector)
p6: motor (forward)
p7: motor (reverse)

Of course I would have to play with the timing.  If you could give me a skeleton program, I would be very grateful.  Now, I plan on doing much more than this (I will probably tax the power supply) which includes another servo, a triggered voice recording, three more motors and more LEDs.  To handle everything, I will need the prop 2 to trigger my prop 1 that I just bought because I knew the prop 2 wouldn't handle it all.  Start simple you said?  Where is the fun in that?

James

JonnyMac

I did offer, and I will help.  I need more.  This part -- the splainin' -- you'll find is the most difficult part of this process.  What makes perfect sense to you may not to me or others, and because it makes so much sense to you there may be details left out.

Instead of a 555 and decade counter you could use one or two 74HC595 shift registers to control your floor lights; this will give you as many lights as you want with programmatic timing control, but it will cost three IO pins.

I think the biggest challenge is going to be motor control.  I remember from the other forums that you want forward and reverse control, but doing it with relays gives you NO speed control -- this could be a problem.  I know you're a bit budget conscious on this one, but the suggestions you got for using the HB-25 are good ones; that will give you speed AND direction control (of up to two motors) with just on I/O pin.  Consider it -- might be a real saver.

The other stuff is pretty straightforward, though to keep the servos refreshed you must run what is called a state-machine program.  I've produced a skeleton below.

' =========================================================================
'
'   File...... Elevator.BS2
'   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 BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Sio             PIN     15                      ' SETUP = out; no ULN
Trigger         PIN     14                      ' SETUP = DN

MotorDir        PIN     9
MotorRun        PIN     8

LedsCenter      PIN     6
LedsInner       PIN     5
LedsOuter       PIN     4

Servos          PIN     3

Latch           PIN     2                       ' latch 74HC595 outputs
Clock           PIN     1                       ' shift clock to 74HC595
Dpin            PIN     0                       ' data pin to 74HC595


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

IsOn            CON     1
IsOff           CON     0

MtrFwd          CON     0
MtrRev          CON     1


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

state           VAR     Byte                    ' program state
timer           VAR     Byte                    ' for input debouncing
level           VAR     Byte                    ' for LED brightness
pos             VAR     Byte                    ' servo position, 100 - 200

floors          VAR     Word                    ' up to 16 floors


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

Reset:
  OUTS = %0000000000111000                      ' LEDs on
  DIRS = %0000000000111111

  state = 0
  timer = 0

  floors = %0000000000000001                    ' 1st floor indicator on
  GOSUB Update_Floors

  pos = 100                                     ' closed position


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

Main:
  PULSOUT Servos, (pos * 5)                     ' refresh servos
  PAUSE 18

  BRANCH state, [Get_Trigger, State_1, State_2, State_3]
  state = 0


Get_Trigger:
  timer = timer + 20 * Trigger                  ' scan input
  IF (trigger > 100) THEN                       ' wait for valid trigger
    state = 1                                   ' advance state
    timer = 0                                   ' clear for next state
  ENDIF
  GOTO Main


State_1:
  ' state code
  GOTO Main


State_2:
  ' state code
  GOTO Main


State_3:
  ' state code
  GOTO Main


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

' Transfers the contents of 'floors' to 74HC595s
' -- floors 1 to 8 are connected to '595 closest to Prop-2

Update_Floors:
  SHIFTOUT Dpin, Clock, MSBFIRST, [floors.BYTE1, floors.BYTE0]
  PULSOUT Latch, 1
  RETURN

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


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


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


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


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


' -----[ User Data ]-------------------------------------------------------


Jon McPhalen
EFX-TEK Hollywood Office

GOT

Damn, Johnny! you don't sleep much, do you.  I must complement you on the incredible customer service here.  Yes, the HB-25 looks great, but I have already more than blown my budget with your products.  I will have to forgo the speed control and stick with my $5 H-bars and limit switches without a feedback signal (the limit switches will cut the power, but a diode will allow the reverse current to flow).  I am a perfectionist, but I have learned that perfectionism can just get in the way on Halloween.  The kids don't notice how perfectly you timed everything.  Maybe I will pick up an HB-25 next year.  I like your suggestion of the 74HC595 shift register. The floor signal timing is not critical but this does make for a little more precision.
So, here is more splainin'.  I don't think I can get more specific than this.  By the way, I added one motor and some side-lit LEDs in this mix, just to be a little more complete.

p1-p3: light tree for all floor indicators (74HC595 shift register)
p4: center LED light
p5: inner ring of 4 LED lights
p6: outer ring of 4 LED lights
p7: runs both servos (branch with a Y-connector)
p8: motor 1(forward)
p9: motor 1(reverse)
p10: motor 2 (forward)
p11: motor 2 (reverse)
p12: side LED
p14: 1st floor indicator/start program trigger. (note, this is a separate LED than the 1st floor indicator operated by the shift register, but it lights the same button).
p15: reset trigger
p16: triggers Prop 1 program


Program waits for reset trigger.
Reset trigger does following:
LED 1 is on.
LED outer ring is off.
LED inner ring is on.
Center LED is on.
Servos are at 20% open state.
Side LED is off.

Program is now waiting for me to flip a switch and turn LED 1 off.

When I turn off LED 1, the program initiates the following:
Time 0:  Servos go from 20% open to 40% open in 5 sec.
Time 5 sec: Side LED fades on (take 5 seconds to reach full brightness). LED outer ring fades on (5 sec to reach full brightness).  Servos go from 40% open to 60% open in 5 sec.
Time 10 sec: motor 1 initiates forward motion. Servos go from 60% open to 100% open in 10 sec. 2nd floor indicator lights.
Time 20 sec: motor 1 stops.  Side LED fades out (5 second fade). Motor 2 initiates forward motion.  2nd floor indicator turns off.  3rd floor indicator lights.
Time 25 sec: motor 2 stops. Pause 5 sec.
Time 30 sec: motor 2 initiates reverse motion. Side LED fades on (5 sec).
Time 35 sec: motor 2 stops.  Motor 1 initiates reverse motion. Servos go from 100% open to 60% open in 10 seconds. 3rd floor indicator turns off.  2nd floor indicator turns on.
Time 45 sec: motor 1 stops.  Side LED fades off (5 sec).  Outer ring LED fades off (5 sec). Servos go from 60% open to 40% open in 5 sec.
Time 50 sec: Servos go from 40% open to 20% open in 5 sec. 2nd floor indicator turns off.  1st floor indicator turns on.
Time 55 sec: Pause 5 sec. Trigger Prop 1 program (not described here).
Time 60 sec: Servos go from 20% open to 10% open in 5 sec.
Time 65 sec: inner LED ring fades off (5 sec).  1st floor indicator turns off.  -1 floor indicator turns on.
Time 70 sec: Servos go from 10% open to fully closed (off) state in 5 sec.
Time 75 sec: center LED light fades to black (10 sec fade time).  -1 floor light goes out.  -2 floor light turns on.
Time 85 sec: -2 floor light turns off.  -3 floor light turns on.
Time 95 sec: -3 floor light turns off.  -4 light turns on.
Time 105 sec: program waits for reset trigger.

I hope that is enough gory detail...

JonnyMac

I can be said that I don't sleep as much as I should....

Now, to the bigger issue: You have two elements of your program that are mutually-exclusive: servo control and LED fading.  Here's the rub: servos must be updated every 20 ms or so in order to hold their position, especially if they're under any kind of load.  LED fading with the Prop-2 requires the PWM instruction which must run uninterrupted to do a fade.  So, if you try one of those long fades you'll end up ignoring the servos which may start moving in ways you don't want.  Also, with PWM you can only run one fade at a time and it must finish (be full on or full off before moving on).

From our catalog, only the Prop-SX can do what you want, and it will be a complicate program (I'll still write it for you).  That's an expense you don't want, hoever, so let's figure out how to use what you have.  Do you really need the fades?  Could you use with digital servos ($$$) that don't need constant updating?

I'm curious, what other products were you considering for this project -- this is far more sophisticated that what most home Halloweeners consider (bravo for you).
Jon McPhalen
EFX-TEK Hollywood Office

GOT

Well, I am planing on having both a prop 1 and a prop 2 running together for this elevator, so I should be able to run the servos off one and the LEDs off the others.  I have three servos to control so that shouldn't overload any one system.  Here is the total list of stuff to control:
2 servos linked with a Y cable
1 stand alone servo
4 DC motors (3 of which will reverse direction)
1 scary terry board with a recorder chip which I will use for sound only
1 LED light tree
1 LED
2 LEDs wired in parallel
2 sets of 4 LEDs wired in parallel
8 LEDs wired in parallel (could be split out into 2 sets of 4 if necessary).

All stuff has been purchased.  I am trying to not spend more here.  By the way, can a prop 2 handle a digital servo?  I though you needed the SX for that.

Every year, I dig myself deeper.  And every year, I say it will be my last haunt.

JonnyMac

Can you draw up a schematic and e-mail it to me?  You know, a picture is worth a thousand words... especially with a project as involved as this.

I'm think for the LED fades we should use the Prop-1 as a slave to the Prop-2.  The Prop-2 would send the Prop-1 a serial message telling it which LED to fade and for how long.  The Prop-1 would hold its serial input (P7) low while doing the fade so that the Prop-2 could tell that it's busy (it wouldn't try to send anything to the Prop-1 unless the serial line was pulled high [pull-up on the Prop-1]).  Again, the Prop-1 can only do one thing at a time -- SERIN blocks until data shows up, and PWM must run to its conclusion, hence the manipulation of the serial input pin to manage data flow between the two.

My understanding is that digital servos work just like regular servos, except that there is circuitry inside that measures the incoming pulse and will continue to use that setting until a new pulse arrives.  Standard servos us an analog circuit that must be refreshed by the incoming pulse, hence a pulse must arrive on a regular basis.
Jon McPhalen
EFX-TEK Hollywood Office

GOT

OK, way to complicated.  After thinking about it, I can work things so that there is no fading while operating servos.  Not as elegant visually but certainly workable.

Program waits for reset trigger.
Reset trigger does following:
LED 1 is on.
LED outer ring is on.
LED inner ring is on.
Center LED is on.
Servos are at 20% open state.
Side LED is on.

Program is now waiting for me to flip a switch and turn LED 1 off.

Program is now waiting for me to flip a switch and turn LED 1 off.

When I turn off LED 1, the program initiates the following:
Time 0:  Servos go from 20% open to 40% open in 5 sec.
Time 5 sec: Servos go from 40% open to 60% open in 5 sec.
Time 10 sec: motor 1 initiates forward motion. Servos go from 60% open to 100% open in 10 sec. 2nd floor indicator lights.
Time 20 sec: motor 1 stops. Motor 2 initiates forward motion.  2nd floor indicator turns off.  3rd floor indicator lights.
Time 25 sec: motor 2 stops. Pause 5 sec.
Time 30 sec: motor 2 initiates reverse motion.
Time 35 sec: motor 2 stops.  Motor 1 initiates reverse motion. Servos go from 100% open to 60% open in 10 seconds. 3rd floor indicator turns off.  2nd floor indicator turns on.
Time 45 sec: motor 1 stops.  Servos go from 60% open to 40% open in 5 sec.
Time 50 sec: Servos go from 40% open to 20% open in 5 sec. 2nd floor indicator turns off.  1st floor indicator turns on.
Time 55 sec: Pause 5 sec. Trigger Prop 1 program (not described here).
Time 60 sec: Servos go from 20% open to 10% open in 5 sec.
Time 65 sec: 1st floor indicator turns off.  -1 floor indicator turns on.
Time 70 sec: Servos go from 10% open to fully closed (off) state in 5 sec.
Time 75 sec:  Outer ring ring fades off (1 second). Inner ring fades off (2 seconds). Side light fades off (2 seconds).
Time 80 sec: center LED light fades to black (10 sec fade time).  -1 floor light goes out.  -2 floor light turns on.
Time 90 sec: -2 floor light turns off.  -3 floor light turns on.
Time 100 sec: -3 floor light turns off.  -4 light turns on.
Time 110 sec: program waits for reset trigger.

Using this, there is no reason to separate out the inner and outer rings.  My question is, can the prop 2 with a 12V, 1 amp power source handle 8 ultrabright white LEDs at one pin (wired in parallel, of course, the are 3.2 V forward voltage and 20 ma current)?  Do you still need schematics?  It's all pretty simple.  Just LEDs and H-bars.  Oh, and that 74HC595 thing you told me about.

JonnyMac

July 10, 2008, 12:14:15 PM #7 Last Edit: July 10, 2008, 12:24:15 PM by JonnyMac
James,

You've still got the issue of servo control and fading which are mutually-exclusive with the Prop-2.  You also seem to want to fade multiple simultaneous channels which is not possible with the Prop-2 (the PWM instruction works on one pin at a time). 

Honestly, the level of control you're looking for requires the horsepower of a Prop-SX and some serious programming.  How were you intending to do this before deciding on the Prop-2?  Other than the Prop-SX, I'm not aware of a budget-friendly controller that can handle the requires you have for your prop (I could be wrong, though, so I'm asking in all sincerity).

Regarding you LEDs, I agree with using a standard parallel circuit with a current limiter per LED; this will let you have one LED or up to 10 LEDs on the same control port without any problems.  This circuit gives you the greatest flexibility.

Jon McPhalen
EFX-TEK Hollywood Office

livinlowe

James-

A SEMI cheap solution is available:

http://www.parallax.com/Store/Accessories/MotorServoControllers/tabid/160/CategoryID/35/List/0/Level/a/ProductID/481/Default.aspx?SortField=ProductName%2cProductName

It's the servo pal by parallax, and it will control 2 servo in a "set and forget" way. I understand what your saying about spending money, but this will probably make your prop work the way you want.

FWIW-
Shawn
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

I hadn't considered that, Shawn, and what it does help with is timing, too.  The ServoPal has a timing function built in that would also be useful with this project.  It might be cheaper to use the ServoPal with the Prop-2 than upgrading to a Prop-SX.
Jon McPhalen
EFX-TEK Hollywood Office

GOT

Let me understand something.  I turned off the servos (put them in the closed, resting state, I guess they still have power) before I faded any LEDs.  I needn't worry about them at this point, even if they drift.  I also faded all LED in a serial fashion, not parallel.  Am I still out of luck here?  Forgive me since I am new to all of this but I don't get the issues.  I am doing a lot but it is all simple instructions that don't really overlap.  I'm assuming I can turn on a motor/LED and forget about it in between refreshing the servo.  Please bare with me here.  How much is the servoPal?

livinlowe

Well, Ok. Hang on. First the Servo Pal is $19.99, and will hook up great to either the prop-1 or 2. But lets back track....

Upon reading your project description, yeah, I don't think you will have to worry about updating the servos, because there wont be a load on them (horizontal track). My question is - what are these doors for again? Are they simulating the lights turning off?
Quote from: GOT on July 07, 2008, 09:46:04 PM
THE RESULT:  This is a light panel for my elevator simulator.  The kids will see the diamond-shaped lighted panel through some frosted glass so it will be out of focus.  This panel will be about three feet above the frosted glass but I want it to appear about twenty feet up.  I will use two servos moving sliding panels to make the diamond grow larger then lower the entire assembly down just a few inches from the frosted glass.  This will give the appearance of the elevator rising up to the light panel.  When the elevator drops (in simulation only), I will raise the panel up about three feet, then use the servos to make the diamond grow smaller (turning off the LED rings as they are covered up) until just the center LED is visible.  I will then slowly dim the LED to finish the decent into darkness.  There will be a light tree inside the elevator counting off the floors. 
Can't we simulate this by fading the LED's? Do we even need the servos moving the panel?
Maybe we just aren't understanding each other in the "translation" of the effect your trying to create. If we can do this with the Prop-2, that would be cool.
Shawn
Scaring someone with a prop you built -- priceless!

GOT

This diamond shaped light panel will be just out of focus through some frosted glass.  The illusion I am going for with the servos is to grow/shrink the diamond shape so that it appears to be moving towards/away from you.  It could be done with fading lights but I would have to go further out of focus and I don't think the effect would be as cool.  If I can't make this work, fading LEDs will be my fallback.  The center led, by the way, is never covered and fades away at the end.
$20 aint bad.  But what about the cable adaptors and accesories to make the thing operational.  Is the programming a pain?

JonnyMac

The ServoPal isn't difficult to program and will allow you to have proper servo control of your aperture panels as well as provide an external timer that will be useful with the program.  If you were using a Prop-SX I would code these features as "background" processes.
Jon McPhalen
EFX-TEK Hollywood Office

livinlowe

Ohhhh, Ok. I get what the panels are doing, there allowing more light from the Led's to come into the room. Yeah, Ok, but I bet you could come close with some of Jon's programming magic with PWMing the LED's. But, if the $20 bucks isn't too stiff, it will take care of the servo problem. Maybe try with programming, see if you get close (since programming the Prop-2 is free  ;)  )
Shawn
Scaring someone with a prop you built -- priceless!