Skip to content

Commit

Permalink
Finished LED code v1 (#135)
Browse files Browse the repository at this point in the history
* Finished LED code v1

Co-authored-by: Harry C <[email protected]>

* Formatting fixes

---------

Co-authored-by: Harry C <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 24, 2024
1 parent 6ab3a53 commit a08258f
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/main/cpp/IntakeBehaviour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include <frc/XboxController.h>

IntakeManualControl::IntakeManualControl(Intake* intake, frc::XboxController& codriver)
: _intake(intake), _codriver(codriver) {
IntakeManualControl::IntakeManualControl(Intake* intake, frc::XboxController& codriver, LED* led)
: _intake(intake), _codriver(codriver), _led(led) {
Controls(intake);
}

Expand All @@ -33,24 +33,30 @@ void IntakeManualControl::OnTick(units::second_t dt) {
if (_codriver.GetRightBumperPressed()) {
if (_intake->getState() == IntakeState::kIntake) {
_intake->setState(IntakeState::kIdle);
_led->SetState(LEDState::kIdle);
} else {
_intake->setState(IntakeState::kIntake);
_led->SetState(LEDState::kIntaking);
}
}

if (_codriver.GetLeftBumper()) {
if (_intake->getState() == IntakeState::kEject) {
_intake->setState(IntakeState::kIdle);
_led->SetState(LEDState::kIdle);
} else {
_intake->setState(IntakeState::kEject);
_led->SetState(LEDState::kIdle);
}
}

if (_codriver.GetAButtonPressed()) {
if (_intake->getState() == IntakeState::kPass) {
_intake->setState(IntakeState::kIdle);
_led->SetState(LEDState::kIdle);
} else {
_intake->setState(IntakeState::kPass);
_led->SetState(LEDState::kIntaking);
}
}
}
Expand Down
42 changes: 42 additions & 0 deletions src/main/cpp/LED.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2023-2024 CurtinFRC
// Open Source Software, you can modify it according to the terms
// of the MIT License at the root of this project

#include "LED.h"

LED::LED() {}

void LED::OnUpdate(units::second_t dt) {
switch (_state) {
case LEDState::kIdle: {
_led.frc::PWM::SetSpeed(0);
} break;

case LEDState::kAiming: {
_led.frc::PWM::SetSpeed(0.27);
} break;
case LEDState::kAmpReady: {
_led.frc::PWM::SetSpeed(0.87);
} break;
case LEDState::kHold: {
_led.frc::PWM::SetSpeed(0.57);
} break;
case LEDState::kIntaking: {
_led.frc::PWM::SetSpeed(0.07);
} break;
case LEDState::kShooterReady: {
_led.frc::PWM::SetSpeed(0.77);
} break;

default:
break;
}
}

void LED::SetState(LEDState state) {
_state = state;
}

LEDState LED::GetState() {
return _state;
}
5 changes: 5 additions & 0 deletions src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ void Robot::RobotInit() {
// robotmap.swerveBase.moduleConfigs[2].turnMotor.encoder->SetEncoderOffset(0_rad);
// robotmap.swerveBase.moduleConfigs[3].turnMotor.encoder->SetEncoderOffset(0_rad);

_led = new LED();

lastPeriodic = wom::now();
}

Expand All @@ -126,6 +128,9 @@ void Robot::RobotPeriodic() {
// shooter->OnUpdate(dt);
// intake->OnUpdate(dt);
// alphaArm->OnUpdate(dt);

_led->OnUpdate(dt);

_swerveDrive->OnUpdate(dt);
}

Expand Down
9 changes: 7 additions & 2 deletions src/main/cpp/ShooterBehaviour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include "ShooterBehaviour.h"

ShooterManualControl::ShooterManualControl(Shooter* shooter, frc::XboxController* tester)
: _shooter(shooter), _codriver(tester) {
ShooterManualControl::ShooterManualControl(Shooter* shooter, frc::XboxController* tester, LED* led)
: _shooter(shooter), _codriver(tester), _led(led) {
Controls(shooter);
}

Expand Down Expand Up @@ -33,17 +33,22 @@ void ShooterManualControl::OnTick(units::second_t dt) {
if (_codriver->GetXButton()) {
_shooter->SetPidGoal(150_rad_per_s);
_shooter->SetState(ShooterState::kSpinUp);
_led->SetState(LEDState::kAiming);
} else if (_codriver->GetYButton()) {
_shooter->SetPidGoal(300_rad_per_s);
_shooter->SetState(ShooterState::kSpinUp);
_led->SetState(LEDState::kAiming);
} else if (_codriver->GetLeftTriggerAxis() > 0.1) {
_shooter->SetState(ShooterState::kRaw);
_led->SetState(LEDState::kIdle);
_shooter->SetRaw(12_V * _codriver->GetLeftTriggerAxis());
} else if (_codriver->GetRightTriggerAxis() > 0.1) {
_shooter->SetState(ShooterState::kRaw);
_shooter->SetRaw(-12_V * _codriver->GetRightTriggerAxis());
_led->SetState(LEDState::kIdle);
} else {
_shooter->SetState(ShooterState::kIdle);
_led->SetState(LEDState::kIdle);
}
}
}
6 changes: 5 additions & 1 deletion src/main/include/IntakeBehaviour.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
#include <frc/XboxController.h>

#include "Intake.h"
#include "LED.h"
#include "Wombat.h"

class IntakeManualControl : public behaviour::Behaviour {
public:
explicit IntakeManualControl(Intake* intake, frc::XboxController& codriver);
explicit IntakeManualControl(Intake* intake, frc::XboxController& codriver, LED* led);

void OnTick(units::second_t dt) override;

private:
Intake* _intake;
frc::XboxController& _codriver;
LED* _led;

units::volt_t _rawVoltage;
units::volt_t _setVoltage;
Expand All @@ -31,4 +33,6 @@ class IntakeAutoControl : public behaviour::Behaviour {

private:
Intake* _intake;

LED* _led;
};
26 changes: 26 additions & 0 deletions src/main/include/LED.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2023-2024 CurtinFRC
// Open Source Software, you can modify it according to the terms
// of the MIT License at the root of this project

#pragma once

#include <frc/PWM.h>

#include "Wombat.h"

enum class LEDState { kIntaking, kHold, kAiming, kShooterReady, kAmpReady, kIdle };

class LED : public behaviour::HasBehaviour {
public:
LED();

void OnUpdate(units::second_t dt);

void SetState(LEDState state);
LEDState GetState();

private:
LEDState _state = LEDState::kIdle;

frc::PWM _led{0};
};
3 changes: 3 additions & 0 deletions src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "AlphaArmBehaviour.h"
#include "Intake.h"
#include "IntakeBehaviour.h"
#include "LED.h"
#include "RobotMap.h"
#include "Shooter.h"
#include "ShooterBehaviour.h"
Expand Down Expand Up @@ -58,6 +59,8 @@ class Robot : public frc::TimedRobot {
ctre::phoenix6::hardware::TalonFX* frontLeft;
// AlphaArm *alphaArm;

LED* _led;

// ctre::phoenix6::hardware::TalonFX *frontLeft;
// ctre::phoenix6::hardware::TalonFX *frontRight;
// ctre::phoenix6::hardware::TalonFX *backLeft;
Expand Down
5 changes: 4 additions & 1 deletion src/main/include/ShooterBehaviour.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@

#include <memory>

#include "LED.h"
#include "Shooter.h"
#include "Wombat.h"

class ShooterManualControl : public behaviour::Behaviour {
public:
ShooterManualControl(Shooter* shooter, frc::XboxController* codriver);
ShooterManualControl(Shooter* shooter, frc::XboxController* codriver, LED* led);

void OnTick(units::second_t dt) override;

private:
Shooter* _shooter;
frc::XboxController* _codriver;

LED* _led;

bool _rawControl = false;
std::shared_ptr<nt::NetworkTable> table =
nt::NetworkTableInstance::GetDefault().GetTable("Shooter Behaviour");
Expand Down

0 comments on commit a08258f

Please sign in to comment.