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

Commit 88a73c5

Browse files
authored
Update HITL Simulation (#317)
* update HITL sim * clarify use of IP address * whitespace
1 parent 29ece51 commit 88a73c5

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

source/docs/simulation/hardware-in-the-loop-sim.rst

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,35 @@ Hardware In The Loop Simulation
33

44
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.
55

6-
The first step is to install PhotonVision on your target device. Instructions can be found :ref:`here <docs/installation/index:Installation & Setup>` for all devices.
6+
Before continuing, ensure PhotonVision is installed on your target device. Instructions can be found :ref:`here <docs/installation/index:Installation & Setup>` for all devices.
77

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".
8+
Your coprocessor and computer running simulation will have to be connected to the same network, like a home router. Connecting the coprocessor directly to the computer will not work.
99

10-
.. warning:: Do not leave this toggle on when accessing your device on a full robot.
10+
To simulate with hardware in the loop, a one-line change is required. From the PhotonVision UI, go to the sidebar and select the Settings option. Within the Networking settings, find "Team Number/NetworkTables Server Address".
1111

12-
.. image:: images/nt-server-toggle.png
12+
During normal robot operation, a team's number would be entered into this field so that the PhotonVision coprocessor connects to the roboRIO as a NT client. Instead, enter the IP address of your computer running the simulation here.
1313

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.
14+
.. note::
1515

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.
16+
To find the IP address of your Windows computer, open command prompt and run ``ipconfig``.
1717

18-
.. tab-set-code::
18+
.. code-block:: console
1919
20-
.. code-block:: java
20+
C:/Users/you>ipconfig
2121
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-
}
22+
Windows IP Configuration
2923
30-
.. code-block:: c++
24+
Ethernet adapter Ethernet:
3125
32-
#include <frc/RobotBase.h>
33-
#include <networktables/NetworkTable.h>
26+
Connection-specific DNS Suffix . : home
27+
Link-local IPv6 Address . . . . . : fe80::b41d:e861:ef01:9dba%10
28+
IPv4 Address. . . . . . . . . . . : 192.168.254.13
29+
Subnet Mask . . . . . . . . . . . : 255.255.255.0
30+
Default Gateway . . . . . . . . . : 192.168.254.254
3431
35-
void Robot::RobotInit() {
36-
if constexpr (frc::RobotBase::IsSimulation()) {
37-
auto inst = nt::NetworkTableInstance::GetDefault();
38-
inst.StopServer();
39-
// Change the IP address in the below function to the IP address you use to
40-
// connect to the PhotonVision UI.
41-
inst.SetServer("localhost");
42-
inst.StartClient4("Robot Simulation");
43-
}
44-
}
32+
.. image:: images/coproc-client-to-desktop-sim.png
33+
34+
No code changes are required, PhotonLib should function similarly to normal operation.
4535

4636
Now launch simulation, and you should be able to see the PhotonVision table on your simulation's NetworkTables dashboard.
4737

70 KB
Loading
-134 KB
Binary file not shown.

0 commit comments

Comments
 (0)