Help controlling servos with buttons
Hi All,
Does anyone have any code that I can use with a BOE, PSC board, and BS2px that would control mutilple servos with buttons?
I need to be able to move different·servos based on the condition of·different buttons making contact.· If a normally open button is pressed then the servo would change direction.
So as an example:· I would have 4 servos and·4 different buttons and when a buton is pressed a corresponding servo would change direction.
If you have this code or can help me with it I would really appreciate it.
Thank to all in advance
Joe
Does anyone have any code that I can use with a BOE, PSC board, and BS2px that would control mutilple servos with buttons?
I need to be able to move different·servos based on the condition of·different buttons making contact.· If a normally open button is pressed then the servo would change direction.
So as an example:· I would have 4 servos and·4 different buttons and when a buton is pressed a corresponding servo would change direction.
If you have this code or can help me with it I would really appreciate it.
Thank to all in advance
Joe
Comments
·· I would recommend reading the "What's A Microcontroller?" text, a free download in PDF format from our website.· It will explain servo control, reading buttons, etc.· Then you can learn how to do the specifics.· A link to this file is posted below.
http://www.parallax.com/dl/docs/books/edu/wamv2_2.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
' Scan and debounce button inputs.· Buttons that have changed
' from 0 to 1 are reported in 'xBtns'
Get_Buttons:
· nBtns = %1111································ ' enable all four inputs
· FOR idx = 1 TO 10
··· nBtns = nBtns & ~BtnPort··················· ' test inputs
··· PAUSE 5···································· ' delay between tests
· NEXT
· xBtns = nBtns ^ oBtns & nBtns················ ' find changes, 0 -> 1
· oBtns = nBtns
· RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
There is an example of controlling a servo with pushbuttons in What's a Microcontroller (Chapter 4, Activity #4). It's got a nice little explanation along with schematic, wiring diagrams, and a simple example program.· What's a Microcontroller is available for free download from www.parallax.com -> Downloads -> Stamps in Class Tutorials.
Regards, Andy
Post Edited (Andy Lindsay (Parallax)) : 5/26/2005 1:04:05 AM GMT
Okay, and then there's the part about multiple servos.· Hmmm, it doesn't look like the example from What's a Microcontroller really applies here.· Better stick with Jon's code; it looks like that's the way to go.
Post Edited (Andy Lindsay (Parallax)) : 5/26/2005 2:02:35 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
You are a Basic Stamp GOD!!!!!
The program worked perfect!!
When I push button 1 then servo 1 goes all the way right and if I push it again it goes all the way to the left, etc...
This is so perfect!
I love it!
Once I go through the code I should be able to tweek it to my needs!
The only question I would have is I'm trying to write a program that will work as follows: While a servo is moving possibly back and forth exploring... if a button or contacts are hit then the servo would stop or change direction and/or another servo would move a little bit and the first servo would continue to move back and forth exploring again. So....
"Since the buttons are Normally Open is this program tweekable so that wile the servos are moving
slowly in one direction a button hit would make then either stop or continue in the opposite direction?"
If you know the tweek or can explain it then I would GREATLY appreciate it.
Thank you soooooo much for this program, it helps out a bunch!
Joe
I'm not sure about what you're after ... are you wanting one servo to scan until another button is pressed at which the original servo would stop and the new servo would start scanning?· It's a little more complicated but could be done.· I'll help out with code if you confirm what you want, even going so far as to spelling out your logic in gut-simple steps.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Basically I am trying to create an autonomous robot that can navigate up a wall which has holes drilled in it in random locations. So... the robot would have two arms with an elbow and shoulder joints like human arms, three servos per arm. Joints would be 1 servo for the elbow and 2 for the shoulder. The program would run as follows:
1. Set robot in starting location on wall
1. The right arm would raise out of the hole and reach up as high it is could and start its "motion tracking".
2. "Motion Tracking" - Forearm on right arm "#1 servo" would track back and forth the full 180 degree, once the full left to right is made without finding a hole the second shoulder servo "#2 servo" would move the arm down a little and the process would start again. This process would continue till either a hole is found or the full downward motions is made.
2. If no hole were found then the left arm would go back to its original starting location and the process would go to the left arm!
3. If a hole were found than a contact would be made "#3 servo" would rotate the arm down and lock in the hole and the right arm would station itself in the hole for support, then the process would continue with the left arm.
So...
1. Start location - both arms set in start holes.
2. The right arm pulls out of starting hole "#3 servo"
3. The right arm reaches up as high as possible "#1 and #2 servos"
4. The right forearm tracks back and forth "#1 servo"
5. NO HOLE – lower shoulder - "#2 servo" go to 4.
6. Continue process till hole is found
7. No Hole Found at all – Lock right arm in original location – Left arm tracks now
7. HOLE FOUND - lower shoulder "#3 servo" - lock arm in hole
8. Left arm now runs from line 2.
9. The robot tries to make its way up the wall to final location.
All the contact or button responses are based on a button on the end of the arm under the part that fits in the hole. This button runs along the wall making constant contact "NORMALLY CLOSED", if the hole is reached the contact is "OPEN"! When the contact opens then the arm know to lower and lock in hole! Once one arm lock than the other arm raises and continues searching for holes! Etc…
I hope this explains what I am trying to do, if I missed something let me know.
Thanks for all your help!
Joe
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I'm a little lost as to the circuitry of the program you wrote. I'm using a NX-1000 board and was just using one of the 8 push buttons at the bottom of the board. Any pointers would be greatly appreciated!
By the way, in case you were curious...
I am currently working on a sectional, retractable arm. My goal is to be able to press a button, have the servos raise the arm, press the button again and have them lower the arm. So far the servos can support the arm, but I have a feeling I'll eventually have to use something stronger.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Steve Reust
Wichita, KS
BS2
NX-1000 Project Board
Parallax Servo Controller
Motor Mind C coming soon
Post Edited (Steve-O) : 6/8/2005 6:07:23 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I have a continuation to Steve-O's question... I to have made a servo controlled arm where the joints are the servos and I need the same funtionality with the buttons. BUT... I wrote a program loop that has the servos moving back and forth waiting for a button push but when the button is pushed it seems as if the program dosen't acknowledge the pushed button! I would like to see it work as follows:
1. Arm moves back and forth with a button in the off state but when the button is pushed the servo will stop and another servo will move till button is pushed again!
This is rather a test program for more of what I need but this would help me out greatly if you could show me the how the code you sent would include these button ckeckers.
"Servo_Buttons2.BPX"
I understand the above program code but can't seem to get it to work with the opposite of how it works now. Right now the button controls a motionless servo and moves it to an extreme. I would like the button to be in a constant check mode and when pressed it stops the servo and starts another.
Thanks
Joe