We are writing autonomous code and our isFinished statement has an error in it. currentTimeInMillis is undefined for the type system. Where should we define this? This is my first time coding autonomous and a timer.
I’m looking at the code now, which command in specific is causing the error when isFinished is called? All of them are returning false from what I see.
Sorry, I forgot to save the code. It should be fixed now.
Okay, I think I see the problem now. You are trying to call System.currentTimeInMillis(). That’s what you’d use on a desktop to get the time; instead, check out the Timer class from WPILib. You want to create an instance of a Timer object, .start() the Timer at the beginning of the command, and then your isFinished() would be timer.get() >= endTime. Let me know if that works for you.
Edit: I originally said that System does not work on the Rio, but @retrodaredevil cleared things up with his reply in regards to that.
Depending on why you need a timer in your use case, there’s always the command decorators that make it easy for your command to have a ceiling in terms of execution time.
It’s perfectly fine to use System.currentTimeMillis()
, but System.currentTimeInMillis()
is the wrong method name.
I would recommend using Timer.getFPGATimestamp()
as that can be more precise.
Also, as an extra precaution I take while writing Java programs, I don’t use System.currentTimeMillis()
because if the system clock changes, that value will jump.
This is especially good to avoid on the Rio. The Rio does not have a battery, so its clock is only synchronized when the DS connects, which means there’s always going to be a time discontinuity at that point (which can happen after your robot code is running).
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.