Skip to content

Commit

Permalink
Fixed more build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
prawny-boy committed Jan 21, 2024
2 parents d91b5e0 + ac6ce9b commit bdcb9fd
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 108 deletions.
41 changes: 16 additions & 25 deletions src/main/cpp/Mag.cpp
Original file line number Diff line number Diff line change
@@ -1,60 +1,56 @@
// 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 "Mag.h"

Mag::Mag(MagConfig config) : _config(config) {}

void Mag::OnUpdate(units::second_t dt) {
switch (_state) {
case MagState::kIdle:
{
case MagState::kIdle: {
if (_config.intakeSensor->Get()) {
SetState(MagState::kHold);
} else if (_config.intakeSensor->Get()){
} else if (_config.intakeSensor->Get()) {
SetState(MagState::kHold);
}
_setVoltage = 0_V;
_stringStateName = "Idle";
}
break;
} break;

case MagState::kHold:
{
case MagState::kHold: {
if (_config.magSensor->Get() == 0) {
SetState(MagState::kIdle);
}
_setVoltage = 0_V;
_stringStateName = "Hold";
}
break;
} break;

case MagState::kEject:
{
if (_config.magSensor->Get() == 0 && _config.intakeSensor->Get() == 0) {
case MagState::kEject: {
if (_config.magSensor->Get() == 0 && _config.intakeSensor->Get() == 0) {
SetState(MagState::kIdle);
}
_setVoltage = -5_V;
_stringStateName = "Eject";
}
break;
} break;

case MagState::kRaw:
_setVoltage = _rawVoltage;
_stringStateName = "Raw";
break;
break;

case MagState::kPass:
{
case MagState::kPass: {
if (_config.shooterSensor->Get()) {
SetState(MagState::kIdle);
} else {
_setVoltage = 5_V;
_stringStateName = "Pass";
}
}
break;
} break;

default:
std::cout << "Error magazine in invalid state" << std::endl;
break;
break;
}
_config.magGearbox.motorController->SetVoltage(_setVoltage);
_table->GetEntry("State: ").SetString(_stringStateName);
Expand All @@ -64,7 +60,6 @@ void Mag::OnUpdate(units::second_t dt) {
_table->GetEntry("Magazine Sensor: ").SetDouble(_config.magSensor->Get());
}


void Mag::SetState(MagState state) {
_state = state;
}
Expand All @@ -75,7 +70,3 @@ void Mag::SetRaw(units::volt_t voltage) {
MagState Mag::GetState() {
return _state;
}




9 changes: 4 additions & 5 deletions src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ void Robot::RobotInit() {

mag = new Mag(robotmap.magSystem.config);
wom::BehaviourScheduler::GetInstance()->Register(mag);
mag->SetDefaultBehaviour([this]() {
return wom::make<MagManualControl>(mag, &robotmap.controllers.coDriver);
});
mag->SetDefaultBehaviour(
[this]() { return wom::make<MagManualControl>(mag, &robotmap.controllers.coDriver); });
}

void Robot::RobotPeriodic() {
auto dt = wom::now() - lastPeriodic;
lastPeriodic = wom::now();

loop.Poll();
wom::BehaviourScheduler::GetInstance()->Tick();

Expand All @@ -41,7 +40,7 @@ void Robot::RobotPeriodic() {

void Robot::TeleopInit() {
loop.Clear();
wom::BehaviourScheduler *scheduler = wom::BehaviourScheduler::GetInstance();
wom::BehaviourScheduler* scheduler = wom::BehaviourScheduler::GetInstance();
scheduler->InterruptAll();

m_chooser.SetDefaultOption("Default Auto", "Default Auto");
Expand Down
34 changes: 18 additions & 16 deletions src/main/cpp/behaviours/MagBehaviour.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
// 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 "behaviours/MagBehaviour.h"

MagManualControl::MagManualControl(Mag *mag, frc::XboxController *codriver) : _mag(mag), _codriver(codriver) {
MagManualControl::MagManualControl(Mag* mag, frc::XboxController* codriver) : _mag(mag), _codriver(codriver) {
Controls(mag);
}

void MagManualControl::OnTick(units::second_t dt) {

if (_codriver->GetAButtonPressed()) {
if (_rawControl == true) {
_rawControl = false;
} else {
_rawControl = true;
}
}

if (_rawControl) {
// Manual control, right bumper for manual override.
if (_codriver->GetLeftBumper()) {
Expand All @@ -26,24 +29,23 @@ void MagManualControl::OnTick(units::second_t dt) {
} else {
_mag->SetRaw(0_V);
}

} else {
_mag->SetState(MagState::kIdle);
if (_codriver->GetLeftBumper()) {
_mag->SetState(MagState::kPass);

}
}
}

MagAutoPass::MagAutoPass(Mag *mag) {}

void MagAutoPass::OnTick(units::second_t dt) {
_mag->SetState(MagState::kPass);
}

MagAutoHold::MagAutoHold(Mag *mag) {}

void MagAutoHold::OnTick(units::second_t dt) {
_mag->SetState(MagState::kHold);
}
MagAutoPass::MagAutoPass(Mag* mag) {}

void MagAutoPass::OnTick(units::second_t dt) {
_mag->SetState(MagState::kPass);
}

MagAutoHold::MagAutoHold(Mag* mag) {}

void MagAutoHold::OnTick(units::second_t dt) {
_mag->SetState(MagState::kHold);
}
48 changes: 24 additions & 24 deletions src/main/include/Mag.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// 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 "Wombat.h"
#include <frc/DigitalInput.h>
#include <string>

#include <memory>
#include <string>

#include "Wombat.h"

struct MagConfig {
wom::Gearbox magGearbox;
Expand All @@ -12,27 +17,22 @@ struct MagConfig {
frc::DigitalInput* shooterSensor;
};

enum class MagState {
kIdle,
kHold,
kEject,
kRaw,
kPass
};
enum class MagState { kIdle, kHold, kEject, kRaw, kPass };

class Mag : public behaviour::HasBehaviour {
public:
explicit Mag(MagConfig config);

void OnUpdate(units::second_t dt);
void SetState(MagState state);
void SetRaw(units::volt_t voltage);
MagState GetState();
private:
MagConfig _config;
MagState _state;
units::volt_t _rawVoltage = 0_V;
std::string _stringStateName = "No State";
units::volt_t _setVoltage = 0_V;
std::shared_ptr<nt::NetworkTable> _table = nt::NetworkTableInstance::GetDefault().GetTable("Magazine");
};
public:
explicit Mag(MagConfig config);

void OnUpdate(units::second_t dt);
void SetState(MagState state);
void SetRaw(units::volt_t voltage);
MagState GetState();

private:
MagConfig _config;
MagState _state;
units::volt_t _rawVoltage = 0_V;
std::string _stringStateName = "No State";
units::volt_t _setVoltage = 0_V;
std::shared_ptr<nt::NetworkTable> _table = nt::NetworkTableInstance::GetDefault().GetTable("Magazine");
};
8 changes: 4 additions & 4 deletions src/main/include/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

#pragma once

#include "behaviours/MagBehaviour.h"
#include <frc/TimedRobot.h>
#include <frc/Encoder.h>
#include <frc/TimedRobot.h>
#include <frc/Timer.h>
#include <frc/event/EventLoop.h>
#include <frc/simulation/DifferentialDrivetrainSim.h>
Expand All @@ -19,6 +18,7 @@

#include "RobotMap.h"
#include "Wombat.h"
#include "behaviours/MagBehaviour.h"

class Robot : public frc::TimedRobot {
public:
Expand All @@ -37,7 +37,7 @@ class Robot : public frc::TimedRobot {

private:
behaviour::BehaviourScheduler* sched;

RobotMap robotmap;

frc::EventLoop loop;
Expand All @@ -47,5 +47,5 @@ class Robot : public frc::TimedRobot {
frc::SendableChooser<std::string> m_path_chooser;

wom::SwerveDrive* _swerveDrive;
Mag *mag;
Mag* mag;
};
38 changes: 16 additions & 22 deletions src/main/include/RobotMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@

#pragma once

#include "mag.h"
#include "Wombat.h"

#include <frc/XboxController.h>
#include <frc/DigitalInput.h>

#include <frc/Compressor.h>
#include <frc/DigitalInput.h>
#include <frc/DoubleSolenoid.h>
#include <frc/XboxController.h>
#include <frc/system/plant/DCMotor.h>
#include <units/angle.h>
#include <units/length.h>
Expand All @@ -22,14 +18,17 @@
#include <ctre/phoenix6/Pigeon2.hpp>
#include <ctre/phoenix6/TalonFX.hpp>

#include "Wombat.h"
#include "mag.h"

struct RobotMap {
struct Controllers {
frc::XboxController driver = frc::XboxController(0);
frc::XboxController coDriver = frc::XboxController(1);
frc::XboxController testController = frc::XboxController(2);
};
Controllers controllers;

struct SwerveBase {
ctre::phoenix6::hardware::CANcoder frontLeftCancoder{19};
ctre::phoenix6::hardware::CANcoder frontRightCancoder{17};
Expand Down Expand Up @@ -134,26 +133,21 @@ struct RobotMap {
SwerveBase swerveBase;

struct Mag {
rev::CANSparkMax *magMotor = new rev::CANSparkMax{99, rev::CANSparkMax::MotorType::kBrushless};
//wom::VoltageController magMotorGroup = wom::VoltageController::Group(magMotor);
rev::CANSparkMax* magMotor = new rev::CANSparkMax{99, rev::CANSparkMax::MotorType::kBrushless};
// wom::VoltageController magMotorGroup = wom::VoltageController::Group(magMotor);
wom::CANSparkMaxEncoder magEncoder{magMotor, 0.1_m};
frc::DigitalInput intakeSensor{0};
frc::DigitalInput magSensor{1};
frc::DigitalInput shooterSensor{1};

wom::Gearbox magGearbox {
magMotor,
&magEncoder,
frc::DCMotor::NEO(1)
};
wom::Gearbox magGearbox{magMotor, &magEncoder, frc::DCMotor::NEO(1)};

MagConfig config {
magGearbox,
&intakeSensor,
&magSensor,
&shooterSensor,
};
};
MagConfig config{
magGearbox,
&intakeSensor,
&magSensor,
&shooterSensor,
};
};
Mag magSystem;

};
Loading

0 comments on commit bdcb9fd

Please sign in to comment.