Still Cloudy
When I started this blog, I was really hoping that I'd be taking lots of photos and this would be my opportunity to share them all with you. Unfortunately, the weather here in Southern Poland has other ideas. Since November 1, there have only been 3 clear enough nights to shoot, and as you know, I've been testing away on the tracker.So, since I don't have any cool pictures to share, I thought I'd spend a little time this week to share the Lego Boost program that I'm using to control the tracker.
Keep reading to learn how really simple it was to control the Lego Star Tracker with this app.
The Sole Consistent Aspect of the Lego Star Tracker
One of the cool things about this project is that I've basically used the same program with only minor tweaks since the earliest versions of the Lego Star Tracker project. The Boost platform is available from the Google Play or Apple Store and is fairly intuitive to use, but I'll admit, I did need to experiment around with some of the functions.
By way of reminder, the latest version of the Lego Star Trackers has a gear ratio of 5760:1 which means for each 360 degree rotation on the input, the output will rotate by 0.0625 degrees. The rotation of the Earth will effect a change in the apparent position of the stars by 0.25 degrees per minute. So I need to execute 4 rotations on the input every minute to achieve the proper tracking rate. Or put another way, I need to rotate 24 degrees every second on the input.
Below is a screen capture of my Boost program.
Lego Boost Program for the Lego Star Tracker
There are 3 main sections of my program. First, the start button where I initialize a variable which will keep track of how many degrees I've rotated since starting the program. Second, a totally unnecessary conditional loop statement where I want to stop the program when the output changes by 40 degrees (really just for testing). And finally, the meat of the program where I control the stepper motor.
In the third or final stage, there is a fork that allows me to run 2 statements simultaneously. Now, I'm not entirely sure how the Boost program implements this branch, but given that I'm not running a lot of code here, I'm assuming the number of machine instructions is much much much less than the operating frequency of my iPad, so for all intents and purposes, I'm calling this simultaneous. But I know there are some programming purists out there who might beg to differ. I suppose down the road I can test this if I feel this is a problem. Or I could probably write Lego and ask...
The first branch of the third stage simply instructs the motor to rotate counterclockwise by 48 degrees. At the same time, the second branch increments my variable "a" and pauses for 2 seconds. Once the pause completes, the variable is tested to ensure that it's less than 40 "degrees" and then executes the branch again. Lather, rinse, and repeat.
The only nit you might be inclined to pick would be that I'm incrementing my variable by 0.01 in the image above. I have programed the device to increment the variable by 0.0083 but in the display, it rounds to a number with a precision of 2 and that is why it displays 0.01. Now, I have no idea if the code is incrementing by 0.0083 or 0.01, but once again, close enough for testing purposes. I know I can handle this in a more precise way, but I'm trying to keep the code to a minimum because as mentioned, I don't know how the branch is really handled internally.
That's really all there is to it. Once again, this is all made possible because the Lego Boost stepper motor allows me to rotate the motor in 1 degree increments. But it's that simple.
Conclusion
As you can see, there's not a lot of voodoo here. The Boost program handles all the hard stuff that you'd need to build and program into a microprocessor along with a little more external hardware. That makes this about as out-of-the-box as you can get. I'm not opposed to using a microprocessor for this project, but I'm not going to torture myself by doing it the hard way when Lego has made it so easy.
The only downside to using Boost, is that I need to run the program using the app. I'm OK with that, but others may not be. I know there is a Scratch implementation for Boost that you can theoretically download onto the device, but believe it or not, it doesn't allow for the precise stepper motor control I was looking for - at least as of a couple of months ago when I looked into it. But, it is kind of neat that you can use Scratch with the Lego Boost controller. At least my kids thought it was cool because that is what they are using for their introduction into computer programming.
No comments:
Post a Comment