Servo motor control of a small solar panel
Tuhawk
Posts: 2
I'm new to Basic stamp (I have a BS2 on BOE Rev. C). I'm trying to figure out how to make the servo motor, with solar panel attached mechanically track the sun. I have been able to get the motor to react with the photoresistor. I can make it turn by varying the amount of light but have been unable to make it seek out the brightest light. Any help?
Comments
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
DEBUG " Value"
time VAR Word
DO
HIGH 7
PAUSE 10
RCTIME 7, 1, time
time = time */ 170 ' Scale by 0.4 (X 256 for */). This value is max pulses divided by 500
time = time + 500 ' Offset by 510. (this is to make the value fall between 500 and 1000)
PULSOUT 14, time ' Send pulse to servo.
DEBUG HOME, DEC5 time ' Display adjusted time value.
LOOP
I Sure i am missing something to help it seek the brightest light. Thank you Jonathan fot the idea of using two photo resistors but I'm not sure what to add. Possibly some type of IF.. Then Else statement?
Your code will use the If/then statement to compare the new and old readings in order to set the direction. Direction_to_move is a 1 or a 0 for left and right. You use this to add or subtract 10 deg off your position. Then command your servo accordingly. You most likely would not want to loop this process unless you plain on having a charge complete state or factor in a do/until state which would require another reading variable.
Thinking about this I might have to build a tracker.
' {$STAMP BS2}
' {$PBASIC 2.5}
'This program is to control a Parallax continous rotation servo
'The Idea is to mount a solar panel on the servo along with a photoresistor.
'The Program will move the servo about one pulse at a time and compair RCT
'of the photo resister readings.
'Flow of the program
'Main:-which sets pausetime and cushion then jumps to Readlight:
'ReadLight:-Measures the RTC and debugs the current reading then jumps to CheckValue:
'CheckValue:-Basically this checks to see if the light level is worth adjusting to and what direction.
' If so then it jumps to SwapValue: If not then goes back to main:
'SwapValue: - replaces the old reading with the new and jump to one of the servomovement subs.
'MoveRight: and MoveLeft: tell the servo to move
'Connections
'Connect the photoresister an Parallax continous servo as described in the
Servo_pin CON 14 'I/O pin that is connected to servo
PhotoPin CON 2 'I/O pin that is connected to PhotoResister
READold VAR Word 'old readin from PhotoResister
READnew VAR Word 'Now reading rom photoresister
LeftRight VAR Bit '0 for leftrotation 1 Right Rotation
cushion VAR Word 'allows for a small amount of fluctuation in resistor without causing the servo to move
time VAR Word 'sets the delays before reading photoresister again
'First get reading of currect posistion from Photoresister.
Main:
time = 1000
cushion = 10
GOTO Readlight
READnew = READold
GOTO CheckValue
'__________________Add additional tasks below__________________________________
'Now search for more light.
ReadLight: 'Measures brightness of light when you first power on the stamp
'It also give the READold varable a value
HIGH PhotoPin
PAUSE 100
RCTIME PhotoPin, 1, READnew
DEBUG HOME, "current light level = ", DEC5 READnew
GOTO CheckValue
MoveRight:
PULSOUT servo_pin,600
PAUSE 20
GOTO Main
MoveLeft:
PULSOUT servo_pin, 800
PAUSE 20
GOTO Main
CheckValue:
'
IF READnew < 11 THEN
PAUSE time
GOTO Main
ELSEIF READnew > 1000 THEN
PAUSE time
GOTO Main
ENDIF
IF READnew - cushion > READold THEN
LeftRight = 1
GOTO swapvalue
ELSEIF READnew + cushion < READold THEN
LeftRight = 0
GOTO swapvalue
ENDIF
swapvalue:
READold = READnew
IF LeftRight = 1 THEN 'The 1 and 0 might need switching if tries to move away from light.
GOTO MoveLeft
ELSEIF LeftRight = 0 THEN
GOTO MoveRight
ENDIF
Put yourself in the stamp's shoes. You're looking at the sky through a piece of material with a given number of holes in it at a given size.·Based on what you see you have to decide whether the sun has moved or a random cloud drifted across it and now the sky is brighter than the spot where the sun was. Not a big problem for the human brain but for a basic stamp it could be a task. Your software has to be able to decide if the·brighter light source is really the sun or not so relative brightness versus time as conditions change becomes a factor. What if it's just the sun reflecting off a shiny object? That's a condition that could persist for awhile. You don't want to waste energy chasing phantoms or have the tracker pointing at your neighbor's car mirror·but you don't want to freeze up because you can't make a decision. You could rely on a time delay and wait for the cloud to pass but what happens on a partly sunny day with clouds randomly drifting across the sun at unpredictable intervals? How long do you let the tracker sit there before you decide the sun has really moved?
Just tossing out food for thought. These aren't impossible issues but you have to bear in mind that they do exist and the more of them that become apparent the more complex your system starts to become so it's a tradeoff between how accurate you want the tracker to be versus simplicity.
see Chapter_4 --
http://www.parallax.com/dl/docs/prod/sic/ExpRenewNRG1_0.pdf