I’m not allowed to post a zip file now or at least not yet, so here is what seems likely to be the relevant code for this robot.
I reiterate that we have used no compressor code in our robot classes. All the compressor work is being done under the covers by the wpilib code.
Here is the robot map class:
// RobotBuilder Version: 2.0
//
// This file was generated by RobotBuilder. It contains sections of
// code that are automatically generated and assigned by robotbuilder.
// These sections will be updated in the future when you export to
// Java from RobotBuilder. Do not put any code or make any change in
// the blocks indicating autogenerated code or it will be lost on an
// update. Deleting the comments indicating the section will prevent
// it from being updated in the future.
package org.usfirst.frc5585.PowerUp2018;
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=IMPORTS
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.PWMTalonSRX;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Spark;
import edu.wpi.first.wpilibj.SpeedController;
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=IMPORTS
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
/**
-
The RobotMap is a mapping from the ports sensors and actuators are wired into
-
to a variable name. This provides flexibility changing wiring, makes checking
-
the wiring easier and significantly reduces the number of magic numbers
-
floating around.
*/
public class RobotMap {
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
public static SpeedController driveTrainLeftRear;
public static SpeedController driveTrainLeftFront;
public static SpeedController driveTrainRightRear;
public static SpeedController driveTrainRightFront;
public static RobotDrive driveTrainRobortDrive;
public static DoubleSolenoid pnuematicsGripper;
public static DoubleSolenoid pnuematicsLift;
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
public static void init() {
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
driveTrainLeftRear = new PWMTalonSRX(3);
LiveWindow.addActuator(“DriveTrain”, “Left Rear”, (PWMTalonSRX) driveTrainLeftRear);
driveTrainLeftRear.setInverted(false);
driveTrainLeftFront = new Spark(0);
LiveWindow.addActuator(“DriveTrain”, “Left Front”, (Spark) driveTrainLeftFront);
driveTrainLeftFront.setInverted(false);
driveTrainRightRear = new PWMTalonSRX(2);
LiveWindow.addActuator(“DriveTrain”, "Right Rear ", (PWMTalonSRX) driveTrainRightRear);
driveTrainRightRear.setInverted(false);
driveTrainRightFront = new Spark(1);
LiveWindow.addActuator(“DriveTrain”, “Right Front”, (Spark) driveTrainRightFront);
driveTrainRightFront.setInverted(false);
driveTrainRobortDrive = new RobotDrive(driveTrainLeftFront, driveTrainLeftRear,
driveTrainRightFront, driveTrainRightRear);
driveTrainRobortDrive.setSafetyEnabled(true);
driveTrainRobortDrive.setExpiration(0.1);
driveTrainRobortDrive.setSensitivity(0.5);
driveTrainRobortDrive.setMaxOutput(1.0);
pnuematicsGripper = new DoubleSolenoid(0, 3, 2);
LiveWindow.addActuator("Pnuematics", "Gripper", pnuematicsGripper);
pnuematicsLift = new DoubleSolenoid(0, 0, 1);
LiveWindow.addActuator("Pnuematics", "Lift", pnuematicsLift);
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
}
}
Here is the Robot class:
// RobotBuilder Version: 2.0
//
// This file was generated by RobotBuilder. It contains sections of
// code that are automatically generated and assigned by robotbuilder.
// These sections will be updated in the future when you export to
// Java from RobotBuilder. Do not put any code or make any change in
// the blocks indicating autogenerated code or it will be lost on an
// update. Deleting the comments indicating the section will prevent
// it from being updated in the future.
package org.usfirst.frc5585.PowerUp2018;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import org.usfirst.frc5585.PowerUp2018.commands.;
import org.usfirst.frc5585.PowerUp2018.subsystems.;
/**
-
The VM is configured to automatically run this class, and to call the
-
functions corresponding to each mode, as described in the TimedRobot
-
documentation. If you change the name of this class or the package after
-
creating this project, you must also update the build.properties file in
-
the project.
*/
public class Robot extends TimedRobot {
Command autonomousCommand;
SendableChooser<Command> chooser = new SendableChooser<>();
public static OI oi;
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
public static DriveTrain driveTrain;
public static Pnuematics pnuematics;
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
SendableChooser auto;
public static AutonomousVars autoVars;
/**
-
This function is run when the robot is first started up and should be
-
used for any initialization code.
*/
@Override
public void robotInit() {
RobotMap.init();
autoVars = new AutonomousVars(); // subsystems
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
driveTrain = new DriveTrain();
pnuematics = new Pnuematics();
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
// OI must be constructed after subsystems. If the OI creates Commands
//(which it very likely will), subsystems are not guaranteed to be
// constructed yet. Thus, their requires() statements may grab null
// pointers. Bad news. Don’t move it.
oi = new OI();
auto = new SendableChooser(); // auto chooser code
//auto.addDefault(“center”, new CenterAuto());
//auto.addObject(“baseline”, new BaselineAuto());
SmartDashboard.putData(“Autonomous program”, auto);
SmartDashboard.putData(Scheduler.getInstance()); // init smartdashboard
SmartDashboard.putData(Robot.driveTrain);
//SmartDashboard.putData(Robot.lift);
SmartDashboard.putString(“Camera Direction:”, “Forward”);
//dashboard();
// Add commands to Autonomous Sendable Chooser
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS
chooser.addDefault("Auto Drive", new AutoDrive());
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS
SmartDashboard.putData(“Auto mode”, chooser);
}
/**
- This function is called when the disabled button is hit.
- You can use it to reset subsystems before shutting down.
*/
@Override
public void disabledInit(){
}
@Override
public void disabledPeriodic() {
Scheduler.getInstance().run();
}
@Override
public void autonomousInit() {
autonomousCommand = chooser.getSelected();
// schedule the autonomous command (example)
if (autonomousCommand != null) autonomousCommand.start();
}
/**
- This function is called periodically during autonomous
*/
@Override
public void autonomousPeriodic() {
Scheduler.getInstance().run();
}
@Override
public void teleopInit() {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
if (autonomousCommand != null) autonomousCommand.cancel();
}
/**
- This function is called periodically during operator control
*/
@Override
public void teleopPeriodic() {
Scheduler.getInstance().run();
// dashboard();
}
}
Here is the OI class:
// RobotBuilder Version: 2.0
//
// This file was generated by RobotBuilder. It contains sections of
// code that are automatically generated and assigned by robotbuilder.
// These sections will be updated in the future when you export to
// Java from RobotBuilder. Do not put any code or make any change in
// the blocks indicating autogenerated code or it will be lost on an
// update. Deleting the comments indicating the section will prevent
// it from being updated in the future.
package org.usfirst.frc5585.PowerUp2018;
import org.usfirst.frc5585.PowerUp2018.commands.*;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import org.usfirst.frc5585.PowerUp2018.subsystems.*;
/**
-
This class is the glue that binds the controls on the physical operator
-
interface to the commands and command groups that allow control of the robot.
*/
public class OI {
//// CREATING BUTTONS
// One type of button is a joystick button which is any button on a joystick.
// You create one by telling it which joystick it’s on and which button
// number it is.
// Joystick stick = new Joystick(port);
// Button button = new JoystickButton(stick, buttonNumber);
// There are a few additional built in buttons you can use. Additionally,
// by subclassing Button you can create custom triggers and bind those to
// commands the same as any other Button.
//// TRIGGERING COMMANDS WITH BUTTONS
// Once you have a button, it’s trivial to bind it to a button in one of
// three ways:
// Start the command when the button is pressed and let it run the command
// until it is finished as determined by it’s isFinished method.
// button.whenPressed(new ExampleCommand());
// Run the command while the button is being held down and interrupt it once
// the button is released.
// button.whileHeld(new ExampleCommand());
// Start the command when the button is released and let it run the command
// until it is finished as determined by it’s isFinished method.
// button.whenReleased(new ExampleCommand());
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
public JoystickButton gripperButton;
public JoystickButton dropperButton;
public JoystickButton liftButton;
public JoystickButton lowerButton;
public JoystickButton grabLiftButton;
public JoystickButton grabLiftReleaseButton;
public Joystick joystick;
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
public OI() {
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
joystick = new Joystick(0);
grabLiftReleaseButton = new JoystickButton(joystick, 7);
grabLiftReleaseButton.whenPressed(new GrabLiftReleaseGroup());
grabLiftButton = new JoystickButton(joystick, 8);
grabLiftButton.whenPressed(new GrabLiftGroup());
lowerButton = new JoystickButton(joystick, 6);
lowerButton.whileHeld(new LowerCube());
liftButton = new JoystickButton(joystick, 5);
liftButton.whileHeld(new LiftCube());
dropperButton = new JoystickButton(joystick, 4);
dropperButton.whileHeld(new ReleaseCube());
gripperButton = new JoystickButton(joystick, 3);
gripperButton.whileHeld(new GrabCube());
// SmartDashboard Buttons
SmartDashboard.putData("Auto Drive", new AutoDrive());
SmartDashboard.putData("Arcade Drive", new ArcadeDrive());
SmartDashboard.putData("Lift Cube", new LiftCube());
SmartDashboard.putData("Lower Cube", new LowerCube());
SmartDashboard.putData("Grab Cube", new GrabCube());
SmartDashboard.putData("Release Cube", new ReleaseCube());
SmartDashboard.putData("Grab Lift Group", new GrabLiftGroup());
SmartDashboard.putData("Grab Lift Release Group", new GrabLiftReleaseGroup());
SmartDashboard.putData("Drive Forward", new DriveForward());
SmartDashboard.putData("Turn Left", new TurnLeft());
SmartDashboard.putData("Turn Right", new TurnRight());
SmartDashboard.putData("Auto Drive Left Group", new AutoDriveLeftGroup());
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
}
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=FUNCTIONS
public Joystick getJoystick() {
return joystick;
}
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=FUNCTIONS
}
Here is the pneumatics subsystem class:
// RobotBuilder Version: 2.0
//
// This file was generated by RobotBuilder. It contains sections of
// code that are automatically generated and assigned by robotbuilder.
// These sections will be updated in the future when you export to
// Java from RobotBuilder. Do not put any code or make any change in
// the blocks indicating autogenerated code or it will be lost on an
// update. Deleting the comments indicating the section will prevent
// it from being updated in the future.
package org.usfirst.frc5585.PowerUp2018.subsystems;
import org.usfirst.frc5585.PowerUp2018.RobotMap;
import org.usfirst.frc5585.PowerUp2018.commands.*;
import edu.wpi.first.wpilibj.command.Subsystem;
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=IMPORTS
import edu.wpi.first.wpilibj.DoubleSolenoid;
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=IMPORTS
/**
*
*/
public class Pnuematics extends Subsystem {
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTANTS
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTANTS
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
private final DoubleSolenoid gripper = RobotMap.pnuematicsGripper;
private final DoubleSolenoid lift = RobotMap.pnuematicsLift;
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
@Override
public void initDefaultCommand() {
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DEFAULT_COMMAND
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DEFAULT_COMMAND
//
// DoubleSolenoid Grabber = new DoubleSolenoid(1, 2);
//
// Grabber.set(DoubleSolenoid.Value.kOff);
// Grabber.set(DoubleSolenoid.Value.kForward);
// Grabber.set(DoubleSolenoid.Value.kReverse);
// }
// Set the default command for a subsystem here.
// setDefaultCommand(new MySpecialCommand());
}
@Override
public void periodic() {
// Put code here to be run every loop
}
// Put methods for controlling this subsystem
// here. Call these from Commands.
public void gripCube() {
gripper.set(DoubleSolenoid.Value.kForward);
}
public void dropCube() {
gripper.set(DoubleSolenoid.Value.kReverse);
}
public void liftCube() {
lift.set(DoubleSolenoid.Value.kForward);
}
public void lowerCube() {
lift.set(DoubleSolenoid.Value.kReverse);
}
}
And finally one of the pneumatics command classes:
// RobotBuilder Version: 2.0
//
// This file was generated by RobotBuilder. It contains sections of
// code that are automatically generated and assigned by robotbuilder.
// These sections will be updated in the future when you export to
// Java from RobotBuilder. Do not put any code or make any change in
// the blocks indicating autogenerated code or it will be lost on an
// update. Deleting the comments indicating the section will prevent
// it from being updated in the future.
package org.usfirst.frc5585.PowerUp2018.commands;
import edu.wpi.first.wpilibj.command.Command;
import org.usfirst.frc5585.PowerUp2018.Robot;
/**
*
*/
public class GrabCube extends Command {
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=VARIABLE_DECLARATIONS
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=VARIABLE_DECLARATIONS
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTOR
public GrabCube() {
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTOR
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=VARIABLE_SETTING
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=VARIABLE_SETTING
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
requires(Robot.pnuematics);
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
}
// Called just before this Command runs the first time
@Override
protected void initialize() {
}
// Called repeatedly when this Command is scheduled to run
@Override
protected void execute() {
Robot.pnuematics.gripCube();
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return true;
}
// Called once after isFinished returns true
@Override
protected void end() {
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
@Override
protected void interrupted() {
}
}
Let us know if any of this looks fundamentally wrong. A lot of the code is generated by the Robot Builder and then we add what’s needed to make things work.
Thanks,
Merritt