Skip to content

Commit d20c4f0

Browse files
Merge branch 'master' into release
2 parents 50a6be6 + 6071f97 commit d20c4f0

File tree

12 files changed

+389
-102
lines changed

12 files changed

+389
-102
lines changed

src/main/cpp/Robot.cpp

Lines changed: 121 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,94 @@ void Robot::RobotInit()
3434
mSwerveDrive = new SwerveDrive(false);
3535

3636
mDriveTeleopCommand = new AltDriveTeleopCommand(driverController, mSwerveDrive);
37+
mClimbMidbarOnly = new ClimbMidBarOnly(mClimber, toml->get_table_qualified("command.climb.midbar"));
3738
mRunIntakeCommand = new RunIntakeCommand(mIntake);
3839
mShootCommand = new ShootCommand(mShooter);
3940

41+
mManualRetractInnerArms = new frc2::FunctionalCommand(
42+
[&]() {},
43+
[&]() {
44+
bool isInner1NearTarget = mClimber->isInner1NearTarget(0.0);
45+
bool isInner2NearTarget = mClimber->isInner2NearTarget(0.0);
46+
47+
if (isInner1NearTarget) {
48+
mClimber->stopInner1();
49+
} else {
50+
mClimber->runInner1(0.2);
51+
}
52+
53+
if (isInner2NearTarget) {
54+
mClimber->stopInner2();
55+
} else {
56+
mClimber->runInner2(0.2);
57+
}
58+
},
59+
[&](bool) {
60+
mClimber->stopInner1();
61+
mClimber->stopInner2();
62+
},
63+
[&]() { return mClimber->isInner1NearTarget(0.0) || mClimber->isInner2NearTarget(0.0); },
64+
{ mClimber }
65+
);
66+
67+
mManualExtendInnerArms = new frc2::FunctionalCommand(
68+
[&]() {},
69+
[&]() {
70+
bool isInner1NearTarget = mClimber->isInner1NearTarget(20.0);
71+
bool isInner2NearTarget = mClimber->isInner2NearTarget(20.0);
72+
73+
if (isInner1NearTarget) {
74+
mClimber->stopInner1();
75+
} else {
76+
mClimber->runInner1(-0.2);
77+
}
78+
79+
if (isInner2NearTarget) {
80+
mClimber->stopInner2();
81+
} else {
82+
mClimber->runInner2(-0.2);
83+
}
84+
},
85+
[&](bool) {
86+
mClimber->stopInner1();
87+
mClimber->stopInner2();
88+
},
89+
[&]() { return mClimber->isInner1NearTarget(20.0) || mClimber->isInner2NearTarget(20.0); },
90+
{ mClimber }
91+
);
92+
93+
// Shooter commands
94+
95+
mShootNear = new frc2::StartEndCommand(
96+
[&]() { mShooter->shootNear(); },
97+
[&]() { mShooter->stopShooter(); },
98+
{ mShooter }
99+
);
100+
101+
mShootFar = new frc2::StartEndCommand(
102+
[&]() { mShooter->shootFar(); },
103+
[&]() { mShooter->stopShooter(); },
104+
{ mShooter }
105+
);
106+
40107
m_chooser.SetDefaultOption(kAutoNameDefault, kAutoNameDefault);
41-
m_chooser.AddOption(kAutoShootAndDrive, kAutoShootAndDrive);
108+
m_chooser.AddOption(kAutoDriveAndShoot, kAutoDriveAndShoot);
42109
frc::SmartDashboard::PutData("Auto Modes", &m_chooser);
43110

44-
mShootAndDrive = new frc2::SequentialCommandGroup {
45-
ShootCommand {mShooter}.WithTimeout(1_s),
46-
frc2::FunctionalCommand { // drive backwards
47-
[](){},
48-
[&](){
49-
mSwerveDrive->setMotion(0, -0.5, 0);
50-
},
51-
[&](bool _interrupted){
52-
mSwerveDrive->setMotion(0, 0, 0); //stop swerve
53-
},
54-
[](){ return false; },
55-
{mSwerveDrive}
56-
}.WithTimeout(2_s)
111+
mDriveAndShoot = new frc2::SequentialCommandGroup {
112+
frc2::FunctionalCommand { // drive backwards
113+
[](){},
114+
[&](){
115+
// Turn slightly right to compensate for drift/drag.
116+
mSwerveDrive->setMotion(0, -0.5, -0.03);
117+
},
118+
[&](bool _interrupted){
119+
mSwerveDrive->setMotion(0, 0, 0); //stop swerve
120+
},
121+
[](){ return false; },
122+
{mSwerveDrive}
123+
}.WithTimeout(1.2_s),
124+
frc2::StartEndCommand(*mShootNear).WithTimeout(3_s)
57125
};
58126
}
59127

