Skip to content

Commit 6c4a67e

Browse files
committed
Started auto, merged subsystems to auto
2 parents 985b881 + cd963d4 commit 6c4a67e

File tree

9 files changed

+176
-16
lines changed

9 files changed

+176
-16
lines changed

src/main/cpp/AlphaArm.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2023-2024 CurtinFRC
2+
// Open Source Software, you can modify it according to the terms
3+
// of the MIT License at the root of this project
4+
5+
#include "AlphaArm.h"
6+
7+
AlphaArm::AlphaArm(AlphaArmConfig config) : _config(config) {}
8+
9+
void AlphaArm::OnUpdate(units::second_t dt) {
10+
switch (_state) {
11+
case AlphaArmState::kIdle:
12+
// transmission translate
13+
_config.alphaArmGearbox.motorController->SetVoltage(0_V);
14+
_config.wristGearbox.motorController->SetVoltage(0_V);
15+
16+
break;
17+
case AlphaArmState::kRaw:
18+
setAlphaArmVoltage = _armVoltage;
19+
break;
20+
default:
21+
std::cout << "oops, wrong state" << std::endl;
22+
break;
23+
}
24+
// transmission translate
25+
// _config.armGearBox.motorController->SetVoltage(setAlphaArmVoltage);
26+
_config.alphaArmGearbox.motorController->SetVoltage(setAlphaArmVoltage);
27+
_config.wristGearbox.motorController->SetVoltage(setWristVoltage);
28+
}
29+
30+
void AlphaArm::SetState(AlphaArmState state) {
31+
_state = state;
32+
}
33+
34+
void AlphaArm::SetRaw(units::volt_t voltR) {
35+
_voltR = voltR;
36+
}

src/main/cpp/Auto.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// #include "Auto.h"
1+
#include "Auto.h"
22

33
// std::shared_ptr<Behaviour> Taxi(DriveBase _driveBase, Shooter _shooter, Mag _mag, Intake _intake, Arm _arm) {
44
// return
@@ -248,4 +248,12 @@
248248
// 15. Shoot note
249249
// 16. Climb down
250250
// */
251-
// }
251+
// }
252+
253+
std::shared_ptr<Behaviour> AutoTest(DriveBase _driveBase, Shooter _shooter, Mag _mag, Intake _intake, Arm _arm) {
254+
return
255+
<<make<ArmToSetPoint>(_arm, 0, -90)
256+
<<make<DriveToLocation>(_driveBase, raw, distance)
257+
<<make<AutoShoot>(_shooter, 8_V)
258+
<<make<AutoIntake>(_intake, 8_V)
259+
} // This auto is a test for auto to see if all things work, it does not build as the behaviours are not done.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2023-2024 CurtinFRC
2+
// Open Source Software, you can modify it according to the terms
3+
// of the MIT License at the root of this project
4+
5+
#include "Behaviours/AlphaArmBehaviour.h"
6+
7+
#include <frc/XboxController.h>
8+
9+
AlphaArmManualControl::AlphaArmManualControl(AlphaArm* alphaArm, frc::XboxController* codriver)
10+
: _alphaArm(alphaArm), _codriver(codriver) {
11+
Controls(alphaArm);
12+
}
13+
14+
void AlphaArmManualControl::OnTick(units::second_t dt) {
15+
if (_codriver->GetXButtonPressed()) {
16+
if (_rawControl == true) {
17+
_rawControl = false;
18+
} else {
19+
_rawControl = true;
20+
}
21+
}
22+
23+
if (_rawControl) {
24+
_alphaArm->SetState(AlphaArmState::kRaw);
25+
// mess around with _rightStick later
26+
_alphaArm->SetRaw(_codriver->GetRightY() * 2_V);
27+
}
28+
}

src/main/cpp/Robot.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void Robot::RobotPeriodic() {
3535
mag->OnUpdate(dt);
3636
climber->OnUpdate(dt);
3737
intake->OnUpdate(dt);
38+
alphaArm->OnUpdate(dt);
3839
}
3940

