Skip to content

Commit ff47b3d

Browse files
Changes from practice field on Friday, 21 Feb 2020. Tuned azimuth control (thresholds, FOV sizing, PID tuning, motion magic, camera lag), tweaked "drive straight" PID loop, initial autonomous shooting and "trench run" programs. Added various "TODO" comments in code; still lots of others!
1 parent 2be49c9 commit ff47b3d

14 files changed

+198
-41
lines changed

src/main/java/frc/robot/Robot.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
package frc.robot;
99

10+
import java.util.Date;
11+
1012
import org.mayheminc.robot2020.RobotContainer;
1113

1214
import edu.wpi.first.wpilibj.TimedRobot;
15+
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
1316
import edu.wpi.first.wpilibj2.command.Command;
1417
import edu.wpi.first.wpilibj2.command.CommandScheduler;
1518

@@ -35,6 +38,9 @@ public void robotInit() {
3538
// and put our
3639
// autonomous chooser on the dashboard.
3740
m_robotContainer = new RobotContainer();
41+
42+
// TODO: Improve below to display something like "Code Last Loaded: 7 minutes ago"
43+
SmartDashboard.putString("Robot Loaded on:", new Date().toLocaleString());
3844
}
3945

4046
/**

src/main/java/org/mayheminc/robot2020/RobotContainer.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,12 @@ private void configureDefaultCommands() {
8080

8181
private void configureAutonomousPrograms() {
8282
LinkedList<Command> autonomousPrograms = new LinkedList<Command>();
83-
84-
autonomousPrograms.push(new StayStill());
85-
autonomousPrograms.push(new DriveStraight());
83+
// TODO: fix "wierdness" with auto program selection - sometimes doesn't seem to work
84+
// TODO: fix so that auto program is shown not just when changed (as shows old setting sometimes)
85+
86+
// autonomousPrograms.push(/* 01 */ new StayStill());
87+
autonomousPrograms.push(/* 00 */ new TrenchAuto());
88+
// autonomousPrograms.push( new ShooterReadyAimFire());
8689
// autonomousPrograms.push(new TestTurret());
8790

