I want to make a program for an EV3 solar heliostat.
It consists of two motors and a color sensor. I want it to follow the light. The station is fixed.
Bricks is a question and answer site for LEGO® and building block enthusiasts. It only takes a minute to sign up.Sign up to join this community
As far as I see, you have two possible ways of accomplishing this, given that you have already built an Altazimuth mount or any other two-dimension mount from the two motors that can hold the color sensor and point it in any direction.
This is the harder way but it grants neater results. It involves taking a precise measurement of the device's location and orientation, setting up a known orientation for both motors as zero, and porting a known solar-tracking algorithm to the EV3 (like this or this). The resulting setup then must not be shut down, moved or rotated since the control of the motors is done by an algorithm which only takes into account the starting conditions (spatial and temporal) and the elapsed time. The accuracy of the EV3 internal clock may also factor into the precision if the project is to be left running for a long time. As an added bonus, you don't need the color sensor at all.
This approach requires a lot less intial setup but offers a not-so polished end result. The basic premise is using the color sensor to get an estimation of the amount of the light incoming from the current direction, then comparing it with the measurement(s) from some other direction(s), finally turning toward the higher value.
There are two problems to be solved here: first, the current position of the Sun (or its equivalent if you are indoors) must be found among all possible orientations. This is an example of the mathematical operation known as finding the global maxima of a two-dimensional function on a constrained range, where the two input dimensions are the altitude and the azimuth and the output is the measured amount of light coming from the given direction.
Then, the software must account for the inevitable changes due to the relative movement of the Sun in the sky. Since you have chosen this way and not the first (Calculation), you can not know in advance which direction the Sun will move in. So you can only attempt to find it again after a set amount of time or after the measured brightness drops to (or by) a specified amount.
There are countless ways this approach can be fine-tuned, depending on the precision of the motors, the precision, update rate and measuring range of the sensor, the amount of location and orientation information known beforehand, the required precision of the resulting system, the allowed complexity of the software, etc.
The most basic and a very ineffective system would consist of the following pseudocode:
repeat forever: oldBrightness = read(colorSensor) movementXAxis = getRandom(-10, 10) // decide on a random direction to turn to movementYAxis = getRandom(-10, 10) moveXAxis(movementXAxis) // turn to the new direction moveYAxis(movementYAxis) newBrightness = read(colorSensor) if(newBrightness < oldBrightness) // if the new direction is worse than the old moveXAxis(-movementXAxis) // then turn back to the old direction moveYAxis(-movementYAxis) wait(someTime) // bask in the sun for a while :)
This of course can be updated with more advanced logic, including but not limited to
Consult the relevant Wikipedia page for some advanced reading material and as a starting point if you are interested in learning more about the applicable algorithms.