4041
void Robot::TeleopInit() {
@@ -69,17 +70,22 @@ void Robot::TeleopInit() {
6970
climber = new Climber(robotmap.climberSystem.config);
7071
wom::BehaviourScheduler::GetInstance()->Register(climber);
7172
climber->SetDefaultBehaviour(
72-
[this]() { return wom::make<ClimberManualControl>(climber, &robotmap.controllers.coDriver); });
73+
[this]() { return wom::make<ClimberManualControl>(climber, &robotmap.controllers.codriver); });
7374

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

7980
intake = new Intake(robotmap.intakeSystem.config);
8081
wom::BehaviourScheduler::GetInstance()->Register(intake);
8182
intake->SetDefaultBehaviour(
82-
[this]() { return wom::make<IntakeManualControl>(intake, &robotmap.controllers.coDriver); });
83+
[this]() { return wom::make<IntakeManualControl>(intake, &robotmap.controllers.codriver); });
84+
85+
alphaArm = new AlphaArm(robotmap.alphaArmSystem.config);
86+
wom::BehaviourScheduler::GetInstance()->Register(alphaArm);
87+
alphaArm->SetDefaultBehaviour(
88+
[this]() { return wom::make<AlphaArmManualControl>(alphaArm, &robotmap.controllers.codriver); });
8389

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

src/main/include/AlphaArm.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2023-2024 CurtinFRC
2+
// Open Source Software, you can modify it according to the terms
3+
// of the MIT License at the root of this project
4+
5+
#pragma once
6+
#include <frc/DigitalInput.h>
7+
8+
#include "Wombat.h"
9+
10+
struct AlphaArmConfig {
11+
// wom::Gearbox armGearBox;
12+
wom::Gearbox alphaArmGearbox;
13+
wom::Gearbox wristGearbox;
14+
};
15+
16+
enum class AlphaArmState { kIdle, kIntakeAngle, kAmpAngle, kSpeakerAngle, kRaw };
17+
18+
class AlphaArm : public ::behaviour::HasBehaviour {
19+
public:
20+
explicit AlphaArm(AlphaArmConfig config);
21+
22+
void OnUpdate(units::second_t dt);
23+
void SetRaw(units::volt_t volt);
24+
void SetState(AlphaArmState state);
25+
26+
private:
27+
AlphaArmConfig _config;
28+
AlphaArmState _state = AlphaArmState::kIdle;
29+
units::volt_t setAlphaArmVoltage = 0_V;
30+
units::volt_t setWristVoltage = 0_V;
31+
units::volt_t _armVoltage;
32+
units::volt_t _voltR;
33+
};

src/main/include/Auto.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
// #pragma once
1+
#pragma once
22

3-
// #include "Wombat.h"
3+
#include "Wombat.h"
44

5-
// namespace autos {
6-
// std::shared_ptr<behaviour::Behaviour> Taxi(Drivebase driveBase, Shooter shooter, Mag mag, Intake intake, Arm _arm);
5+
namespace autos {
6+
std::shared_ptr<behaviour::Behaviour> AutoTest(Drivebase driveBase, Shooter shooter, Mag mag, Intake intake, Arm _arm);
77

8-
// std::shared_ptr<behaviour::Behaviour> QuadrupleClose(Drivebase driveBase, Shooter shooter, Mag mag, Intake intake, Arm _arm);
8+
// std::shared_ptr<behaviour::Behaviour> Taxi(Drivebase driveBase, Shooter shooter, Mag mag, Intake intake, Arm _arm);
99

10-
// std::shared_ptr<behaviour::Behaviour> QuadrupleFar(Drivebase driveBase, Shooter shooter, Mag mag, Intake intake, Arm _arm);
10+
// std::shared_ptr<behaviour::Behaviour> QuadrupleClose(Drivebase driveBase, Shooter shooter, Mag mag, Intake intake, Arm _arm);
1111

12-
// std::shared_ptr<behaviour::Behaviour> QuadrupleCloseDoubleFar(Drivebase driveBase, Shooter shooter, Mag mag, Intake intake, Arm _arm);
12+
// std::shared_ptr<behaviour::Behaviour> QuadrupleFar(Drivebase driveBase, Shooter shooter, Mag mag, Intake intake, Arm _arm);
1313

14-
// std::shared_ptr<behaviour::Behaviour> QuadrupleCloseSingleFar(Drivebase driveBase, Shooter shooter, Mag mag, Intake intake, Arm _arm);
15-
// }
14+
// std::shared_ptr<behaviour::Behaviour> QuadrupleCloseDoubleFar(Drivebase driveBase, Shooter shooter, Mag mag, Intake intake, Arm _arm);
15+
16+
// std::shared_ptr<behaviour::Behaviour> QuadrupleCloseSingleFar(Drivebase driveBase, Shooter shooter, Mag mag, Intake intake, Arm _arm);
17+
}
1618

