-
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
Feature/intake phx6 alon #6
base: main
Are you sure you want to change the base?
Conversation
@@ -106,6 +106,9 @@ public Command lowerIntake() { | |||
.andThen(new RunCommand(() -> setAngleMotorAngle(-40), this)); | |||
} | |||
|
|||
// You Jerk :) 😎 | |||
// I'm gonna kill them all. | |||
// All the jews must die |
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.
pls no
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.
OK sorry
@@ -48,27 +50,30 @@ public void setSpinMotorPower(double power) { | |||
|
|||
@Override | |||
public void setAngleMotorAngle(double angle) { | |||
angleMotor.set(ControlMode.Position, angle); | |||
var motorRequest = new PositionVoltage(Units.radiansToRotations(angle)); |
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.
From the Phoenix 6 documentation:
Java users should reuse control requests to prevent excessive invocation of the Garbage Collector.
You can create the request object as a class member and change the value as needed with withPosition()
(this doesn't create a new object but changes the same one).
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.
done.
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.
Not really, you still create the request every time this function is called. You should create it once and only once.
var motorRequest = new DutyCycleOut(power); | ||
powerMotorSim.setControl(motorRequest); | ||
} | ||
|
||
@Override | ||
public void setAngleMotorAngle(double angle) { | ||
double angleMotorAppliedVoltage = angleFeedback.calculate(angleMotor.getAngleRads(), angle); | ||
angleMotor.setInputVoltage(angleMotorAppliedVoltage); | ||
var motorRequest = new PositionVoltage(Units.radiansToRotations(angle)); | ||
angleMotorSim.setControl(motorRequest); | ||
} | ||
|
||
@Override | ||
public void setAngleMotorPower(double power) { | ||
angleMotor.setInputVoltage(power * 12); | ||
var motorRequest = new DutyCycleOut(power); | ||
angleMotorSim.setControl(motorRequest); |
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, you should reuse control requests.
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.
done.
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.
Nope, you still create it in each function call.
|
||
spinMotor.update(0.02); | ||
angleMotor.update(0.02); | ||
inputs.angleMotorPower = angleMotorSim.getAppliedVoltage() / 12; |
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, better to log the voltage directly.
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.
OK
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 write OK but change nothing, and resolve the thread?
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.
yes but this is a simulation and the BatterySim Class is private for some reason.
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.
WDYM private? It's very much public https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/simulation/BatterySim.html
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.
I understand your problem, you're trying to instantiate BatterySim
. True, it's constructor is private, but all of its methods are static, so you don't need to instantiate the class.
inputs.angleMotorPower = angleMotorSim.getAppliedVoltage() / 12; | ||
inputs.angleMotorcurrent = angleMotorSim.getAppliedCurrent(); | ||
inputs.angleMotorVelocity = angleMotorSim.getRotorVelocity(); | ||
inputs.angleMotorAngle = angleMotorSim.getRotorPosition() * Math.PI * 2 % Math.PI * 2; |
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.
IntakeConstants.ANGLE_GEAR_RATIO
should be calculated to take the conversion to rotations.
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.
what do you mean?
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.
Modify this constant so getRotorPosition()
will already return a value in rotations and not in meters (I presume). Also, why not use degrees instead of rotations?
@@ -9,7 +10,8 @@ public class IntakeConstants { | |||
public static final double kP = 2; | |||
public static final double kI = 0; | |||
public static final double kD = 0.2; | |||
public static final double kF = 0; | |||
public static final double kF = 0; // not relevant anymore |
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.
If that's not relevant, delete it. Why isn't it, though?
@@ -9,7 +10,8 @@ public class IntakeConstants { | |||
public static final double kP = 2; | |||
public static final double kI = 0; | |||
public static final double kD = 0.2; | |||
public static final double kF = 0; | |||
public static final double kF = 0; // not relevant anymore | |||
public static final Slot0Configs PIDGains = new Slot0Configs().withKP(IntakeConstants.kP).withKI(IntakeConstants.kI).withKD(IntakeConstants.kD); |
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 don't need to create individual constants, just put the numbers on this line instead.
|
||
|
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.
Redundant
private final TalonFXConfigurator angleConfigurator; | ||
private TalonFXConfiguration angleConfiguration = new TalonFXConfiguration(); |
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.
Do you need a variable for that? And as a class member, even?
motorControlReqeust = new PositionVoltage(angle); | ||
angleMotor.setControl(motorControlReqeust); | ||
} | ||
|
||
@Override | ||
public void setAngleMotorPower(double power) { | ||
angleMotor.set(ControlMode.PercentOutput, power); | ||
motorControlReqeust = new DutyCycleOut(power); |
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.
Cache control requests.
angleMotorSim.setController(angleController); | ||
|
||
angleConfiguration.Slot0 = IntakeConstants.PIDGains; | ||
// angleMotorSim.configure(angleConfiguration); |
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.
...
|
||
spinMotor.update(0.02); | ||
angleMotor.update(0.02); | ||
inputs.angleMotorPower = angleMotorSim.getAppliedVoltage() / 12; |
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 write OK but change nothing, and resolve the thread?
// | ||
//import org.junit.Test; | ||
// | ||
//public class ExampleSubsystemTest { | ||
// | ||
// @Test | ||
// public void setPower() { | ||
// } | ||
//} |
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.
Why is that needed?
private final SwerveDrive swerveDrive = SwerveDrive.getInstance(Robot.isReal()); | ||
static { | ||
SwerveDrive.setInstance(Robot.isReal(), | ||
Ports.SwerveDrive.DRIVE_IDS, | ||
Ports.SwerveDrive.ANGLE_IDS, | ||
Ports.SwerveDrive.ENCODER_IDS); | ||
} | ||
private final SwerveDrive swerveDrive = SwerveDrive.getInstance(); |
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.
Why did you change this here? It's not related to this branch.
|
||
rb.whileTrue(new ArmAxisControl(0.02, 0.02) | ||
.until(() -> gripper.getDistance() < ArmConstants.FEEDER_DISTANCE)); | ||
// a.whileTrue(new RunCommand(()-> intake.setAngleMotorAngle(Math.PI))); |
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.
...
leftJoystickTrigger.onTrue(new InstantCommand(swerveDrive::resetGyro)); | ||
y.whileTrue(new ArmWithSpline(ArmPosition.TOP_SCORING)); | ||
x.whileTrue(new ArmWithSpline(ArmPosition.MIDDLE_SCORING)); | ||
b.whileTrue(new ArmWithSpline(ArmPosition.FEEDER)); | ||
back.whileTrue(new ArmWithSpline(ArmPosition.FEEDER_CONE)); | ||
a.whileTrue(new ArmWithSpline(ArmPosition.NEUTRAL)); | ||
|
||
lb.onTrue(new InstantCommand(gripper::toggle)); | ||
|
||
start.onTrue(new InstantCommand(leds::toggle)); | ||
|
||
leftJoystickTopBottom.toggleOnTrue( | ||
new InstantCommand(swerveDrive::lock, swerveDrive) | ||
); | ||
leftJoystickTopBottom.onTrue( | ||
new InstantCommand(leds::toggleRainbow) | ||
); | ||
|
||
xboxLeftTrigger.whileTrue(new PickUpCubeTeleop()) | ||
.onFalse(new Retract(Retract.Mode.UP).andThen(new InstantCommand(() -> intake.setSpinMotorPower(0)))); | ||
xboxRightTrigger.whileTrue(new ReturnIntake()); | ||
|
||
rb.whileTrue(new ArmAxisControl(0.02, 0.02) | ||
.until(() -> gripper.getDistance() < ArmConstants.FEEDER_DISTANCE)); |
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.
Why did you delete all of that?
@@ -12,7 +13,7 @@ public FeedTeleop(boolean outtake) { | |||
|
|||
addCommands( | |||
new Retract(Retract.Mode.DOWN) | |||
.andThen(new RunCommand(() -> intake.setAngleMotorAngle(IntakeConstants.ANGLE_DOWN))), | |||
.andThen(new RunCommand(() -> intake.setAngleMotorAngle(Rotation2d.fromDegrees(IntakeConstants.ANGLE_DOWN)))), |
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.
Instead of creating a Rotation2d
here, ANGLE_DOWN
should already be a Rotation2d
.
@@ -7,7 +7,7 @@ | |||
|
|||
public class CheckSwerve extends SequentialCommandGroup { | |||
public CheckSwerve() { | |||
SwerveDrive swerveDrive = SwerveDrive.getInstance(Robot.isReal()); | |||
SwerveDrive swerveDrive = SwerveDrive.getInstance(); |
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.
Shouldn't be changed here. You can use interactive rebasing to remove this diff.
// You Jerk :) 😎 | ||
// I'm gonna kill them all. | ||
// All the juice must die |
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.
Aren't you going to delete it?
angleMotorSim.update(Timer.getFPGATimestamp()); | ||
powerMotorSim.update(Timer.getFPGATimestamp()); |
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.
Does update
receive the time since the last call or the system clock since the system started?
Also, I'm not sure the function you used is available in simulation.
public double spinMotorPower; | ||
public double spinMotorAppliedCurrent; | ||
public double spinMotorAppliedVoltage; | ||
public Rotation2d angleMotorVelocity = new Rotation2d(); |
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.
How is a velocity value represented by a Rotation2d
?
@@ -1,18 +1,21 @@ | |||
package frc.robot.subsystems.intake; | |||
|
|||
import edu.wpi.first.math.geometry.Rotation2d; | |||
import org.littletonrobotics.junction.LogTable; | |||
import org.littletonrobotics.junction.inputs.LoggableInputs; | |||
|
|||
public class IntakeLoggedInputs implements LoggableInputs { |
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.
Why not use @Autolog
?
@@ -17,9 +18,9 @@ public HoldIntakeInPlace() { | |||
@Override | |||
public void execute() { | |||
if (intake.switchedToDefaultCommand() || Robot.justEnabled()) { |
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.
Why are these two conditions needed?
angle = MathUtil.clamp(angle, IntakeConstants.ANGLE_DOWN, IntakeConstants.ANGLE_UP); | ||
} | ||
intake.setAngleMotorAngle(IntakeConstants.ANGLE_UP); | ||
intake.setAngleMotorAngle(Rotation2d.fromDegrees( IntakeConstants.ANGLE_UP)); |
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.
Instead of casting, IntakeConstants.ANGLE_UP
should be of type Rotation2d
. Be consistent in your code, try to minimize the types you use.
…5987/Sim-bot-2023 into feature/Intake-phx6-Alon
@@ -132,10 +132,10 @@ public void periodic() { | |||
!(lastCommand instanceof HoldIntakeInPlace); | |||
lastCommand = currentCommand; | |||
|
|||
intakeP1.setAngle(Math.toDegrees(getAngleMotorAngle()) + IntakeConstants.INTAKE_MECH_OFFSET); | |||
intakeP1.setAngle(getAngleMotorAngle().getDegrees() + IntakeConstants.INTAKE_MECH_OFFSET); |
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.
MechanismLigament2d
can also receive Rotation2d
objects.
Hello we are donating washing machines for homeless dogs
תודה