November 23, 2024, 12:01:07 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.


Having trouble with input

Started by Deathtouch, April 19, 2010, 08:36:08 PM

Previous topic - Next topic

Deathtouch

I have a prop-1 that I am having problems with.  Maybe someone could help.  I am trying to get the prop-1 to trigger off of the trainer but can't seem to get it work.  I have tried using the demo for the trainer but it doesn't seem to be changing speed.  I have used simpler programs but still can't get a trigger.

This is the program that I have in there now.  I have tried to change the variable "No" to 0 or 1.  If No =1 then the program just plays thru.  Changing it to 0, just makes it loop forever.  The switch has no effect.

' {$STAMP BS1}
' Program for Ghouleir Prop
' Writen by Mark Sloat April 2010
' For Prop-1


SYMBOL head = 0  ' Turn head connected to P0
SYMBOL led = 1  ' light on connected to P1
SYMBOL body1 = 2 ' body1 is 1st relay on P2
SYMBOL body2 = 3 ' body2 is 2nd relay on P3
SYMBOL mot = PIN6
SYMBOL No = 0

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

'          76543210        ' bit positions
PINS = %00000000                              ' clear all
DIRS = %00001111                              ' set output pins

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

Main:
PAUSE 10000 ' hold for 10 seconds
HIGH led ' turn led on
PAUSE 5000 ' hold for 5 seconds
HIGH head ' Head turns forward
PAUSE 5000 ' hold for 5 seconds


HIGH body1 ' body moves forward
PAUSE 1000 ' hold for 1 seconds

Forward:

IF mot = No THEN Forward

LOW body1  ' body stops
PAUSE 10000 ' hold for 10 seconds

' Body moves reverse

HIGH body2 ' Body moves back
PAUSE 1000 ' hold for 1 seconds

REV:

IF mot = No THEN REV

LOW body2  ' body stops
LOW led     ' Light goes out
LOW head   'head turns around
PAUSE 100000 ' hold for 1 min

GOTO Main

Deathtouch

Want to add that I changed the chip to the 7 output one.  No luck.

JonnyMac

Do you have the P6 SETUP jumper in the DN position?
Jon McPhalen
EFX-TEK Hollywood Office

Deathtouch

Yes I did. I took out the jumper completely this morning and it worked.  I thought the jumper had to be in to work?

JonnyMac

No, the ULN will act as a pull-down for active-high inputs.  For that you want a normally-open switch between P6.W (IO pin) and P6.R (+5v).  Also, you should debounce any inputs to prevent false starts in noisy environments.  If you describe how you want your prop to behave (English, not code), I write a sample for you that will show you how we write robust code.
Jon McPhalen
EFX-TEK Hollywood Office

Deathtouch

April 20, 2010, 03:00:40 PM #5 Last Edit: April 20, 2010, 03:18:40 PM by Deathtouch
This is what I plan to do.  I will do by steps.

1) The first thing that happens is that a ultra bright LED will turn on and hold for 5 seconds.(Actually is it on the whole time until the end. Using LED as var on this.)
2)  Next, going to have a servo move his head, fast for 45 degs and then hold for a few second. The program shows that I used a solenoid but I have had to change that since a servo would be better.  The head that was originally turned to the side, is now facing forward.  I am using Head for var but I know this has to be redone to work with servo motor instead of solenoid.
3)  The body of skeleton in a coffin will then launch forward with his arm out.(grabbing motion)  I am using a motor with this.  So, as seen in the program, I am turning on the 1st relay to have the motor go forward.  The motor will trigger a switch(pin6) which will turn that relay off.(As seen in the program)  After the program turns off the motor, it will wait 10 seconds in that position.  The motor is being stopped by putting a ground on both sides of the motor.  I am using Body1 var for that relay.
4)  After 10 seconds have elapsed; the program will turn on the 2nd relay so that the motor will go in reverse.  As the motor is going in reverse, the servo will return back to normal.  There will be a switch to detect when the motor has hit home.  Once the trigger has been hit, the motor will turn off.(Ground on both side)  Using Body2 for relay2.
5)  After a few seconds the Ultra bright LED(s) will turn off.  Only using one channel for the LED(s).  Again var is LED.
6.  After about 1 to 2 mins, the program will restart.

Just FYI.  The two switches used as trigger for the main motor will be connected in parallel to each other, so that I know there is a trigger condition.  Kind of like an or condition.

JackMan

A couple of things I see in your code at first glance.  1) The 1 minute PAUSE at the end needs to be 60000, not 100000. Anything over 65535 and the Basic Stamp will ignore it. 2) Not sure what the 1 second PAUSE's are accomplishing.  3) There isn't any type of trigger at the beginning so the program will just run right through and then loop because your last command is GOTO Main.

Deathtouch

Thank you Jackman.   Didn't know about the pause issue.  Thanks.  The 1 second pause is my way to ignor the switch if for some reason it still thinks it is closed.  Kind of like a debouncer.  So it gives it time before it looks for the trigger again.  Isn't the goto main acceptable?

JonnyMac

