PDA

View Full Version : help with servo



piezyxw
09-16-2011, 01:09 AM
Hi I recently made a sun tracker with solar panels and all that good stuff but when nearly completed I couldn't figure out how to make the servo go in reverse if it's just code fine, if it's just that I need to tweak the servo fine. Thank you for your help. by the way I'm using the basic stamp 2 with the board of education.

Beau Schwabe
09-16-2011, 01:32 AM
Can you post the code that you are currently using, along with a schematic or a description of how you have things connected? That would help give us a better picture of your set-up and what you have tried.

piezyxw
09-16-2011, 01:39 AM
I just need to know how to get the servo to go the opposite way. But here's the code. The timeTop, Bottom, and Middle are just the photo resistors to tell it were the sun is most concentrated. The servo is plugged into p12

' {$STAMP BS2}
' {$PBASIC 2.5}

timeTop VAR Word
timeBottom VAR Word
timeMiddle VAR Word
DO

HIGH 6
HIGH 1
HIGH 10
PAUSE 2
RCTIME 1,1,timeBottom
RCTIME 6,1,timeMiddle
RCTIME 10,1,timeTop

DEBUG HOME, "timeTop = ", DEC5 timeTop, "timeBottom = ", DEC5 timeBottom, "timeMiddle = ", DEC5 timeMiddle
PAUSE 100

IF (timeTop+30<timeMiddle) THEN
PULSOUT 12, 625
ELSEIF (timebottom+30<timeMiddle) THEN
PULSOUT 12, 625 'this is were i'm having trouble with getting the servo to go the opposite way
ENDIF
LOOP

Publison
09-16-2011, 01:49 AM
What values do you get in the Debug window in the different lighting situations? When do you want it to change directions?

BTW "I just need to know" is not a good way to get an answer. "I'd like to know" would be more appropriate.

Beau Schwabe
09-16-2011, 01:54 AM
Let me direct you to the PDF "What’s a Microcontroller"...

http://www.parallax.com/Portals/0/Downloads/docs/prod/edu/28123-WAM-v3.0.pdf

... Specifically Chapter 4 Activity #2 "ACTIVITY #2: SERVO CONTROL TEST PROGRAM"

piezyxw
09-16-2011, 01:57 AM
I want it to turn so light is more direct on the solar panels it works going one way but it won't go the other ways everything else works perfectly. If there is more light on the bottom it turns so there is more light on the middle however I want it so when there is more light on the top it will spin the other way so the light is more direct on the middle. But it only spins one way so if there's more light on the bottom it wants to spin all the way back around instead of just going backwards.

Matt Gilliland
09-16-2011, 02:12 AM
Hi piezyxw-
As Beau suggested - Specifically check out:
Figure 4-18: Servo Horn Positions, PULSOUT Commands, and ms Pulse Duration
on page 109.

That should get you started, plus by entering different values for the duration of the pulses, you'll get a feel for how a servo works.

In other words, make mistakes and see what happens :-)

That's the way I learn best - and remember that "letting the smoke out" isn't always bad - I've learned a lot by doing exactly that :)

Oh, and BTW, welcome to the Forums!
-Matt

piezyxw
09-16-2011, 02:33 AM
thanks for the help however just telling me that I had to enter a value lower than 350 or whatever would have made this go much faster. But it's working so thanks I can now track the sun so my solar panels are more efficient. keep up the good work!

graffix
09-16-2011, 03:35 AM
Less than an hour after you posted code,and its fixed.Thats not a bad turn around.

Matt Gilliland
09-16-2011, 06:56 AM
however just telling me that I had to enter a value lower than 350 or whatever would have made this go much faster.

That is absolutely true, piezyxw!

However, a "head full of answers" isn't nearly as good as a "thinking head". :-) You asked a question, got some advice on where to find the info you needed, did the research yourself - and came up with the answer you were looking for.

Well done! Build upon this and the sky's the limit ;-)

-Matt

Matt Gilliland
09-16-2011, 06:57 AM
Hey piezyxw -

Could you post a pic of what you've done? It sounds pretty cool :-)
-Matt