This template provides a partially completed WPILib Java project for a vision subsystem.
Programmers are expected to fill in the missing code to
-
Set up the Vision Simulation
a. Set up the simulation camera's properties in the
Constantsfile.b. Add the camera to the Vision Simulation.
-
View the Vision Simulator.
-
Be able to read the
TXandTYvalues fromSmartDashboardusingElastic.
The remainder of the document is a guide to how to get your simulation running.
Once you’ve filled in the required code, you can run the robot in simulation using the WPILib extension:
- Open the Command Palette in VS Code:
Ctrl+Shift+P(Windows) /Cmd+Shift+P(Mac). - Select
WPILib: Simulate Robot Code. - Choose the option: Sim GUI.
To control the robot simulation:
- In AS, open the "Robot Simulation" window (usually on the right or bottom).
- Under Joysticks, find the
Joysticks[0]slot. - Drag Keyboard 0 into
Joysticks[0](unless you have a physical controller connected).Joysticks[0],[1], etc., represent the slots used in your robot code (e.g.,new Joystick(0)).- Binding
Keyboard 0simulates a gamepad using your keyboard.
- Under Robot State, click “Teleoperated” to enable the robot.
W= Drive ForwardS= Drive BackwardA= Drive LeftD= Drive Right
Elastic is used to obtain and read data provided by the robot.
- Launch Elastic.
- Right-click on the grey-shaded boxes and click
Add Widget. - Click the
SmartDashboarddrop-down box. - Scroll all the way down until you see the
TXandTYvariables corresponding to your camera. - Drag the variables onto the grey-shaded boxes to be able to see the data.
- In your web-brower, type in the URL:
localhost:1182(this is for the middle camera, increment by two for additional cameras. E.g:localhost:1184) - The Vision Simulator should be visible! Move the robot around and see the values change!