Skip to content

Commit aa28f89

Browse files
author
Noah Gleason
committed
Fix map errors
1 parent ac456c7 commit aa28f89

File tree

8 files changed

+144
-10
lines changed

8 files changed

+144
-10
lines changed

RoboRIO/src/main/java/org/usfirst/frc/team449/robot/Robot.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public void robotInit() {
107107
System.out.println("Config file is bad/nonexistent!");
108108
e.printStackTrace();
109109
}
110+
111+
//Read sensors
112+
this.robotMap.getUpdater().run();
113+
110114
//Set fields from the map.
111115
this.loggerNotifier = new Notifier(robotMap.getLogger());
112116
this.driveSubsystem = robotMap.getDrive();
@@ -179,6 +183,12 @@ public void robotInit() {
179183
*/
180184
@Override
181185
public void teleopInit() {
186+
//Do the startup tasks
187+
doStartupTasks();
188+
189+
//Read sensors
190+
this.robotMap.getUpdater().run();
191+
182192
//Run startup command if we start in teleop.
183193
if (!enabled) {
184194
if (robotMap.getStartupCommand() != null) {
@@ -187,9 +197,8 @@ public void teleopInit() {
187197
enabled = true;
188198
}
189199

190-
//Do the startup tasks
191200
driveSubsystem.stopMPProcesses();
192-
doStartupTasks();
201+
193202
if (robotMap.getTeleopStartupCommand() != null) {
194203
robotMap.getTeleopStartupCommand().start();
195204
}
@@ -208,6 +217,10 @@ public void teleopInit() {
208217
public void teleopPeriodic() {
209218
//Refresh the current time.
210219
Clock.updateTime();
220+
221+
//Read sensors
222+
this.robotMap.getUpdater().run();
223+
211224
//Run all commands. This is a WPILib thing you don't really have to worry about.
212225
Scheduler.getInstance().run();
213226
}
@@ -217,6 +230,12 @@ public void teleopPeriodic() {
217230
*/
218231
@Override
219232
public void autonomousInit() {
233+
//Do startup tasks
234+
doStartupTasks();
235+
236+
//Read sensors
237+
this.robotMap.getUpdater().run();
238+
220239
//Run startup command if we start in auto.
221240
if (!enabled) {
222241
if (robotMap.getStartupCommand() != null) {
@@ -225,8 +244,6 @@ public void autonomousInit() {
225244
enabled = true;
226245
}
227246

228-
//Do startup tasks
229-
doStartupTasks();
230247
if (robotMap.getAutoStartupCommand() != null) {
231248
robotMap.getAutoStartupCommand().start();
232249
}
@@ -247,6 +264,8 @@ public void autonomousInit() {
247264
public void autonomousPeriodic() {
248265
//Update the current time
249266
Clock.updateTime();
267+
//Read sensors
268+
this.robotMap.getUpdater().run();
250269
//Run all commands. This is a WPILib thing you don't really have to worry about.
251270
Scheduler.getInstance().run();
252271
}
@@ -282,6 +301,8 @@ public void testInit() {
282301
@Override
283302
public void disabledPeriodic() {
284303
Clock.updateTime();
304+
//Read sensors
305+
this.robotMap.getUpdater().run();
285306
}
286307

287308
/**

RoboRIO/src/main/java/org/usfirst/frc/team449/robot/RobotMap2017.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.jetbrains.annotations.Nullable;
88
import org.usfirst.frc.team449.robot.drive.unidirectional.DriveTalonCluster;
99
import org.usfirst.frc.team449.robot.jacksonWrappers.MappedDigitalInput;
10+
import org.usfirst.frc.team449.robot.jacksonWrappers.MappedRunnable;
1011
import org.usfirst.frc.team449.robot.jacksonWrappers.YamlCommand;
1112
import org.usfirst.frc.team449.robot.oi.buttons.CommandButton;
1213
import org.usfirst.frc.team449.robot.oi.unidirectional.OIUnidirectional;
@@ -58,6 +59,12 @@ public class RobotMap2017 {
5859
@NotNull
5960
private final Command defaultDriveCommand;
6061

62+
/**
63+
* A runnable that updates cached variables.
64+
*/
65+
@NotNull
66+
private final Runnable updater;
67+
6168
/**
6269
* The climber for boarding the airship. Can be null.
6370
*/
@@ -215,6 +222,7 @@ public class RobotMap2017 {
215222
* @param logger The logger for recording events and telemetry data.
216223
* @param drive The drive.
217224
* @param defaultDriveCommand The command for the drive to run during the teleoperated period.
225+
* @param updater A runnable that updates cached variables.
218226
* @param climber The climber for boarding the airship. Can be null.
219227
* @param shooter The multiSubsystem for shooting fuel. Can be null.
220228
* @param camera The cameras on this robot. Can be null.
@@ -258,6 +266,7 @@ public RobotMap2017(@Nullable List<CommandButton> buttons,
258266
@NotNull @JsonProperty(required = true) Logger logger,
259267
@NotNull @JsonProperty(required = true) DriveTalonCluster drive,
260268
@NotNull @JsonProperty(required = true) YamlCommand defaultDriveCommand,
269+
@NotNull @JsonProperty(required = true) MappedRunnable updater,
261270
@Nullable ClimberCurrentLimited climber,
262271
@Nullable LoggingShooter shooter,
263272
@Nullable CameraNetwork camera,
@@ -289,6 +298,7 @@ public RobotMap2017(@Nullable List<CommandButton> buttons,
289298
this.pneumatics = pneumatics;
290299
this.gearHandler = gearHandler;
291300
this.logger = logger;
301+
this.updater = updater;
292302
this.RIOduinoPort = RIOduinoPort;
293303
this.allianceSwitch = allianceSwitch;
294304
this.dropGearSwitch = dropGearSwitch;
@@ -542,4 +552,12 @@ public boolean getDoMP() {
542552
public Command getStartupCommand() {
543553
return startupCommand;
544554
}
555+
556+
/**
557+
* @return A runnable that updates cached variables.
558+
*/
559+
@NotNull
560+
public Runnable getUpdater() {
561+
return updater;
562+
}
545563
}

RoboRIO/src/main/java/org/usfirst/frc/team449/robot/generalInterfaces/updatable/Updatable.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package org.usfirst.frc.team449.robot.generalInterfaces.updatable;
22

3+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
4+
35
/**
46
* An interface for any object that caches values.
57
*/
8+
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_OBJECT, property = "@class")
69
public interface Updatable {
710

811
/**
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.usfirst.frc.team449.robot.other;
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.usfirst.frc.team449.robot.generalInterfaces.updatable.Updatable;
9+
import org.usfirst.frc.team449.robot.jacksonWrappers.MappedRunnable;
10+
11+
/**
12+
* A Runnable for updating cached variables.
13+
*/
14+
@JsonIdentityInfo(generator = ObjectIdGenerators.StringIdGenerator.class)
15+
public class Updater implements MappedRunnable{
16+
17+
/**
18+
* The objects to update.
19+
*/
20+
@NotNull
21+
private final Updatable[] updatables;
22+
23+
/**
24+
* Default constructor
25+
*
26+
* @param updatables The objects to update.
27+
*/
28+
@JsonCreator
29+
public Updater(@NotNull @JsonProperty(required = true) Updatable[] updatables) {
30+
this.updatables = updatables;
31+
}
32+
33+
/**
34+
* Update all the updatables.
35+
*/
36+
@Override
37+
public void run() {
38+
for (Updatable updatable : updatables){
39+
updatable.update();
40+
}
41+
}
42+
}

RoboRIO/src/main/resources/ballbasaur_map.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,12 @@ logger:
179179
eliPoseEstimator
180180
loopTimeSecs: 0.02
181181
eventLogFilename: "/home/lvuser/logs/eventLog-"
182-
telemetryLogFilename: "/home/lvuser/logs/telemetryLog-"
182+
telemetryLogFilename: "/home/lvuser/logs/telemetryLog-"
183+
updater:
184+
org.usfirst.frc.team449.robot.other.Updater:
185+
'@id': updater
186+
updatables:
187+
- org.usfirst.frc.team449.robot.drive.unidirectional.DriveTalonClusterShiftable:
188+
drive
189+
- org.usfirst.frc.team449.robot.oi.unidirectional.arcade.OIArcadeWithDPad:
190+
oi

RoboRIO/src/main/resources/calcifer_outreach_map.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,22 @@ buttons:
354354
subsystem:
355355
org.usfirst.frc.team449.robot.subsystem.interfaces.solenoid.SolenoidSimple:
356356
gearHandler
357-
action: WHEN_RELEASED
357+
action: WHEN_RELEASED
358+
updater:
359+
org.usfirst.frc.team449.robot.other.Updater:
360+
'@id': updater
361+
updatables:
362+
- org.usfirst.frc.team449.robot.drive.unidirectional.DriveTalonClusterShiftable:
363+
drive
364+
- org.usfirst.frc.team449.robot.subsystem.complex.climber.ClimberCurrentLimited:
365+
climber
366+
- org.usfirst.frc.team449.robot.oi.unidirectional.OIOutreach:
367+
oi
368+
- org.usfirst.frc.team449.robot.oi.throttles.ThrottleBasic:
369+
overridenPushGearThrottle
370+
- org.usfirst.frc.team449.robot.oi.throttles.ThrottleBasic:
371+
overridenClimbButtonThrottle
372+
- org.usfirst.frc.team449.robot.oi.throttles.ThrottleBasic:
373+
overridingPushGearThrottle
374+
- org.usfirst.frc.team449.robot.oi.throttles.ThrottleBasic:
375+
overridingClimbButtonThrottle

RoboRIO/src/main/resources/nate_map.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ buttons:
662662
climber
663663
action: WHEN_PRESSED
664664
- button:
665-
org.usfirst.frc.team449.robot.oi.buttons.TriggerButton:
665+
org.usfirst.frc.team449.robot.oi.buttons.SimpleButton:
666666
climbButton
667667
command:
668668
org.usfirst.frc.team449.robot.subsystem.interfaces.binaryMotor.commands.TurnMotorOffWithRequires:
@@ -719,12 +719,22 @@ buttons:
719719
'@id': openGearHandlerCommand
720720
action: WHEN_PRESSED
721721
- button:
722-
org.usfirst.frc.team449.robot.oi.buttons.TriggerButton:
722+
org.usfirst.frc.team449.robot.oi.buttons.SimpleButton:
723723
pushGearButton
724724
command:
725725
org.usfirst.frc.team449.robot.subsystem.interfaces.solenoid.commands.SolenoidForward:
726726
'@id': closeGearHandlerCommand
727727
subsystem:
728728
org.usfirst.frc.team449.robot.subsystem.interfaces.solenoid.SolenoidSimple:
729729
gearHandler
730-
action: WHEN_RELEASED
730+
action: WHEN_RELEASED
731+
updater:
732+
org.usfirst.frc.team449.robot.other.Updater:
733+
'@id': updater
734+
updatables:
735+
- org.usfirst.frc.team449.robot.drive.unidirectional.DriveTalonClusterShiftable:
736+
drive
737+
- org.usfirst.frc.team449.robot.subsystem.complex.climber.ClimberCurrentLimited:
738+
climber
739+
- org.usfirst.frc.team449.robot.oi.unidirectional.arcade.OIArcadeWithDPad:
740+
oi

RoboRIO/src/main/resources/naveen_map.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,4 +723,18 @@ buttons:
723723
subsystem:
724724
org.usfirst.frc.team449.robot.subsystem.interfaces.solenoid.SolenoidSimple:
725725
gearHandler
726-
action: WHEN_RELEASED
726+
action: WHEN_RELEASED
727+
updater:
728+
org.usfirst.frc.team449.robot.other.Updater:
729+
'@id': updater
730+
updatables:
731+
- org.usfirst.frc.team449.robot.drive.unidirectional.DriveTalonClusterShiftable:
732+
drive
733+
- org.usfirst.frc.team449.robot.subsystem.complex.climber.ClimberCurrentLimited:
734+
climber
735+
- org.usfirst.frc.team449.robot.oi.unidirectional.arcade.OIArcadeWithDPad:
736+
oi
737+
- org.usfirst.frc.team449.robot.oi.throttles.ThrottleBasic:
738+
pushGearThrottle
739+
- org.usfirst.frc.team449.robot.oi.throttles.ThrottleBasic:
740+
climbButtonThrottle

0 commit comments

Comments
 (0)