This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move robot-specific code to sub-package (#1)
- Loading branch information
Showing
13 changed files
with
117 additions
and
98 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
src/main/java/com/team766/robot/example/AutonomousModes.java
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
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()), | ||
}; | ||
} |
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
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. | ||
} | ||
} | ||
} |
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
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.** |
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
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 | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/team766/robot/example/mechanisms/ExampleMechanism.java
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
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); | ||
} | ||
} |
File renamed without changes.
8 changes: 3 additions & 5 deletions
8
...m/team766/robot/procedures/DoNothing.java → ...6/robot/example/procedures/DoNothing.java
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
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) {} | ||
} |
File renamed without changes.
22 changes: 0 additions & 22 deletions
22
src/main/java/com/team766/robot/mechanisms/ExampleMechanism.java
This file was deleted.
Oops, something went wrong.