A Master Program allows you to combine all your missions in one program. It is a big time saver and reduces stress. The starting team just presses one button to move to the next program versus hunting and pecking through the menu structure. A good master program allows you to navigate backwards and forward over runs.
Building a simple Master Program
A simple master program uses the wait block and my blocks. For information on My Blocks, see the EV3 help. Word of warning, kids love picking icons for their My Blocks. They will spend hours if allowed. It works by waiting for the middle button to be released before running the next program. If you have a young or inexperienced team, I would recommend this master program. It is simple to understand and program.
Building a Robot Nerd Master Program that displays the program and allows you move forward and back.
I know, what the hell is this. It looks complicated. If you team understands loops and switches, then it is actually simple. The big concept is the variable block, which stores a value in memory. To teach the concept of memory and variable block, assign one team member to be the memory block. You ask and give her a new number. This worked for teaching this concept to my team.
The Robot Nerd Master Program displays the active program and allows you move forward and back over the programs.
- Create my blocks for each program you want to include in your master. See the EV3 help for instructions on creating a my block.
- Create new program.
Add a Variable Block as the first block. Set it to number and write. Name it count and set the value to 1. The variable tracks the active program to run in memory. You add or subtract 1 to move between programs.
Add a loop and set the exit condition to “unlimited”. The loop runs listening for actions inside. The rest of the blocks will be inside the unlimited loop.
Displaying the Active Program
So the starting team can see the program that they are going to run, we want to display the active program. We read the count value and pass it to a switch. The switch reads the numbers and runs the block in the corresponding case statement.
- Add a variable block and set it read.
- Add a Switch that takes a number input.
- Connect the Count variable and switch block, the yellow wire.
- Add a case (the plus button) for each program you want to run. In this example 4.
- Number the switches, 1-4 in this example. Set the first one to the default.
- Add a display block to each switch. I recommend adding numbers to the label.
If you were to run this now, it would display “1. Door”. We set the variable to 1.
123 Lego – Running the first mission
The next step is triggering a program to run and then increment the Count variable by 1.
Running the Program
To achieve this, we add a switch block triggered by the brick button (Brick Button – Compare – Brick Buttons). We set the switch brick button properties to the middle button and state to 2, indicating the middle button was pressed and released.
Like the display logic, read the Count variable and pass it into a switch. Instead of the display, the associated My Blocks (the program) is in the case statement.
Automatically Moving Forward to the next program
Next we want to increment the count variable by 1 so will move to the next program. There is a catch, we do not want to increment the count variable if it is set to the last program. In this case, we don’t want to go from 4 to 5. This requires some comparison logic.
- Read the Count Variable
- Compare the Count Variable to the number of your last run. If the count variable does not equal the max value, 4 in this example. The Compare block will pass a true or false.
- Pass the compare results (true or false) to the switch. If the is true (Count does not equal 4), run the true case.
- In the true case, read the Count variable.
- Increment the Count Variable by 1
- Write the new Count Variable.
Moving Back a Program
Things happen and sometimes you want to go back a program. You could exit out of the master, restart it or hunt and peck to find your program. Here’s an idea, let’s add some logic that allows you to go back. To do this, all you need to do is subtract 1 from the Count Variable when it is not equal 1.
In the code below, you press the left button. If the Count Variable is not 1, is subtracts 1 and updates the Count Variable.
Moving Forward a Program
You are at a tournament and realize your runs are over 2.5 minutes and need to skip over a program. Just like moving back, all we need to do is increment the Count variable by 1. This logic already exist, we just need to trigger it with the right button. You could make this logic a My Block.
Coast your motors
In a master program, if a run program ends when the motors ending with a stop, the motors lock. You cannot roll the robot or adjust a motorized arm. For example, the starting team can not roll the robot into position or position the arm. This is simple to resolve, just set the last move or motor blocks to coast in your run My Blocks. This unlocks the motors.
Beware of Master Program Ghost
The program worked perfect when run as a standalone program but does strange things in the master. I call this ghost.
I cannot explain why this happens but it is like the motor rotation sensors drift. The issue is similar to the gyro drifting (which is more of a demon than a ghost). We did figure out that adding a Motor Rotation Sensor and setting it to reset for each motor is our ghost buster.