I’m looking for a step-by-step guide on how to simulate our robot in the dashboards (we code in Java). WPILib is not sufficiently instructive for us, as we really don’t know what we’re reading. (Example: Where does putstring/getstring go?) Though I see the code on WPILib and understand it theoretically, the practical aspects don’t make sense to us. A video leading us through the process from start to finish on how to take our code and simulate it would be extremely helpful.
We are complete beginners, currently using the 0 to Autonomous YouTube channel to learn how to code. There’s a simulation in video 5 but I’d like to integrate with something like LabVIEW instead (or any other dashboard that’s recommended).
So with tank you have to create a Field2d object, publish it to SmartDashboard, and set the robot pose on it every cycle. To get the pose you need a PoseEstimator for TankDrive AKA DifferentialDrivePoseEstimator then update that with encoder values or velocity every cycle, it’s best to convert controller inputs directly to desired velocity then use that as the actual velocity for an easy sim.
Orrrr you could just use a swerve drive library like YAGSL and CTRE Swerve (if applicable) which does that for you.
It’s hard to provide a generalized step by step. For example, I’m not sure what WPILib document that you’re reading that says to use putString/getString to be able to figure out what the missing steps are. Additionally sometimes the docs specifically don’t tell you where to put things because it will vary based on how you structure your program. So we need you to describe as much about your program in order to be able to help with a step by step. We also need to understand what your goal is in simulation, as that term means a lot of things to different people. Do you want to just execute your code without a roboRIO to figure out why it’s crashing? Do you want to write unit-tests for your code? Do you want to be able to visualize what mechanisms are doing? Do you want to have a 3d field and do driver practice?
This is complicated, so the more you can help us understand what you want to do, why you want to do it, and what you’ve already read and have, the more we can help.
The OP very clearly wants a better guide to starting out with simulating robot code behavior in a broad way and they even reference a YouTube series teaching step by step introductory FRC specific programming.
Update: Continued…
My team did our first ever attempts at simulation this season and found that the WPILIB documentation on simulation to be extremely lacking in figuring out how to do simulation beyond the drivetrain. The documentation is not written in such a way that considers the primary audience. I had to read through other team code try and understand how to teach my kids to simulate a simple 1 DOF arm + telescopic mechanism. The fact you can use mechanism2D UI elements to visually show how a subsystem moves is not even mentioned in the simulation section at all… it’s hidden in a submenu of functions of Glass.
I can provide one example: simulating an elevator. It won’t help you with drivetrain, but it is relevant to simulating mechanisms. It’s based on a WPILib example (found on this page).
I don’t think Joe’s reply is defensive–it’s just seeking clarification on what the OP wants to accomplish, so answers can be helpful instead of leading the OP down a rabbit hole that’s not useful to them. As he said, simulation is a very broad topic, and different teams indeed have different goals.
I agree the docs on simulation can be improved. The primary focus of the step-by-step (0-to-robot) docs has traditionally been to get a physical robot moving, because that’s what’s most important for a team to compete when they get the KOP, and simulation was considered an advanced use case. The docs haven’t kept up with the reality that more and more teams are learning software before getting any physical robot at all. For example, Mechanism2d is under Glass because it works for visualizing what’s happening on a physical robot–it’s also useful for simulation, but it’s dual purpose, so you’re right, it should be mentioned in the simulation section as well. I’ll just reiterate that we’re all volunteers and WPILib and its docs are almost entirely a community effort. As such, the most certain way to improve the docs is to contribute improvements that can help others succeed, based on your experience figuring it out yourself. In many ways the WPILib development team are the worst people to write these kinds of docs–we know too much! Note contributions can range from the simple act of adding a cross-reference that was lacking, to more major projects like developing a “0-to-sim-robot” tutorial that doesn’t currently exist.
On a separate note, I would personally argue the teams just starting out would be best served by getting some XRPs and getting them physically moving, because I think the key thing to get a student hooked on robotics programming is to see their line of code physically move something, not just move a line on a screen, but it’s valid to support those who want to do a simulation-based approach as well.
One thing you’ll want to keep in mind, especially as a mentor:
A key skill to cultivate is breaking a large problem down into small ones.
I say this because…
Nit-picking this particular query, it’s actually about declaring and using an object in Java, not about simulation. But you have to be able to break that down: It’s improbably that you’ll find answers that simultaneously explain working with Java objects, and Differential Drive simulation.