Java code "restarting" randomly

Hi All,
I am my team’s lead programmer, and I have ran into a pretty big issue for the past couple of days I have been unable to solve.

Our robot will periodically disable itself and the robot code indicator will go red and display no robot code. Within ten seconds, we have our code back and we are able to re-enable and continue driving. This behavior seems very similar to pressing the “restart robot code” button on the drive station. However, it is less than optimal for us to be stopping in the middle of running. We have had this error occur when the robot is disabled as well. We have switched roboRIOs and gone over our wiring.

Any ideas what we can do to fix it? Thanks

Is there anything in the stack trace? I’m assuming the code is crashing.

When it does crash, there is nothing out of the ordinary in the stack trace. There is a constant error of “Loop time of 0.02s overun” that is always in the stack trace.

I just ran the robot and it happened again. There is a DS Disable Driver Station in the VS code console that does not show up on the drive station console.

The issue sounds very much like an unhandled runtime exception.

Comb through the rioLog output - try to pause the stream it right when you see the reset happen.

You are looking for the text “Robots shouldn’t quit, but yours did!”. There is additional information called a “stack trace” near it which will indicate the exact line of code that caused the reset.

I was able to pause it right on the reset twice, and I did not see a “Robots shoudn’t quit, but yours did!” line in the rioLog. I paused it as soon as it happened and went through it.

that means your code is crashing. post the stack trace and it will show us the line number where there is an issue. if you posted your code, we could crawl through that and probably find the issue as well.

Here is my code:

1 Like

A stack trace would help as well.

Usually if it shows no robot code that means your code has crashed somehow when it runs. When does it change to “No robot code”? In my experience it happens because I forget to allocate enough space in an array or I access a variable that is uninitialized. Try to see what you are doing right before it crashes and see if there is a pattern. Look through your code where it crashes and comment out sections until it runs properly.

There is nothing unusual in any of the logs when it crashes, so I don’t have a stack trace to share.

If you’re not getting a stack trace in riolog, try doing the following:

  • SSH into the RoboRIO as “lvuser”
  • Rename robotCommand (e.g. mv robotCommand testCommand)
  • Kill currently running program (killall java)
  • Run the renamed robotCommand interactively (./testCommand)

Try to reproduce your issue–if there’s a stack trace it will show up in the SSH console.

the first thing I notice is that your overruns are probably caused by setting up your buttons in robotPeriodic. That should be done in OI, there are even instructions commented out for you. the stack trace would really make things easier for us (or if the code crashes after pressing a certain button)

Setting up the buttons in robotPeriodic may be the root cause, actually–those represent a lot of memory allocation, so doing that every 50 ms may ultimately get ahead of the GC and crash the JVM due to running out of memory.


I added all my buttons to OI, but it gives “Syntax error on token, @ expected after this token” on each one.

all of the configuration needs to be done inside of public OI(){}

Here is a good example:

I’m testing now, seems to work so far, thanks!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.