-
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
Intake #1
base: master
Are you sure you want to change the base?
Intake #1
Changes from 6 commits
e8dda8f
49433ad
5fda56e
759f0ff
42689a0
e9afee6
377e96c
af850d7
207419e
b07a4bb
d16f0e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,14 +11,23 @@ | |||||||||||||
import edu.wpi.first.wpilibj.GenericHID; | ||||||||||||||
import edu.wpi.first.wpilibj.XboxController; | ||||||||||||||
import edu.wpi.first.wpilibj2.command.Command; | ||||||||||||||
import frc.robot.subsystems.ExampleSubsystem.ExampleSubsystem; | ||||||||||||||
import edu.wpi.first.wpilibj2.command.button.JoystickButton; | ||||||||||||||
import frc.robot.subsystems.intake.Intake; | ||||||||||||||
import frc.robot.subsystems.intake.commands.Commandy; | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* This class is where the bulk of the robot should be declared. Since Command-based is a | ||||||||||||||
* "declarative" paradigm, very little robot logic should actually be handled in the {@link Robot} | ||||||||||||||
* periodic methods (other than the scheduler calls). Instead, the structure of the robot | ||||||||||||||
* (including subsystems, commands, and button mappings) should be declared here. | ||||||||||||||
*/ | ||||||||||||||
public class RobotContainer { | ||||||||||||||
public XboxController Xbox = new XboxController(1); | ||||||||||||||
public JoystickButton a = new JoystickButton(Xbox, XboxController.Button.kA.value); | ||||||||||||||
public JoystickButton b = new JoystickButton(Xbox, XboxController.Button.kB.value); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Also, make them |
||||||||||||||
private Intake intake; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
// The robot's subsystems and commands are defined here... | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
|
@@ -37,6 +46,7 @@ public RobotContainer() { | |||||||||||||
* {@link edu.wpi.first.wpilibj2.command.button.JoystickButton}. | ||||||||||||||
*/ | ||||||||||||||
private void configureButtonBindings() { | ||||||||||||||
a.whileHeld(new Commandy(intake, Constants.Intake.power)); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,62 @@ | ||||||||||||||
package frc.robot.subsystems.intake; | ||||||||||||||
|
||||||||||||||
import com.ctre.phoenix.motorcontrol.ControlMode; | ||||||||||||||
import com.ctre.phoenix.motorcontrol.can.TalonSRX; | ||||||||||||||
import edu.wpi.first.wpilibj.Solenoid; | ||||||||||||||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Add&named motors in Intake. | ||||||||||||||
*/ | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add proper documentation!!! (everywhere) |
||||||||||||||
public class Intake extends SubsystemBase { | ||||||||||||||
private TalonSRX motor = new TalonSRX(Ports.Intake.MOTOR); | ||||||||||||||
private Solenoid piston = new Solenoid(Ports.Intake.SOLENOID); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to call it "retractor" or something similar, to explain what the piston's purpose is. Make sure you change the name everywhere, for example, change every function name that has "piston" inside it. |
||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Add motor inverted. | ||||||||||||||
*/ | ||||||||||||||
public void TalonSRXSelenoid() { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
this.motor.setInverted(Ports.Intake.IS_MOTOR_INVERTED); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "this" isn't necessary here |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Set power for motor. | ||||||||||||||
* @param power the speed times the torque. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong units, it's just percentage |
||||||||||||||
*/ | ||||||||||||||
public void setMotorPower(double power) { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename to setPower There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I disagree, it might not be the proper naming, maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure it's just repetitive to call the method setMotorPower |
||||||||||||||
motor.set(ControlMode.PercentOutput, power); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* A check to see if piston is open or close. | ||||||||||||||
* @return | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should write what true mean (does it mean open or closed?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A shorter solution will be renaming the function |
||||||||||||||
*/ | ||||||||||||||
public boolean isPistonEngaged() { | ||||||||||||||
return piston.get(); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Set piston position. | ||||||||||||||
* @param engaged | ||||||||||||||
*/ | ||||||||||||||
public void setPistonMode(boolean engaged) { | ||||||||||||||
piston.set(engaged); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Change piston position. | ||||||||||||||
*/ | ||||||||||||||
public void toggle() { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the component name to the function, i.e. |
||||||||||||||
if (isPistonEngaged()) { | ||||||||||||||
setPistonMode(false); | ||||||||||||||
} else { | ||||||||||||||
setPistonMode(true); | ||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can shorten this code:
Suggested change
|
||||||||||||||
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
||||||||||||||
|
||||||||||||||
|
||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for all those blank lines. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package frc.robot.subsystems.intake; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ports should be in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤢🤮 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
|
||
/** | ||
* Data of MOTOR & SOLENOID power. | ||
* Data of is MOTOR inverted. | ||
*/ | ||
public class Ports { | ||
public static class Intake { | ||
public static final int MOTOR = 0; | ||
public static final int SOLENOID = 0; | ||
public static final boolean IS_MOTOR_INVERTED = true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package frc.robot.subsystems.intake.commands; | ||
|
||
import edu.wpi.first.wpilibj2.command.CommandBase; | ||
import frc.robot.subsystems.intake.Intake; | ||
|
||
/** | ||
* Add Commandy function; | ||
*/ | ||
public class Commandy extends CommandBase { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a command that only opens and closes the intake There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, and add another command that powers the wheels. Then, if needed, combine both commands in a command group. |
||
private final Intake intake; | ||
private final double power; | ||
|
||
/** | ||
* Add Requirements | ||
* | ||
* @param intake name to Intake. | ||
*/ | ||
public Commandy(Intake intake, double power) { | ||
this.intake = intake; | ||
this.power = power; | ||
addRequirements(intake); | ||
|
||
} | ||
|
||
|
||
@Override | ||
public void initialize() { | ||
super.initialize(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for this call to public interface Command {
/** The initial subroutine of a command. Called once when the command is initially scheduled. */
default void initialize() {}
/** The main body of a command. Called repeatedly while the command is scheduled. */
default void execute() {}
/**
* The action to take when the command ends. Called when either the command finishes normally, or
* when it interrupted/canceled.
*
* <p>Do not schedule commands here that share requirements with this command. Use {@link
* #andThen(Command...)} instead.
*
* @param interrupted whether the command was interrupted/canceled
*/
default void end(boolean interrupted) {}
/**
* Whether the command has finished. Once a command finishes, the scheduler will call its end()
* method and un-schedule it.
*
* @return whether the command has finished.
*/
default boolean isFinished() {
return false;
} |
||
intake.setPistonMode(false); | ||
} | ||
|
||
|
||
@Override | ||
public void execute() { | ||
super.execute(); | ||
intake.setMotorPower(power); | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return super.isFinished(); | ||
} | ||
|
||
|
||
@Override | ||
public void end(boolean interrupted) { | ||
super.end(interrupted); | ||
intake.setMotorPower(0); | ||
intake.setPistonMode(true); | ||
} | ||
} |
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.
CAPITALIZE