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

Feature/intake phx6 alon #6

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

Conversation

AlonSchwierz
Copy link

Hello we are donating washing machines for homeless dogs

תודה

@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

pls no

Copy link
Author

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

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).

Copy link
Author

Choose a reason for hiding this comment

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

done.

Copy link
Member

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.

src/main/java/frc/robot/subsystems/intake/IntakeIOSim.java Outdated Show resolved Hide resolved
Comment on lines 41 to 54
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);
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

done.

Copy link
Member

@katzuv katzuv Dec 16, 2023

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.

src/main/java/frc/robot/subsystems/intake/IntakeIOSim.java Outdated Show resolved Hide resolved

spinMotor.update(0.02);
angleMotor.update(0.02);
inputs.angleMotorPower = angleMotorSim.getAppliedVoltage() / 12;
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

OK

Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

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

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.

Copy link
Author

Choose a reason for hiding this comment

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

what do you mean?

Copy link
Member

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
Copy link
Member

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

@katzuv katzuv Dec 12, 2023

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.

Comment on lines +16 to +17


Copy link
Member

Choose a reason for hiding this comment

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

Redundant

Suggested change

Comment on lines +20 to +21
private final TalonFXConfigurator angleConfigurator;
private TalonFXConfiguration angleConfiguration = new TalonFXConfiguration();
Copy link
Member

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?

Comment on lines 48 to 54
motorControlReqeust = new PositionVoltage(angle);
angleMotor.setControl(motorControlReqeust);
}

@Override
public void setAngleMotorPower(double power) {
angleMotor.set(ControlMode.PercentOutput, power);
motorControlReqeust = new DutyCycleOut(power);
Copy link
Member

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

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

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?

Comment on lines +1 to +10
//
//import org.junit.Test;
//
//public class ExampleSubsystemTest {
//
// @Test
// public void setPower() {
// }
//}
Copy link
Member

Choose a reason for hiding this comment

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

Why is that needed?

Comment on lines 32 to 38
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();
Copy link
Member

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

Choose a reason for hiding this comment

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

...

Comment on lines 85 to 108
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));
Copy link
Member

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)))),
Copy link
Member

@katzuv katzuv Dec 16, 2023

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

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.

Comment on lines +111 to +113
// You Jerk :) 😎
// I'm gonna kill them all.
// All the juice must die
Copy link
Member

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?

Comment on lines +53 to +54
angleMotorSim.update(Timer.getFPGATimestamp());
powerMotorSim.update(Timer.getFPGATimestamp());
Copy link
Member

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

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 {
Copy link
Member

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

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

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.

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

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.

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.

3 participants