Quote:
Originally Posted by Sinani201
One of the problem with our teams code this year was that teleop had a huge amount of if statements for each element of the control system (i.e. if this button is pressed, perform this function). This seems like bad practice and the the code isn't as maintainable as it could be.
|
The code you provided actually seems pretty clean to me; the logic is clear, and I can't think of any direct improvements that can be made. I will however echo others' suggestion to use the Command-based setup, as it makes button-mapping code much easier to maintain. Internally, the logic is the same, but it's encapsulated in nice things like button.whenPressed(). As an example,
here's our OI class, which handles input from the drivers. A snippet from it shows that it can simplify things greatly:
Code:
shootButton .whenPressed(new Shoot());
shootFullButton .whenPressed(new Shoot(SpinUp.SPEED_FULLCOURT));
spinDownButton .whenPressed(new SpinDown());
spinDown2Button .whenPressed(new SpinDown());
recordEncoderButton.whenPressed(new PrintAutonomousMove(0.6, 0.5));
tomahawkButton .whenPressed(new SpinTomahawk(true));
tomahawkBackButton .whenPressed(new SpinTomahawk(false));
feederAwayButton .whenPressed(new FeederTurn(false));
feederTowardButton .whenPressed(new FeederTurn(true));