Skip to content
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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Drive train #1

wants to merge 15 commits into from

Conversation

Mika4239
Copy link
Owner

@Mika4239 Mika4239 commented Aug 9, 2021

No description provided.

@barakshelef barakshelef self-requested a review August 13, 2021 12:42
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
Robot.driveTrain.setBothPrecent(Robot.joysticks.getLeftY(), Robot.joysticks.getRightY());
Copy link
Collaborator

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:

Suggested change
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();
Copy link
Collaborator

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);
Copy link
Collaborator

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){
Copy link
Collaborator

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.

Suggested change
public void setRightPercent(double percentage){
private void setRightPercent(double percentage){

Comment on lines 45 to 48
public void setDistance(double distanceR, double distanceL) {
this._talonL.set(ControlMode.Position, distanceR);
this._talonL.set(ControlMode.Position, distanceL);
}
Copy link
Collaborator

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.

Suggested change
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.

Comment on lines 19 to 21
public double getLeftX(){
return this._leftJoystick.getX();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again... aren't used...

Suggested change
public double getLeftX(){
return this._leftJoystick.getX();
}

Comment on lines 58 to 66
public void setBothPercent(double percentageL, double percentageR){
setRightPercent(percentageR);
setLeftPercent(percentageL);
}

public void setpercent(double percentage){
setRightPercent(percentage);
setLeftPercent(percentage);
}
Copy link
Collaborator

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:

Suggested change
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


public static DriveTrain driveTrain;

public static Joysticks joysticks;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you never initialize Joysticks

@@ -15,6 +17,11 @@
* project.
*/
public class Robot extends TimedRobot {

public static DriveTrain driveTrain;
Copy link
Collaborator

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;
Copy link
Collaborator

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?

Suggested change
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants