-
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
Shooter pull request #7
base: main
Are you sure you want to change the base?
Changes from 2 commits
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 |
---|---|---|
|
@@ -2,7 +2,13 @@ | |
|
||
import edu.wpi.first.wpilibj2.command.Subsystem; | ||
import org.usfirst.frc4904.standard.custom.controllers.CustomJoystick; | ||
import org.usfirst.frc4904.standard.custom.motioncontrollers.CANTalonFX; | ||
import org.usfirst.frc4904.standard.custom.motioncontrollers.CANTalonSRX; | ||
import org.usfirst.frc4904.standard.custom.motioncontrollers.CustomPIDController; | ||
import org.usfirst.frc4904.standard.custom.controllers.CustomXbox; | ||
import org.usfirst.frc4904.standard.custom.sensors.CANTalonEncoder; | ||
import org.usfirst.frc4904.robot.subsystems.Flywheel; | ||
import org.usfirst.frc4904.standard.custom.CustomPIDSourceType; | ||
|
||
public class RobotMap { | ||
public static class Port { | ||
|
@@ -12,6 +18,8 @@ public static class HumanInput { | |
} | ||
|
||
public static class CANMotor { | ||
public static final int FLYWHEEL_MOTOR_A = -1; // TODO: set port | ||
public static final int FLYWHEEL_MOTOR_B = -1; | ||
} | ||
|
||
public static class PWM { | ||
|
@@ -39,9 +47,28 @@ public static class Chassis { | |
public static final double INCHES_PER_TICK = Metrics.Chassis.CIRCUMFERENCE_INCHES | ||
/ Metrics.Chassis.TICKS_PER_REVOLUTION; | ||
} | ||
|
||
public static class Encoders { | ||
public static class TalonEncoders { | ||
public static final double TICKS_PER_REVOLUTION = 2048.0; | ||
public static final double REVOLUTIONS_PER_TICK = 1 / TICKS_PER_REVOLUTION; | ||
} | ||
|
||
public static class CANCoders { | ||
public static final double TICKS_PER_REVOLUTION = 4096.0; | ||
public static final double REVOLUTIONS_PER_TICK = 1 / TICKS_PER_REVOLUTION; | ||
} | ||
} | ||
} | ||
|
||
public static class PID { | ||
public static class Flywheel { | ||
public static final double P = -1; // TODO: tune PID constants | ||
public static final double I = -1; | ||
public static final double D = -1; | ||
public static final double F = -1; | ||
} | ||
|
||
public static class Drive { | ||
} | ||
|
||
|
@@ -51,6 +78,11 @@ public static class Turn { | |
} | ||
|
||
public static class Component { | ||
public static Flywheel flywheel; | ||
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. why does this exist? 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. remove. |
||
public static CANTalonEncoder flywheelEncoderA; | ||
public static CANTalonEncoder flywheelEncoderB; | ||
public static Flywheel shooter; | ||
public static CustomPIDController flywheelPID; | ||
} | ||
|
||
public static class Input { | ||
|
@@ -70,5 +102,21 @@ public RobotMap() { | |
HumanInput.Driver.xbox = new CustomXbox(Port.HumanInput.xboxController); | ||
HumanInput.Operator.joystick = new CustomJoystick(Port.HumanInput.joystick); | ||
|
||
CANTalonFX flywheelATalon = new CANTalonFX(Port.CANMotor.FLYWHEEL_MOTOR_A); | ||
flywheelATalon.setInverted(true); // todo: check if flywheel is in the correct direction (check if it is inverted) | ||
CANTalonFX flywheelBTalon = new CANTalonFX(Port.CANMotor.FLYWHEEL_MOTOR_B); | ||
|
||
Component.flywheelEncoderB = new CANTalonEncoder(flywheelBTalon, false, | ||
Metrics.Encoders.TalonEncoders.REVOLUTIONS_PER_TICK); | ||
Component.flywheelEncoderB.setCustomPIDSourceType(CustomPIDSourceType.kRate); | ||
/** Motion Controllers */ | ||
Component.flywheelPID = new CustomPIDController(PID.Flywheel.P, PID.Flywheel.I, PID.Flywheel.D, PID.Flywheel.F, | ||
Component.flywheelEncoderB); | ||
|
||
Component.shooter = new Flywheel("Shooter", Component.flywheelPID, flywheelATalon, flywheelBTalon); | ||
/** Classes */ | ||
// Component.intake = new Intake(Component.intakeRollerMotor, | ||
// Component.liftBeltMotor, Component.funnelMotor, | ||
// Component.intakeSolenoid); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.usfirst.frc4904.robot.commands; | ||
|
||
import org.usfirst.frc4904.robot.RobotMap; | ||
import org.usfirst.frc4904.robot.subsystems.Flywheel; | ||
|
||
public class FlywheelOff extends FlywheelSetSpeed { | ||
|
||
/** | ||
* Set flywheel speed to zero | ||
* | ||
* @param flywheel The flywheel to manipulate | ||
*/ | ||
public FlywheelOff(Flywheel flywheel) { | ||
super(flywheel, 0.0); | ||
} | ||
|
||
public FlywheelOff() { | ||
super(RobotMap.Component.flywheel, 0.0); | ||
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. change to |
||
} | ||
} | ||
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. Generally, you should leave a newline at the end of your file. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.usfirst.frc4904.robot.commands; | ||
|
||
import org.usfirst.frc4904.robot.RobotMap; | ||
import org.usfirst.frc4904.robot.subsystems.Flywheel; | ||
import org.usfirst.frc4904.standard.commands.motor.MotorVelocitySet; | ||
|
||
public class FlywheelSetSpeed extends MotorVelocitySet { | ||
|
||
/** | ||
* Spin up the flywheel to a speed | ||
* | ||
* @param flywheel The flywheel to manipulate | ||
* @param speed The speed to spin the flywheel up to | ||
*/ | ||
public FlywheelSetSpeed(Flywheel flywheel, double speed) { | ||
super("FlywheelMaintainSpeed", flywheel, speed); | ||
} | ||
|
||
public FlywheelSetSpeed(double speed) { | ||
this(RobotMap.Component.flywheel, speed); | ||
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. change to |
||
} | ||
} | ||
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. See above comment |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package org.usfirst.frc4904.robot.subsystems; | ||
|
||
import edu.wpi.first.wpilibj.motorcontrol.MotorController; | ||
|
||
import org.usfirst.frc4904.standard.custom.motioncontrollers.MotionController; | ||
import org.usfirst.frc4904.standard.subsystems.motor.VelocitySensorMotor; | ||
import org.usfirst.frc4904.standard.subsystems.motor.speedmodifiers.IdentityModifier; | ||
import org.usfirst.frc4904.standard.subsystems.motor.speedmodifiers.SpeedModifier; | ||
|
||
/** | ||
* Flywheel Base Class | ||
* | ||
* ! This class does not include a piston, use Shooter.java for the 2020-season | ||
* ! specific flywheel subsystem. | ||
* | ||
* This class is designed to go into standard, eventually. | ||
*/ | ||
public class Flywheel extends VelocitySensorMotor { | ||
public static enum FlywheelStatus { | ||
IDLE, SPINNING_UP, AT_SPEED | ||
} | ||
|
||
protected FlywheelStatus currentStatus = FlywheelStatus.IDLE; | ||
protected double targetSpeed = 0.0; | ||
|
||
/** | ||
* Flywheel constructor - extends VelocitySensorMotor | ||
* motionController.absoluteTolerance should be set. | ||
* | ||
* @param name The name of the flywheel | ||
* @param SpeedModifier The speedModifier | ||
* @param motionController The motionController | ||
* @param motors Motors to control | ||
*/ | ||
public Flywheel(String name, SpeedModifier speedModifier, MotionController motionController, | ||
MotorController... motors) { | ||
super(name, speedModifier, motionController, motors); | ||
// super.enableMotionController(); | ||
} | ||
|
||
/** | ||
* Flywheel constructor - extends VelocitySensorMotor | ||
* | ||
* @param SpeedModifier The speedModifier | ||
* @param motionController The motionController | ||
* @param motors Motors to control | ||
*/ | ||
public Flywheel(SpeedModifier speedModifier, MotionController motionController, MotorController... motors) { | ||
this("Flywheel", speedModifier, motionController, motors); | ||
} | ||
|
||
/** | ||
* Flywheel constructor - extends VelocitySensorMotor | ||
* | ||
* @param name The name of the flywheel | ||
* @param motionController The motionController | ||
* @param motors Motors to control | ||
*/ | ||
public Flywheel(String name, MotionController motionController, MotorController... motors) { | ||
this(name, new IdentityModifier(), motionController, motors); | ||
} | ||
|
||
/** | ||
* Flywheel constructor - extends VelocitySensorMotor | ||
* | ||
* @param motionController The motionController | ||
* @param motors Motors to control | ||
*/ | ||
public Flywheel(MotionController motionController, MotorController... motors) { | ||
this("Flywheel", motionController, motors); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
syncStatus(); | ||
} | ||
|
||
protected void syncStatus() { | ||
// TODO:// Infinitely idle? | ||
if (Math.abs(targetSpeed) < motionController.getAbsoluteTolerance() || currentStatus == FlywheelStatus.IDLE) { | ||
currentStatus = FlywheelStatus.IDLE; | ||
return; | ||
} | ||
if (motionController.onTarget()) { | ||
currentStatus = FlywheelStatus.AT_SPEED; | ||
} else { | ||
currentStatus = FlywheelStatus.SPINNING_UP; | ||
} | ||
} | ||
|
||
public FlywheelStatus getStatus() { | ||
return currentStatus; | ||
} | ||
|
||
public double getVelocity() { | ||
return motionController.getSensorValue(); | ||
} | ||
|
||
public double getTargetVelocity() { | ||
return targetSpeed; | ||
} | ||
|
||
public void setVelocity() { | ||
super.set(targetSpeed); | ||
} | ||
|
||
public void setVelocity(double speed) { | ||
targetSpeed = speed; | ||
setVelocity(); | ||
} | ||
|
||
public MotionController getMC() { | ||
return motionController; | ||
} | ||
} |
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.
Vaguely concerning, but as long as it's good I guess that's fine.