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

VEXcode VR Python workspace showing the Monitor Console with variable and sensor values for a virtual robot

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

VEXcode VR Python project showing the Print Console used to monitor variable and sensor values

The Monitor Console reports Sensor and Variable values.

Using the Monitor Sensor Command

VEXcode VR Tutorials interface with a Python project open for monitoring variable and sensor values

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

VEXcode VR Python project showing the Monitor Console displaying variable and sensor values during a simulation

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.

VEXcode VR Python project showing the Playground console displaying variable and sensor values during execution

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

VEXcode VR Python project showing the Print Console displaying variable and sensor values during a run

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

Using the Monitor Variable Command

VEXcode VR Python workspace showing the Print Console used to monitor variable and sensor values during a project

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.

VEXcode VR Python project showing the Monitor Console with variable and sensor values displayed during runtime

The variable value will appear when the project is started.

VEXcode VR Python workspace showing the Playground window and monitor console for viewing variable and sensor values

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.

VEXcode VR Python project showing the Monitor Console displaying variable and sensor values during a simulation

The list values will appear when the project is started.

VEXcode VR Monitor Console displaying variable and sensor values while a Python project runs

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: