Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
simplify Robot classes by initializing mechanisms in initializeMechan…
Browse files Browse the repository at this point in the history
…isms
  • Loading branch information
dejabot committed Jan 16, 2024
1 parent fb79cf7 commit 5f8885f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
8 changes: 1 addition & 7 deletions src/main/java/com/team766/robot/example/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@
public class Robot implements RobotConfigurator {
// Declare mechanisms (as static fields) here

public static void robotInit() {
// Initialize mechanisms here
}

@Override
public void initializeMechanisms() {
robotInit();
}
public void initializeMechanisms() {}

@Override
public Procedure createOI() {
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/com/team766/robot/gatorade/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ public class Robot implements RobotConfigurator {
public static Drive drive;
public static Lights lights;

public static void robotInit() {
// Initialize mechanisms here
intake = new Intake();
wrist = new Wrist();
elevator = new Elevator();
shoulder = new Shoulder();
drive = new Drive();
lights = new Lights();
}
private static boolean initialized = false;

@Override
public void initializeMechanisms() {
robotInit();
if (!initialized) {
// get rid of the synchronized if there are no thread-safety considerations
synchronized (Robot.class) {
intake = new Intake();
wrist = new Wrist();
elevator = new Elevator();
shoulder = new Shoulder();
drive = new Drive();
lights = new Lights();
initialized = true;
}
}
}

@Override
Expand Down

0 comments on commit 5f8885f

Please sign in to comment.