Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

Commit be2d3a7

Browse files
authored
Hardware In The Loop Simulation Documentation (#270)
* Hardware in the loop sim docs * Fix warning * Resolve review comments * Add note to inform users that the internal NT server will be shut down * Fix lint * Add another reason to use this * Added image for nt server toggle * Add extra image, fix text spacing * Fix strange wording * Add tentative C++ code * Fix initial review comments
1 parent 413404e commit be2d3a7

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Hardware In The Loop Simulation
2+
===============================
3+
4+
Hardware in the loop simulation is using a physical device, such as a supported co-processor running PhotonVision, to enhance simulation capabilities. This is useful for developing and validating code before the camera is attached to a robot, as well as reducing the work required to use WPILib simulation with PhotonVision.
5+
6+
The first step is to install PhotonVision on your target device. Instructions can be found `here <https://docs.photonvision.org/en/latest/docs/getting-started/installation/sw_install/index.html>`_ for all devices.
7+
8+
A small amount of configuration is required after installation. From the PhotonVision UI, go to the sidebar and select the Settings option. Within the settings, turn on "Run NetworkTables Server".
9+
10+
.. warning:: Do not leave this toggle on when accessing your device on a full robot.
11+
12+
.. image:: images/nt-server-toggle.png
13+
14+
The final step is to configure your code to connect to the NetworkTables server run by your instance of PhotonVision. The code below shows how to disconnect your simulation from the default NetworkTables server and connect it to the PhotonVision hosted one.
15+
16+
.. note:: This will disable your robot code's internal NT server. Applications connecting to a NT server (e.g. Shuffleboard or Glass) must be connected to the PhotonVision NT server if this code has been run.
17+
18+
.. tab-set-code::
19+
20+
.. code-block:: java
21+
22+
if(RobotBase.isSimulation()) {
23+
NetworkTableInstance inst = NetworkTableInstance.getDefault();
24+
inst.stopServer();
25+
// Change the IP address in the below function to the IP address you use to connect to the PhotonVision UI.
26+
inst.setServer("photonvision.local");
27+
inst.startClient4("Robot Simulation");
28+
}
29+
30+
.. code-block:: c++
31+
32+
if(RobotBase.IsSimulation()) {
33+
auto inst = NetworkTableInstance.getDefault();
34+
inst.StopServer();
35+
// Change the IP address in the below function to the IP address you use to connect to the PhotonVision UI.
36+
inst.SetServer("photonvision.local");
37+
inst.StartClient4("Robot Simulation");
38+
}
39+
40+
Now launch simulation, and you should be able to see the PhotonVision table on your simulation's NetworkTables dashboard.
41+
42+
.. image:: images/hardware-in-the-loop-sim.png
147 KB
Loading
134 KB
Loading

source/docs/programming/photonlib/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ PhotonLib: Robot Code Interface
1111
driver-mode-pipeline-index
1212
controlling-led
1313
simulation
14+
hardware-in-the-loop-sim

0 commit comments

Comments
 (0)