NorviewFIRSTRobotics / FRCStrongHold2016

http://www.norviewrobotics.org/
1 stars 0 forks source link

Call activity.initialize() in Robot.setActivity() #9

Closed Seairth closed 8 years ago

Seairth commented 8 years ago

Each time we switch to an activity, we want to call the initialize code to reset the activity. Then, when we start calling update(), we know that we are starting the activity in a known state.

Note: For the autonomy activity, we are going to leave initialize() empty! That way, every time that the currentActivity is set back to that object, calls to update() will continue from the last known state. For instance, imagine the following sequence:

  1. setActivity(getDefaultActivity()) sets currentActivity to the autonomy activity
  2. since this activity is in its initial state, the first thing that update() does is update it's internal state to 'breaching' (don't worry how we implement this yet). Part of that state update causes autonomy to call robot.setActivity(robot.getDetectDefenseActivity()).
  3. currentActivity is now DetectDefenseType. Calls to update() go through whatever sequence (always from the beginning, since initialize() had reset the internal state) we program to detect the defense. Assume it determines the defense to be Low Bar. It then calls robot.setActivity(robot.getBreachLowBarActivity()).
  4. currentActivity is now BreachLowBar. Calls to update() go through the sequence (always from the beginning, since initialize() had reset the internal state) we program to breach the low bar. Once complete, it calls robot.setActivity(robot.getDefaultActivity()).
  5. currentActivity is now back to the autonomy activity. However, since initialize() is empty, the internal state is still at "breaching". Then, when update() is call, it moves onto the next state. For instance, it might be "turning". In which case, it will also call robot.setActivity(robot.getTurnActivity()).
  6. currentActivity is now Turn... and so on...
primetoxinz commented 8 years ago

to be sure I understand what you mean, this is what it should look like instead?

@Override
public void setActivity(Activity activity) {
    this.currentActivity = activity;
    this.currentActivity.initialize();
}
Seairth commented 8 years ago

Exactly.