Solar Tracking with Basic Stamp
Tru Custom
Posts: 13
Good afternoon!
I am a student and this my 1st post. I have built a pan-tilt device driven by Parallax Standard Servos and am using the BS2 on BOE rev d board. I am following the Student guide from Parallax by the name of this post.
The problem is that the student guide specifies a separate motor control and drives including a gear-head motor and pneumatic cylinder and I am using only parallax components.
The debug screen reads the RCTIME across the reverse-biased LEDs and does respond slightly to the light through the tilting action but is not consistent and is will tilt downward almost the whole way but when the light is moved up it will only move sightly. BUT, it will not respond at all in the horizontal axis even though the debug displays the decay in the RCTIME. I have built the circuitry to move both axis with pushbuttons and when that program is running the horizontal axis (Pan or Azimuth) moves perfectly and the the vertical axis (Tilt or Altitude) response is somewhat simular to the tracking program.
I have completed the BOE-Bot course last fall and this is an extracurricular project that I have requested to build to cap the 1st year of my EE degree, I am scheduled to demonstrate next Wednesday for the Advisory Board and am hoping to find a summer internship.
This project is beyond my current education but I find the study of Electronics fascinating. My studies in the fall will involve more advanced circuit logic and robotics.
If anyone can review the source code and see the error of my ways, I would be most appreciative.
I tried to create and attachment but this did not work so I have pasted the code below. Any help that you can give would terrific!!
Best regards, Tru
I am a student and this my 1st post. I have built a pan-tilt device driven by Parallax Standard Servos and am using the BS2 on BOE rev d board. I am following the Student guide from Parallax by the name of this post.
The problem is that the student guide specifies a separate motor control and drives including a gear-head motor and pneumatic cylinder and I am using only parallax components.
The debug screen reads the RCTIME across the reverse-biased LEDs and does respond slightly to the light through the tilting action but is not consistent and is will tilt downward almost the whole way but when the light is moved up it will only move sightly. BUT, it will not respond at all in the horizontal axis even though the debug displays the decay in the RCTIME. I have built the circuitry to move both axis with pushbuttons and when that program is running the horizontal axis (Pan or Azimuth) moves perfectly and the the vertical axis (Tilt or Altitude) response is somewhat simular to the tracking program.
I have completed the BOE-Bot course last fall and this is an extracurricular project that I have requested to build to cap the 1st year of my EE degree, I am scheduled to demonstrate next Wednesday for the Advisory Board and am hoping to find a summer internship.
This project is beyond my current education but I find the study of Electronics fascinating. My studies in the fall will involve more advanced circuit logic and robotics.
If anyone can review the source code and see the error of my ways, I would be most appreciative.
I tried to create and attachment but this did not work so I have pasted the code below. Any help that you can give would terrific!!
Best regards, Tru
'Indoor Light Tracker.BS2 ' {$STAMP BS2} ' {$PBASIC 2.5} '------[I/O Pin Definition ]----------------------------------------- AZIMUTH PIN 12 'Pan motor driving Azimuth axis ALTITUDE PIN 13 'Tilt motor driving Altitude axis 'Parallax Standard Servo motors LED_TOP CON 9 'Top LED sensor circuit LED_WEST CON 8 'West LED sensor circuit LED_BOTTOM CON 7 'Bottom LED sensor circuit LED_EAST CON 6 'East LED sensor circuit ' Note, LED's are reversed biased for RCTIME. '-----------------[Constants]----------------------------------------- ' User defined constants PULSE_CCW CON 870 'Counterclockwise motor speed PULSE_CW CON 650 'Clockwise motor speed PULSE_STOP CON 760 ALTITUDE_UP CON 960 '"too dark" threshold ALTITUDE_DN CON 760 'Horizontal error threshold MAX_ERROR_H CON 6 'Horizontal error threshold MAX_ERROR_V CON 2 'Vertical error threshold PULSE_DELAY CON 20 '20ms minimum between pulses MAX_TIME CON 30000 '"too dark" threshold ' Program constants LIGHT_TOP CON 3 'Top light measurement index LIGHT_WEST CON 2 'West light measurement index LIGHT_BOTTOM CON 1 'Bottom light measurement LIGHT_EAST CON 0 'East light measurement index '---------[ Variables ]--------------------------------------------- ewmotorPulse VAR Word 'Panning motor control pulse duration udmotorPulse VAR Word 'Tilting motor control pulse duration counter VAR Word 'Loop counter average VAR Word 'Average measurement error VAR Word 'Difference between measurements time VAR Word(4) 'Light sensor array variable index VAR Nib 'Indexing variable pindex VAR index 'Pin index variable alias x VAR Nib 'x cursor position for Debug y VAR Nib 'y cursor position for Debug '-------[ Intialization ]------------------------------------------- GOSUB ST_Controller_Init 'Required, takes - 4 s. DEBUG CLS, " Light Levels", 'Display legend for mesurements CRSRXY, 8,3, "U", CRSRXY, 8,5, "D", CRSRXY, 6,4, "W", CRSRXY, 10,4, "E" '------[Main ]------------------------------------------------------ DO 'Repeat indefinitly (DO...LOOP) GOSUB Get_Decay_Times 'Get light measurements GOSUB Display_Decay_Times 'Display measurements in DEBUG GOSUB Tracker_Control 'Decide what action to do GOSUB Azimuth_Altitude_Control 'Control pan and tilt motor LOOP '------[Subroutine Get_Decay_Times ]------------------------------- Get_Decay_Times: 'Get light measurements FOR pindex = LED_EAST TO LED_TOP 'Loop thru 4 sensors HIGH pindex 'Charge diode junction PAUSE 1 'wait 1 ms RCTIME pindex, 1, time(pindex - LED_EAST) 'Time diode junction cap decay NEXT 'Repeat FOR...NEXT loop RETURN 'Return from Subroutine '-------[Subroutine Display_Decay_Times ]------------------------- Display_Decay_Times: 'Light sensor display subroutine FOR index = LIGHT_EAST TO LIGHT_TOP 'Loop thru 4 measurements LOOKUP index, [12,6,0,6], x 'Set cursor - x position LOOKUP index, [4,6,4,2], y 'Set cursor - y position DEBUG CRSRXY, x,y, DEC5 time (index), CR 'Display indexed measurements NEXT 'Repeat the loop RETURN 'Return from subroutine '--------[ Subroutine Tracker_Control]------------------------------- 'Set control variables based on sensor measurements. Tracker_Control: ' East/West rotation ' If it's light enough, divide difference between axis light measurements ' into average light for the axis. IF the result is less than MAX_ERROR_H, ' tracker rotates platform to catch up with light source provided the limit ' switch for that direction is not pressed. IF time (LIGHT_WEST) < MAX_TIME AND time (LIGHT_EAST) < MAX_TIME THEN error = time (LIGHT_WEST) - time (LIGHT_EAST) average = time (LIGHT_EAST) + time (LIGHT_WEST) / 2 IF average / ABS (error) < MAX_ERROR_H THEN IF time (LIGHT_WEST) > time (LIGHT_EAST) THEN ENDIF ENDIF ENDIF ' Up/Down adjustment ' If it's light enough, divide difference between axis light measurements 'into average light for the axis. If the result is less than MAX_ERROR_V, 'tracker tilts platform to face the light source. IF time (LIGHT_TOP) < MAX_TIME AND time (LIGHT_BOTTOM) < MAX_TIME THEN error = time (LIGHT_TOP) - time (LIGHT_BOTTOM) average = time (LIGHT_TOP) + time (LIGHT_BOTTOM) / 2 IF average / ABS(error) < MAX_ERROR_V THEN IF time ( LIGHT_BOTTOM) > time (LIGHT_TOP) THEN udmotorPulse =ALTITUDE_UP ELSE udmotorPulse = ALTITUDE_DN ENDIF ENDIF ENDIF RETURN '------[Subroutine Azimuth_Altitude_Control]----------------- 'Send pulses simular to standard hobby servo control signals to control 'the Solar Tracker's Azimuth and Altitude motors. 'must call at least every 500ms. Azimuth_Altitude_Control: PULSOUT AZIMUTH, ewmotorPulse 'Send pan motor control pulse PULSOUT ALTITUDE, udmotorPulse 'Send tilt motor control pulse PAUSE PULSE_DELAY 'Delay for at least PAUSE_DELAY RETURN '----[Subroutine ST_Controller_Init]------------------------------ '************************************************* ******************** '************************************************* ******************** 'THE ORIGINAL STUDENT GUIDE; SOLAR TRACKING W/ BASIC STAMP USED A SECOND CONTROLLER 'TO COMMUNICATE WITH NON-PARALLAX MOTOR AND PNEUMATIC PISTON. 'I NEED TO REPLACE THIS SUB-ROUTINE TO CONTROL 2 PARALLAX STANDARD SERVOS ' ************************************************** ************************ '************************************************* ************************** ST_Controller_Init: ewmotorPulse = 760 udmotorPulse = 760 'Pause 1/10 s, 100 neutral pulses for ~2 s to indicate activity on 'channels, pause another 1/10 s, then neutral pulses for ~ 2 s so 'that Azimuth (panning) and Altitude (tilting) controller gives BS2 control. FOR counter = 0 TO 199 IF counter//100 = 0 THEN PAUSE 100 GOSUB Azimuth_Altitude_Control IF counter//50 = 0 THEN DEBUG "initializing...", CR NEXT RETURN
Comments
I just swapped the servo cables and the horizontal (Azimuth) axis responds although still somewhat irradic. One thing that puzzles me is that when I operate the axes with the pushbuttons they both respond just fine.
Tru
Are you required to use a pneumatic cylinder and if so, do you already have it?
I am not required to use pneumatics, I want to stick to servos and I have mag reed switches to put in place as limit switches once I get the thing running. I will post some photos later on this AM, I will try to make a video but am not sure how to attach it?
As far as a hardware problem, I am a little stumped because it functions fine under the control of the push-buttons and I dont know exactly what you mean " configuration" issue.
There are 4 LEDs arranged in a quadrant pattern which are reversed biased and the Cathodes are attached 10K resistors and Anodes to ground.. The 10K resistors are then connected to a I/O pin.
The only real difference in the pushbutton arrangement is that they have a 220 ohm resistor in series with the button and
ground whereas the LEDs are directly connected to ground
Thanks for your help !!
One more thing, I have also set up the terminal controlled solar tracker from the terminal in the debug screen and it worked ok as well
If you remove the RCTIME subroutines and just plug in values, or maybe get user input via DEBUGIN, do you get better results?
Also see this clever one, no active electronics: http://www.josepino.com/lego/simple_sun_tracker
The malfunction is that the data in the Debug from the reverse biased LED's does not allow the servo motors to find a "sweet spot" and stay put. In the photos there is no shield around the LED's that creates a shadow, it got left accidently at school and I have fashioned one from cardboard temporarily to create a shadow on one or more LED's so when the RCTIME compares their values. It does respond somewhat to the light but kind of spasms around and wont settle in.
Also it wont allow for 180 degree rotation even though I set the Standard Servos so that they have a 90 degree freedom in both directions for both axes and yet the pushbutton programs works beautiful. I am attaching the pushbutton program here so in case something is obviously (Not to me!) different.
As far as the proximity of the LED's to each other, I am following the Student guide and am using a slightly larger protoboard than the one on the Basic Stamp, I have stuck with this layout because the LED's fit somewhat snugly inside the 3/4" PVC tube. One of the biggest gaps in my understanding this student guide is eliminating the second controller for the motor and would be pneumatic cylinder as I am using two standard servos instead. Once I get this to work smoothly I want to add some magnetic reed switches to serve as limit switches.
I am not sure about replacing the RCTIME with Debuggin, the idea I thought was to allow the decay of the current, read by RCTIME would translate into directional values.
I am new to programming, I have downloaded most of the Parallax student guides and the Basic stamp manual. If anyone can reccommend an alternate text that could help with my understanding about the ins and outs of programming language for Basic Stamp I would appreciate it. Next Fall we get into solid state circuitry and digital and linear circuits and I saw some student guides that I can work on over the summer but I would like to get a better handle on the programming syntax
The project is supposed to be complete for Wednesday AM so I have a working backup plan using the continuous rotation servo's and a some code to simulate a daily sun tracking path, but I am really hopeful to show the advisory board members the real project in hopes that they might be able to help with a summer internship so I am really trying to get this system working correctly.
Thanks, all! Tru
Start with just one axis, either east/west or up/down, and show us exactly what your sensors are outputting. A screen shot of debug data at least, even better is a video showing the numerical trends as the sensors move in & out of the shadows when you move the light around.
Is that right? They mention a pneumatic cylinder there. Man, how I hate all that bloated universal code. The specific portion you need to demonstrate tracking is probably only about 30 lines long crunched. Are you up to it?
I meant that for a (temporary) troubleshooting aid (DEBUGIN data in lieu of "sensor" data), just to see what's going on.
Well Wednesday has come and gone and I was able to present the project with a basic program running a demo operation of a solar path. I had to switch over to the continuous rotation servos because the standard servos were not giving me the full 180 degree rotation (?)
There is one more person (The adjunct of the EET department) that I have to show it to this AM and then I can break it down and reinstall the standard servos and start again. I have had my head buried in the books for finals which are over today!
I am willing to make any adjustments to the design or program to get this system to work. I was using LED's as notated in the Student guide. I am not 100% sure if LEDs are more sensitive to decay when reversed biased or if they just suggested them because they are inexpensive. As far as the array is concerned I can move them outward but my understanding was that the tight pattern worked inside of the pvc fitting because of the shadows it created.
I am taking a summer course in advanced micro-controllers using the professional development board and Stamp Works guide, but I really need to boost my knowledge in programming syntax. Do you have any suggested reading that might help?
I will post to the forum when I have returned my project back to the original design. By the way, what does HTH mean?
Thanks for your willingness to help,
Tru
Well classes are over for a while, I am starting to prepare for a summer class. It is a directed study using the Professional Development Board and following Stamp Works. I have put the solar tracker aside for now because I realize that it is an ambitious project for which I dont really understand the PBasic Language. I am now trying to develop a solid foundation in the command syntax. I guess I have to crawl before I can walk! If you have any suggested reading to develop a practical understanding of PBasic I am all ears?
Tru