1719

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2023-2024 CurtinFRC
2+
// Open Source Software, you can modify it according to the terms
3+
// of the MIT License at the root of this project
4+
5+
#pragma once
6+
7+
#pragma once
8+
#include <frc/XboxController.h>
9+
10+
#include "AlphaArm.h"
11+
#include "Wombat.h"
12+
13+
class AlphaArmManualControl : public behaviour::Behaviour {
14+
public:
15+
explicit AlphaArmManualControl(AlphaArm* alphaArm, frc::XboxController* codriver);
16+
void OnTick(units::second_t dt);
17+
18+
private:
19+
AlphaArm* _alphaArm;
20+
frc::XboxController* _codriver;
21+
// units::volt_t _rightStick = ((_codriver->GetRightY()>0.05 || _codriver->GetRightY() < -0.05
22+
// )?_codriver->GetRightY():0) * 2_V;
23+
bool _rawControl;
24+
};

src/main/include/Robot.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919

2020
#include <string>
2121

22+
#include "AlphaArm.h"
23+
#include "Climber.h"
24+
#include "Intake.h"
25+
#include "Mag.h"
26+
#include "Behaviours/AlphaArmBehaviour.h"
2227
#include "Behaviours/ClimberBehaviour.h"
2328
#include "Behaviours/IntakeBehaviour.h"
2429
#include "Behaviours/MagBehaviour.h"
@@ -52,6 +57,8 @@ class Robot : public frc::TimedRobot {
5257
frc::SendableChooser<std::string> m_path_chooser;
5358

5459
wom::SwerveDrive* _swerveDrive;
60+
61+
AlphaArm* alphaArm;
5562
Mag* mag;
5663
Climber* climber;
5764
Intake* intake;

src/main/include/RobotMap.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,33 @@
2121

2222
#include "Climber.h"
2323
#include "Mag.h"
24-
#include "Wombat.h"
24+
#include "AlphaArm.h"
2525
#include "Intake.h"
26+
#include "Behaviours/AlphaArmBehaviour.h"
27+
#include "Behaviours/ClimberBehaviour.h"
28+
#include "Behaviours/MagBehaviour.h"
29+
#include "Behaviours/IntakeBehaviour.h"
30+
#include "Wombat.h"
2631

2732
struct RobotMap {
2833
struct Controllers {
2934
frc::XboxController driver = frc::XboxController(0);
30-
frc::XboxController coDriver = frc::XboxController(1);
35+
frc::XboxController codriver = frc::XboxController(1);
3136
frc::XboxController testController = frc::XboxController(2);
3237
};
3338
Controllers controllers;
3439

40+
struct AlphaArmSystem {
41+
rev::CANSparkMax alphaArmMotor{99, rev::CANSparkMax::MotorType::kBrushless};
42+
rev::CANSparkMax wristMotor{99, rev::CANSparkMax::MotorType::kBrushless};
43+
44+
wom::Gearbox alphaArmGearbox{&alphaArmMotor, nullptr, frc::DCMotor::NEO(1)};
45+
wom::Gearbox wristGearbox{&wristMotor, nullptr, frc::DCMotor::NEO(1)};
46+
47+
AlphaArmConfig config{alphaArmGearbox, wristGearbox};
48+
};
49+
AlphaArmSystem alphaArmSystem;
50+
3551
struct SwerveBase {
3652
ctre::phoenix6::hardware::CANcoder frontLeftCancoder{19};
3753
ctre::phoenix6::hardware::CANcoder frontRightCancoder{17};

0 commit comments

Comments
 (0)