Have you or anyone else had luck connecting this simulated robot code to the driver station? Not being able to enable the simulation’s teleop mode severely limits the functionality one is able to test.
This is really funny… I just was running into the same issue and mentioned it to @gerthworm . Neither of us know of a solution to this yet either, so hopefully someone who has figured it out or worked on WPILib can chime in.
I just got the simulator working in teleop/auto earlier today! You can use the DriverStationSim class to set the enabled/disabled mode and switch between autonomous and teleop. Here’s the Kotlin code we’re using:
In this example, I’m first creating a DriverStationSim instance, then simulating the match as below:
Enable the robot/autonomous
Switch to autonomous
Disable the robot
Note that in this example I’m using Kotlin coroutines, but you can use those simulator calls anywhere. Also note that I haven’t tried using IterativeRobot yet, but in my testing, I had to remove the call to ds.waitForData() and I’d expect you to have to do the same in IterativeRobot here. Presumably, this is because there is no connection to a real DriverStation, so the robot code will be stuck waiting. I’m not sure if this is the expected WPILib behavior (maybe @Peter_Johnson can chime in), but removing that waitForData() call worked for me.
Edit: Just realized IterativeRobot is deprecated. I’m guessing TimedRobot works as-is, so test something like the above out and let me know how it goes!
This is along the lines of what I was thinking - sim infrastructure would have to call the appropriate enabled functions?
I would in general want to have access to the HAL IO so we could write a plant model to interact directly with the robot code (rather than introducing an alternate IO layer for sim). Also, joystick input would be slick for students to interactively test.
All things i have in my head which is not necessarily reality.
You can also run an interactive simulation with a real driverstation using a HAL extension. This is still a bit of a WIP, hence no solid docs (and a less elegant impl), but in your build.gradle chuck the following:
Set your Driverstation team # to localhost and it should connect. We have a few other simulation harnesses as well, like one which lets you use NetworkTables / Shuffleboard as a Driverstation (halsim_ds_nt), and one that just prints values (halsim_print). They’re all on the simulation/ subproject in allwpilib.
Any documentation on how to get the “Simulate Robot Code on Desktop” set up? I am able to run the simulated robot but not sure how to make it do anything. Unable to get the driver station to recognize that the simulator is running on my desktop like mentioned above. This is what I get.
`NetworkTables LowFi Simulator Initializing.
NetworkTables LowFi Simulator Initialized!
********** Robot program starting **********
Default disabledInit() method… Overload me!
Default disabledPeriodic() method… Overload me!
Default robotPeriodic() method… Overload me!
Watchdog not fed within 0.020000s
Warning at edu.wpi.first.wpilibj.IterativeRobotBase.printLoopOverrunMessage(IterativeRobotBase.java:273): Loop time of 0.02s overrun
Watchdog not fed within 0.020000s
Warning at edu.wpi.first.wpilibj.IterativeRobotBase.printLoopOverrunMessage(IterativeRobotBase.java:273): Loop time of 0.02s overrun`
I’ll admit, I still haven’t gotten the shim @Jaci mentioned to fully function. While launching VS code reports that there’s a new “Hal Sim” thing available to select, but my DS won’t connect on my local machine. I strongly suspect it’s a “my PC configuration” thing, but we’ve had other things to do of recent :). As soon as bag day rolls around, this will start to get a bit more prioity from us.
We’re still able to simulate in disabled, which is allowing for plenty of checkout anyway.
Hello, @Jaci I am trying your solution for connecting the simulation to the driver station, and the simulation runs and I see it on the Shuffleboard. However, I tried putting the 3 halsim libraries in a folder called libs in the robot directory, but the driver station still won’t connect.
Ensure that you can see the “DriverStation Initialized” / etc text in the console log when you start the simulation. If it’s not there, delete build/debug and try launching from VSCode, making sure you select the HALSIM dll when it prompts for extensions.
I’ve tried again, using a new project and putting the DLLS inside of it. Here are the steps that I did in a screenshot. I see networktables connected, but I don’t see anything about the driver station.
On the driver station program I try both my team number and localhost as the team number.