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

Commit 56a826e

Browse files
authored
Fix C++ HITL sim code (#280)
1 parent be2d3a7 commit 56a826e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

source/docs/programming/photonlib/hardware-in-the-loop-sim.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@ The final step is to configure your code to connect to the NetworkTables server
2929
3030
.. code-block:: c++
3131

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");
32+
#include <frc/RobotBase.h>
33+
#include <networktables/NetworkTable.h>
34+
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+
}
3844
}
3945

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

0 commit comments

Comments
 (0)