8891
autonomous.setAutonomousPrograms(autonomousPrograms);
@@ -139,11 +142,21 @@ private void configureDriverPadButtons() {
139142
// ShooterSetTurretAbs(-5500));// about -30 degrees
140143
// DRIVER_PAD.DRIVER_PAD_D_PAD_RIGHT.whenPressed(new
141144
// ShooterSetTurretAbs(+5500));// about +30 degrees
142-
DRIVER_PAD.DRIVER_PAD_D_PAD_LEFT.whileHeld(new ShooterSetTurretVBus(-0.2));// about -30 degrees
143-
DRIVER_PAD.DRIVER_PAD_D_PAD_RIGHT.whileHeld(new ShooterSetTurretVBus(+0.2));// about +30 degrees
145+
// DRIVER_PAD.DRIVER_PAD_D_PAD_LEFT.whileHeld(new ShooterSetTurretVBus(-0.2));//
146+
// about -30 degrees
147+
// DRIVER_PAD.DRIVER_PAD_D_PAD_RIGHT.whileHeld(new
148+
// ShooterSetTurretVBus(+0.2));// about +30 degrees
144149
DRIVER_PAD.DRIVER_PAD_D_PAD_UP.whenPressed(new ShooterSetHoodAbs(Shooter.HOOD_INITIATION_LINE_POSITION));
145150
DRIVER_PAD.DRIVER_PAD_D_PAD_DOWN.whenPressed(new ShooterSetHoodAbs(Shooter.HOOD_TARGET_ZONE_POSITION));
146151

152+
// DRIVER_PAD.DRIVER_PAD_D_PAD_LEFT.whenPressed(new
153+
// ShooterSetTurretRel(-200.0));
154+
// DRIVER_PAD.DRIVER_PAD_D_PAD_RIGHT.whenPressed(new
155+
// ShooterSetTurretRel(+200.0));
156+
// DRIVER_PAD.DRIVER_PAD_D_PAD_UP.whenPressed(new ShooterSetTurretAbs(+0.0));
157+
// DRIVER_PAD.DRIVER_PAD_D_PAD_DOWN.whenPressed(new
158+
// ShooterSetHoodAbs(Shooter.HOOD_TARGET_ZONE_POSITION));
159+
147160
// Debug Hood
148161
// DRIVER_PAD.DRIVER_PAD_D_PAD_UP.whenPressed(new ShooterSetHoodRel(+1000));
149162
// DRIVER_PAD.DRIVER_PAD_D_PAD_DOWN.whenPressed(new ShooterSetHoodRel(-1000));
@@ -154,7 +167,8 @@ private void configureDriverPadButtons() {
154167
DRIVER_PAD.DRIVER_PAD_BLUE_BUTTON.whenPressed(new ShooterAdjustWheel(100.0));
155168
DRIVER_PAD.DRIVER_PAD_GREEN_BUTTON.whenPressed(new ShooterAdjustWheel(-100.0));
156169
DRIVER_PAD.DRIVER_PAD_RED_BUTTON.whenPressed(new ShooterSetWheel(0.0));
157-
DRIVER_PAD.DRIVER_PAD_YELLOW_BUTTON.whenPressed(new ShooterSetWheel(2700));
170+
DRIVER_PAD.DRIVER_PAD_YELLOW_BUTTON.whenPressed(new ShooterSetWheel(3000));
171+
// TODO: above hard-coded constant (3000) should be a named constant from Shooter.java
158172

159173
DRIVER_PAD.DRIVER_PAD_LEFT_UPPER_TRIGGER_BUTTON.whileHeld(new ShooterSetFeeder(1.0));
160174

src/main/java/org/mayheminc/robot2020/autonomousroutines/DriveStraight.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ public DriveStraight() {
2222
addCommands(new DriveZeroGyro());
2323
// addCommands(new DriveStraightOnHeading(0.2, DistanceUnits.INCHES, 100, 0));
2424
addCommands(new DriveStraightOnHeading(-0.3, DistanceUnits.INCHES, 50, 0));
25-
addCommands(new ShooterSetHoodAbs(Shooter.HOOD_TARGET_ZONE_POSITION));
25+
addCommands(new ShooterSetHoodAbs(Shooter.HOOD_INITIATION_LINE_POSITION));
2626
// addCommands(new DriveStraightOnHeading(0.4, DistanceUnits.INCHES, 100, 0));
2727

28-
// addCommands(new ParallelCommandGroup(new IntakeSetPosition(true), new
29-
// MagazineSetTurntable(0.0)));
3028
}
3129
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*----------------------------------------------------------------------------*/
2+
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
3+
/* Open Source Software - may be modified and shared by FRC teams. The code */
4+
/* must be accompanied by the FIRST BSD license file in the root directory of */
5+
/* the project. */
6+
/*----------------------------------------------------------------------------*/
7+
8+
package org.mayheminc.robot2020.autonomousroutines;
9+
10+
import org.mayheminc.robot2020.RobotContainer;
11+
import org.mayheminc.robot2020.commands.*;
12+
import org.mayheminc.robot2020.commands.DriveStraightOnHeading.DistanceUnits;
13+
import org.mayheminc.robot2020.subsystems.Shooter;
14+
15+
import edu.wpi.first.wpilibj2.command.*;
16+
17+
public class TrenchAuto extends SequentialCommandGroup {
18+
/**
19+
* Add your docs here.
20+
*/
21+
public TrenchAuto() {
22+
23+
addCommands(new DriveZeroGyro());
24+
// first, shoot the balls that were pre-loaded
25+
26+
addCommands(new IntakeSetPositionWithoutWaiting(RobotContainer.intake.PIVOT_DOWN));
27+
addCommands(new ShooterReadyAimFire());
28+
29+
// then, perform a 3-point turn
30+
addCommands(new DriveStraightOnHeading(0.3, DistanceUnits.INCHES, 48, 160));
31+
32+
// pick up balls while heading down the trench.
33+
addCommands(new ParallelRaceGroup(
34+
// intake while driving down the trench
35+
new IntakeSetRollers(-1.0),
36+
new SequentialCommandGroup(new DriveStraightOnHeading(0.2, DistanceUnits.INCHES, 132, 180),
37+
new Wait(0.5), new DriveStraightOnHeading(-0.2, DistanceUnits.INCHES, 12, 180))));
38+
39+
// after getting all three balls, go back to shooting position
40+
addCommands(new DriveStraightOnHeading(-0.2, DistanceUnits.INCHES, 24, 30));
41+
addCommands(new DriveStraightOnHeading(0.3, DistanceUnits.INCHES, 120, 0));
42+
addCommands(new DriveStraightOnHeading(-0.1, DistanceUnits.INCHES, 6, 0));
43+
44+
addCommands(new ShooterReadyAimFire());
45+
46+
// turn the wheel off now that the shooting is all done
47+
addCommands( new ShooterSetWheel(0.0));
48+
49+
addCommands(new ShooterSetHoodAbs(Shooter.HOOD_TARGET_ZONE_POSITION));
50+
}
51+
}

src/main/java/org/mayheminc/robot2020/commands/AirCompressorDefault.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public AirCompressorDefault() {
2424
@Override
2525
public void initialize() {
2626
// robot.is
27-
RobotContainer.compressor.setCompresor(true);
27+
RobotContainer.compressor.setCompressor(true);
2828
}
2929

3030
// Called every time the scheduler runs while the command is scheduled.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*----------------------------------------------------------------------------*/
2+
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
3+
/* Open Source Software - may be modified and shared by FRC teams. The code */
4+
/* must be accompanied by the FIRST BSD license file in the root directory of */
5+
/* the project. */
6+
/*----------------------------------------------------------------------------*/
7+
8+
package org.mayheminc.robot2020.commands;
9+
10+
import org.mayheminc.robot2020.RobotContainer;
11+
12+
import edu.wpi.first.wpilibj2.command.CommandBase;
13+
14+
public class IntakeSetPositionWithoutWaiting extends CommandBase {
15+
double m_position;
16+
17+
/**
18+
* Creates a new IntakeSetPositionWithoutWaiting.
19+
*/
20+
public IntakeSetPositionWithoutWaiting(Double position) {
21+
// Use addRequirements() here to declare subsystem dependencies.
22+
addRequirements(RobotContainer.intake);
23+
m_position = position;
24+
25+
}
26+
27+
// Called when the command is initially scheduled.
28+
@Override
29+
public void initialize() {
30+
RobotContainer.intake.setPivot(m_position);
31+
}
32+
33+
// Returns true when the command should end.
34+
@Override
35+
public boolean isFinished() {
36+
return true;
37+
}
38+
}

src/main/java/org/mayheminc/robot2020/commands/ShooterReadyAimFire.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
package org.mayheminc.robot2020.commands;
99

10+
import org.mayheminc.robot2020.subsystems.Shooter;
11+
12+
import edu.wpi.first.wpilibj2.command.ParallelCommandGroup;
1013
import edu.wpi.first.wpilibj2.command.ParallelRaceGroup;
1114
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
1215

@@ -21,15 +24,31 @@ public ShooterReadyAimFire() {
2124
// Add your commands in the super() call, e.g.
2225
// super(new FooCommand(), new BarCommand());
2326
super();
24-
addCommands(new TargetingIsOnTarget());
25-
addCommands(new ShooterFireWhenReady());
26-
addCommands(new ShooterSetFeeder(1.0));
27-
addCommands(new ChimneySetChimney(0.5));
28-
addCommands(new MagazineSetTurntable(0.3));
2927

30-
addCommands(new Wait(4.0));
28+
addCommands(new ShooterSetHoodAbs(Shooter.HOOD_INITIATION_LINE_POSITION));
29+
// addCommands(new ShooterSetWheel(3000.0, true));
30+
31+
// addCommands(new Wait(3.0));
32+
33+
// TODO: Add compressor control so that compressor is turned off while actively shooting.
34+
35+
// aim to the target until we are on target.
36+
addCommands(
37+
new ParallelRaceGroup(
38+
new ParallelCommandGroup(new TargetingIsOnTarget(), new ShooterSetWheel(3000.0, true)),
39+
new TurretAimToTarget()));
40+
41+
// turn on the feeder, wiat 0.1, turn on the Chimney, wait 0.1, turn on the magazine, shoot for about 4 seconds
42+
addCommands(new ParallelRaceGroup(
43+
new ShooterSetFeeder(1.0),
44+
new SequentialCommandGroup(new Wait(0.1), new ChimneySetChimney(0.5)),
45+
new SequentialCommandGroup(new Wait(0.2), new MagazineSetTurntable(0.3)),
46+
new Wait(6.0)));
3147

32-
addCommands(new MagazineSetTurntable(0.0));
33-
addCommands(new ChimneySetChimney(0.0));
48+
addCommands(new ParallelRaceGroup(
49+
new MagazineSetTurntable(0.0),
50+
new ChimneySetChimney(0.0),
51+
new ShooterSetFeeder(0.0),
52+
new Wait(0.1)));
3453
}
3554
}

src/main/java/org/mayheminc/robot2020/commands/ShooterSetFeeder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public void initialize() {
3232
// Called once the command ends or is interrupted.
3333
@Override
3434
public void end(boolean interrupted) {
35-
RobotContainer.shooter.setFeederSpeed(0.0);
35+
36+
RobotContainer.shooter.setFeederSpeed(0.0);
37+
3638
}
3739

3840
}

src/main/java/org/mayheminc/robot2020/commands/ShooterSetWheel.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,21 @@
1313

1414
public class ShooterSetWheel extends CommandBase {
1515
double m_rpm;
16+
boolean m_waitForSpeed;
17+
18+
public ShooterSetWheel(double rpm) {
19+
this(rpm, false);
20+
}
1621

1722
/**
1823
* Creates a new ShooterSetWheel.
1924
*/
20-
public ShooterSetWheel(double rpm) {
25+
public ShooterSetWheel(double rpm, boolean wait) {
2126
// Use addRequirements() here to declare subsystem dependencies.
22-
addRequirements(RobotContainer.shooter);
27+
// addRequirements(RobotContainer.shooter);
2328

2429
m_rpm = rpm;
30+
m_waitForSpeed = wait;
2531
}
2632

2733
// Called when the command is initially scheduled.
@@ -33,6 +39,13 @@ public void initialize() {
3339
// Returns true when the command should end.
3440
@Override
3541
public boolean isFinished() {
36-
return true;
42+
if( m_waitForSpeed)
43+
{
44+
return (Math.abs( m_rpm - RobotContainer.shooter.getShooterWheelSpeed() ) < 100);
45+
}
46+
else
47+
{
48+
return true;
49+
}
3750
}
3851
}

src/main/java/org/mayheminc/robot2020/commands/TargetingIsOnTarget.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
package org.mayheminc.robot2020.commands;
99

10+
import org.mayheminc.robot2020.RobotContainer;
11+
1012
// import org.mayheminc.robot2020.RobotContainer;
1113
// import org.mayheminc.robot2020.subsystems.Targeting;
1214

@@ -50,6 +52,10 @@ public boolean isFinished() {
5052
// Math.abs(Targeting.convertRangeToWheelSpeed(RobotContainer.targeting.getRangeToTarget())
5153
// - RobotContainer.shooter.getShooterWheelSpeed()) < 100;
5254
// return bearingGood && wheelsGood;
53-
return true;
55+
56+
double targetPos = RobotContainer.targeting.getDesiredAzimuth();
57+
double turretPos = RobotContainer.shooter.getTurretPosition();
58+
59+
return ( Math.abs( targetPos - turretPos) < 50);
5460
}
5561
}

0 commit comments

Comments
 (0)