Skip to content

Commit 10f7b45

Browse files
authored
Remove Climbing Limits when Enabled and Add the Real OwO Binding (#165)
* Add ability to remove limits on climbing in shuffleboard * Slow down amp arm speed * Make auto factory generic * bind the real OwO * linter
1 parent 7beb7f7 commit 10f7b45

File tree

15 files changed

+156
-87
lines changed

15 files changed

+156
-87
lines changed

src/main/cpp/Robot.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ void Robot::RobotInit() {
3838
* <p> This runs after the mode specific periodic functions, but before
3939
* LiveWindow and SmartDashboard integrated updating.
4040
*/
41-
void Robot::RobotPeriodic() { frc2::CommandScheduler::GetInstance().Run(); m_container.Periodic(); }
41+
void Robot::RobotPeriodic() {
42+
frc2::CommandScheduler::GetInstance().Run();
43+
m_container.Periodic();
44+
}
4245

4346
/**
4447
* This function is called once each time the robot enters Disabled mode. You

src/main/cpp/RobotContainer.cpp

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ void RobotContainer::RegisterAutos() {
9999
.AndThen(IntakingCommands::Intake(&m_intake, &m_scoring)));
100100

101101
m_autoChooser.Initialize();
102+
m_ignoreLimitChooser.SetDefaultOption("Don't Ignore", false);
103+
m_ignoreLimitChooser.AddOption("Ignore", true);
104+
frc::SmartDashboard::PutData("Climb Limits", &m_ignoreLimitChooser);
102105
}
103106

104107
void RobotContainer::ConfigureButtonBindings() {
@@ -268,22 +271,34 @@ void RobotContainer::ConfigureAutoBindings() {
268271
}).ToPtr());
269272

270273
// Maps to 4 on keyboard
271-
m_operatorController.Button(7).OnTrue(frc2::InstantCommand([this] {
272-
if (!m_state.m_active) {
273-
m_state.m_currentState =
274-
RobotState::AutoSequenceAmp;
275-
m_state.SetDesiredState();
276-
}
277-
}).ToPtr());
274+
m_operatorController.Button(7).OnTrue(
275+
m_leds.OwOFace()
276+
.AndThen(m_leds.Error())
277+
.AndThen(m_rightClimb.MoveToPositionAbsolute(10_in).AlongWith(
278+
m_leftClimb.MoveToPositionAbsolute(10_in)))
279+
.AndThen(m_arm.MoveToPositionAbsolute(ArmConstants::kAmpRotation))
280+
.AndThen(frc2::WaitCommand(8_s).ToPtr())
281+
.AndThen(m_rightClimb.MoveToPositionAbsolute(1_in).AlongWith(
282+
m_leftClimb.MoveToPositionAbsolute(1_in)))
283+
.AndThen(m_arm.MoveToPositionAbsolute(ArmConstants::kHomeRotation))
284+
.AndThen(m_leds.Idling()));
285+
286+
// .OnTrue(frc2::InstantCommand([this] {
287+
// if (!m_state.m_active) {
288+
// m_state.m_currentState =
289+
// RobotState::AutoSequenceAmp;
290+
// m_state.SetDesiredState();
291+
// }
292+
// }).ToPtr());
278293

279294
// Maps to 5 on keyboard
280295
m_operatorController.Button(8).OnTrue(
281296
frc2::InstantCommand([this] { m_drive.ZeroHeading(); }).ToPtr());
282297

283298
// Maps to 6 on keyboard
284299
m_operatorController.Button(9).OnTrue(
285-
m_rightClimb.MoveToPositionAbsolute(18_in).AlongWith(
286-
m_leftClimb.MoveToPositionAbsolute(18_in)));
300+
m_rightClimb.MoveToPositionAbsolute(20_in).AlongWith(
301+
m_leftClimb.MoveToPositionAbsolute(20_in)));
287302

288303
// Maps to 1 on keyboard
289304
m_operatorController.Button(10).OnTrue(frc2::InstantCommand([this] {
@@ -333,7 +348,7 @@ void RobotContainer::ConfigureAutoBindings() {
333348

334349
frc2::Command* RobotContainer::GetAutonomousCommand() {
335350
auto autoType = m_autoChooser.GetSelectedValue();
336-
autoCommand = AutoFactory::GetAuto(autoType);
351+
autoCommand = m_autoFactory.GetAuto(autoType);
337352

338353
return autoCommand.get();
339354
}
@@ -383,6 +398,8 @@ units::degree_t RobotContainer::CurveRotation(double sensitivity, double val,
383398
}
384399

385400
void RobotContainer::Periodic() {
401+
frc::SmartDashboard::PutBoolean("Disable Climb Limits", m_ignoreClimbLimits);
402+
386403
frc::SmartDashboard::PutData("Robot2d", &m_mech);
387404

388405
frc::SmartDashboard::PutBoolean("TURN TO POSE AT GOAL",
@@ -476,6 +493,8 @@ void RobotContainer::Periodic() {
476493
m_shouldAim = false;
477494
}
478495
}
496+
497+
m_ignoreClimbLimits = m_ignoreLimitChooser.GetSelected();
479498
}
480499

481500
std::optional<frc::Rotation2d> RobotContainer::GetRotationTargetOverride() {

src/main/cpp/subsystems/LedSubsystem.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ using namespace ConnectorX;
1010
using namespace LEDConstants;
1111

1212
void LedSubsystem::Periodic() {
13-
if (abs(m_accel.GetX()) >= kAccelThreshold ||
14-
abs(m_accel.GetY()) >= kAccelThreshold) {
15-
showFace(EyePattern::Surprised);
13+
// if (abs(m_accel.GetX()) >= kAccelThreshold ||
14+
// abs(m_accel.GetY()) >= kAccelThreshold) {
15+
// showFace(EyePattern::Surprised);
16+
// }
17+
if (m_accel.GetY() <= -kAccelThreshold) {
18+
showFace(EyePattern::OwO);
1619
}
1720
}
1821

@@ -368,6 +371,14 @@ frc2::CommandPtr LedSubsystem::AmogusFace() {
368371
.ToPtr();
369372
}
370373

374+
frc2::CommandPtr LedSubsystem::OwOFace() {
375+
return frc2::InstantCommand([this] {
376+
ConsoleWriter.logInfo("LedSubsystem", "Setting LEDs to %s", "OwO");
377+
showFace(EyePattern::OwO);
378+
})
379+
.ToPtr();
380+
}
381+
371382
frc2::CommandPtr LedSubsystem::setZoneColorPattern(LedZone zone, LedPort port,
372383
frc::Color8Bit color,
373384
PatternType pattern,

src/main/include/RobotContainer.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <pathplanner/lib/commands/PathPlannerAuto.h>
2020

2121
#include "Constants.h"
22+
#include "autos/AutoFactory.h"
2223
#include "subsystems/ArmSubsystem.h"
2324
#include "subsystems/DriveSubsystem.h"
2425
#include "subsystems/IntakeSubsystem.h"
@@ -73,22 +74,32 @@ class RobotContainer {
7374

7475
LedSubsystem m_leds;
7576

77+
bool m_ignoreClimbLimits = false;
78+
7679
// The chooser for the autonomous routines
7780
AutoChooser<AutoConstants::AutoType> m_autoChooser{
7881
AutoConstants::kChooserEntries, AutoConstants::kChooserGroups,
7982
"Auto Selector"};
8083

84+
AutoFactory<AutoConstants::AutoType> m_autoFactory{AutoConstants::kPpAutos};
85+
86+
frc::SendableChooser<bool> m_ignoreLimitChooser;
87+
8188
#ifdef TEST_SWERVE_BOT
8289

8390
#endif
8491

8592
#ifndef TEST_SWERVE_BOT
86-
LeftClimbSubsystem m_leftClimb{(frc::MechanismObject2d*)m_mech.GetRoot(
87-
"Climber Left", MechanismConstants::kClimberLeftX,
88-
MechanismConstants::kClimberLeftY)};
89-
RightClimbSubsystem m_rightClimb{(frc::MechanismObject2d*)m_mech.GetRoot(
90-
"Climber Right", MechanismConstants::kClimberRightX,
91-
MechanismConstants::kClimberRightY)};
93+
LeftClimbSubsystem m_leftClimb{
94+
[this] { return m_ignoreClimbLimits; },
95+
(frc::MechanismObject2d*)m_mech.GetRoot(
96+
"Climber Left", MechanismConstants::kClimberLeftX,
97+
MechanismConstants::kClimberLeftY)};
98+
RightClimbSubsystem m_rightClimb{
99+
[this] { return m_ignoreClimbLimits; },
100+
(frc::MechanismObject2d*)m_mech.GetRoot(
101+
"Climber Right", MechanismConstants::kClimberRightX,
102+
MechanismConstants::kClimberRightY)};
92103
frc::MechanismRoot2d* armRoot = m_mech.GetRoot(
93104
"Arm Root", MechanismConstants::kArmRootX, MechanismConstants::kArmRootY);
94105
frc::MechanismLigament2d* armPost = armRoot->Append<frc::MechanismLigament2d>(

src/main/include/autos/AutoFactory.h

Lines changed: 41 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,77 +9,65 @@
99

1010
#include <filesystem>
1111
#include <functional>
12+
#include <map>
1213
#include <memory>
1314
#include <string>
15+
#include <vector>
1416

1517
#include "Constants.h"
1618
#include "utils/ConsoleLogger.h"
1719

18-
namespace AutoFactory {
19-
frc2::CommandPtr GetEmptyCommand() { return frc2::WaitCommand(15_s).ToPtr(); }
20+
template <typename T>
21+
class AutoFactory {
22+
public:
23+
explicit AutoFactory(const std::map<T, std::string>& autos)
24+
: m_autos{autos} {}
2025

21-
bool AutoFileExists(std::string fileName) {
22-
const std::string filePath = frc::filesystem::GetDeployDirectory() +
23-
"/pathplanner/autos/" + fileName + ".auto";
26+
private:
27+
const std::map<T, std::string>& m_autos;
2428

25-
std::error_code error_code;
26-
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
27-
wpi::MemoryBuffer::GetFile(filePath, error_code);
28-
29-
if (fileBuffer == nullptr || error_code) {
30-
return false;
29+
inline frc2::CommandPtr GetEmptyCommand() {
30+
return frc2::WaitCommand(15_s).ToPtr();
3131
}
3232

33-
return true;
34-
}
33+
bool AutoFileExists(const std::string fileName) {
34+
const std::string filePath = frc::filesystem::GetDeployDirectory() +
35+
"/pathplanner/autos/" + fileName + ".auto";
3536

36-
frc2::CommandPtr PathPlannerPathFromName(std::string autoName) {
37-
if (!AutoFileExists(autoName)) {
38-
ConsoleWriter.logError("Auto Factory",
39-
"AUTO '%s' DOES NOT EXIST HELP US EVAN",
40-
autoName.c_str());
41-
return GetEmptyCommand();
42-
}
43-
return pathplanner::PathPlannerAuto(autoName).ToPtr();
44-
}
37+
std::error_code error_code;
38+
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
39+
wpi::MemoryBuffer::GetFile(filePath, error_code);
4540

46-
frc2::CommandPtr GetAuto(AutoConstants::AutoType type) {
47-
using namespace AutoConstants;
41+
if (fileBuffer == nullptr || error_code) {
42+
return false;
43+
}
44+
45+
return true;
46+
}
4847

49-
switch (type) {
50-
case AutoType::EmptyAuto:
48+
frc2::CommandPtr PathPlannerPathFromName(const std::string autoName) {
49+
if (!AutoFileExists(autoName)) {
50+
ConsoleWriter.logError("Auto Factory",
51+
"AUTO '%s' DOES NOT EXIST HELP US EVAN",
52+
autoName.c_str());
5153
return GetEmptyCommand();
52-
case AutoType::FourNoteAuto:
53-
return PathPlannerPathFromName("4 Note Auto");
54-
case AutoType::PlaceAndLeave:
55-
return PathPlannerPathFromName("Place and leave");
56-
case AutoType::ThreeNoteAuto:
57-
return PathPlannerPathFromName("3 Note Auto");
58-
case AutoType::TwoNoteAmpSide:
59-
return PathPlannerPathFromName("2 Note Amp Side");
60-
case AutoType::TwoNoteCenter:
61-
return PathPlannerPathFromName("2 Note Center Note 3");
62-
case AutoType::TwoNoteSource:
63-
return PathPlannerPathFromName("2 Note Source Side");
64-
case AutoType::ThreeNoteCenter:
65-
return PathPlannerPathFromName("3 Note Center Note 3 + 4");
66-
case AutoType::TwoNoteAuto:
67-
return PathPlannerPathFromName("2 Note Auto");
68-
case AutoType::TwoNoteInAmp:
69-
return PathPlannerPathFromName("2 In Amp");
70-
case AutoType::TwoInSpeakerTwoInAmp:
71-
return PathPlannerPathFromName("2 In Speaker 2 In Amp");
72-
case AutoType::ThreeNoteSimp:
73-
return PathPlannerPathFromName("3 Note Simp");
74-
case AutoType::LeaveWing:
75-
return PathPlannerPathFromName("Leave Wing");
76-
default:
54+
}
55+
return pathplanner::PathPlannerAuto(autoName).ToPtr();
56+
}
57+
58+
public:
59+
frc2::CommandPtr GetAuto(T type) {
60+
using namespace AutoConstants;
61+
62+
if (!m_autos.contains(type)) {
7763
ConsoleWriter.logWarning(
7864
"Auto Factory",
7965
"Auto type %d does not exist, defaulting to empty "
8066
"auto",
8167
static_cast<int>(type));
8268
return GetEmptyCommand();
69+
}
70+
71+
return PathPlannerPathFromName(m_autos.at(type));
8372
}
84-
}
85-
} // namespace AutoFactory
73+
};

src/main/include/constants/AutoConstants.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static const std::vector<AutoChooser<AutoType>::AutoChooserEntry>
5656
{{AutoType::ThreeNoteAuto, "3 Note Auto"},
5757
{"3 notes", "close", "decent", "center"}},
5858
{{AutoType::ThreeNoteSimp, "3 Note Simp Edition"},
59-
{"3 notes", "close", "decent", "center"}},
59+
{"3 notes", "close", "decent", "center"}},
6060
{{AutoType::TwoNoteCenter, "2 Note Center Note Under Stage"},
6161
{"2 notes", "far", "high", "center"}},
6262
{{AutoType::LeaveWing, "Leave Wing"},
@@ -83,6 +83,21 @@ static const std::vector<AutoChooser<AutoType>::AutoChooserSelectorGroup>
8383
{"Motion", {"amp", "center", "source", "complex"}},
8484
};
8585

86+
static const std::map<AutoType, std::string> kPpAutos = {
87+
{AutoType::FourNoteAuto, "4 Note Auto"},
88+
{AutoType::ThreeNoteAuto, "3 Note Auto"},
89+
{AutoType::ThreeNoteSimp, "3 Note Simp"},
90+
{AutoType::TwoNoteCenter, "2 Note Center Note 3"},
91+
{AutoType::LeaveWing, "Leave Wing"},
92+
{AutoType::PlaceAndLeave, "Place and leave"},
93+
{AutoType::TwoNoteAmpSide, "2 Note Amp Side"},
94+
{AutoType::TwoNoteSource, "2 Note Center Note 3"},
95+
{AutoType::ThreeNoteCenter, "3 Note Center Note 3 + 4"},
96+
{AutoType::TwoNoteAuto, "2 Note Auto"},
97+
{AutoType::TwoNoteInAmp, "2 In Amp"},
98+
{AutoType::TwoInSpeakerTwoInAmp, "2 In Speaker 2 In Amp"},
99+
};
100+
86101
extern const frc::TrapezoidProfile<units::radians>::Constraints
87102
kThetaControllerConstraints;
88103

@@ -99,9 +114,9 @@ const std::string kLedFunniName = "LedFunni";
99114

100115
const auto PathConfig = pathplanner::HolonomicPathFollowerConfig(
101116
pathplanner::PIDConstants(1.5, 0.0,
102-
0.0), // Translation PID constants
117+
0.0), // Translation PID constants
103118
pathplanner::PIDConstants(2, 0.0, 0.0), // Rotation PID constants
104-
3.0_mps, // Max module speed, in m/s
119+
3.0_mps, // Max module speed, in m/s
105120
#ifdef TEST_SWERVE_BOT
106121
0.4579874_m, // Drive base radius in meters. Distance from robot center to
107122
#endif

src/main/include/constants/LEDConstants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
namespace LEDConstants {
77
constexpr uint8_t kLedAddress = 23;
88
constexpr units::second_t kConnectorXDelay = 0.002_s;
9-
constexpr double kAccelThreshold = 7;
9+
constexpr double kAccelThreshold = 1;
1010
}

src/main/include/constants/ScoringConstants.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ constexpr double kSubwooferVectorSpeed = 1;
1919
constexpr double kFeedPodiumVectorSpeed = -1;
2020

2121
// These need to be different
22-
constexpr double kAmpLowerSpeed = -0.254 * 1.9; // .264
23-
constexpr double kAmpUpperSpeed = -0.168 * 1.4; // .278
22+
constexpr double kAmpLowerSpeed = -0.254 * 1.7; // .264
23+
constexpr double kAmpUpperSpeed = -0.168 * 1.3; // .278
2424

2525
// These should match
2626
constexpr double kSpeakerLowerSpeed = 1;

src/main/include/moduledrivers/ConnectorX.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ enum class PatternType {
244244
SetAll = 1,
245245
Blink = 2,
246246
RGBFade = 3,
247-
HackerMode = 4, // No worky
247+
HackerMode = 4, // No worky
248248
Breathe = 5,
249249
SineRoll = 6,
250250
Chase = 7,
@@ -253,6 +253,7 @@ enum class PatternType {
253253
BlinkingEyes = 10,
254254
SurprisedEyes = 11,
255255
Amogus = 12,
256+
OwOEyes = 14,
256257
};
257258

258259
enum class PinMode {

src/main/include/subsystems/ArmSubsystem.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class ArmSubsystem : public RotationalSingleAxisSubsystem<
3737
// Mechanism2d
3838
ArmConstants::kArmMechanism,
3939
// Conversion Function
40-
std::nullopt},
40+
std::nullopt,
41+
42+
[] { return false; }},
4143
ArmConstants::kArmLength,
4244
node} {
4345
m_SpinnyBoi.SetIdleMode(rev::CANSparkBase::IdleMode::kBrake);

0 commit comments

Comments
 (0)