We decided to switch to java this year. We’re trying to get the framework set up.
The RobotBuilder tool created a Robot class that extends IterativeRobot. Most of the examples I have seen on line so far show a Robot class that extends SimpleRobot. What are the pros & cons of each?
Also, for the IterativeRobot, the autonomousPeriodic() and teleopPeriodic() methods both call Scheduler.getInstance().run(). What does this method do? Do I need to add code to these methods or does Scheduler.getInstance().run() call some other methods periodically in which I would put my code?
IterativeRobot is set up like telop and disabled were in LabVIEW. Each time a new packet is received from the driver station, it calls the appropriate method (telopPeriodic, etc). Each of the Periodic methods must return quickly, or else you will miss processing driver station packets. Initialization should go in the init methods, as those only get called once per transition to each mode.
SimpleRobot does not have any built in looping structure, you need to add it. It generates less code, which might be why it’s called Simple, but since you need to add loops to it, it might not really be simpler.
RobotBuilder extends IterativeRobot with what they call the Command based model. The Scheduler calls you notice call Commands that you define that run based on triggers you define (such as pressing a button). This is described in much more detail in the RobotBuilder documentation. http://wpilib.screenstepslive.com/s/3120/m/7882
As Joe Ross said, the Robot Builder gives you a Command based model code. These commands are first defined in the Robot Builder. Scheduler.getInstance().run() just controls the top-level commands.
The command model might be a bit confusing to begin with, and you can always just put your teleop and auton code in their respective methods. You may also want a teleopInit method and a autonInit method, both of which are executed when switching from disabled to auton or teleop.
If you want to continue using the CommandBased Robot template, then the link Joe Ross is very helpful in getting started.
Also, you don’t need to use the RobotBuilder to start. If you are using netbeans, you can rightclick the Projects area, click New Project, click FRC Java, and then choose the RobotTemplate that you want to use.
SimpleRobot requires you to do your loops yourself, so IterativeRobot may be the way to go.
If you see a SimpleRobot example, you can change it into an IterativeRobot by finding the operatorControl method, copying it to your teleopPeriodic method, and then removing the first line of that code that says something like “while (…)”