In Need of a Step-by-Step on How to Simulate a Robot

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).

Thank you!

1 Like

Are you using a swerve drive or tank?

Tank as a learning tool, though we do have swerve.

1 Like

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.

2 Likes

Thanks for taking time to help us, but we really need a step-by-step tutorial. None of that advice means much to us.

How do we create the Field2d object? How do we publish it? How do we set the pose every cycle? That’s just some of the things we don’t know how to do.

1 Like
1 Like

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.

2 Likes

I made these walkthroughs for my teams training. Highlanders-Training/Docs/Architecture/KitbotExampleWalkthrough.md at main · HighlanderRobotics/Highlanders-Training · GitHub Highlanders-Training/Docs/Architecture/KitbotExampleWalkthroughSim.md at main · HighlanderRobotics/Highlanders-Training · GitHub. However, this is just one way of doing simulation and a relatively complex one at that, and it also is built to do other things like logging. Id strongly recommend learning more of the tools you have available to make an informed decision about how to simulate your code.
For a dashboard I strongly suggest advantagescope.

3 Likes

Why are you being so defensive?

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.

4 Likes

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 took the code a few steps farther – here’s the expanded code: GitHub - FRCTeam695/CommandElevatorSimulation: An adaptation and expansion of the WPILib Elevator Simulation into a Command-based version

Look at the commit history to see the sequence of modifications: Commits · FRCTeam695/CommandElevatorSimulation · GitHub

2 Likes

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.

3 Likes

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.

1 Like