Code for our robot:
// 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.frc5247.robot2018;
import edu.wpi.first.wpilibj.AnalogInput;
//import edu.wpi.first.wpilibj.Talon;
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.frc5247.robot2018.commands.;
import org.usfirst.frc5247.robot2018.subsystems.;
import org.usfirst.frc5247.robot2018.RobotMap;
import edu.wpi.cscore.CvSink;
import edu.wpi.cscore.CvSource;
import edu.wpi.cscore.UsbCamera;
import edu.wpi.first.wpilibj.Ultrasonic;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.IterativeRobot;
/**
-
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.
*/
@SuppressWarnings(“unused”)
public class Robot extends IterativeRobot {
Object autonomousCommand;
SendableChooser<Command> autoChooser = new SendableChooser<>();
public static OI oi;
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
public static Chassis chassis;
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
/**
- This function is run when the robot is first started up and should be
- used for any initialization code.
-
*/
Ultrasonic Ultra = new Ultrasonic(1,1); //ports
@Override
public void robotInit() {
RobotMap.init();
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
chassis = new Chassis();
// 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();
// Add commands to Autonomous Sendable Chooser
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS
autoChooser.addDefault("Autonomous Command", new Auton());
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS
SmartDashboard.putData(“Auto mode”, autoChooser);
UsbCamera camera = CameraServer.getInstance().startAutomaticCapture();
Ultra.setAutomaticMode(true);
}
//public void ultrasonicStart() {
double range = Ultra.getRangeInches();
// }
/**
* 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 = autoChooser.getSelected();
// schedule the autonomous command (example)
}
/**
* This function is called periodically during autonomous
*/
@Override
public void autonomousPeriodic() {
Scheduler.getInstance().run();
Ultra.setAutomaticMode(true);
}
@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.
}
/**
* This function is called periodically during operator control
*/
@Override
public void teleopPeriodic() {
Scheduler.getInstance().run();
/**
// sensor returns a value from 0-4095 that is scaled to inches
double currentDistance = ultrasonic.getValue() * kValueToInches;
// convert distance error to a motor speed
double currentSpeed = (kHoldDistance - currentDistance) * kP;
// drive robot
RobotDrive.drive(currentSpeed, 0);
*/
}
//public static void AutonL() {
//System.out.println("AutonL");
// TODO Auto-generated method stub
//}
}
Code for our auton:
// 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.frc5247.robot2018.commands;
import edu.wpi.first.wpilibj.command.Command;
import org.usfirst.frc5247.robot2018.Robot;
import edu.wpi.first.wpilibj.Ultrasonic;
/**
*
*/
public class Auton 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
Ultrasonic ultraAuton = new Ultrasonic(1, 1);
public Auton() {
requires(Robot.chassis);
ultraAuton.setAutomaticMode(true);
// 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
// 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() {
double urange = ultraAuton.getRangeInches();
Robot.chassis.driveforward();
//later
//while (urange ) {
if (urange > 10) {
Robot.chassis.driveforward();
}
else {
Robot.chassis.driveStop();
}
// }
}
// Make this return true when this Command no longer needs to run execute()
@Override
protected boolean isFinished() {
return false;
}
// Called once after isFinished returns true
@Override
protected void end() {
Robot.chassis.driveStop();
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
@Override
protected void interrupted() {
}
}
Ignore all our our notes. We haven`t been using any code in them.