Skip to content

Commit 2731492

Browse files
committed
Merge branch 'ImageAction_optimization' into RPMCalculations
2 parents 74eed28 + b71bc38 commit 2731492

File tree

6 files changed

+62
-12
lines changed

6 files changed

+62
-12
lines changed

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
package frc.robot;
66

7+
import java.awt.image.BufferedImage;
8+
import java.io.File;
9+
import java.io.IOException;
10+
11+
import javax.imageio.ImageIO;
12+
13+
import edu.wpi.first.wpilibj.Filesystem;
714
import edu.wpi.first.wpilibj.Preferences;
815
import edu.wpi.first.wpilibj.TimedRobot;
916
import edu.wpi.first.wpilibj.util.Color;
@@ -40,6 +47,12 @@ public class Robot extends TimedRobot {
4047
private static final int NUM_LOOPS = 40;
4148
private int delay = NUM_LOOPS;
4249

50+
public static BufferedImage fiveBallAutoImage;
51+
public static BufferedImage fourBallAutoImage;
52+
53+
public static BufferedImage twentySecondImage;
54+
public static BufferedImage tenSecondImage;
55+
4356
/**
4457
* This function is run when the robot is first started up and should be used
4558
* for any
@@ -67,9 +80,28 @@ public void robotInit() {
6780
Preferences.initDouble("BLP.Velocity", 500.0);
6881
Preferences.initDouble("BLP.Angle", 60.0);
6982

83+
String pathname = "None";
84+
try {
85+
File deployDir = Filesystem.getDeployDirectory();
86+
String pathPrefix = deployDir.getAbsolutePath() + "/images/";
87+
88+
pathname = "THfade.png";
89+
Robot.fiveBallAutoImage = ImageIO.read(new File( pathPrefix+ pathname));
90+
pathname = "yellow_stripes.png";
91+
Robot.twentySecondImage = ImageIO.read(new File( pathPrefix+ pathname));
92+
pathname = "noise.png";
93+
Robot.tenSecondImage = ImageIO.read(new File( pathPrefix+ pathname));
94+
pathname = "fade.png";
95+
Robot.fourBallAutoImage = ImageIO.read(new File( pathPrefix+ pathname));
96+
97+
} catch (IOException e) {
98+
e.printStackTrace();
99+
System.out.println("Problem opening image. Check the path.\nImage path = " + pathname);
100+
}
101+
102+
70103
// Instantiate our RobotContainer. This will perform all our button bindings,
71-
// and put our
72-
// autonomous chooser on the dashboard.
104+
// and put our autonomous chooser on the dashboard.
73105
mRobotContainer = new RobotContainer();
74106
}
75107

src/main/java/frc/robot/RobotContainer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,12 @@ public Command getAutonomousCommand() {
155155
autoCommand = new FourBallAuto(mDrive, mIntake, mShooter);
156156
}
157157
} finally {
158+
/*
158159
fiveBallAuto.close();
159160
twoBallSouthAuto.close();
160161
twoBallEastAuto.close();
161162
fourBallAuto.close();
163+
*/
162164
}
163165
return autoCommand;
164166
}

