Skip to content

Commit

Permalink
intake sim working
Browse files Browse the repository at this point in the history
  • Loading branch information
r4stered committed Sep 2, 2024
1 parent 93bc473 commit ee3109c
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/main/cpp/RobotContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void RobotContainer::ConfigureBindings() {
},
true));

controller.LeftTrigger().WhileTrue(swerveSubsystem.AlignToAmp());
//controller.LeftTrigger().WhileTrue(swerveSubsystem.AlignToAmp());
controller.LeftBumper().WhileTrue(swerveSubsystem.XPattern());
controller.Back().WhileTrue(
swerveSubsystem.WheelRadius(frc2::sysid::Direction::kReverse));
Expand All @@ -52,6 +52,9 @@ void RobotContainer::ConfigureBindings() {
controller.A().WhileTrue(shooterSubsystem.RunShooter([] { return consts::shooter::PRESET_SPEEDS::AMP; }));
controller.A().OnFalse(shooterSubsystem.RunShooter([] { return consts::shooter::PRESET_SPEEDS::OFF; }));

controller.LeftTrigger().WhileTrue(intakeSubsystem.IntakeNote());
controller.RightTrigger().WhileTrue(intakeSubsystem.PoopNote());

// controller.A().WhileTrue(shooterSubsystem.TopWheelSysIdQuasistatic(frc2::sysid::Direction::kForward));
// controller.B().WhileTrue(shooterSubsystem.TopWheelSysIdQuasistatic(frc2::sysid::Direction::kReverse));
// controller.X().WhileTrue(shooterSubsystem.TopWheelSysIdDynamic(frc2::sysid::Direction::kForward));
Expand Down
51 changes: 50 additions & 1 deletion src/main/cpp/subsystems/IntakeSubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "subsystems/IntakeSubsystem.h"
#include <frc/smartdashboard/SmartDashboard.h>
#include "constants/Constants.h"
#include <frc2/command/Commands.h>

IntakeSubsystem::IntakeSubsystem() {
SetName("IntakeSubsystem");
Expand All @@ -13,8 +14,56 @@ IntakeSubsystem::IntakeSubsystem() {
frc::SmartDashboard::PutData(this);
}

bool IntakeSubsystem::TouchingNote() {
return isTouchingNote;
}

frc2::CommandPtr IntakeSubsystem::IntakeNote() {
return frc2::cmd::RunEnd([this] {
intakeWheelVoltageSetpoint = consts::intake::gains::NOTE_INTAKE_VOLTAGE;
}, [this] {
intakeWheelVoltageSetpoint = 0_V;
}, {this});
}

frc2::CommandPtr IntakeSubsystem::PoopNote() {
return frc2::cmd::RunEnd([this] {
intakeWheelVoltageSetpoint = consts::intake::gains::NOTE_EJECT_VOLTAGE;
}, [this] {
intakeWheelVoltageSetpoint = 0_V;
}, {this});
}

// This method will be called once per scheduler run
void IntakeSubsystem::Periodic() {}
void IntakeSubsystem::Periodic() {
ctre::phoenix::StatusCode shooterWaitResult = ctre::phoenix6::BaseStatusSignal::RefreshAll({
&intakeMotorVoltageSig,
&intakeMotorTorqueCurrentSig
});

currentIntakeWheelVoltage = intakeMotorVoltageSig.GetValue();
intakeWheelTorqueCurrent = intakeMotorTorqueCurrentSig.GetValue();

isTouchingNote = intakeSpikeDebouncer.Calculate(intakeWheelTorqueCurrent > consts::intake::gains::NOTE_SPIKE_THRESHOLD);

intakeMotor.SetControl(intakeMotorVoltageSetter.WithOutput(intakeWheelVoltageSetpoint));

UpdateNTEntries();
}

void IntakeSubsystem::UpdateNTEntries() {
intakeWheelMotorVoltagePub.Set(currentIntakeWheelVoltage.value());
intakeWheelMotorVoltageSetpointPub.Set(intakeWheelVoltageSetpoint.value());
intakeWheelTorqueCurrentPub.Set(intakeWheelTorqueCurrent.value());
touchingNotePub.Set(isTouchingNote);
}

void IntakeSubsystem::SimulationPeriodic() {
intakeMotorSim.SetSupplyVoltage(frc::RobotController::GetBatteryVoltage());
intakeSim.SetInputVoltage(intakeMotorSim.GetMotorVoltage());
intakeSim.Update(consts::LOOP_PERIOD);
intakeMotorSim.SetRotorVelocity(intakeSim.GetAngularVelocity());
}

bool IntakeSubsystem::ConfigureIntakeMotor(bool invert,
units::scalar_t intakeGearing,
Expand Down
2 changes: 1 addition & 1 deletion src/main/deploy/commit.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7857c51
93bc473
6 changes: 6 additions & 0 deletions src/main/include/constants/IntakeConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,11 @@ inline constexpr units::meter_t WHEEL_RADIUS = 1_in;
//From onshape doc
inline constexpr units::kilogram_square_meter_t INTAKE_MOI = 12.350445 * 1_in * 1_in * 1_lb;
} // namespace physical

namespace gains {
inline constexpr units::ampere_t NOTE_SPIKE_THRESHOLD = 100_A;
inline constexpr units::volt_t NOTE_INTAKE_VOLTAGE = 10_V;
inline constexpr units::volt_t NOTE_EJECT_VOLTAGE = -5_V;
}
} // namespace intake
} // namespace consts
25 changes: 25 additions & 0 deletions src/main/include/subsystems/IntakeSubsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <ctre/phoenix6/TalonFX.hpp>
#include <frc/system/plant/LinearSystemId.h>
#include <frc/simulation/FlywheelSim.h>
#include <frc/filter/Debouncer.h>
#include <frc2/command/CommandPtr.h>

class IntakeSubsystem : public frc2::SubsystemBase {
public:
Expand All @@ -22,7 +24,11 @@ class IntakeSubsystem : public frc2::SubsystemBase {
* Will be called periodically whenever the CommandScheduler runs.
*/
void Periodic() override;
void SimulationPeriodic() override;
bool TouchingNote();

frc2::CommandPtr IntakeNote();
frc2::CommandPtr PoopNote();

private:
void UpdateNTEntries();
Expand All @@ -46,4 +52,23 @@ class IntakeSubsystem : public frc2::SubsystemBase {

std::shared_ptr<nt::NetworkTable> nt{
nt::NetworkTableInstance::GetDefault().GetTable("Intake")};
nt::DoublePublisher intakeWheelMotorVoltagePub{
nt->GetDoubleTopic("IntakeWheelMotorVoltage").Publish()
};
nt::DoublePublisher intakeWheelMotorVoltageSetpointPub{
nt->GetDoubleTopic("IntakeWheelMotorVoltageSetpoint").Publish()
};
nt::DoublePublisher intakeWheelTorqueCurrentPub{
nt->GetDoubleTopic("IntakeWheelMotorTorqueCurrent").Publish()
};
nt::DoublePublisher touchingNotePub{
nt->GetDoubleTopic("TouchingNote").Publish()
};

frc::Debouncer intakeSpikeDebouncer{.25_s, frc::Debouncer::kFalling};
bool isTouchingNote{false};

units::volt_t intakeWheelVoltageSetpoint{0_V};
units::volt_t currentIntakeWheelVoltage{0_V};
units::ampere_t intakeWheelTorqueCurrent{0_A};
};

0 comments on commit ee3109c

Please sign in to comment.