Programming Techniques
A. MyBlocks
OnStage programs quickly become unwieldy, with a string of hundreds of move blocks that make it impossible to work out where each move is in relation to the music. Many of those moves are repeated, which makes them a perfect candidate to become a MyBlock.
Go to the My Blocks section in the sidebar and select “Make a Block.” Type a name in the block and select “Save”
2. Build the block of code under the My Block definition block:
3. Then use the My Block whenever you want to run that code:
B. Variables
Even with MyBlocks, you'll still end up with a lot of Move blocks. When it comes time to tweak the timing it gets very tedious adjusting the time for every one of those by 0.002 seconds. That's where variables come in handy:
C. Parallel tasks
Adding more movements to a robot can make it much more interesting, and gives the students opportunities to learn about different mechanisms. You'll need to synchronise the additional movements.
D. Advanced techniques
Edge detection can save you from losing points when your robot tries to run off the mat. It is quite simple to detect the border of the performance area so you don't lose points. The complex part is working out what to do when you do detect it.
Timers enable you to start a “stopwatch” and then start parts of your program when different time points are reached. For example, you might start a timer at the beginning of your performance and run the “Chorus” MyBlock 23.56 seconds later.
Struggling with robot turns that overshoot or undershoot? In this video, we use the Scientific Method to test and adjust our LEGO Spike Prime robot’s yaw-based turning accuracy. By running multiple trials at different power levels, we calculate the perfect offset to nail turns every time.