Created
December 16, 2020 20:05
-
-
Save williamhaley/8b9085716a835ff080cf1066eeed7999 to your computer and use it in GitHub Desktop.
NCP Java Demo (Commands)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MoveLeftCommand extends RobotCommand { | |
public MoveLeftCommand(String button) { | |
super(button); | |
} | |
protected void logic() { | |
// Set up the motors | |
// Move the robot | |
// Make sure robot is in the right position | |
System.out.println("move left!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PickUpBallCommand extends RobotCommand { | |
public PickUpBallCommand(String button) { | |
super(button); | |
} | |
protected void logic() { | |
// Set up the motors | |
// Move the arm | |
// Open the claw | |
// Close the claw | |
System.out.println("pick up ball!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class RobotCommand { | |
private final String button; | |
protected abstract void logic(); | |
public RobotCommand(String button) { | |
this.button = button; | |
this.setup(); | |
} | |
private void setup() { | |
/* | |
Magic where we configure the button. | |
*/ | |
} | |
private void doCommonButtonMagic() { | |
/* | |
Lots of magic here | |
*/ | |
} | |
public void runTheCommand() { | |
System.out.printf("'%s' button was pressed!\n", this.button); | |
this.doCommonButtonMagic(); | |
this.setup(); | |
this.logic(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment