Skip to content

Commit

Permalink
Drivetrain now implements RobotLikeComponent. This required some
Browse files Browse the repository at this point in the history
renaming of methods in Drivetrain to match the standard for the
FRC robotic class, but even absent the goal of my current effort,
that's a good idea if only for consistency and ease of understanding
of the code.

This also required extending the RobotLikeComponent to accept an optional
"debug" argument to methods.  The current default is false.

Should it really use an argument?  It seems to me that there may be a
more efficient approach, such as checking some "registry" or set of
options that can be configured at runtime.  In more conventional code,
I could simply use environment variables.
  • Loading branch information
Andrew Gideon committed Dec 15, 2019
1 parent 532dae5 commit 795c8dc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void robotInit() {
launcher = new Launcher(this);

controlSystem.init(true);
drivetrain.init(true);
drivetrain.robotInit(true);
launcher.init(true);


Expand Down Expand Up @@ -127,7 +127,7 @@ public void teleopPeriodic() {

// Note: These should be changed to telepopOeriodic() calls on these objects
// via the componentsForDelegation collection
drivetrain.teleop(true);
drivetrain.teleopPeriodic(true);
launcher.teleop(true);

}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/frc/robot/core/Drivetrain.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import frc.robot.core.ControlSystem.Axis;
import frc.robot.core.ControlSystem.Sticks;

public class Drivetrain{
public class Drivetrain implements RobotLikeComponent
{

private Robot robot;

Expand All @@ -31,7 +32,7 @@ public Drivetrain(Robot robot){
this.robot = robot;
}

public void init(boolean debug){
public void robotInit(boolean debug){
controlSystem = robot.getControlSystem();

driveFL = new CANSparkMax(0, MotorType.kBrushless);
Expand All @@ -45,7 +46,7 @@ public void init(boolean debug){

}

public void teleop(boolean debug){
public void teleopPeriodic(boolean debug){
leftPower = controlSystem.getJoystickAxis(Sticks.DRIVE_STICK, Axis.X)
+ controlSystem.getJoystickAxis(Sticks.DRIVE_STICK, Axis.Y);

Expand All @@ -62,4 +63,4 @@ public void teleop(boolean debug){
SmartDashboard.putNumber("DT Right Power", rightPower);
}
}
}
}
13 changes: 10 additions & 3 deletions src/main/java/frc/robot/core/RobotLikeComponent.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package frc.robot.core;

public interface RobotLikeComponent {
default public void robotInit() {}
default public void teleopInit() {}
default public void robotInit() {robotInit(false);}
default public void robotInit(boolean debug) {}

default public void teleopInit() {teleopInit(false);}
default public void teleopInit(boolean debug) {}

default public void autonomousInit() {}

default public void roboticPeriodic() {}
default public void teleopPeriodic() {}

default public void teleopPeriodic() {teleopPeriodic(false);}
default public void teleopPeriodic(boolean debug) {}

default public void autonomousPeriodic() {}
default public void testPeriodic() {}
}

0 comments on commit 795c8dc

Please sign in to comment.