garykac / amhs-robotics-4681

Repository for AMHS's FRC (FIRST Robotics Competition) team
3 stars 0 forks source link

Identical Code Between Auto & Teleop #25

Closed cmarley3-14 closed 5 years ago

cmarley3-14 commented 5 years ago

Old:

public class Robot {
    public void AutonomousPeriodic() {
        do a1();
        do a2();
        do a3();
        do a4();
        do b();
    }
    public void TeleopPeriodic() {
        do a1();
        do a2();
        do a3();
        do a4();
        do c();
    }
}

Proposed New:

public class Robot {
    public void mainA() {
        do a1();
        do a2();
        do a3();
        do a4();
    }
    public void AutonomousPeriodic() {
        mainA();
        do b();
    }
    public void TeleopPeriodic() {
        mainA();
        do c();
    }
}

Of course, the code that goes into mainA() is about 80 lines long, because its the same get button pressed, go up a level, but check if it's hatch or ball, etc. etc. etc. long code. And if we have to change it in the autonomous function, then we'll have to hunt it down in the teleop too. Just create a shared function may be easier.

cmarley3-14 commented 5 years ago

I'm just wondering if it's legal to go and declare a new function mainA() within Robot, and then call it in each auto and teleop periodics.

cmarley3-14 commented 5 years ago

FYI, tomorrow (Saturday), I plan to go through all the java files and do a bit of work. Improving efficiency, writing code as physically imagined (non-idealized), etc. After all, we have the time (that is lost from the portable) (And I'm kinda glad, because my house is warmer than the portable)