View Full Version : Help! [Basic Stamp 2] Programming 6 servos with only 2 tact switches
kahyee
Jul 29, 2006, 10:24 AM
Dear all,
Is there any way i can use only 2 switches to control my servos (i have six servos) individually?
When i added PULSOUT 15, DURATION below the PULSOUT 14, DURATION
Both servos rotate identically at the same time, which is not what i want.
I want to be able to control each of the six servos individually with the 2 switches ... (or do i need 12 switches to control these 6 servos instead?)
Would anyone lend me a helping hand, please?
Thanksss.
Kah Yee Wong
Melbourne, Australia
--------------------------------------
' {$STAMP BS2}
' {$PBASIC 2.5}
DURATION VAR Word
DURATION =750
DO
IF IN0=1 THEN
IF DURATION > 500 THEN
DURATION = DURATION - 25
ENDIF
ENDIF
IF IN1=1 THEN
IF DURATION < 1000 THEN
DURATION = DURATION + 25
ENDIF
ENDIF
PULSOUT 14, DURATION
' PULSOUT 15, DURATION
PAUSE 10
DEBUG HOME, DEC4 DURATION, " = DURATION"
LOOP
-----------------------------------------------------------
Katanadon
Jul 29, 2006, 01:35 PM
Pulsout 14, Duration
' Pulsout 15, Duration
For Starters You Commented The Second Channel
Katanadon
Jul 29, 2006, 01:47 PM
OR YOU COULD TRY SOMETHING A LITTLE MORE LIKE THIS....
define OSC 20
'DEGUG PORT SETUP
DEFINE DEBUG_REG PORTC
DEFINE DEBUG_BIT 6 'SERIAL DATA OUT POTC.6
DEFINE DEBUG_BAUD 57600 '57600 BITS PS 7200 BYTES PS
DEFINE DEBUG_MODE 0 ' RS232TRUE
'DEBUGIN PORT SETUP
DEFINE DEBUGIN_REG PORTC
DEFINE DEBUGIN_BIT 7 'SERIAL DATA IN PORTC.7
DEFINE DEBUGIN_BAUD 57600 '57600 BITS PS 7200 BYTES PS
DEFINE DEBUGIN_MODE 0 ' RS232TRUE
DURATION1 VAR WORD
DURATION2 VAR WORD
LOOP:
DEBUGIN 20,LOOP, [WAIT ("DUR1"), HEX DURATION1,WAIT ("DUR2"), HEX DURATION2]
'THAT WOULD BE FOR A SERIAL LOOP WAIT FOR CHR DUR1 THE HEX DATA DURATION
' OR FOR PIN TOGGLE
IF PORTB.5 = 1 THEN
DURATION1 = DURATION1 + 25
ENDIF
IF PORTB.5 = 0 THEN
DURATION1 = DURATION1 - 25
ENDIF
IF PORTB.4 = 1 THEN
DURATION2 = DURATION2 + 25
ENDIF
IF PORTB.4 = 0 THEN
DURATION2 = DURATION2 - 25
ENDIF
' THEN POSITION THE SERVOS USING HIGH ,PAUSE IN MICROSECONDS, THEN LOW
HIGH PORTB.6
PAUSEUS DURATION1
LOW PORTB.6
HIGH PORTB.7
PAUSEUS DURATION2
LOW PORTB.7
DEBUG DEC DURATION1, "-DURATION 1 ",DEC DURATION2, "-DURATION 2",13
PAUSE 10
' ADJUST PAUSE FOR TOTAL 20 MILLISECONDS DEPENDING ON BAUDE AND DATA AMOUNT
GOTO LOOP
HOPE THIS HELPS I FOUND THIS WAY TO BE EASIER AND BETTER TIMING THEN THE GARBAGE THAT USUALY COMES OFF A PULSOUT COMMAND, IT IS VERY NOISY COMPARED TO RAISING AND LOWERING A PIN
xorcise
Jul 29, 2006, 02:21 PM
Yes, it's possible to control 6 servos individually with 2 buttons. The only problem I see is knowing which servo is active for control. That's easily resolved by using a single 8-bit port, with 2 Button inputs and 6 LED outputs, each LED will represent the servo under control by the buttons. Then you will need another 6 outputs for your servos.
Let me know which PIC you're using and I can give you something written in mikroBASIC (the compiler's free).
Edit: oops...I see Basic Stamp in the title...sorry.
Acetronics
Jul 30, 2006, 04:40 AM
Hi, Kahyee
You could use a simple trick ... one short pushing on a button means position modifying; one long button pushing ( or both buttons pushed !!! ) toggles you in the servo select mode ...
Then once more long or both pushing comes back to position mode.
Note you''ll have to use a Duration Word for each servo ...
just a simple idea ...
Alain
kahyee
Jul 30, 2006, 08:12 AM
Dear Acetronics,
That's smart !!
Would u briefly spell out the code that will allow me to toggle different servos when different kind of pushing is made ?
Any help is much appreciated....
Kah Yee Wong
Melbourne, Australia.
Acetronics
Jul 30, 2006, 08:47 AM
Here you will find strong answers ... very little mods to do to the code : PBP is BS2 compatible !!!
http://www.picbasic.co.uk/forum/showthread.php?t=4272
This one is from a very trustable Guy ... :
http://www.picbasic.co.uk/forum/showpost.php?p=23224&postcount=5
Alain
kahyee
Jul 30, 2006, 09:26 AM
Dear Katanadon,
I copied and pasted your code into the Basic Stamp Editor, and when i try to run it, i got this following error message, with the 'define' being hightlighted...
Label is missing ':'
I am actually very new to PBasic programming ... would u please comment the code so that i can understand more fully ?
For example, i couldn't make sense of these following codes that u've written here
------------------------------------------------------------------
define OSC 20
DEFINE DEBUG_REG PORTC
DEFINE DEBUG_BIT 6 'SERIAL DATA OUT POTC.6
DEFINE DEBUG_BAUD 57600 '57600 BITS PS 7200 BYTES PS
DEBUGIN 20,LOOP, [WAIT ("DUR1"), HEX DURATION1,WAIT ("DUR2"), HEX DURATION2]
'THAT WOULD BE FOR A SERIAL LOOP WAIT FOR CHR DUR1 THE HEX DATA DURATION
' OR FOR PIN TOGGLE
IF PORTB.5 = 1 THEN
DURATION1 = DURATION1 + 25
ENDIF
DEFINE DEBUG_MODE 0 ' RS232TRUE
------------------------------------------------------------------
I couldn't picture what will response if this code is successfully loaded into my BS2 chip...
Controlling 6 servos with 2 tact switches really needs this long of code? Is there any more simplified and more understandable way of doing it? Please forgive me, i am really really new to this languange and i really need some helps from u guys..
i have already had my 5 axis robotic arm build but now i am soooo stucked on this programming ...
Now in front of me, i have a PCB with 2 tact switches with 6 servos with BS2 .... but i just couldn't get it to go ~~~
kahyee
Jul 30, 2006, 09:32 AM
Dear Acetronics,
I know the link u recommended was great ... for the advanced programmers ... i really couldn't make sense of it ..
for example ,
---------------------------------------------------------
CounterA Var Byte
CounterA=0
Start:
If PORTB.0=0 then
If CounterA<=1 then
CounterA=CounterA+1
else
CounterA=0
endif
endif
While PORTB.0=0 : Wend : pause 50
BRANCHL CounterA,[LabelOne,LabelTwo,LabelThree]
'
' stuf and other
'
Goto Main
LabelOne:
' Stuff
goto Main
LabelTwo:
' Stuff
goto Main
LabelThree:
' Stuff
goto Main
--------------------------------------
Each of the Label such as LabelOne,LabelTwo,LabelThree is finally 'going back to Main' , but where is the Main programmes?
Also, what does 'PORTB.0=0' and 'While PORTB.0=0 : Wend : pause 50' mean ?
I am really so confused ~~~
Would u clarify a litle bit ?
vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.