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

Commit

Permalink
move robot-specific code to sub-package (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
dejabot authored Jan 8, 2024
1 parent 1cce76e commit dc32322
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 98 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/team766/hal/GenericRobotMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import com.team766.logging.Category;
import com.team766.logging.Logger;
import com.team766.logging.Severity;
import com.team766.robot.AutonomousModes;
import com.team766.robot.OI;
import com.team766.robot.Robot;
import com.team766.robot.example.AutonomousModes;
import com.team766.robot.example.OI;
import com.team766.robot.example.Robot;
import com.team766.web.AutonomousSelector;
import com.team766.web.ConfigUI;
import com.team766.web.Dashboard;
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/com/team766/robot/AutonomousModes.java

This file was deleted.

38 changes: 0 additions & 38 deletions src/main/java/com/team766/robot/OI.java

This file was deleted.

12 changes: 0 additions & 12 deletions src/main/java/com/team766/robot/Robot.java

This file was deleted.

19 changes: 19 additions & 0 deletions src/main/java/com/team766/robot/example/AutonomousModes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.team766.robot.example;

import com.team766.framework.AutonomousMode;
import com.team766.robot.example.procedures.*;

public class AutonomousModes {
public static final AutonomousMode[] AUTONOMOUS_MODES =
new AutonomousMode[] {
// Add autonomous modes here like this:
// new AutonomousMode("NameOfAutonomousMode", () -> new MyAutonomousProcedure()),
//
// If your autonomous procedure has constructor arguments, you can
// define one or more different autonomous modes with it like this:
// new AutonomousMode("DriveFast", () -> new DriveStraight(1.0)),
// new AutonomousMode("DriveSlow", () -> new DriveStraight(0.4)),

new AutonomousMode("DoNothing", () -> new DoNothing()),
};
}
37 changes: 37 additions & 0 deletions src/main/java/com/team766/robot/example/OI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.team766.robot.example;

import com.team766.framework.Context;
import com.team766.framework.Procedure;
import com.team766.hal.JoystickReader;
import com.team766.hal.RobotProvider;
import com.team766.logging.Category;
import com.team766.robot.example.procedures.*;

/**
* This class is the glue that binds the controls on the physical operator
* interface to the code that allow control of the robot.
*/
public class OI extends Procedure {
private JoystickReader joystick0;
private JoystickReader joystick1;
private JoystickReader joystick2;

public OI() {
loggerCategory = Category.OPERATOR_INTERFACE;

joystick0 = RobotProvider.instance.getJoystick(0);
joystick1 = RobotProvider.instance.getJoystick(1);
joystick2 = RobotProvider.instance.getJoystick(2);
}

public void run(final Context context) {
while (true) {
// wait for driver station data (and refresh it using the WPILib APIs)
context.waitFor(() -> RobotProvider.instance.hasNewDriverStationData());
RobotProvider.instance.refreshDriverStationData();

// Add driver controls here - make sure to take/release ownership
// of mechanisms when appropriate.
}
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/team766/robot/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Package for robot-specific code. Copy this example package for each robot,
eg reva, revb, burrobotprime, gatorade, etc.

Each package will contain the following:
* `Robot.java` - contains static references to that robot's mechanisms.
* `OI.java` - procedure for reading joystick input, controlling the robot via the Operator Interface.
* `AutonomousModes.java` - contains array of autonomous procedures for this robot.
* `mechanisms` - sub-package containing mechanisms for this robot.
* `procedures` - sub-package containing procedures for this robot.

Once you've created the appropriate package for this robot, remember to update
`com.team766.hal.GenericRobotMain` to reference this code. This will typically involve
updating the following imports:

import com.team766.robot.example.AutonomousModes;
import com.team766.robot.example.OI;
import com.team766.robot.example.Robot;

By organizing your code with a sub-package for each robot, with the exception of `GenericRobotMain`,
the code for each of our robots should be able to co-exist across branches.

NOTE: **You should only update `GenericRobotMain` on the branch that's specific to your robot.**
11 changes: 11 additions & 0 deletions src/main/java/com/team766/robot/example/Robot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.team766.robot.example;

import com.team766.robot.example.mechanisms.*;

public class Robot {
// Declare mechanisms here

public static void robotInit() {
// Initialize mechanisms here
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.team766.robot.example.mechanisms;

import com.team766.framework.Mechanism;
import com.team766.hal.MotorController;
import com.team766.hal.RobotProvider;

public class ExampleMechanism extends Mechanism {
private MotorController leftMotor;
private MotorController rightMotor;

public ExampleMechanism() {
leftMotor = RobotProvider.instance.getMotor("exampleMechanism.leftMotor");
rightMotor = RobotProvider.instance.getMotor("exampleMechanism.rightMotor");
}

public void setMotorPower(final double leftPower, final double rightPower) {
checkContextOwnership();

leftMotor.set(leftPower);
rightMotor.set(rightPower);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.team766.robot.procedures;
package com.team766.robot.example.procedures;

import com.team766.framework.Context;
import com.team766.framework.Procedure;

public class DoNothing extends Procedure {

public void run(final Context context) {
}

}
public void run(final Context context) {}
}
22 changes: 0 additions & 22 deletions src/main/java/com/team766/robot/mechanisms/ExampleMechanism.java

This file was deleted.

0 comments on commit dc32322

Please sign in to comment.