Quote:
Originally Posted by H2O Enthusiast
By robotMain() do you mean outside the robotInit() but inside the Robot() class? Also, by operational part of my code do you mean where I publish the data?
|
Yes to both questions. If you look at SampleRobot.java (the base class your code is using), you'll see there's a number of different functions you can override. robotInit() is one. robotMain() is another (as is operatorControl(), disabled(), autonomous(), etc). The startCompetition() function shows the sequence in which these functions are called. robotInit() is called first, and should contain only initialization code -- code you want to run before the match. Only after robotInit() returns does startCompetition() call the FRCNetworkCommunicationsLibrary to let the driver station know robot code is ready to run (which is what makes "No Robot Code" disappear). Note it's somewhat risky to override robotMain() instead of the individual operatorControl(), disabled(), etc. functions, as you will need to handle the state transitions between these modes yourself (versus having startCompetition() handle it for you).
While SampleRobot is okay for small test programs like this one, for your actual competition robot code, if you don't want to do command-based programming, I recommend you use a different template such as IterativeRobot and override only robotInit and the various autonomous/operatorControl functions. The IterativeRobot class startCompetition() function will take care of calling these functions in the right order and putting in appropriate delays to not swamp the CPU.
__________________
Author of
cscore - WPILib CameraServer for 2017+
Author of
ntcore - WPILib NetworkTables for 2016+
Creator of
RobotPy - Python for FRC
2010 FRC World Champions (
294, 67, 177)
2007 FTC World Champions (30, 74,
23)
2001 FRC National Champions (71,
294, 125, 365, 279)