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

Screen_Shot_2022-04-20_at_4.30.40_PM.png

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

Screen_Shot_2022-04-20_at_4.32.32_PM.png

The Monitor Console reports Sensor and Variable values.

Using the Monitor Sensor Command

monitor_sensor.png

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

string_identifiers.png

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.

Screen_Shot_2021-10-18_at_12.06.48_PM.png

Add the correct string identifier as a parameter in the Monitor Sensor command. For example, add the string "distance.get_distance" to report the distance sensor reading in the Monitor Console.

Screen_Shot_2022-04-20_at_4.34.28_PM.png

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

Screen_Shot_2022-04-20_at_4.35.32_PM.png

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

Using the Monitor Variable Command

monitor_variable.png

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.

Screen_Shot_2021-10-18_at_12.16.35_PM.png

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

Screen_Shot_2021-10-18_at_12.16.56_PM.png

Assign an initial value to the variable.

Screen_Shot_2021-10-18_at_12.22.11_PM.png

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

Screen_Shot_2022-04-20_at_4.38.15_PM.png

The variable value will appear when the project is started.

example_list.png

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

Screen_Shot_2021-10-18_at_11.50.56_AM.png

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

Screen_Shot_2021-10-18_at_11.51.05_AM.png

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

Screen_Shot_2021-10-18_at_11.51.34_AM.png

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.

Screen_Shot_2022-04-20_at_4.39.58_PM.png

The list values will appear when the project is started.

Screen_Shot_2022-04-20_at_4.42.00_PM.png

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