It has been a while since I last posted and a lot has happened in the meantime. I will not bore you with Thanksgiving celebrations, but I will let you know the last few weekends have not been my own. I have been technical judging at various FIRST LEGO League (FLL) tournaments. These are tiring days. We start early, work hard with the students and get home late. I am physically tired, mentally exhausted and in no mood to work on electronic projects.
But for a few days over the holiday and the past few nights I have gotten some quality time to work on the SUNDAR. I had had all kinds of problems with the stepper motor, but a higher voltage current chopper driver board from Pololu fixed that. I also found that the mass I had spinning on the output shaft was too much for the accelerations I wanted. So I replaced my hand etched board and super fancy (and expensive) photodiode with a $4 ambient sensor from AdaFruit.
After some fiddling, I got a nested finite state machine working that takes care of initialy finding the home position, then making a few full scans looking for the sun, and then finally dropping into scan mode where the head dithers right and left of the sun by a few degrees. If I move my ‘sun’ (a massively bright LED the type they put in street lights) the scanner follows along.
But a sudden rotation in the base of the system (like a sharp turn of a robot), and the sun is no longer in the sweep (+- 15 degrees) of scanner. To combat this problem, I purchased a MEMS gyro from AdaFruit that is based on the L3GD20 chip. Their unit has voltage regulators and level translators on board as well as supporting I2C and SPI. This gyro will be able to inform the system that the base has rotated and let the scanner know to adjust its scan pattern.
So it took some time to get the gyro to work properly. The simple I2C and SPI libraries from AdaFruit were much too slow to integrate the heading with any degree of accuracy. It was also slow enough (480 micro seconds) each sample that it prevented my motor from stepping as fast as I would have liked. So I spent some time writing a non bit-banged SPI interface to the gyro. Now my samples (including integration computations) are only 4.8 micro seconds long. That was a 100x improvement in speed and I have still not fully optimized the code. There is a bunch of floating point math I could replace with integer math.
In a separate test application, I had the gyro working well enough to keep an accurate heading (+- a few degrees) over a minute non moving. Of course shaking it about, the heading drifts at an alarming rate. Many degrees in a few seconds. But for my purposes, this is not an issue. All I want is the change in heading during a single scan that takes less than a seconds. Once I find the sun, I can assume it has not moved and reset the gyro heading based on that.
So tonight I moved the gyro code into my Sundar application and in a short period of time had it up and running. The device will find the sun and the regardless of how you spin the base (within reason!) the scanner will adjust itself and keep tracking the sun.
My next goal is to make it smart enough that if it losses lock on the sun, it will go back to hunt mode and spin around fully to look for the sun again.
I may also have a problem with the cheap ambient light sensor I got from AdaFruit. The previous sensor had a filter on the front to only pass visible light. The sensor was very expensive and needed a 3 stage opamp circuit to get useable results from it. The filtering was great because I could put cheap neutral density filters in front of the sensor to cut down the light and prevent the sensor from saturating.
The new ambient sensor will not be as easy as it is sensitive in the near IR band as well. Cheap plastic film neutral density filters only cut out visible light and still pass near IR. This may mean my sensor will be saturated for many degrees around the sun. I have looked into IR stop band filters and they are possible, but they are heavy and made of glass. Lets hope I do not have to go down that path.
I will try to get pictures and perhaps some video in the next few days.