Using the Location Sensor in VEXcode VR

The VR Robot has a multitude of sensors, including a Location Sensor.


Location Sensor on the VR Robot

Diagram illustrating the key features of VEXcode VR, showcasing the virtual robot's capabilities and user interface designed for coding education in STEM, including block-based and text-based programming options.

The VR Robot has a Location Sensor built in that reports the (X, Y) position of the VR Robot. The location of the VR Robot is determined by the center turning point. This is also the location of the pen on the VR Robot.

Diagram illustrating the key features of the VEXcode VR robot, highlighting its capabilities for programming and simulation in a virtual environment, designed for educational purposes in STEM learning.

The Location Sensor also reports the location angle which ranges from 0 degrees to 359.9 degrees following a compass heading style.

Diagram illustrating the key features of the VEXcode VR robot, including sensors, wheels, and programming interface, designed to enhance learning in coding and robotics for students and educators.

Each Playground ranges from -1000mm to 1000mm for the X and Y positions. The starting location of the VR Robot depends on the Playground selected. For more information about location details on a Playground and the coordinate system, view the following articles:

Diagram showcasing the features of the VEXcode VR robot, highlighting its capabilities and components within the context of an online programming environment for learning coding concepts.

The Location Sensor values can be displayed on the Dashboard in VEXcode VR. To learn more about the Dashboard, view the Dashboard - Playground Features - VEXcode VR article.

Diagram illustrating the key features of VEXcode VR robots, highlighting components such as sensors, motors, and programming interface, designed to enhance learning in coding and robotics for students and educators.

The Location Sensor values can be displayed on the Monitor Console in VEXcode VR.

  • To learn more about using the Monitor Console with VEXcode VR Blocks, see this article.
  • To learn more about using the Monitor Console with VEXcode VR Python, see this article.

Common Uses of the Location Sensor

The Location Sensor on the VR Robot can be used in many ways.

VEXcode VR Blocks Castle Crasher Playground
Diagram illustrating the key features of the VEXcode VR robot, highlighting its capabilities and components for programming and robotics education. Illustration of VEXcode VR robot features, showcasing various components and functionalities that enhance coding and robotics learning in a virtual environment.
VEXcode VR Python
def main():
while not location.position(Y, MM) > -300:
drivetrain.drive(FORWARD)
wait(20, MSEC)
drivetrain.stop()

The Location Sensor can be used to navigate the coordinates of any Playground. Each Playground ranges from -1000mm to 1000mm for the X and Y positions.

For example, if you wanted the VR Robot to stop once it crossed a certain value on the Y-axis, you could set a threshold on the Y-axis to be greater than that value. This center castle in the Castle Crasher Playground is close to a Y-value of -250. So the example project sets the VR Robot to stop driving after it passes a Y-value greater than -300, and will not crash into the castle.

VEXcode VR Blocks Disk Mover Playground
Diagram showcasing the features of the VEXcode VR robot, highlighting its capabilities and components in a virtual programming environment designed for educational purposes in STEM learning. Diagram illustrating the key features of VEXcode VR robots, highlighting components such as sensors, motors, and programming capabilities, designed to enhance learning in coding and robotics for students and educators.
VEXcode VR Python
def main():
drivetrain.turn_for(RIGHT, 90, DEGREES)
while not location.position(X, MM) > 800:
drivetrain.drive(FORWARD)
wait(20, MSEC)
drivetrain.turn_for(LEFT, 90, DEGREES)
while not location.position(Y, MM) > -100:
drivetrain.drive(FORWARD)
wait(20, MSEC)
drivetrain.stop()
magnet.energize(BOOST)

The Location Sensor can also be used to move the VR Robot to a known location. In this project, the first green disk appears to be at the location (800, -200). To reach that point, the VR Robot can drive along the X-axis until it reaches 800 and then along the Y-axis until it reaches -200 to pick up the disk.

VEXcode VR Blocks Art Canvas Playground
Diagram showcasing the features of the VEXcode VR robot, highlighting its capabilities and components within the context of an online programming environment for learning coding concepts. Diagram illustrating the key features of the VEXcode VR robot, highlighting its virtual programming capabilities, block-based and text-based coding options, and educational applications in STEM learning.
VEXcode VR Python
def main():
pen.move(DOWN)
drivetrain.drive_for(FORWARD, 400, MM)
while location.position_angle(DEGREES) < 89:
drivetrain.turn(RIGHT)
wait(20, MSEC)
pen.set_pen_color(RED)
drivetrain.drive_for(FORWARD, 400, MM)

The Location Sensor can also be used to determine the current angle of the VR Robot. In this project, the VR Robot will drive forward, and then turn right. It will wait until the VR Robot's angle is greater than 89 degrees and then change the pen color to red and drive forward another 400mm.

Note that the location angle in the Dashboard is 92 instead of exactly 90 or even 89.1. This is because it takes time for the flow of the project to proceed and process each command as they are executed. Thus, the 92 degrees is not a mistake, it is intended due to processing time and the speed of the VR Robot.


Using the Location Sensor in VEXcode VR Blocks

(Position of robot) block

Diagram illustrating the features of the VEXcode VR robot, highlighting its capabilities and components in the context of an online programming environment for learning coding and robotics.

The (Position of robot) block reports the X or Y coordinate position of the VR Robot.

Diagram illustrating the key features of the VEXcode VR robot, highlighting its virtual programming capabilities, block-based and text-based coding options, and educational applications in STEM learning.

The X or Y coordinate position can be selected from the drop-down menu on the block.

Diagram illustrating the features of the VEXcode VR robot, highlighting its capabilities and components in the context of an online programming environment for learning coding and robotics.

The mm or inches units can be selected from the drop-down menu on the block.

(Position angle in degrees) block

Diagram illustrating the key features of the VEXcode VR robot, highlighting its components and functionalities within the context of an online programming environment for learning coding concepts.

The (Position angle in degrees) block reports the angle of the VR Robot in degrees to the nearest tenths place. The values range from 0.0 to 359.9 degrees.


Using the Location Sensor in VEXcode VR Python

Diagram illustrating the key features of the VEXcode VR robot, highlighting its capabilities and functionalities for educational programming and robotics learning.

To begin programming the Location Sensor with Python, you will need to first open a new text project in VEXcode VR. For more information, see this article.

Diagram illustrating the features of the VEXcode VR robot, highlighting its capabilities in programming, simulation, and educational applications for STEM learning.

The position command reports the X or Y coordinate position of the VR Robot.

The position angle command reports the angle of the VR Robot in degrees.

To add either of these commands to your project, you can drag the command in from the Toolbox, or type out the command in the workspace using the Autocomplete function. To learn more about Autocomplete in VEXcode VR with Python, see this article.

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

Last Updated: