Skip to content

Commit 84af45e

Browse files
committed
added beam break
1 parent 99ed0fd commit 84af45e

File tree

4 files changed

+83
-82
lines changed

4 files changed

+83
-82
lines changed

src/main/cpp/Intake.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ IntakeConfig Intake::GetConfig() {
1313
void Intake::OnUpdate(units::second_t dt) {
1414
switch (_state) {
1515
case IntakeState::kIdle: {
16-
// _config.IntakeMotor.motorController->SetVoltage(0_V);
17-
// if (_config.intakeSensor->Get()) {
18-
// setState(IntakeState::kHold);
19-
// }
16+
_config.IntakeMotor.motorController->SetVoltage(0_V);
17+
if (_config.intakeSensor->Get()) {
18+
setState(IntakeState::kHold);
19+
}
2020
_stringStateName = "Idle";
2121
_setVoltage = 0_V;
2222
} break;
@@ -26,10 +26,10 @@ void Intake::OnUpdate(units::second_t dt) {
2626
_setVoltage = _rawVoltage;
2727
} break;
2828
case IntakeState::kEject: {
29-
// _config.IntakeMotor.motorController->SetVoltage(-5_V);
30-
// if (_config.intakeSensor->Get() == 0 && _config.magSensor->Get() == 0) {
31-
// setState(IntakeState::kIdle);
32-
// }
29+
_config.IntakeMotor.motorController->SetVoltage(-5_V);
30+
if (_config.intakeSensor->Get() == 0 && _config.magSensor->Get() == 0) {
31+
setState(IntakeState::kIdle);
32+
}
3333
_stringStateName = "Eject";
3434
_setVoltage = -5_V;
3535
} break;
@@ -57,7 +57,7 @@ void Intake::OnUpdate(units::second_t dt) {
5757
}
5858
_table->GetEntry("State: ").SetString(_stringStateName);
5959
_table->GetEntry("Motor Voltage: ").SetDouble(_setVoltage.value());
60-
// _table->GetEntry("Intake Sensor: ").SetBoolean(_config.intakeSensor->Get());
60+
_table->GetEntry("Intake Sensor: ").SetBoolean(_config.intakeSensor->Get());
6161
// _table->GetEntry("Shooter Sensor: ").SetBoolean(_config.shooterSensor->Get());
6262
// _table->GetEntry("Magazine Sensor: ").SetBoolean(_config.magSensor->Get());
6363

src/main/cpp/IntakeBehaviour.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,22 @@ void IntakeManualControl::OnTick(units::second_t dt) {
1919
_rawControl = true;
2020
}
2121
}
22-
23-
if (_rawControl) {
24-
_intake->setState(IntakeState::kRaw);
25-
if (_codriver.GetLeftBumper()) {
26-
_intake->setRaw(10_V);
27-
} else if (_codriver.GetRightBumper()) {
28-
_intake->setRaw(-10_V);
22+
if (_codriver.GetRightTriggerAxis() > 0.1) {
23+
_intake->setRaw(_codriver.GetRightTriggerAxis() * 10_V);
24+
} else if (_codriver.GetLeftTriggerAxis() > 0.1) {
25+
_intake->setRaw(_codriver.GetLeftTriggerAxis() * -10_V);
26+
} else if (_rawVoltage != 0_V) {
27+
if (_intake->GetConfig().intakeSensor->Get() == 1) {
28+
_intake->setRaw(0_V);
2929
} else {
3030
_intake->setRaw(0_V);
31-
}
32-
33-
// _intake->setRaw(_codriver.GetLeftBumper() * 10_V);
34-
// _intake->setRaw(_codriver.GetRightBumper() * -10_V);
35-
std::cout << "Raw" << std::endl;
31+
}
32+
} else {
33+
_intake->setRaw(0_V);
3634
}
35+
_intake->setState(IntakeState::kRaw);
36+
}
37+
3738
// } else {
3839
// if (_codriver.GetYButtonPressed()) {
3940
// _intake->setState(IntakeState::kIntake);
@@ -42,14 +43,14 @@ void IntakeManualControl::OnTick(units::second_t dt) {
4243
// _intake->setState(IntakeState::kPass);
4344
// }
4445
// }
45-
}
46+
4647

4748
// IntakeAutoControl::IntakeAutoControl(Intake* intake) : _intake(intake) {}
4849

49-
// void IntakeAutoControl::OnTick(units::second_t dt) {
50-
// if (_intake->GetConfig().intakeSensor->Get() == 1) {
51-
// _intake->setState(IntakeState::kPass);
52-
// } else if (_intake->GetConfig().magSensor->Get() == 0) {
53-
// _intake->setState(IntakeState::kIdle);
54-
// }
55-
// }
50+
void IntakeAutoControl::OnTick(units::second_t dt) {
51+
if (_intake->GetConfig().intakeSensor->Get() == 1) {
52+
_intake->setState(IntakeState::kPass);
53+
} /*else if (_intake->GetConfig().magSensor->Get() == 0) {
54+
_intake->setState(IntakeState::kIdle);
55+
}*/
56+
}

src/main/cpp/Shooter.cpp

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,60 +10,60 @@ Shooter::Shooter(ShooterConfig config) : _config(config)
1010
{} //config.path + "/pid", config.pidConfig
1111
void Shooter::OnUpdate(units::second_t dt) {
1212
// _pid.SetTolerance(0.1, 1);
13-
switch (_state) {
14-
case ShooterState::kIdle: {
15-
std::cout << "KIdle" << std::endl;
16-
_setVoltage = 0_V;
17-
// if (_shooterSensor.Get()) {
18-
// _state = ShooterState::kReverse;
19-
// }
20-
} break;
21-
case ShooterState::kSpinUp: {
22-
// std::cout << "KSpinUp" << std::endl;
23-
// _pid.SetSetpoint(_goal.value());
24-
// units::volt_t pidCalculate =
25-
// units::volt_t{_pid.Calculate(_config.ShooterGearbox.encoder->GetEncoderAngularVelocity().value())};
26-
// _setVoltage = pidCalculate;
13+
// switch (_state) {
14+
// case ShooterState::kIdle: {
15+
// std::cout << "KIdle" << std::endl;
16+
// _setVoltage = 0_V;
17+
// // if (_shooterSensor.Get()) {
18+
// // _state = ShooterState::kReverse;
19+
// // }
20+
// } break;
21+
// case ShooterState::kSpinUp: {
22+
// // std::cout << "KSpinUp" << std::endl;
23+
// // _pid.SetSetpoint(_goal.value());
24+
// // units::volt_t pidCalculate =
25+
// // units::volt_t{_pid.Calculate(_config.ShooterGearbox.encoder->GetEncoderAngularVelocity().value())};
26+
// // _setVoltage = pidCalculate;
2727

28-
// if (_pid.AtSetpoint()) {
29-
// SetState(ShooterState::kShooting);
30-
// }
31-
} break;
32-
case ShooterState::kShooting: {
33-
// std::cout << "KShooting" << std::endl;
34-
// _pid.SetSetpoint(_goal.value());
35-
// units::volt_t pidCalculate =
36-
// units::volt_t{_pid.Calculate(_config.ShooterGearbox.encoder->GetEncoderAngularVelocity().value())};
37-
// _setVoltage = pidCalculate;
28+
// // if (_pid.AtSetpoint()) {
29+
// // SetState(ShooterState::kShooting);
30+
// // }
31+
// } break;
32+
// case ShooterState::kShooting: {
33+
// // std::cout << "KShooting" << std::endl;
34+
// // _pid.SetSetpoint(_goal.value());
35+
// // units::volt_t pidCalculate =
36+
// // units::volt_t{_pid.Calculate(_config.ShooterGearbox.encoder->GetEncoderAngularVelocity().value())};
37+
// // _setVoltage = pidCalculate;
3838

39-
// if (!_pid.AtSetpoint()) {
40-
// SetState(ShooterState::kSpinUp);
41-
// }
42-
// if (_shooterSensor.Get()) {
43-
// SetState(ShooterState::kIdle);
44-
// }
45-
} break;
39+
// // if (!_pid.AtSetpoint()) {
40+
// // SetState(ShooterState::kSpinUp);
41+
// // }
42+
// // if (_shooterSensor.Get()) {
43+
// // SetState(ShooterState::kIdle);
44+
// // }
45+
// } break;
4646

47-
case ShooterState::kReverse: {
48-
_setVoltage = -5_V;
49-
std::cout << "KReverse" << std::endl;
50-
// if (!_shooterSensor.Get()) {
51-
// SetState(ShooterState::kIdle);
52-
// }
53-
} break;
54-
case ShooterState::kRaw: {
55-
_setVoltage = _rawVoltage;
56-
std::cout << "KRaw" << std::endl;
57-
// if (_shooterSensor.Get()) {
58-
// SetState(ShooterState::kRaw);
59-
// }
60-
} break;
61-
default: {
62-
std::cout << "Error shooter in invalid state" << std::endl;
63-
} break;
64-
}
65-
std::cout << "Voltage:" << _setVoltage.value() << std::endl;
66-
_config.ShooterGearbox.motorController->SetVoltage(_setVoltage);
47+
// case ShooterState::kReverse: {
48+
// _setVoltage = -5_V;
49+
// std::cout << "KReverse" << std::endl;
50+
// // if (!_shooterSensor.Get()) {
51+
// // SetState(ShooterState::kIdle);
52+
// // }
53+
// } break;
54+
// case ShooterState::kRaw: {
55+
// _setVoltage = _rawVoltage;
56+
// std::cout << "KRaw" << std::endl;
57+
// // if (_shooterSensor.Get()) {
58+
// // SetState(ShooterState::kRaw);
59+
// // }
60+
// } break;
61+
// default: {
62+
// std::cout << "Error shooter in invalid state" << std::endl;
63+
// } break;
64+
// }
65+
// std::cout << "Voltage:" << _setVoltage.value() << std::endl;
66+
// _config.ShooterGearbox.motorController->SetVoltage(_setVoltage);
6767

6868
}
6969

src/main/include/RobotMap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ struct RobotMap {
3131
struct IntakeSystem {
3232
rev::CANSparkMax intakeMotor{2, rev::CANSparkMax::MotorType::kBrushed};
3333
// wom::CANSparkMaxEncoder intakeEncoder{&intakeMotor, 0.1_m};
34-
// frc::DigitalInput intakeSensor{0};
34+
frc::DigitalInput intakeSensor{4};
3535
// frc::DigitalInput magSensor{0};
3636
// frc::DigitalInput shooterSensor{0};
3737

3838
wom::Gearbox IntakeGearbox{&intakeMotor, nullptr, frc::DCMotor::CIM(1)};
3939

40-
IntakeConfig config{IntakeGearbox /*, &intakeSensor, &magSensor, &shooterSensor*/};
40+
IntakeConfig config{IntakeGearbox , &intakeSensor/*, &magSensor, &shooterSensor*/};
4141
}; IntakeSystem intakeSystem;
4242

4343

0 commit comments

Comments
 (0)