Lego Boost Program – A Peek At My Boost Program

Lego Boost App
Lego Boost App

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. Since I don’t have any cool pictures to share, I’ll spend a little time this week sharing my Lego Boost Program. This is what I’m using to control the tracker. 

The Sole Consistent Aspect of the Lego Star Tracker

I’ve basically used the same program with only minor tweaks since the earliest versions of the Lego Star Tracker project.  This is one of the best aspects of working through different versions of this project. The Lego Boost platform is available from Google Play or Apple Store. While it is fairly intuitive to use, 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. That 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.

Lego Boost Program for the Lego Star Tracker
Lego Boost Program for the Lego Star Tracker

There are 3 main sections of my program.  First, the start button to run the program. Here, I initialize a variable that will keep track of how many degrees I’ve rotated since starting the program.  Second, I have a test control loop. While totally unnecessary, I wanted to be able to stop the program when the output changes by 40 degrees.  And finally, the meat of the program where I control the stepper motor.

Lego Boost Program Third Stage – Where the Magic Happens

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 programmed the device to increment the variable by 0.0083. But when displayed, 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. This is because I don’t really know how the branch is being handled internally as mentioned. 

That’s really all there is to it.  This is all made possible because the Lego Boost stepper motor can rotate the motor in 1-degree increments.  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 Lego 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 to computer programming.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.