Skip to main content
Teacher Portal

Robot Behaviors - C++

Teacher Tips icon Teacher Tips

As mentioned previously, behaviors are a way to talk about the robot's actions. One way to get students thinking about behaviors and organizing actions in a sequence is to have students label different parts of their project using comments. The students can label the different behaviors from the challenges throughout the project.

Consider a simple example challenge of playing Tag. The students are asked to program the robot to turn quickly to avoid being tagged, drive slowly to tag someone, and then turn quickly again to run away. View the example below of using the comments to describe the sequence of behaviors:

A VEX C++ program code that includes the vex.h library and uses the vex namespace. The program starts by initializing the robot configuration with vexcodeInit(). It then sets the drivetrain's turn velocity to 75 percent and commands the robot to turn 180 degrees to the right, followed by setting the drive velocity to 25 percent and driving forward for 80 mm. Lastly, the robot turns 180 degrees to the right again. The comments in the code describe the actions as Turn quickly to avoid being tagged, Drive forward slowly to tag someone, and Turn quickly again to run away.

Notice that the description of the behavior is in simple language and the comments capture single components (i.e., turning quickly, driving forward slowly, and turning slowly) of the larger behavior (playing tag).

It is good practice to ask the students to explain how they will plan for these challenges in terms of how they want and expect the robot to behave.