In our last class before Spring Break, we tried to apply proportional control to the drive-straight program while running a proportional-control version of the distance-sensing program. This proved more difficult than we expected; while the previous class had ended with our seeming success in a drive-straight program, Professor Turbak began this day with a lecture which explained about five different incorrect assumptions we had made while writing the program (order of operations, negative power, etc.). We lamented a bit about how neither my partner nor I had ever programmed before, and then set about to fixing our many errors.
We had initially attempted to fix the negative signs on the error by using an if-then-else statement to make sure that the final value for the engine power was positive; however, this method hinged on our error being either very small or very large. This caused an unwanted result when we held one wheel and let the other spin: ideally, the unheld wheel would stop quickly of its own accord, but our program caused the wheel to continue spinning indefinitely.
To fix this error, Professor Turbak used the text language to define a new expression, "valid". This was initially meant to define a value as 0 if it were negative (and leave the value alone if positive). However, since my partner and I had built the rest of our program around the assumption that a negative error would simply switch the direction of the wheels, we made this an absolute value expression (outputting -n if n<0, n if n>0). After a bit more experimentation, Professor Turbak patiently explained how this method could never possibly work, and we went back to the absolute value program.
The absolute value program, "valid" (lower text):
This made our program much neater by cutting out two large if-then-else loops, but we needed to change large portions of the rest of it since a negative value now made the wheel's power go to zero. After much (almost two hours) fussing, we eventually made our way to a program that stopped Snow White's other wheel when one was held. Hooray!
(I had hoped to include images of my programs in this blog post, but after the OS switch, the engineering room computers refused to open my old PicoBlocks programs. Hopefully we'll find away around this problem soon.)
Then we began to play around with the light sensors for our next project--the final project, whose theme is "Follow the Light", will center around...following light. Some suggestions for projects are a sun tracker for photovoltaic panels, a fire extinguisher (sensing candle light), or moving mirrors to more naturally and efficiently light an indoor space (or the greenhouse). I'm most enthusiastic about solar panels at the moment (though there are various other types under development that do not need a perfect angle of sunlight), but I have not yet decided on my project. In the meantime, it seems like we'll be learning Matlab soon, which is truly exciting--I look forward to finally learning the baby steps of a text programming language!

No comments:
Post a Comment