Created
February 10, 2021 22:02
-
-
Save zavallabots/feb29f1d37b062d1d9b66f974858cdf8 to your computer and use it in GitHub Desktop.
TankDrive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) FIRST and other WPILib contributors. | |
// Open Source Software; you can modify and/or share it under the terms of | |
// the WPILib BSD license file in the root directory of this project. | |
package frc.robot.commands; | |
import edu.wpi.first.wpilibj.command.Command; | |
/** Add your docs here. */ | |
public class TankDrive extends Command { | |
public TankDrive() { | |
} | |
@Override | |
protected boolean isFinished() { | |
// TODO Auto-generated method stub | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) FIRST and other WPILib contributors. | |
// Open Source Software; you can modify and/or share it under the terms of | |
// the WPILib BSD license file in the root directory of this project. | |
package frc.robot; | |
import edu.wpi.first.wpilibj.RobotBase; | |
/** | |
* Do NOT add any static variables to this class, or any initialization at all. Unless you know what | |
* you are doing, do not modify this file except to change the parameter class to the startRobot | |
* call. | |
*/ | |
public final class Main { | |
private Main() {} | |
/** | |
* Main initialization function. Do not perform any initialization here. | |
* | |
* <p>If you change your main robot class, change the parameter type. | |
*/ | |
public static void main(String... args) { | |
RobotBase.startRobot(Robot::new); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) FIRST and other WPILib contributors. | |
// Open Source Software; you can modify and/or share it under the terms of | |
// the WPILib BSD license file in the root directory of this project. | |
package frc.robot; | |
import edu.wpi.first.wpilibj.XboxController; | |
/** Add your docs here. */ | |
public class OI { | |
private XboxController driverController = new XboxController(RobotMap.DRIVER_CONTROLLER); | |
public double GetDriverRawAxis(int axis){ | |
return driverController.getRawAxis(axis); | |
}} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) FIRST and other WPILib contributors. | |
// Open Source Software; you can modify and/or share it under the terms of | |
// the WPILib BSD license file in the root directory of this project. | |
package frc.robot; | |
import edu.wpi.first.wpilibj.TimedRobot; | |
import edu.wpi.first.wpilibj2.command.CommandScheduler; | |
/** | |
* 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.gradle file in the | |
* project. | |
*/ | |
public class Robot extends TimedRobot { | |
public static OI m_oi; | |
public static Object driveTrain; | |
/** | |
* This function is run when the robot is first started up and should be used for any | |
* initialization code. | |
*/ | |
@Override | |
public void robotInit() { | |
// Instantiate our RobotContainer. This will perform all our button bindings, and put our | |
// autonomous chooser on the dashboard. | |
m_oi = new OI(); | |
} | |
/** | |
* This function is called every robot packet, no matter the mode. Use this for items like | |
* diagnostics that you want ran during disabled, autonomous, teleoperated and test. | |
* | |
* <p>This runs after the mode specific periodic functions, but before LiveWindow and | |
* SmartDashboard integrated updating. | |
*/ | |
@Override | |
public void robotPeriodic() { | |
// Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled | |
// commands, running already-scheduled commands, removing finished or interrupted commands, | |
// and running subsystem periodic() methods. This must be called from the robot's periodic | |
// block in order for anything in the Command-based framework to work. | |
CommandScheduler.getInstance().run(); | |
} | |
/** This function is called once each time the robot enters Disabled mode. */ | |
@Override | |
public void disabledInit() {} | |
@Override | |
public void disabledPeriodic() {} | |
/** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */ | |
@Override | |
public void autonomousInit() { | |
// schedule the autonomous command (example) | |
} | |
/** This function is called periodically during autonomous. */ | |
@Override | |
public void autonomousPeriodic() {} | |
@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() {} | |
@Override | |
public void testInit() { | |
// Cancels all running commands at the start of test mode. | |
CommandScheduler.getInstance().cancelAll(); | |
} | |
/** This function is called periodically during test mode. */ | |
@Override | |
public void testPeriodic() {} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) FIRST and other WPILib contributors. | |
// Open Source Software; you can modify and/or share it under the terms of | |
// the WPILib BSD license file in the root directory of this project. | |
package frc.robot; | |
public class RobotMap { | |
public static final int MOTOR_LEFT_1_ID = 0; | |
public static final int MOTOR_LEFT_2_ID = 1; | |
public static final int MOTOR_RIGHT_1_ID = 2; | |
public static final int MOTOR_RIGHT_2_ID = 3; | |
public static final int DRIVER_CONTROLLER = 0;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) FIRST and other WPILib contributors. | |
// Open Source Software; you can modify and/or share it under the terms of | |
// the WPILib BSD license file in the root directory of this project. | |
package frc.robot.subsystems; | |
import com.ctre.phoenix.motorcontrol.ControlMode; | |
import com.ctre.phoenix.motorcontrol.can.TalonSRX; | |
import edu.wpi.first.wpilibj.command.*; | |
import edu.wpi.first.wpilibj2.command.Command; | |
import edu.wpi.first.wpilibj2.command.Subsystem; | |
import edu.wpi.first.wpilibj2.command.SubsystemBase; | |
import frc.robot.RobotMap; | |
import frc.robot.commands.TankDrive; | |
public class DriveTrain extends SubsystemBase { | |
private TalonSRX motorLeft1 = new TalonSRX(RobotMap.MOTOR_LEFT_1_ID); | |
private TalonSRX motorLeft2 = new TalonSRX(RobotMap.MOTOR_LEFT_2_ID); | |
private TalonSRX motorRight1 = new TalonSRX(RobotMap.MOTOR_RIGHT_1_ID); | |
private TalonSRX motorRight2 = new TalonSRX(RobotMap.MOTOR_RIGHT_2_ID); | |
public void initDefaultCommand() { | |
setDefaultCommand(new TankDrive()); | |
} | |
public void setLeftMotors(double speed) { | |
motorLeft1.set(ControlMode.PercentOutput, -speed); | |
motorLeft2.set(ControlMode.PercentOutput, -speed); | |
} | |
public void setRightMotors(double speed) { | |
motorRight1.set(ControlMode.PercentOutput, speed); | |
motorRight2.set(ControlMode.PercentOutput, speed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment