Skip to content

Commit

Permalink
started pid (oliver kingsley add a remote from this)
Browse files Browse the repository at this point in the history
  • Loading branch information
prawny-boy committed Feb 4, 2024
2 parents 73e8eb6 + a9c619d commit d29bf9e
Show file tree
Hide file tree
Showing 47 changed files with 662 additions and 656 deletions.
5 changes: 0 additions & 5 deletions .editorconfig

This file was deleted.

1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* text=auto
*.sh text eol=lf
*.bat text eol=crlf
*.gradle text eol=lf
*.java text eol=lf
*.json text eol=lf
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/comment-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: React Rocket
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: |
const {owner, repo} = context.issue
Expand All @@ -34,7 +34,7 @@ jobs:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
NUMBER: ${{ github.event.issue.number }}
- name: Set up Python 3.8
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install wpiformat
Expand Down
1 change: 0 additions & 1 deletion .styleguide
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

cppHeaderFileInclude {
\.h$
\.hpp$
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ Cleaning removes caches of your compiled code. If you do not understand an error
Simulation
----------
**Release**
`./gradlew :nativeSimulation`
`./gradlew :simulateNative`
Runs a simulation of your code at highest optimisation.

**Debug**
`./gradlew :nativeSimulationDebug`
`./gradlew :simulateNativeDebug`
Runs a debug simulation of your code, including a variety of debugging tools similar to glass but at lower optimisation.

Documentation
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
2 changes: 0 additions & 2 deletions init.ps1

This file was deleted.

5 changes: 0 additions & 5 deletions init.sh

This file was deleted.

66 changes: 66 additions & 0 deletions src/main/cpp/AlphaArm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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 "AlphaArm.h"

AlphaArm::AlphaArm(AlphaArmConfig config) : _config(config) {}

AlphaArmConfig AlphaArm::GetConfig() {
return _config;
}

void AlphaArm::OnUpdate(units::second_t dt) {
switch (_state) {
case AlphaArmState::kIdle:

// _config.alphaArmGearbox.motorController->SetVoltage(0_V);
// _config.wristGearbox.motorController->SetVoltage(0_V);
_setAlphaArmVoltage = 0_V;
_setWristVoltage = 0_V;

break;
case AlphaArmState::kRaw:
_setAlphaArmVoltage = _rawArmVoltage;
_setWristVoltage = _rawWristVoltage;
_config.alphaArmGearbox.motorController->SetVoltage(_rawArmVoltage);
_config.wristGearbox.motorController->SetVoltage(_rawWristVoltage);

break;
case AlphaArmState::kForwardWrist:
_config.wristGearbox.motorController->SetVoltage(3_V);
_setWristVoltage = 3_V;

case AlphaArmState::kReverseWrist:
_config.wristGearbox.motorController->SetVoltage(-3_V);
_setWristVoltage = -3_V;
default:
std::cout << "oops, wrong state" << std::endl;
break;
}
// transmission translate
// _config.armGearBox.motorController->SetVoltage(setAlphaArmVoltage);
// _config.alphaArmGearbox.motorController->SetVoltage(setAlphaArmVoltage);
// _config.wristGearbox.motorController->SetVoltage(setWristVoltage);
_config.alphaArmGearbox.motorController->SetVoltage(_setAlphaArmVoltage);
_config.wristGearbox.motorController->SetVoltage(_setWristVoltage);

// _config.wristGearbox.motorController->SetVoltage(_setVoltage);
}

void AlphaArm::SetState(AlphaArmState state) {
_state = state;
}

// void AlphaArm::SetRaw(units::volt_t voltage){
// _rawArmVoltage = voltage;
// _rawWristVoltage = voltage;
// }

void AlphaArm::SetArmRaw(units::volt_t voltage) {
_rawArmVoltage = voltage;
}

void AlphaArm::setWristRaw(units::volt_t voltage) {
_rawWristVoltage = voltage;
}
35 changes: 35 additions & 0 deletions src/main/cpp/AlphaArmBehaviour.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 "AlphaArmBehaviour.h"

#include <frc/XboxController.h>

AlphaArmManualControl::AlphaArmManualControl(AlphaArm* alphaArm, frc::XboxController* codriver)
: _alphaArm(alphaArm), _codriver(codriver) {
Controls(alphaArm);
}

void AlphaArmManualControl::OnTick(units::second_t dt) {
if (_codriver->GetXButtonPressed()) {
if (_rawControl == true) {
_rawControl = false;
} else {
_rawControl = true;
}
}

if (_rawControl) {
_alphaArm->SetState(AlphaArmState::kRaw);
_alphaArm->SetArmRaw(_codriver->GetRightY() * 6_V);
_alphaArm->setWristRaw(_codriver->GetLeftY() * -6_V);
} else {
if (_codriver->GetRightBumperPressed()) {
_alphaArm->SetState(AlphaArmState::kForwardWrist);
}
if (_codriver->GetLeftBumperPressed()) {
_alphaArm->SetState(AlphaArmState::kReverseWrist);
}
}
}
4 changes: 3 additions & 1 deletion src/main/cpp/Intake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ void Intake::OnUpdate(units::second_t dt) {
_passing = false;
}
} break;

default:
std::cout << "Error: Intake in INVALID STATE." << std::endl;
break;
Expand All @@ -74,6 +73,9 @@ void Intake::OnUpdate(units::second_t dt) {
_table->GetEntry("Error").SetDouble(_pid.GetError().value());
_table->GetEntry("SetPoint").SetDouble(_pid.GetSetpoint().value());
// _table->GetEntry("Shooter Sensor: ").SetBoolean(_config.shooterSensor->Get());
// _table->GetEntry("Intake Sensor: ").SetBoolean(_config.intakeSensor->Get());
// _table->GetEntry("Shooter Sensor: ").SetBoolean(_config.shooterSensor->Get());
// _table->GetEntry("Magazine Sensor: ").SetBoolean(_config.magSensor->Get());

std::cout << _setVoltage.value() << std::endl;

Expand Down
5 changes: 3 additions & 2 deletions src/main/cpp/IntakeBehaviour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

#include <frc/XboxController.h>

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

Expand All @@ -24,7 +25,7 @@ void IntakeManualControl::OnTick(units::second_t dt) {
_intake->setState(IntakeState::kRaw);
}
}

if (_rawControl) {
if (_codriver.GetRightTriggerAxis() > 0.1) {
_intake->setRaw(_codriver.GetRightTriggerAxis() * 10_V);
Expand Down
66 changes: 33 additions & 33 deletions src/main/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,52 @@
#include <units/velocity.h>
#include <units/voltage.h>

#include <frc/kinematics/DifferentialDriveKinematics.h>
#include <frc/controller/RamseteController.h>
#include <frc/Timer.h>
#include "behaviour/HasBehaviour.h"

static units::second_t lastPeriodic;

void Robot::RobotInit() {

shooter = new Shooter(robotmap.shooterSystem.config);
wom::BehaviourScheduler::GetInstance()->Register(shooter);
shooter->SetDefaultBehaviour(
[this]() {return wom::make<ShooterManualControl>(shooter, &robotmap.controllers.codriver); });
[this]() { return wom::make<ShooterManualControl>(shooter, &robotmap.controllers.codriver); });

sched = wom::BehaviourScheduler::GetInstance();
m_chooser.SetDefaultOption("Default Auto", "Default Auto");

frc::SmartDashboard::PutData("Auto Selector", &m_chooser);
// frc::SmartDashboard::PutData("Auto Selector", &m_chooser);

m_path_chooser.SetDefaultOption("Path1", "paths/output/Path1.wpilib.json");
// m_path_chooser.SetDefaultOption("Path1", "paths/output/Path1.wpilib.json");

m_path_chooser.AddOption("Path1", "paths/output/Path1.wpilib.json");
m_path_chooser.AddOption("Path2", "paths/output/Path2.wpilib.json");
// m_path_chooser.AddOption("Path1", "paths/output/Path1.wpilib.json");
// m_path_chooser.AddOption("Path2", "paths/output/Path2.wpilib.json");

frc::SmartDashboard::PutData("Path Selector", &m_path_chooser);
// frc::SmartDashboard::PutData("Path Selector", &m_path_chooser);

frc::SmartDashboard::PutData("Field", &m_field);
// frc::SmartDashboard::PutData("Field", &m_field);

simulation_timer = frc::Timer();
// simulation_timer = frc::Timer();

robotmap.swerveBase.gyro->Reset();
// robotmap.swerveBase.gyro->Reset();

_swerveDrive =
new wom::SwerveDrive(robotmap.swerveBase.config, frc::Pose2d());
_swerveDrive = new wom::SwerveDrive(robotmap.swerveBase.config, frc::Pose2d());
wom::BehaviourScheduler::GetInstance()->Register(_swerveDrive);
_swerveDrive->SetDefaultBehaviour([this]() {
return wom::make<wom::ManualDrivebase>(_swerveDrive,
&robotmap.controllers.driver);
});
_swerveDrive->SetDefaultBehaviour(
[this]() { return wom::make<wom::ManualDrivebase>(_swerveDrive, &robotmap.controllers.driver); });


// m_driveSim = new wom::TempSimSwerveDrive(&simulation_timer, &m_field);
// m_driveSim = wom::TempSimSwerveDrive();

alphaArm = new AlphaArm(robotmap.alphaArmSystem.config);
wom::BehaviourScheduler::GetInstance()->Register(alphaArm);
alphaArm->SetDefaultBehaviour(
[this]() { return wom::make<AlphaArmManualControl>(alphaArm, &robotmap.controllers.codriver); });

robotmap.swerveBase.moduleConfigs[0].turnMotor.encoder->SetEncoderOffset(0_rad);
robotmap.swerveBase.moduleConfigs[1].turnMotor.encoder->SetEncoderOffset(0_rad);
robotmap.swerveBase.moduleConfigs[2].turnMotor.encoder->SetEncoderOffset(0_rad);
robotmap.swerveBase.moduleConfigs[3].turnMotor.encoder->SetEncoderOffset(0_rad);




// frontLeft = new ctre::phoenix6::hardware::TalonFX(7, "Drivebase"); // front left
// frontRight = new ctre::phoenix6::hardware::TalonFX(2, "Drivebase"); // front right
// backLeft = new ctre::phoenix6::hardware::TalonFX(6, "Drivebase"); // back left
Expand All @@ -95,24 +89,30 @@ void Robot::RobotPeriodic() {
shooter->OnUpdate(dt);
sched->Tick();

robotmap.swerveTable.swerveDriveTable->GetEntry("frontLeftEncoder").SetDouble(robotmap.swerveBase.moduleConfigs[0].turnMotor.encoder->GetEncoderPosition().value());
robotmap.swerveTable.swerveDriveTable->GetEntry("frontRightEncoder").SetDouble(robotmap.swerveBase.moduleConfigs[1].turnMotor.encoder->GetEncoderPosition().value());
robotmap.swerveTable.swerveDriveTable->GetEntry("backLeftEncoder").SetDouble(robotmap.swerveBase.moduleConfigs[2].turnMotor.encoder->GetEncoderPosition().value());
robotmap.swerveTable.swerveDriveTable->GetEntry("backRightEncoder").SetDouble(robotmap.swerveBase.moduleConfigs[3].turnMotor.encoder->GetEncoderPosition().value());

robotmap.swerveTable.swerveDriveTable->GetEntry("frontLeftEncoder")
.SetDouble(robotmap.swerveBase.moduleConfigs[0].turnMotor.encoder->GetEncoderPosition().value());
robotmap.swerveTable.swerveDriveTable->GetEntry("frontRightEncoder")
.SetDouble(robotmap.swerveBase.moduleConfigs[1].turnMotor.encoder->GetEncoderPosition().value());
robotmap.swerveTable.swerveDriveTable->GetEntry("backLeftEncoder")
.SetDouble(robotmap.swerveBase.moduleConfigs[2].turnMotor.encoder->GetEncoderPosition().value());
robotmap.swerveTable.swerveDriveTable->GetEntry("backRightEncoder")
.SetDouble(robotmap.swerveBase.moduleConfigs[3].turnMotor.encoder->GetEncoderPosition().value());

_swerveDrive->OnUpdate(dt);
alphaArm->OnUpdate(dt);
shooter->OnStart();
intake->OnUpdate(dt);
}

void Robot::AutonomousInit() {
loop.Clear();
sched->InterruptAll();
}
void Robot::AutonomousPeriodic() {
}
void Robot::AutonomousPeriodic() {}

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

// frontLeft->SetVoltage(4_V);
Expand All @@ -130,4 +130,4 @@ void Robot::DisabledInit() {}
void Robot::DisabledPeriodic() {}

void Robot::TestInit() {}
void Robot::TestPeriodic() {}
void Robot::TestPeriodic() {}
Loading

0 comments on commit d29bf9e

Please sign in to comment.