Step 4: Updating Odometry and Visualizing Robot Position¶
Now that the simulated encoder positions, velocities, and gyro angles are being updated with accurate information periodically, this data can be used to update the pose of the robot in a periodic loop (such as the
periodic() method in a
Subsystem). In simulation, the periodic loop will use simulated encoder and gyro readings to update odometry whereas on the real robot, the same code will use real readings from physical hardware.
For more information on using odometry, see this document.
Robot Pose Visualization¶
The robot pose can be visualized on the Simulator GUI (during simulation) or on a dashboard such as Glass (on a real robot) by sending the odometry pose over a
Field2d object. A
Field2d can be trivially constructed without any constructor arguments:
Field2d instance must then be sent over NetworkTables. The best place to do this is in the constructor of your subsystem.
Field2d instance can also be sent using a lower-level NetworkTables API or using the Shuffleboard API.
Finally, the pose from your odometry must be updated periodically into the
Field2d object. Remember that this should be in a general
periodic() method i.e. one that runs both during simulation and during real robot operation.
It is important that this code is placed in a regular
periodic() method – one that is called periodically regardless of mode of operation. If you are using the command-based library, this method already exists. If not, you are responsible for calling this method periodically from the main