Monitoring Variable and Sensor Values in VEXcode VR with Python

Variable and sensor monitoring available in the VEXcode VR Monitor Console provides important visual cues that allow the user to see what is happening in a Python project in real time. The Monitor Console allows users to make a visual connection between the project and the actions of the VR Robot. Monitoring sensor and variable values in the Monitor Console allows the user to view real-time reports of a specific value (or multiple values) in a project.


How to Use the Monitor Console

Screenshot of the VEXcode VR programming interface, showcasing the block-based coding environment used for teaching coding concepts through a virtual robot, part of the Tutorials section for educators and students in STEM education.

To open the Monitor Window and view the Monitor Console, select the Monitor icon next to the Help.

Screenshot of VEXcode VR interface showcasing block-based coding options for programming a virtual robot, highlighting features for beginners and advanced users in a tutorial context.

The Monitor Console reports Sensor and Variable values.

Using the Monitor Sensor Command

Screenshot of VEXcode VR interface displaying a block-based coding environment, designed for learning coding concepts through virtual robotics, as part of the Tutorials section.

Sensor values can be added using the Monitor Sensor command. Add the identifier for the sensor as a string parameter.

Screenshot of the VEXcode VR interface showcasing a block-based coding environment, designed for teaching coding concepts through virtual robotics, as part of the Tutorials section.

The Monitor Sensor command accepts the following string identifiers.

This list of accepted string identifiers can also be found in the Help for the Monitor Sensor command.

Screenshot of the VEXcode VR programming interface, showcasing the block-based coding environment used for teaching coding concepts and robotics principles in a virtual setting.

The sensor value will appear in the Monitor Console when the project is started.

Screenshot of VEXcode VR interface showcasing block-based coding environment for programming a virtual robot, illustrating features for beginners and advanced users in a STEM education context.

Monitor multiple sensor values by using commas to separate the string identifiers.

Using the Monitor Variable Command

Screenshot of VEXcode VR interface showcasing block-based coding options for programming a virtual robot, illustrating features for beginners and advanced users in a tutorial context.

Variables can be added and removed from the Monitor Console using the Monitor Variable command. Define the variable as global, then assign a value. Add the variable as a string parameter.

def main():
global my_variable

To create a global variable, add the keyword "global" before the variable name.

def main():
global my_variable
my_variable = 0

Assign an initial value to the variable.

Screenshot of VEXcode VR interface showcasing the block-based coding environment, designed for teaching coding concepts through virtual robotics, suitable for beginners and advanced users in STEM education.

The variable value will appear when the project is started.

Screenshot of a VEXcode VR tutorial interface, showcasing block-based coding elements and a virtual robot, designed to help users learn coding concepts in a simulated environment.

Lists can also be added to the Monitor Console. Before being added to the Monitor Console, lists and 2D lists must be defined.

def main():
global my_list

To create a new list or 2D list, add the keyword "global" before the list name.

def main():
global my_list
my_list = [1,2,3]

Type the values in square brackets to add values to a list.

def main():
global my_list
my_list = [1,2,3]
monitor_variable("my_list")

To add a list to the Monitor Console, add the list name as a string variable in the Monitor Variables command. A string variable is indicated with " " around the name of the variable.

Screenshot of VEXcode VR interface showing block-based coding elements, designed for teaching coding concepts through virtual robotics in an educational setting.

The list values will appear when the project is started.

Screenshot of VEXcode VR interface showcasing block-based coding options and virtual robot controls, illustrating the platform's features for learning coding concepts in a simulated environment.

Monitor multiple variables and/or lists by using commas to separate the variable name string parameters.


Monitoring Sensor Values Example

Monitoring sensor values in the Monitor Console allows the user to view sensor data in real-time.

In this example, the distance from is being monitored in the Monitor Console. The project directs the VR Robot to stop if the VR Robot is less than 500mm from a wall.

Watch as the values of the distance from command change in the Monitor Console.

Note that the sensor value is referenced using quotations in line 28: monitor_sensor("distance.get_distance")


Monitoring Variable Values Example

The Monitor Console can also be used to monitor variable values. The Monitor Console can provide real-time reports of a specific variable in a project.

In this example, the “timesRepeated” variable is used to monitor the number of times the VR Robot repeats a certain behavior. Because of the parameters of the for loop, when this variable reaches the number 5, the VR Robot will exit the loop.

The variable monitoring on the Monitor Console can help to provide real-time feedback to understand the flow of the project. 

Note that the variable value is referenced using quotations: monitor_variable("times_repeated")

For more information, help, and tips, check out the many resources at VEX Professional Development Plus

Last Updated: