What method is called right after you deploy code to the robot?


What method is called right after you deploy code to the robot?


robotInit I believe, followed by robotPeriodic, disabledInit and disabledPeriodic.


Ok Thanks


There are probably some methods deeper within WPIlib that come first, however I believe robotInit is what you are looking for.


To be clear, robotInit is the first method called, and it will only be called once when the robot boots. disabledInit will be called every time you disable the robot. robotPeriodic will run 50 times a second after robotInit, regardless of what mode you’re in. disabledPeriodic will also run 50 times a second, but only when you’re disabled.

Pick the right one according to your needs. If the code should only be run once, robotInit is your only choice.


Technically speaking, the constructor is called before robotInit.


All right, you got me there :slightly_smiling_face:


Starting in 2019, the program defines a main method instead of using reflection to the get the Robot class, which is either in C++:

int main() { return frc::StartRobot<Robot>(); }

or in Java:

 public static void main(String... args) {

So technically, any statements before StartRobot is called before the constructor


All answers thus far answer the question “What is the first user-defined code to run when user code begins executing?”

OP specifically refers to the deploy process (as supposed to a normal power-on). @Bag, do you have a need to hook the deploy process specifically?


@gerthworm No I don’t need anything that complicated I just wanted to measure the seconds since my last deploy


Ok. This sounds like you are looking to hook the deploy process, not the power-on process. Doing this would require something triggered by the deploy process yourself, not something inside the robot’s software itself. Though not impossible, I would call this “somewhat involved”.

In general the software on its own won’t be able to differentiate between the first time it runs after a deploy, and every other time it runs after you reboot the robot.

Here is a thread I was recently involved on that where there was some discussion about adding a deploy-time hook to capture information about the build that just occurred. This information, if deployed to the robot along with the user executable, could be used at run-time to calculate the quantity you are looking for.


@gerthworm Thanks for the link I’ll check it out.