-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drive train #1
base: master
Are you sure you want to change the base?
Drive train #1
Conversation
// Called every time the scheduler runs while the command is scheduled. | ||
@Override | ||
public void execute() { | ||
Robot.driveTrain.setBothPrecent(Robot.joysticks.getLeftY(), Robot.joysticks.getRightY()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better code structure avoid accessing Robot objects such as joysticks. Create a clear structure:
Robot --registers--> Commands --call--> Subsystems --runs--> SpeedControllers
One way to do this is by creating a supplier like so:
Robot.driveTrain.setBothPrecent(Robot.joysticks.getLeftY(), Robot.joysticks.getRightY()); | |
// in the constructor: | |
public TankDrive(DoubleSupplier leftSupplier, DoubleSupplier rightSupplier) { | |
this.leftSupplier = leftSupplier; | |
this.rightSupplier = rightSupplier; | |
... | |
Robot.driveTrain.setBothPrecent(leftSupplier.getAsDouble(), rightSupplier.getAsDouble()); |
where you create a DoubleSupplier from any function that returns a double like so:
// in Robot.java
DoubleSupplier leftSupplier = joysticks::getLeftY;
DoubleSupplier rightSupplier = joysticks::getRightY;
... new TankDrive(leftSupplier, rightSupplier);
} | ||
|
||
public double getLeftY(){ | ||
return this._leftJoystick.getY(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't forget Y inversion
|
||
this._talonL.setInverted(Constants.DriveTrain.TalonL.inverted); | ||
this._talonR.setInverted(Constants.DriveTrain.TalonR.inverted); | ||
this._victorRB.setInverted(Constants.DriveTrain.VictorRB.inverted); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
followers should be configured to follow whatever inversion their master has. To avoid a case where 2 motors in the same gearbox spin against each other because of a bad configuration.
this._talonL.set(ControlMode.Position, distanceL); | ||
} | ||
|
||
public void setRightPercent(double percentage){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid creating public methods. You don't want someone to misuse your subsystem.
public void setRightPercent(double percentage){ | |
private void setRightPercent(double percentage){ |
public void setDistance(double distanceR, double distanceL) { | ||
this._talonL.set(ControlMode.Position, distanceR); | ||
this._talonL.set(ControlMode.Position, distanceL); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid creating methods which aren't used.
public void setDistance(double distanceR, double distanceL) { | |
this._talonL.set(ControlMode.Position, distanceR); | |
this._talonL.set(ControlMode.Position, distanceL); | |
} |
If there are plans to use it in the future -- leave it in the future branch where we will test it.
public double getLeftX(){ | ||
return this._leftJoystick.getX(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again... aren't used...
public double getLeftX(){ | |
return this._leftJoystick.getX(); | |
} |
public void setBothPercent(double percentageL, double percentageR){ | ||
setRightPercent(percentageR); | ||
setLeftPercent(percentageL); | ||
} | ||
|
||
public void setpercent(double percentage){ | ||
setRightPercent(percentage); | ||
setLeftPercent(percentage); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use overloading to achieve the same method with different inputs:
public void setBothPercent(double percentageL, double percentageR){ | |
setRightPercent(percentageR); | |
setLeftPercent(percentageL); | |
} | |
public void setpercent(double percentage){ | |
setRightPercent(percentage); | |
setLeftPercent(percentage); | |
} | |
public void setPercent(double percentageL, double percentageR){ | |
setRightPercent(percentageR); | |
setLeftPercent(percentageL); | |
} | |
public void setPercent(double percentage){ | |
setPercent(percentage, percentage) | |
} |
this reduces code duplication and improves readability
src/main/java/frc/robot/Robot.java
Outdated
|
||
public static DriveTrain driveTrain; | ||
|
||
public static Joysticks joysticks; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you never initialize Joysticks
src/main/java/frc/robot/Robot.java
Outdated
@@ -15,6 +17,11 @@ | |||
* project. | |||
*/ | |||
public class Robot extends TimedRobot { | |||
|
|||
public static DriveTrain driveTrain; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you never initialize DriveTrain
. instead you init it in as m_exampleSubsystem
in the RobotContainer
public static final class DriveTrain { | ||
|
||
public static final class TalonR { | ||
public static final int TALONR_ID = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any other possible ID?
public static final int TALONR_ID = 1; | |
public static final int ID = 1; |
this would make the usage cleaner:
constants.DriveTrain.TalonR.ID
//instead of
constants.DriveTrain.TalonR.TALONR_ID
which is a bit redundant
No description provided.