Decision Making - Text-based
Teacher Toolbox - The Purpose of this Reading
This STEM Lab focuses on programming the robot to respond to the conditions it detects. This first reading is intended to introduce the idea of conditionals, boolean (TRUE or FALSE) conditions, and the benefit of including these programming structures within a project. Students should begin to recognize that including conditional programming improves how the robot responds to its environment.
While watching a robot, it might seem to be making decisions about its own behavior but within the programming, it is checking on conditions and taking action appropriately. Students could consider how conditions influence their own informed decisions.
Decision to be made: Should I take an umbrella?
Current condition: It is likely to rain (TRUE).
Decision: Take an umbrella.
At their most basic level, programs are written to accomplish simple sequences of behavior. For example, you might want your robot to drive forward and also make some turns to reach a destination. But, what if you want your robot to wait for the right time to start driving forward and complete its route? That would require programming with conditional statements. You would use a conditional statement to define what the "right time to start" is within your project. Maybe the "right time" is after a button is pressed or when a sensor detects a specific level and then it starts driving. When you watch the robot's behavior, it will seem like it is deciding when to start driving but it's because you set the condition for when driving should start.
Conditional statements are powerful programming statements that use a boolean (TRUE or FALSE) condition. Using the same example scenario as above, you could program your robot to repeatedly check if its brain screen is pressed and drive forward when it is. The conditional statement in that project may read something similar to, "If the screen detects that it is pressed (TRUE), run the driving sequence." This statement does not mention any behavior if the condition is FALSE (the screen is not pressed) so the robot takes no action when FALSE. Conditional statements allow you to develop projects that have the robot behave differently depending on what it senses. For more information on Boolean Logic, click here.
In the following example, if the Brain's screen is pressed (TRUE) the robot will drive forward. If the Brain's screen is not pressed (FALSE) the robot will stop driving. This shows the robot only driving forward when the Brain's screen is pressed, otherwise the robot stops.
Teacher Tips - Using Autocomplete
Autocomplete is a feature in VEXcode V5 that predicts the rest of the command you are typing. As students are working in VEXcode V5, encourage them to use the Autocomplete feature to help with the syntax. You may notice an autocomplete function as you start to type the instruction. Use your “Up” and “Down” keys to select the name you want, then press “Tab” or (Enter/Return) on your keyboard to make the selection. For more information on this feature check out the C++ or Python articles.
Extend Your Learning
To expand this activity, ask your students to pair up into teams and create a sketch of a maze for another team to complete. The maze should require a minimum of three to five conditional statements. For example, continue forward until there is a wall. Then, turn left. The students should write a solution to the maze in flowchart form. Students should then trade mazes with another team who should, in turn, create a solution to the maze in flowchart form. The two teams should then compare answers to see how closely they match.
To relate this activity to online or mobile games, ask your students to describe the goal of their favorite game/app. Then have students create a flowchart that outlines the first ten yes/no or true/false decisions that they follow in their game.