SampleRobot vs CommandBasedRobot


I would consider myself an advanced programmer in comparison to others, and I have already spent hundreds of hours working on a command based program for my team. The program that I used implements Multithreading, Synchronization, notifications between threads, UDP (RPi to Roborio), etc… I’d like to say that I took the code to the next level, and I have already completed designing this year’s code in a command based fashion. (Currently the code is in java, however, it could also be in C++.)

The problem is that I’m starting to see some limitations to the command based program that they give you when you take the code to the next level…

When creating an FRC Robot Project it gives you the option to choose Command based (what I’ve chosen so far), Iterative, or Sample. For Sample, it says: “… for highly advanced programs with more complete control over program flow” so a few days ago I tried to create a project using Sample and see what I find. I have already built an interface with a java.util.Timer which calls an update method every 20ms and an enum which represents the current mode of the robot, haven’t done too much yet.

I’m not sure if I should move the code over to using Sample where I build the whole structure for the robot code instead of using the WPILib command based system libraries… My level of programming would not be a problem in my opinion for designing a structure similar in complexity to the command based programming.

My question is:
What are the advantages that you know of for giving my program “complete control over program flow” and would you recommend it?

Thanks, Orian

All the pros of using SampleRobot to get a consistent loop are now gone with the introduction of the TimedRobot base.

And if you have to ask what advantages there are to controlling your own flow, you don’t have any advantages in mind. What limitations are you seeing with command based, and are there ways around these (even hacky ones) other than rolling your own framework in week 3?

I wrote a custom system similar to command based last year because I was annoyed with how command groups worked. It was more effort, had a few issues I didn’t diagnose before they reared their head in competition, and didn’t offer any significant advantages over the stock CommandBased. This year, I’m sticking to principles to train in new programmers.

If you only see those three options, your WPILib is not up to date. In WPILib 2018 there is an additional framework, TimedRobot. TimedRobot does what you want, as it calls a periodic function at a configured and consistent period (by default 20 ms). It’s fairly accurate too, with some basic logging I found the average run time was ~20.0003 ms with a standard deviation of ~174 us after JVM warmup. There’s no longer any real benefit to SampleRobot as a result, which is why SampleRobot is now deprecated.

That said, what issues are you actually running into? I agree with Nick, it might not be worth upending all of your code right now for a small structural change if you don’t already have certain functionalities in mind.