|
Re: C++ Robot: Simple or Iterative?
It really is the case that the SimpleRobot class is designed to have a very straightforward model of the robot. One method for all your autonomous code and another for the teleop code. The Iterative robot was designed to model the older code from previous years.
With SimpleRobot the idea is to write straight-line code to do whatever is needed during the Autonomous period. You are completely in control during that time. One important note: the Autonomous method will keep running at the the end of the autonomous period in the game. It will not stop when the teleop period begins. So it is the programmers responsibility to make sure the Autonomous method returns by the end of the autonomous period. There are methods like IsAutonomous() that you can call or you can use the clock and timers, but be sure to return from the Autonomous method.
IterativeRobot attempts to solve that problem by continuously calling one of its methods over and over again. You write code in the appropriate method that does what it needs to do and returns. When the field (or the switch on your driver station) switches from Autonomous to Teleop, then it will stop calling your AutonomousContinuous() method and start calling your TeleopContinous() method. Your program doesn't have to worry about keeping track of Autonomous vs. Teleop, but you do have to remember what the robot was doing from one call to the next.
For example, if you wanted to drive in a square pattern at the start of Autonomous it would work like this:
IterativeRobot: Your AutonomousContinuous method would be called over and over again during the autonomous period. So you write code that uses some variables to remember from call to call which side of the square it's currently driving or if it's turning. Using those variables the program would set the wheels to either be driving straight or turning. Remembering what the robot is doing is called its state, and this type of program is called a state machine.
SimpleRobot: Your Autonomous function is called once. You write a program that loops 4 times, driving each side of the square, then turning. You should check in the loop if the autonomous period is over by calling the IsAutonomous() method and returning from the Autonomous() method if it is.
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
|