src/main/java/frc/robot/auto/groups/FiveBallAuto.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import frc.paths.FiveBallPartThree;
1717
import frc.paths.FiveBallPartTwo;
1818
import frc.paths.Spinnnn;
19+
import frc.robot.Robot;
1920
import frc.robot.drive.Drivetrain;
2021
import frc.robot.drive.commands.ResetOdometry;
2122
import frc.robot.drive.commands.TrajectoryFollower;
@@ -45,7 +46,7 @@ public FiveBallAuto(Drivetrain drive, Intake intake, Shooter shooter) {
4546
new WaitCommand(0.8), // Give shooter time to spin up & hood to move
4647
new PullTrigger(shooter),
4748
new WaitCommand(0.5)),
48-
// new ActionCommand(new ImageAction("THfade.png", 0.01).brightness(0.7)),
49+
new ActionCommand(new ImageAction(Robot.fiveBallAutoImage, 0.02, ImageAction.FOREVER).brightness(0.7).oscillate()),
4950
new TrajectoryFollower(drive, new FiveBallPartOne()), // Turn to point at center
5051
new FlywheelController(shooter, 1810, 77.90)),
5152
new ParallelDeadlineGroup(

src/main/java/frc/robot/auto/groups/FourBallAuto.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import frc.paths.GoHome;
1414
import frc.paths.OnePointEightMetersForward;
1515
import frc.paths.WeirdAutoPartOne;
16+
import frc.robot.Robot;
1617
import frc.robot.drive.Drivetrain;
1718
import frc.robot.drive.commands.ResetOdometry;
1819
import frc.robot.drive.commands.TrajectoryFollower;
@@ -36,7 +37,7 @@ public class FourBallAuto extends SequentialCommandGroup{
3637

3738
public FourBallAuto(Drivetrain drive, Intake intake, Shooter shooter) {
3839
addCommands(
39-
// new ActionCommand(new ImageAction("fade.png",0.02).oscillate().brightness(0.7)),
40+
new ActionCommand(new ImageAction(Robot.fourBallAutoImage,0.02, ImageAction.FOREVER).oscillate().brightness(0.7)),
4041
new ResetOdometry(drive, new Pose2d(new Translation2d(0,0),Rotation2d.fromDegrees(-90))),
4142
new ResetEncoder(shooter),
4243
new ParallelDeadlineGroup(

src/main/java/frc/robot/status/actions/ImageAction.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ public ImageAction(String pathname, double interval, int count) {
7070

7171
imageFile = new File( pathPrefix+ pathname);
7272
readImage = ImageIO.read(imageFile);
73+
scaledImage = readImage;
74+
75+
} catch (IOException e) {
76+
e.printStackTrace();
77+
System.out.println("Problem opening image. Check the path.\nImage path = " + pathname);
78+
}
79+
intervalCount = count * scaledImage.getWidth();
80+
81+
curIntCount = intervalCount;
82+
83+
}
84+
85+
public ImageAction(final BufferedImage readImage, final double interval, final int count) {
7386

7487
/**
7588
* The below is very frustrating.
@@ -84,21 +97,19 @@ public ImageAction(String pathname, double interval, int count) {
8497
// scaledImage = imageToBufferedImage(si);
8598
scaledImage = readImage;
8699

100+
intervalTime = interval;
101+
87102
intervalCount = count * scaledImage.getWidth();
88103

89104
curIntCount = intervalCount;
90-
} catch (IOException e) {
91-
e.printStackTrace();
92-
System.out.println("Problem opening image. Check the path.\nImage path = " + pathname);
93-
}
94105
}
95106

96107
public void reset() {
97108
super.reset();
98109
this.currentColumn = 0;
99110
}
100111

101-
public ImageAction brightness(double brightness) {
112+
public ImageAction brightness(final double brightness) {
102113
setBrightness(brightness);
103114
return this;
104115
}
@@ -114,7 +125,7 @@ public ImageAction oscillate() {
114125
return this;
115126
}
116127

117-
public void setOscillate(boolean b) {
128+
public void setOscillate(final boolean b) {
118129
oscillate = b;
119130
}
120131

src/main/java/frc/robot/status/commands/IdleCommand.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import edu.wpi.first.wpilibj.util.Color;
88
import edu.wpi.first.wpilibj2.command.CommandBase;
99
import edu.wpi.first.wpilibj2.command.PrintCommand;
10+
import frc.robot.Robot;
1011
import frc.robot.status.Status;
1112
import frc.robot.status.actions.Action;
1213
import frc.robot.status.actions.ChaseAction;
@@ -28,6 +29,8 @@ public class IdleCommand extends CommandBase {
2829
private Status status;
2930
private boolean actionSet;
3031
private int phase = 0;
32+
private Action twentySecondsAction = new ImageAction(Robot.twentySecondImage,0.05, ImageAction.FOREVER);
33+
private Action tenSecondsAction = new ImageAction(Robot.tenSecondImage, 0.15, ImageAction.FOREVER);
3134

3235
public IdleCommand() {
3336
this.status = Status.getInstance();
@@ -63,13 +66,13 @@ Do some gymnastics to try to generate an elapsed time from getMatchTime().
6366
Action action = scannerAction;
6467
// new PrintCommand("Time Left = " + String.valueOf(timeElapsed)).schedule();
6568
if ( 115.0 < timeElapsed && (0 == phase)) { // 20 Seconds left
66-
action = new ImageAction("yellow_stripes.png",0.05);
69+
action = twentySecondsAction;
6770
phase = 1;
6871
actionSet = false;
6972
}
7073

7174
if (125.0 < timeElapsed && 1 == phase) { // Last 10 seconds
72-
action = new ImageAction("noise.png",0.15);
75+
action = tenSecondsAction;
7376
phase = 2;
7477
actionSet = false;
7578
}

0 commit comments

Comments
 (0)