@@ -87,21 +155,18 @@ void Robot::AutonomousInit()
87155
// kAutoNameDefault);
88156
std::cout << "Auto selected: " << m_autoSelected << std::endl;
89157

90-
if (m_autoSelected == kAutoShootAndDrive) {
91-
mShootAndDrive->Schedule();
158+
if (m_autoSelected == kAutoDriveAndShoot) {
159+
mDriveAndShoot->Schedule();
92160
} else {
93161
// Default Auto goes here
94162
}
95163
}
96164

97165
void Robot::AutonomousPeriodic()
98166
{
99-
if (m_autoSelected == kAutoNameCustom)
100-
{
167+
if (m_autoSelected == kAutoNameCustom) {
101168
// Custom Auto goes here
102-
}
103-
else
104-
{
169+
} else {
105170
// Default Auto goes here
106171
}
107172
}
@@ -116,61 +181,61 @@ void Robot::TeleopPeriodic()
116181
drivetrain.tunePIDNetworktables();
117182
#endif
118183
//Shooter
119-
if (operatorController->GetXButtonPressed())
120-
{
121-
mShootCommand->Schedule();
184+
if (operatorController->GetXButtonPressed()) {
185+
mShootNear->Schedule();
186+
} else if(operatorController->GetXButtonReleased()) {
187+
mShootNear->Cancel();
122188
}
123-
else if(operatorController->GetXButtonReleased())
124-
{
125-
mShootCommand->Cancel();
189+
190+
if (operatorController->GetYButtonPressed()) {
191+
mShootFar->Schedule();
192+
} else if(operatorController->GetYButtonReleased()) {
193+
mShootFar->Cancel();
126194
}
127195

128196
//Intake
129-
if (operatorController->GetAButtonPressed())
130-
{
197+
if (operatorController->GetAButtonPressed()) {
131198
mRunIntakeCommand->Schedule();
132-
}
133-
else if(operatorController->GetAButtonReleased())
134-
{
199+
} else if(operatorController->GetAButtonReleased()) {
135200
mRunIntakeCommand->Cancel();
136201
}
137202

138203
//Climber
139-
if (operatorController->GetPOV(0)) // Check up button
140-
{
141-
142-
}
143-
else
144-
{
145-
204+
if (0 == operatorController->GetPOV()) { // Check up button
205+
mClimbMidbarOnly->mReachMidBar->Schedule();
146206
}
147207

148-
if (operatorController->GetPOV(90)) // Check right button
149-
{
150-
151-
}
152-
else
153-
{
154-
155-
}
208+
if (90 == operatorController->GetPOV()) { // Check right button
156209

157-
if (operatorController->GetPOV(180)) // Check down button
158-
{
210+
} else {
159211

160212
}
161-
else
162-
{
163213

214+
if (180 == operatorController->GetPOV()) { // Check down button
215+
mClimbMidbarOnly->mClimbMidBarAndLock->Schedule();
164216
}
165217

166-
if (operatorController->GetPOV(270)) // Check left button
167-
{
218+
if (270 == operatorController->GetPOV()) { // Check left button
168219

169-
}
170-
else
171-
{
220+
} else {
172221

173222
}
223+
224+
// FIXME: Hack to allow operator to manually (and slowly) move inner climb
225+
// arms if no other command is running.
226+
double opY = operatorController->GetLeftY();
227+
opY = fabs(opY) < 0.3 ? 0.0 : opY;
228+
if (opY < 0.0) {
229+
mManualRetractInnerArms->Schedule();
230+
} else if (opY > 0.0) {
231+
mManualExtendInnerArms->Schedule();
232+
} else {
233+
if (mManualRetractInnerArms->IsScheduled()) {
234+
mManualRetractInnerArms->Cancel();
235+
} else if (mManualExtendInnerArms->IsScheduled()) {
236+
mManualExtendInnerArms->Cancel();
237+
}
238+
}
174239
}
175240

176241
void Robot::DisabledInit() {}

0 commit comments

Comments
 (0)