I am going to have 2 servos that will be triggered with a pressure mat. One will be a continuous rotation servo, the other a standard servo.
The standard servo will actually be glued to the side of the continuous servo. When trggered, the standard servo will turn so that the servo horn faces down. This will allow a string that is attached to the continuous servo to drop. This will drop a severed head prop. After about 3-4 seconds the standard servo will go back to its starting position, and the continuous servo will turn, rolling up the string.
I pretty much know nothing about programming this. I know that the values on the continous servo depends on the length of the string and as long as I have a program written and know what value needs adjusted for the string length.... I should be good. Any help I can get would be really appreciated!!!!!
Oh,.... probably a pause in this of about 20 seconds or so would be good so that the prop isnt triggered again too soon.
Lynn,
We're at a disadvanatge here because we don't know -- and you didn't tell us -- what values to use for tilting the servo and the speed/direction for the C/R servo to "haul in the head."
Give this a try without the head to see if the servos move in the correct direction. You may need to swap the up and down values for the tilt servo, and the speed setting for the reel servo. The setting of "delay" controls how long the program wait after the drop, and then how long it takes to reel in the head. Set the reel-in speed first, then adjust the timing.
Have fun!
' =========================================================================
'
' File......
' Purpose...
' Author....
' E-mail....
' Started...
' Updated...
'
' {$STAMP BS1}
' {$PBASIC 1.0}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
' -----[ Revision History ]------------------------------------------------
' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL Trigger = PIN6 ' SETUP = DN
SYMBOL Rotate = 1 ' rotation servo
SYMBOL Tilt = 0 ' tilt servo
' -----[ Constants ]-------------------------------------------------------
SYMBOL IsOn = 1 ' for active-high in/out
SYMBOL IsOff = 0
SYMBOL Yes = 1
SYMBOL No = 0
' -----[ Variables ]-------------------------------------------------------
SYMBOL timer = B2
SYMBOL pos = B3 ' tilt servo position
SYMBOL speed = B4 ' rotating servo speed
SYMBOL delay = W5
' -----[ Initialization ]--------------------------------------------------
Reset:
PINS = %00000000 ' clear all
DIRS = %00000011 ' set output pins
pos = 100 ' up position
speed = 150 ' stopped
' -----[ Program Code ]----------------------------------------------------
Main:
timer = 0 ' reset timer
Check_Trigger:
PULSOUT Tilt, pos ' update servos
PULSOUT Rotate, speed
PAUSE 17 ' loop pad
timer = timer + 20 * Trigger ' update timer
IF timer < 100 THEN Check_Trigger ' wait for 0.1 sec input
Drop:
pos = 200 ' tilt for drop
delay = 4000 ' set for 4 seconds
GOSUB Servo_Pause
Roll_Up:
pos = 100 ' back t up position
speed = 125 ' adjust for roll-up speed
delay = 4000 ' adjust for roll-up time
GOSUB Servo_Pause
GOTO Reset
' -----[ Subroutines ]-----------------------------------------------------
' Use instead of PAUSE
' -- put pause value (ms) in "delay" before calling
Servo_Pause:
PULSOUT Tilt, pos ' update servos
PULSOUT Rotate, speed
IF delay < 20 THEN SP_Exit
PAUSE 17
delay = delay - 20
GOTO Servo_Pause
SP_Exit:
PAUSE delay
RETURN
' -------------------------------------------------------------------------
' -------------------------------------------------------------------------
' -----[ User Data ]-------------------------------------------------------
This will be perfect! I can figure out the speed/time thing and the direction. Since I dont have it built yet, I can make most of it work!!!
Jonny.... This program is working pretty well but for some reason the continuous rotation servo doesnt stop rotating. When it is 'realing in' the head is goes faster but then it goes slower and doesnt stop.
When powered, the contin. rotation servo starts right up. When triggered it contiues to rotate as the tilt servo tilts then tilts back after 4 seconds, then the rotation servo speeds up to real in the head then slows down but doesnt stop.
Just a shot in the dark here but it sounds as though your "continuous rotation servo" is acting more like a simple motor than a servo. My guess is that it doesn't need a position signal from the Prop-1 but just an On/Off/Speed execution.
C/R servos are in fact standard servos that have had the mechanical stops removed and the position pot replaced with two resistors. This means they still need to be treated like servos.
@Lynn: If you have a Parallax C/R servo there should be a small hole in the the side that will let you adjust the stop position. You can start the program (remove the trigger so it doesn't activate) and adjust the pot that it stops when 150 is the command value. If you can't adjust it then you'll need to change the 150 value to find the stop point.
QuoteC/R servos are in fact standard servos that have had the mechanical stops removed and the position pot replaced with two resistors. This means they still need to be treated like servos.
Ahhh.......This old R/C nut learned something new about servos! ;)
Well, I have a Hitec servo.... I'll see if there is an adjust on it.... if not I'll play with the value!
I'm guessing that a larger value will slow it down...
at 150 it goes slower than when its at the roll up speed of 125.
I'll give that a shot.
Thanks a lot!
It it's a C/R servo that you made yourself, probably not. Parallax sells a servo for robotics that includes an adjustment. In your case, you just have to experiment with the value until you find the stop point -- which should be close to 150.
With a regular servo you send it values of 100 to 200 (with Hitec you can go 60 to 240) to move it from one side to the other. With a C/R servo the direction is based on the change from 150 -- lower than 150 goes in one direction, higher that 150 and the servo turns the other way. The difference between your setting at the stop point (150) determines the speed.
OK is changed the speed on the CR servo to 155 and that stopped it !!! First try ! How lucky was that ?
thanks so much for the help.
Next project with be for a pneumatic pop up !
Have one issue with this routine..... I need a delay between triggers. It will trigger right away right after the routine is finished. I would like a pause or delay before it can be triggered again. Maybe about a minute or so. Thanks!
Also, I think a light would be great too.....
Trigger the light just a 1/2 second before the head drops. Then goes out when it rolls up.
Thanks, Hope I,m not asking too much! I gotta learn this myself! I am understanding most of it though.
Light? What light? Since it's not in the original program I added it on P2/OUT2.
The re-trigger delay is built into the reset section as this ensures the light is out and the servos are in the correct position before the trigger is scanned. There is a 500ms delay between the light going on and the head drop.
Yes, it would be a good idea to learn yourself. I walk 5 miles every day (yes, in Los Angeles, and this can be dangerous) -- yesterday I was inches from being run down by a driver ignoring the crossing light.
' =========================================================================
'
' File......
' Purpose...
' Author....
' E-mail....
' Started...
' Updated...
'
' {$STAMP BS1}
' {$PBASIC 1.0}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
' -----[ Revision History ]------------------------------------------------
' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL Trigger = PIN6 ' SETUP = DN
SYMBOL Light = PIN2
SYMBOL Rotate = 1 ' rotation servo
SYMBOL Tilt = 0 ' tilt servo
' -----[ Constants ]-------------------------------------------------------
SYMBOL IsOn = 1 ' for active-high in/out
SYMBOL IsOff = 0
SYMBOL Yes = 1
SYMBOL No = 0
' -----[ Variables ]-------------------------------------------------------
SYMBOL timer = B2
SYMBOL pos = B3 ' tilt servo position
SYMBOL speed = B4 ' rotating servo speed
SYMBOL delay = W5
' -----[ Initialization ]--------------------------------------------------
Reset:
PINS = %00000000 ' clear all
DIRS = %00000111 ' set output pins
pos = 100 ' up position
speed = 150 ' stopped
delay = 60000
GOSUB Servo_Delay
' -----[ Program Code ]----------------------------------------------------
Main:
timer = 0 ' reset timer
Check_Trigger:
PULSOUT Tilt, pos ' update servos
PULSOUT Rotate, speed
PAUSE 17 ' loop pad
timer = timer + 20 * Trigger ' update timer
IF timer < 100 THEN Check_Trigger ' wait for 0.1 sec input
Light_On:
Light = IsOn
delay = 500
GOSUB Servo_Pause
Drop:
pos = 200 ' tilt for drop
delay = 4000 ' set for 4 seconds
GOSUB Servo_Pause
Roll_Up:
Light = IsOff
pos = 100 ' back t up position
speed = 125 ' adjust for roll-up speed
delay = 4000 ' adjust for roll-up time
GOSUB Servo_Pause
GOTO Reset
' -----[ Subroutines ]-----------------------------------------------------
' Use instead of PAUSE
' -- put pause value (ms) in "delay" before calling
Servo_Pause:
PULSOUT Tilt, pos ' update servos
PULSOUT Rotate, speed
IF delay < 20 THEN SP_Exit
PAUSE 17
delay = delay - 20
GOTO Servo_Pause
SP_Exit:
PAUSE delay
RETURN
' -------------------------------------------------------------------------
' -------------------------------------------------------------------------
' -----[ User Data ]-------------------------------------------------------
Thanks Jon!
Sorry about the light.... I hadnt thought about that when I first asked for help. :-[
Hoping this is the last I need ........
Have an LED light attached to the pinouts on the prop1. Pin2, red and white out pins. Is this correct?
The light stays on constantly.
Thanks
Yes, if you're connecting to Px.W and Px.B (the male header pins). That said, you should put a resistor in the circuit as well. I typically use 470 Ohms on a 5v circuit, but the Prop-1 has a 220 built in so you can use another 220 (total of 440 Ohms will be fine).
[Edit] Corrected per Shawn's catch! Led should connect to Px.W (the anode side) and Px.B (the cathode side -- flat spot on LED).
I have the resistor in place..... but the led stays lit through the whole routine.
I'm sorry if I am not helping, but shouldn't the LED go to the White and Black? White-from processor; Red-+5V DC; Black - Ground?
Guess I was only guessing on the red and white. So I really am not sure.
I've tried connecting to the white and black but it stayed on there too!
This thread is getting long-winded -- you'll have to repost the code that is creating the problem. BTW, Shawn is correct: the LED should connect between Px.W and Px.B. I corrected my errant post, above.
Try connecting your LED to OUT2 instead of PIN2. Connect the NEG leg of the LED to OUT2 and the POS leg to V+ with the 470 ohm resistor. Put the power switch on position 2. Hope this helps ya out. ;)
Depending on your application you may want to bump the resistor up to 1K.
True, it does depend on the particular LED being used and the supply voltage to the Prop-1. I assumed the voltage was 12v in this case. With a typical 2.2v LED, a 470 ohm resistor would be fine. (One should never assume :D) It never hurts to go with a higher resistor but if the value is too high the LED will be dimmer than normal. Here's a great site for calculating LED resistor values for anyone interested. Once your at this page you can save it as Web Page, complete (*.htm; *.html) and it will work without having to go online every time you need a calculation.
http://www.laureanno.com/RC/LED-calc.htm
The voltage is 9v.
I'll try the out2.
And since connecting to the whi and red pins.... The led does not light at all.
I checked it and the LED is fine.
I can repost this with the code if needed.
You should be connecting the LED between the white and black pins -- I corrected my early post.
You've got two choices when controller LEDs:
1) Connect the anode (+) side to Px.W (white) and the downstream side of the current limiting resistor to Px.B (black). When the pin, Px, is HIGH, the LED will light.
2) Connect the anode (+) side to V+ (input voltage when power switch is in position 2) and the downstream side of the current limiter to OUTx. When Px is HIGH, the LED will light.
QuoteAnd since connecting to the whi and red pins.... The led does not light at all.
I checked it and the LED is fine.
Lynn,
This is a bit confusing. In you previous posts you stated that your LED stayed lit constantly when connected to P2(W) and P2(R). After reconnecting to P2(W) and P2(B) you again said the LED stayed lit. Something is not adding up. :-\
I'm sorry, I had kinda miss spoke...
When the LED is connected to the white and black wires, it does not come on.
I met Jon at Transworld so I an going to try something... Well see how that goes.
If PIN2 works and will blink while running another program, then I will see what needs done with this program.
Jon,
I tried what you suggested and the LED worked like a charm.
Still wont come on running the drop head program.
I can start a new thread if you want and add the program as I have it....
Or I can put it here.
You had mentioned about starting a new thread a while back and will do that if needed.
Lynn
Go ahead and put the code here -- now that we know the LED works the code will be easy to fix. Since we're so far into this thread, please provide an updated description of what you want; that way I can sort out where the code isn't doing what it should.
2 servos, with one connected to the side of a continuous rotation servo.
When triggered with a mat, light comes on and servo 1 turns 45 degrees dropping a string that is on servo 2. After a 3 second pause, the light goes out and servo 1 turns back to its starting position, and servo 2 rolls up the string.
All works great except the light never comes on.
------------------------------ I/O Def--------------------
SYMBOL Trigger = PIN6 ' SETUP = DN
SYMBOL Light = PIN2
SYMBOL Rotate = 1 ' rotation servo
SYMBOL Tilt = 0 ' tilt servo
--------------------------constants -------------
SYMBOL IsOn = 1 ' for active-high in/out
SYMBOL IsOff = 0
SYMBOL Yes = 1
SYMBOL No = 0
------------------variables-----------
SYMBOL timer = B2
SYMBOL pos = B3 ' tilt servo position
SYMBOL speed = B4 ' rotation servo speed
SYMBOL delay = W5
----------------------------initialization ---------------------
Reset:
PINS - %00000000
DIRS - %00000111
pos - 100
speed = 155
delay = 40000
GOSUB Servo_Pause
------------------program code---------------------------------
Main:
timer = 0
Check_Trigger:
PULSOUT Tilt, pos
PULSOUT Rotate, speed
PAUSE 17
timer - timer + 20 * Trigger
IF timer < 100 THEN Check_Trigger
Light_On:
Light = IsOn
Delay = 500
GOSUB Servo_Pause
Drop:
pos = 200
delay = 3000
GOSUB Servo_Pause
Roll_Up:
Light = IsOff
pos = 100
speed = 125
delay = 11000
GOSUB Servo_Pause
GOTO Reset
----------------subroutines--------------
' Use instead of PAUSE
' -- put pause value (ms) in "delay" before calling
Servo_Pause:
PULSOUT Tilt, pos
PULSOUT Rotate, speed
IF delay < 20 THEN SP_Exit
PAUSE 17
delay = delay - 20
GOTO Servo_Pause
SP_Exit:
PAUSE delay
RETURN
All I did was a code clean-up to remove the syntax errors and it works fine. I'm testing on a Trainer, but I can see that the servos are being updated (P0 and P1 LEDs are dimly lit due to pulsing) and P2 comes on after the trigger. Since you have verified that P2 works with your LED, this should now do it for you.
' =========================================================================
'
' File......
' Purpose...
' Author....
' E-mail....
' Started...
' Updated...
'
' {$STAMP BS1}
' {$PBASIC 1.0}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
' -----[ Revision History ]------------------------------------------------
' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL Trigger = PIN6 ' SETUP = DN
SYMBOL Light = PIN2
SYMBOL Rotate = 1 ' rotation servo
SYMBOL Tilt = 0
' -----[ Constants ]-------------------------------------------------------
SYMBOL IsOn = 1 ' for active-high in/out
SYMBOL IsOff = 0
' -----[ Variables ]-------------------------------------------------------
SYMBOL timer = B2
SYMBOL pos = B3 ' tilt servo position
SYMBOL speed = B4 ' rotation servo speed
SYMBOL delay = W5
' -----[ Initialization ]--------------------------------------------------
Reset:
PINS = %00000000
DIRS = %00000111
pos = 100
speed = 155
delay = 40000
GOSUB Servo_Pause
' -----[ Program Code ]----------------------------------------------------
Main:
timer = 0
Check_Trigger:
PULSOUT Tilt, pos
PULSOUT Rotate, speed
PAUSE 17
timer = timer + 20 * Trigger
IF timer < 100 THEN Check_Trigger
Light_On:
Light = IsOn
Delay = 500
GOSUB Servo_Pause
Drop:
pos = 200
delay = 3000
GOSUB Servo_Pause
Roll_Up:
Light = IsOff
pos = 100
speed = 125
delay = 11000
GOSUB Servo_Pause
GOTO Reset
' -----[ Subroutines ]-----------------------------------------------------
' Use instead of PAUSE
' -- put pause value (ms) in "delay" before calling
Servo_Pause:
PULSOUT Tilt, pos
PULSOUT Rotate, speed
IF delay < 20 THEN SP_Exit
PAUSE 17
delay = delay - 20
GOTO Servo_Pause
SP_Exit:
PAUSE delay
RETURN
' -------------------------------------------------------------------------
' -----[ User Data ]-------------------------------------------------------
Jon,
What would the code look like if a pot was added to control the length of time the roll up the string routine runs?
Steve
You'd have to define a pin for a pot and then read it just before the section the rolls up the prop. Setting the speed is not the problem, it's setting the delay that follows that is. Here's the partially adjusted section:
Roll_Up:
Light = IsOff
pos = 100
POT SpdAdjust, 100, speed
speed = speed / 5 + 100 MAX 150 ' may need tweaking
delay = 11000 ' WARNING!!! - not adjusted for pot
GOSUB Servo_Pause
GOTO Reset
If you have one of these props and can do timing tests on the extreme ends of the pot then we can make the delay time work with the pot setting. To do that, though, will require some empirical data.
I've got the rig sitting on the desk at home.
I took your code and put the pot on the delay value. It compiles. I have no idea if it will work. Can you take a look? I'm still fuzzy on the DIRS instruction and was kinda guessing at the pot implementation
Thanks
Steve
' =========================================================================
'
' File......
' Purpose...
' Author....
' E-mail....
' Started...
' Updated...
'
' {$STAMP BS1}
' {$PBASIC 1.0}
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
' -----[ Revision History ]------------------------------------------------
' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL Trigger = PIN6 ' SETUP = DN
SYMBOL TimeAdjust = PIN3 'POT
SYMBOL Light = PIN2
SYMBOL Rotate = 1 ' rotation servo
SYMBOL Tilt = 0
' -----[ Constants ]-------------------------------------------------------
SYMBOL IsOn = 1 ' for active-high in/out
SYMBOL IsOff = 0
' -----[ Variables ]-------------------------------------------------------
SYMBOL timer = B2
SYMBOL pos = B3 ' tilt servo position
SYMBOL speed = B4
SYMBOL delay = W5
' -----[ Initialization ]--------------------------------------------------
Reset:
PINS = %00000000
DIRS = %00001111
pos = 100
speed = 155
delay = 40000
GOSUB Servo_Pause
' -----[ Program Code ]----------------------------------------------------
Main:
timer = 0
Check_Trigger:
PULSOUT Tilt, pos
PULSOUT Rotate, speed
PAUSE 17
timer = timer + 20 * Trigger
IF timer < 100 THEN Check_Trigger
Light_On:
Light = IsOn
Delay = 500
GOSUB Servo_Pause
Drop:
pos = 200
delay = 3000
GOSUB Servo_Pause
Roll_Up:
Light = IsOff
pos = 100
speed = 125
POT TimeAdjust, 100, delay
delay = delay / 5 * 1000 'SWAG value to be determined by testing
GOSUB Servo_Pause
GOTO Reset
' -----[ Subroutines ]-----------------------------------------------------
' Use instead of PAUSE
' -- put pause value (ms) in "delay" before calling
Servo_Pause:
PULSOUT Tilt, pos
PULSOUT Rotate, speed
IF delay < 20 THEN SP_Exit
PAUSE 17
delay = delay - 20
GOTO Servo_Pause
SP_Exit:
PAUSE delay
RETURN
' -------------------------------------------------------------------------
' -----[ User Data ]-------------------------------------------------------
You need to modify your declaration for the pin called TimeAdjust.
SYMBOL TimeAdjust = 7 ' Pot: No SETUP, No ULN
The POT command takes care of the DIRS stuff. The important thing for POT is to remove the ULN and SETUP influence.