Shop OBEX P1 Docs P2 Docs Learn Events
Solar Tracking with Basic Stamp — Parallax Forums

Solar Tracking with Basic Stamp

Tru CustomTru Custom Posts: 13
edited 2013-05-25 15:46 in BASIC Stamp
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
'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

  • Tru CustomTru Custom Posts: 13
    edited 2013-05-04 15:01
    Hello all,
    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
  • ercoerco Posts: 20,256
    edited 2013-05-04 19:55
    Welcome, Tru! HTH if we can. Sounds like it might be a hardware or configuration issue. Please post some photos if you can, a Youtube video is even more helpful.

    Are you required to use a pneumatic cylinder and if so, do you already have it?
  • Tru CustomTru Custom Posts: 13
    edited 2013-05-05 02:12
    erco wrote: »
    Welcome, Tru! HTH if we can. Sounds like it might be a hardware or configuration issue. Please post some photos if you can, a Youtube video is even more helpful.

    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
  • Tru CustomTru Custom Posts: 13
    edited 2013-05-05 03:01
    Here are a few pics of the project
    1024 x 768 - 95K
    1024 x 768 - 104K
    1024 x 768 - 93K
    1024 x 768 - 87K
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2013-05-05 12:26
    What is the malfunction? It's not moving the way you expect that it ought?
    If you remove the RCTIME subroutines and just plug in values, or maybe get user input via DEBUGIN, do you get better results?
  • ercoerco Posts: 20,256
    edited 2013-05-05 14:28
    Looks like your light sensors (LEDs?) are all grouped together, all seeing the same light. Seems to me that you need to separate them with a light-tight cruciform baffle for directional sensing. Or at least point them in opposing directions, as shown here at http://www.redrok.com/led3xassm.htm#c3schematic

    Also see this clever one, no active electronics: http://www.josepino.com/lego/simple_sun_tracker
  • Tru CustomTru Custom Posts: 13
    edited 2013-05-06 13:00
    Hello,
    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
  • ercoerco Posts: 20,256
    edited 2013-05-06 13:43
    Nothing like a good deadline. Wednesday it is. Time to simplify. OK, your pushbutton version works perfectly. So all that remains is getting your sensors to control them as you wish.

    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.
  • ercoerco Posts: 20,256
    edited 2013-05-06 15:45
    It looks like you got your code in post #1 from http://www.scribd.com/doc/121385995/Solar-Tracker-Const-Guide-Rev4-All3units or http://74.6.116.71/search/srpcache?ei=UTF-8&p=site%3Ascribd.com+Indoor+Light+Tracker.BS2&fr=yfp-t-777&u=http://cc.bingj.com/cache.aspx?q=+Indoor+Light+Tracker.BS2+(site%3ascribd.com)&d=4522962355489043&mkt=en-US&setlang=en-US&w=TMkTBDCsJxYIzi97XShc7BQ2I2FdegSk&icp=1&.intl=us&sig=ZOW346g88pKJtTIMaMrsHQ--

    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?
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2013-05-06 16:38
    Tru Custom wrote: »
    Hello,
    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 meant that for a (temporary) troubleshooting aid (DEBUGIN data in lieu of "sensor" data), just to see what's going on.
  • ercoerco Posts: 20,256
    edited 2013-05-07 13:13
    Here it is Tuesday (a day before deadline) and not a peep from Tru. Just when I was ready to roll up my sleves and help. Hopefully that means he's hard at work and/or has already solved the problem.
  • Tru CustomTru Custom Posts: 13
    edited 2013-05-13 05:21
    Hi Erco and everybody else!,
    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
  • ercoerco Posts: 20,256
    edited 2013-05-13 06:52
    Thanks for the update, Tru. Glad you got something going for your demo. HTH= happy to help,.and many of us here will be HTH when you get back onthe project. Happy finals!
  • Tru CustomTru Custom Posts: 13
    edited 2013-05-25 06:11
    Hi Erco,
    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
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-05-25 10:39
    Have you tried http://www.learn.parallax.com/search/node/pbasic ? There are a bunch of activities that will help you learn more about PBasic there.
  • GenetixGenetix Posts: 1,752
    edited 2013-05-25 15:46
    Parallax has a great Stamp In Class program that you should look at if you haven't already. StampWorks gives a great overview of what you can do with hardware and software. There are also the Nut's and Volts articles on the website that deal with interfacing to hardware, programming techniques and example, and using the BS2 and other Parallax hardware. But probably the best resource of all is the forums because there is a good chance someone might have already asked about something similar. I have read the forums for years but never participated so I know some people will give you a direct answer while others will point you in the right direction. You can always for help and guidance and it's ok to even ask stupid questions as Erco or someone else will reply to them.
Sign In or Register to comment.