Java Maps
From Team 449 Wiki
Maps are where we configure the subsystems and commands for a robot. They go into the frc.team449.javaMaps
package. Once you make a class like frc.team449.javaMaps.ClimberMap
, don't forget to update Robot::loadMap
to call ClimberMap.createRobotMap()
instead of using some other map.
Here's a rough template (be careful, this can and will change from year to year). Don't copy this directly, just take it as a guide for the overall structure of your map if you don't know where to start.
public class TestMap {
//Make sure these IDs are right
// Motor IDs
public static final int RIGHT_LEADER_PORT = 2,
RIGHT_LEADER_FOLLOWER_1_PORT = 3,
LEFT_LEADER_PORT = 1,
LEFT_LEADER_FOLLOWER_1_PORT = 4;
// Controller ports
public static final int MECHANISMS_JOYSTICK_PORT = 0, DRIVE_JOYSTICK_PORT = 1;
//Other constants
private TestMap() {}
@NotNull
public static RobotMap createRobotMap() {
var pdp = new PDP(
1,
new RunningLinRegComponent(250, 0.75),
PowerDistribution.ModuleType.kCTRE);
var mechanismsJoystick = new MappedJoystick(MECHANISMS_JOYSTICK_PORT);
var driveJoystick = new MappedJoystick(DRIVE_JOYSTICK_PORT);
var joysticks = List.of(mechanismsJoystick, driveJoystick);
var navx = new MappedAHRS(SerialPort.Port.kMXP, true);
//driveMasterPrototype is a bunch of settings that will be shared by both
//the left and right leader/master motor controller
//To build talons, use `new TalonConfig()` instead
var driveMasterPrototype =
new SparkMaxConfig()
.setEnableBrakeMode(true)
.setUnitPerRotation(UNIT_PER_ROTATION)
.setCurrentLimit(50)
.setEnableVoltageComp(true);
var rightMaster =
driveMasterPrototype
.copy() //copy() may not be needed but you don't want settings for the right leaking into the left
.setName("right") //Be sure to set different names for logging purposes
.setPort(RIGHT_LEADER_PORT)
.setReverseOutput(false)
.setSlaveSparks(List.of(new SlaveSparkMax(RIGHT_LEADER_FOLLOWER_1_PORT, false)))
.createReal();
var leftMaster =
driveMasterPrototype
.copy()
.setPort(LEFT_LEADER_PORT)
.setName("left")
.setReverseOutput(true)
.setSlaveSparks(List.of(new SlaveSparkMax(LEFT_LEADER_FOLLOWER_1_PORT, false)))
.createReal();
//If you want a simulated motor, use `createSim()`.
//If you want to try creating a real motor but default to a simulated one if it doesn't
// exist, use `createRealOrSim()` instead. This could hide an incorrect ID, though
var drive =
new DriveUnidirectionalWithGyro(
leftMaster,
rightMaster,
navx,
new DriveSettingsBuilder()
.postEncoderGearing(1 / 20.45)
.maxSpeed(2.3)
.leftFeedforward(new SimpleMotorFeedforward(0.24453, 5.4511, 0.7127))
.rightFeedforward(new SimpleMotorFeedforward(0.2691, 5.3099, 0.51261))
.build(),
0.61755);
//Like driveMasterPrototype, this one has shared settings for rotational and fwd/rev throttles
var throttlePrototype =
new ThrottlePolynomialBuilder().stick(driveJoystick).smoothingTimeSecs(0.04).scale(0.7);
var rotThrottle =
throttlePrototype
.axis(0)
.deadband(0.08)
.inverted(false)
.polynomial(new Polynomial(Map.of(1., 0.009, 2., 0.002), null))
.build();
var fwdThrottle =
new ThrottleSum(
new Throttle[] {
throttlePrototype
.axis(3)
.deadband(0.05)
.inverted(true)
.polynomial(
new Polynomial(
Map.of(
1., 0.01,
2., 0.06),
null))
.build(),
throttlePrototype.axis(2).inverted(false).build()
});
var oi =
new OIArcadeWithDPad(
rotThrottle,
fwdThrottle,
0.1,
false,
driveJoystick,
new Polynomial(
Map.of(
0.5, 0.4,
0., 0.2),
null),
0.7,
true);
//This command continuously takes the input from the OI and
//calls drive.setOutput based on that
var defaultDriveCommand =
new DefaultCommand(
drive,
new UnidirectionalNavXDefaultDrive<>(
0,
new Debouncer(1.5),
0,
1.0,
null,
2,
3.0,
false,
0,
0,
0,
new Debouncer(0.15),
drive,
oi,
new RampComponent(2.0, 2.0)));
// Make sure to put all your subsystems in here
var subsystems = List.<Subsystem>of(drive);
// Make sure to put all your updatables here
var updater = new Updater(List.of(pdp, oi, navx, drive));
var defaultCommands = List.of(defaultDriveCommand);
//Make sure all of your commands include the various subsystems they use as requirements
var buttons =
List.<CommandButton>of(
// button bindings go here
);
var robotStartupCommands = List.<Command>of();
var autoStartupCommands = List.<Command>of(
// As the name says, auto commands go here
);
var teleopStartupCommands = List.<Command>of();
var testStartupCommands = List.<Command>of();
var allCommands =
new CommandContainer(
defaultCommands,
buttons,
robotStartupCommands,
autoStartupCommands,
teleopStartupCommands,
testStartupCommands);
//Finally, return the created map
return new RobotMap(subsystems, pdp, updater, allCommands, joysticks, false);
}
}