As is often the case I have to ask for more details -- you know exactly how you want your prop to work and yet explaining it to a code writer like me is not always easy (I'm good at writing code but never claimed to be the sharpest tool in the shed!). 

You're mixing IOs; do you want servo control of the head (hard) or cyclinder (easy)?  I'm also at a loss as to when the trigger comes into play; that usually happens at the beginning of a program.  You seem to be using P6 as a limit input -- if this is the case, I think you will need one trigger input and one limit input.
Jon McPhalen
EFX-TEK Hollywood Office

Deathtouch

April 20, 2010, 07:12:01 PM #9 Last Edit: April 20, 2010, 07:21:24 PM by Deathtouch
Not sure what you mean byt the head(hard) or cylinder(easy).  Let me explain.  Don't want to loss you.  When I wrote the program I was thinking that using a DC soldenoid was the way to go, so I wrote the program thinking I could just turn on that output and that would make the head turn the way I wanted.  Since then I have re-thought about using a servo instead.  Because a DC solenoid would only give me a inch or so, and that isn't good enough to move the head.  Air would work, but I don't have a compressor yet.  So where the head variable comes up in the program, that is where I need a simple servo program to move the head 45 deg.  If that makes sense.  That also means at the end of the program where I turn off the head, I would need the servo to go back to the original place that it started from.

For the trigger I was trying to keep it simple.  It is easier for wiring if I connect the switches together.  Let me explain the motor.  I have a dc motor which will move my prop forward and then back again.   I am using two relays.  When the motor is stopped, both sides of the motor are gnd.  When I want it to move, I just turn on one of the relays to put a positive side on on side of the motor.  Now about how the motor works with the switches.(p6) So as the motor spins forward, it will hit the first switch.  That will tell me that it has hit the first mark.  It will trigger P6 and the controller will stop the motor.  After 10 seconds or so, the prop controller will reverse the motor and now p6 is looking for active high again, to stop the motor again.  Just using the switches to limit the motors actions.  I tried to put a 1 second pause when it starts going reverse so it would give the motor time enough to clear the first switch, so there is no false trigger.  I hope that makes sense.  

JonnyMac

Using a servo to control the head is hard because 1) small servos don't have a lot of torque and, 2) servos MUST be refreshed every 20ms or so -- this complicates the code writing (unless you buy one of those really expensive digital servos that you can set-and-forget).

How is the Prop initially triggered?  Or is it just cycling all the time?  Finally, using one input for limits on opposite ends is a really bad idea; you have the inputs on the Prop-1 so it's best to use a second so that you know you're in the home position (limit 1), in between (neither limit switch active), or at the extended po'stion (limit 2).

So far as I see it you're using 7 IO pins:

I: Trigger
I: Home Limit
I: Extended Limit
O: Motor reverse
O: Motor forward
O: LED
O: Servo or Cylinder for head
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

BTW... this thread:

http://www.efx-tek.com/php/smf/index.php?topic=1176.0

... shows a cute little relay that you can get from All Electronics that makes motor control (forward and reverse) really easy.  It's designed for automotive use so it's plenty tough.
Jon McPhalen
EFX-TEK Hollywood Office

Deathtouch

Ok, two inputs is ok.  What ever you think best.  The servo should be able to move the head.  The head is really like and made from foam.  I don't think it will have any problems.  The one I have from servo city will move a heavier skull, so I am thinking I should be ok. OH, and thanks very much for your help.

Deathtouch

Quote from: Deathtouch on April 20, 2010, 07:27:41 PM
Ok, two inputs is ok.  What ever you think best.  The servo should be able to move the head.  The head is really like and made from foam.  I don't think it will have any problems.  The one I have from servo city will move a heavier skull, so I am thinking I should be ok. OH, and thanks very much for your help.

Thank you very much.  I actually have some relays for it already.  I work in Engineering so I have access to a few items.

JonnyMac

Have a look at the schematic in that thread that I posted on how to connect the relays as as XOR gate -- here's some code to look at.  As you can see, using a servo complicates things (you can't use PAUSE the way you have) because the servo needs to be refreshed.

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


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


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


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

SYMBOL  Trigger         = PIN7                  ' SETUP = DN
SYMBOL  Limit1          = PIN6                  ' SETUP = DN
SYMBOL  Limit2          = PIN5                  ' ULN is pull-down

SYMBOL  MotorR          = PIN3                  ' use OUT3/V+
SYMBOL  MotorF          = PIN2                  ' use OUT2/V+
SYMBOL  LED             = PIN1                  ' use OUT1/V+
SYMBOL  Servo           = 0                     ' use P0


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

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


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

SYMBOL  timer           = B2
SYMBOL  pos             = B3                    ' servo position, 60 to 240

SYMBOL  delay           = W5


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00001111                              ' make P0-P3 outputs

  pos = 60                                      ' or 240 - depends on side
  delay = 60000                                 ' one minute
  GOSUB Servo_Pause


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  PULSOUT Servo, pos                            ' refresh servo
  PAUSE 17
  timer = timer + 20 * Trigger                  ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

  LED = IsOn                                    ' light it
  delay = 5000                                  ' hold 5 secs
  GOSUB Servo_Pause

  pos = 150                                     ' center head
  delay = 5000                                  ' hold 5 secs
  GOSUB Servo_Pause

Lunge:
  GOSUB Motor_Forward
  delay = 50
  GOSUB Servo_Pause
  IF Limit2 = IsOff THEN Lunge
    GOSUB Motor_Stop

  delay = 10000
  GOSUB Servo_Pause                             ' hold body up 10s

Retract:
  GOSUB Motor_Reverse
  delay = 50
  GOSUB Servo_Pause
  IF Limit1 = IsOff THEN Retract
    GOSUB Motor_Stop

  GOTO Reset


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

' Replacement for PAUSE -- holds servo at present position
' * put timing (milliseconds) into 'delay' before calling

Servo_Pause:
  IF delay < 20 THEN SP_Exit
    PULSOUT Servo, pos
    PAUSE 17
    delay = delay - 20
    GOTO Servo_Pause

SP_Exit:
  PAUSE delay
  RETURN

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

Motor_Stop:
  MotorF = IsOff
  MotorR = IsOff
  RETURN

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

Motor_Forward:
  MotorF = IsOn
  MotorR = IsOff
  RETURN

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

Motor_Reverse:
  MotorF = IsOff
  MotorR = IsOn
  RETURN

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


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


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