Skip to main content

GPS Navigation

Create an algorithm to navigate the Hero Bot to a specific position on the Field. Use [Drive for] and [Turn to heading] blocks, the GPS Sensor, the Arm Motor, and the Intake Motor to drive the Hero Bot to the position located at (1380,-1380) to pick up the Triball highlighted in red. Then drive the robot to the position located at(600,-300) and score the Triball in the Red Alliance Goal.

  • Select the VRC Virtual Skills - Over Under Playground.
  • Use the Pre-Match checklist to select Starting Location “H”, Starting Direction ”North”, and Robot Preload “No” for the robot.
  • Create an algorithm to navigate the robot to a specific position.
  • Code the robot to spin the Arm Motor to fully lower the Arm for picking up a Triball on the Field.
  • Use the algorithm to navigate the robot to coordinates (1380, -1380) and turn the robot to Heading 135 degrees.
  • Code the robot to spin the Intake Motor to pick up the Green Triball highlighted in red.
  • Use the algorithm to navigate the robot to coordinates (600, -300) and turn the robot to Heading 90 degrees.
  • Code the robot to spin the Intake Motor to launch the Triball to the Red Alliance Goal. 

Helpful Hints

  • Use the GPS Sensor to identify the X and Y coordinates of the Hero Bot on the Field. For more information about using the GPS Sensor in the VRC Over Under Playground, please click here.
  • Use the Reporter blocks from the Sensing category to get positional values from the GPS Sensor.

    VEXcode GPS position block that reads 'GPS position X in mm'.

    VEXcode GPS position block that reads 'GPS position Y in mm'.

    • Matching Python command:

      gps.x_position(MM)
      gps.y_position(MM)
  • Use the set blocks from the Variables category to declare two variables to store the original X and Y coordinates of the Hero Bot.

    Stack of VEXcode Set variable blocks. The first block reads 'set X1 to GPS position X in mm'. The second block reads 'set Y1 to GPS position Y in mm'.

    • Matching Python command:

      X1 = gps.x_position(MM)
      Y1 = gps.y_position(MM)
  • For help with declaring a variable and storing data in the project, please select the “TUTORIALS” button in VEXcode VR and choose the Storing Data Tutorial.

    Tutorials icon from the VEXcode VR Toolbar.

    VEXcode VR Storing Data Tutorial icon.

  • For more information about the name rules for variables in VEXcode VR, please see this article.
  • Use the coordinates of the robot (x1,y1), the coordinates of the target position(x2,y2), and atan function to find the drive Heading.
    • Calculate the angle theta θ of the line connecting these two points.

      Diagram of two math expressions. The first expression reads 'theta is equal to atan((y2 - y1) / (x2 - x1))'. The second expression reads 'negative pi / 2 is less than theta, which is less than pi / 2'.

      Top down math diagram shows the robot at coordinate (X1, Y1) and a line is pointing towards the coordinate (X2, Y2). The distance is labeled with the variable d, the angle is labeled with the variable theta. The horizontal distance between the points in represented as 'x2 - x1', and the vertical distance is represented as 'y2 - y1'.

    • Convert the angle theta θ to drive Heading.

      Pseudocode example for Math expression (Starting Direction: North):

      if X1 equal to X2:
      	if Y2 > Y1:
      		heading = 0
      	else:
      		heading = 180
      else:
      	if X2 > X1:
      		heading = 90 - atan((Y2 - Y1) / (X2 - X1))
      	else:
      		heading = 270 - atan((Y2 - Y1) / (X2 - X1))
    • Top down diagram shows the robot within a circle that has labels marking the circle's 360 degrees.
  • Use the function block from the Operators category and select the atan function to calculate the angle theta θ

    Empty VEXcode Function block that reads 'atan of blank'.

    • Matching Python command:

      math.atan( ) / math.pi * 180
  • Use the coordinates of the robot (x1,y1), the coordinates of the target position(x2,y2), and the Pythagorean Theorem to find the drive distance.

    Math expression reads 'd = sqrt((X2 - X1) ^ 2 + (Y2 - Y1) ^ 2)'

    The same top down diagram as before showing the difference between two coordinates. The robot is at coordinate (X1, Y1) and a line is pointing towards the coordinate (X2, Y2). The distance is labeled with the variable d, the angle is labeled with the variable theta. The horizontal distance between the points in represented as 'x2 - x1', and the vertical distance is represented as 'y2 - y1'.

  • Use the function block from the Operators category and select sqrt function to calculate drive distance.

    Empty VEXcode Function block that reads 'sqrt of blank'.

    • Matching Python command:

      math.sqrt( )