diff --git a/10 - Basic Drivetrain/README.md b/10 - Basic Drivetrain/README.md new file mode 100644 index 0000000..e69de29 diff --git a/10 - Basic Drivetrain/robot.py b/10 - Basic Drivetrain/robot.py new file mode 100644 index 0000000..c757a34 --- /dev/null +++ b/10 - Basic Drivetrain/robot.py @@ -0,0 +1,34 @@ +import wpilib +import wpilib.drive +import ctre + +class MyRobot(wpilib.TimedRobot): + def robotInit(self): + self.leftFront = ctre.WPI_VictorSPX(0) + self.leftRear = ctre.WPI_VictorSPX(1) + self.rightFront = ctre.WPI_VictorSPX(2) + self.rightRear = ctre.WPI_VictorSPX(3) + + self.left = wpilib.MotorControllerGroup(self.leftFront, self.leftRear) + self.right = wpilib.MotorControllerGroup(self.rightFront, self.rightRear) + self.right.setInverted(True) + + self.drivetrain = wpilib.drive.DifferentialDrive(self.left, self.right) + + self.primary = wpilib.XboxController(0) + + + def autonomousInit(self): + pass + + def autonomousPeriodic(self): + pass + + def teleopInit(self): + pass + + def teleopPeriodic(self): + self.drivetrain.arcadeDrive(self.primary.getLeftY(), self.primary.getLeftX()) + +if __name__ == "__main__": + wpilib.run(MyRobot) \ No newline at end of file diff --git a/11 - Timer Based Autonomous/Challenge/README.md b/11 - Timer Based Autonomous/Challenge/README.md new file mode 100644 index 0000000..e7eda9f --- /dev/null +++ b/11 - Timer Based Autonomous/Challenge/README.md @@ -0,0 +1,6 @@ +Create an autonomous that completes the following steps +- Forward for 2 Seconds +- Right for .5 Seconds +- Forward for 1 Second +- Left for .75 Seconds +- Backward for 2 Seconds \ No newline at end of file diff --git a/11 - Timer Based Autonomous/Challenge/robot.py b/11 - Timer Based Autonomous/Challenge/robot.py new file mode 100644 index 0000000..ec5814d --- /dev/null +++ b/11 - Timer Based Autonomous/Challenge/robot.py @@ -0,0 +1,48 @@ +import wpilib +import wpilib.drive +import ctre + +class MyRobot(wpilib.TimedRobot): + def robotInit(self): + self.leftFront = ctre.WPI_VictorSPX(0) + self.leftRear = ctre.WPI_VictorSPX(1) + self.rightFront = ctre.WPI_VictorSPX(2) + self.rightRear = ctre.WPI_VictorSPX(3) + + self.left = wpilib.MotorControllerGroup(self.leftFront, self.leftRear) + self.right = wpilib.MotorControllerGroup(self.rightFront, self.rightRear) + self.right.setInverted(True) + + self.drivetrain = wpilib.drive.DifferentialDrive(self.left, self.right) + + self.primary = wpilib.XboxController(0) + + self.autoTimer = wpilib.Timer() + + + def autonomousInit(self): + self.autoTimer.reset() + self.autoTimer.start() + + def autonomousPeriodic(self): + if self.autoTimer.get() < 2: + self.drivetrain.tankDrive(.5, .5) + elif self.autoTimer.get() >= 2 and self.autoTimer.get() < 2.5: + self.drivetrain.tankDrive(.5, -.5) + elif self.autoTimer.get() >= 2.5 and self.autoTimer.get() < 3.5: + self.drivetrain.tankDrive(.5, .5) + elif self.autoTimer.get() >= 3.5 and self.autoTimer.get() < 4.25: + self.drivetrain.tankDrive(-.5, .5) + elif self.autoTimer.get() >= 4.25 and self.autoTimer.get() < 6.25: + self.drivetrain.tankDrive(-.5, -.5) + else: + self.drivetrain.tankDrive(0, 0) + + def teleopInit(self): + self.autoTimer.stop() + + def teleopPeriodic(self): + self.drivetrain.arcadeDrive(self.primary.getLeftY(), self.primary.getLeftX()) + +if __name__ == "__main__": + wpilib.run(MyRobot) \ No newline at end of file diff --git a/11 - Timer Based Autonomous/README.md b/11 - Timer Based Autonomous/README.md new file mode 100644 index 0000000..e69de29 diff --git a/11 - Timer Based Autonomous/robot.py b/11 - Timer Based Autonomous/robot.py new file mode 100644 index 0000000..6ac2690 --- /dev/null +++ b/11 - Timer Based Autonomous/robot.py @@ -0,0 +1,46 @@ +import wpilib +import wpilib.drive +import ctre + +class MyRobot(wpilib.TimedRobot): + def robotInit(self): + self.leftFront = ctre.WPI_VictorSPX(0) + self.leftRear = ctre.WPI_VictorSPX(1) + self.rightFront = ctre.WPI_VictorSPX(2) + self.rightRear = ctre.WPI_VictorSPX(3) + + self.left = wpilib.MotorControllerGroup(self.leftFront, self.leftRear) + self.right = wpilib.MotorControllerGroup(self.rightFront, self.rightRear) + self.right.setInverted(True) + + self.drivetrain = wpilib.drive.DifferentialDrive(self.left, self.right) + + self.primary = wpilib.XboxController(0) + + self.autoTimer = wpilib.Timer() + + + def autonomousInit(self): + self.autoTimer.reset() + self.autoTimer.start() + + def autonomousPeriodic(self): + if self.autoTimer.get() < 2: + self.drivetrain.tankDrive(.5, .5) + elif self.autoTimer.get() >= 2 and self.autoTimer.get() < 3: + self.drivetrain.tankDrive(.5, -.5) + elif self.autoTimer.get() >= 3 and self.autoTimer.get() < 4: + self.drivetrain.tankDrive(-.5, .5) + elif self.autoTimer.get() >= 4 and self.autoTimer.get() < 6: + self.drivetrain.tankDrive(-.5, -.5) + else: + self.drivetrain.tankDrive(0, 0) + + def teleopInit(self): + self.autoTimer.stop() + + def teleopPeriodic(self): + self.drivetrain.arcadeDrive(self.primary.getLeftY(), self.primary.getLeftX()) + +if __name__ == "__main__": + wpilib.run(MyRobot) \ No newline at end of file diff --git a/12 - Digital and Analog Inputs/README.md b/12 - Digital and Analog Inputs/README.md new file mode 100644 index 0000000..e69de29 diff --git a/12 - Digital and Analog Inputs/robot.py b/12 - Digital and Analog Inputs/robot.py new file mode 100644 index 0000000..89115a5 --- /dev/null +++ b/12 - Digital and Analog Inputs/robot.py @@ -0,0 +1,41 @@ +import wpilib +import wpilib.drive +import ctre + +class MyRobot(wpilib.TimedRobot): + def robotInit(self): + self.leftFront = ctre.WPI_VictorSPX(0) + self.leftRear = ctre.WPI_VictorSPX(1) + self.rightFront = ctre.WPI_VictorSPX(2) + self.rightRear = ctre.WPI_VictorSPX(3) + + self.left = wpilib.MotorControllerGroup(self.leftFront, self.leftRear) + self.right = wpilib.MotorControllerGroup(self.rightFront, self.rightRear) + self.right.setInverted(True) + + self.drivetrain = wpilib.drive.DifferentialDrive(self.left, self.right) + + self.primary = wpilib.XboxController(0) + + self.wallTouchButton = wpilib.DigitalInput(0) + + self.autoSpeedControl = wpilib.AnalogPotentiometer(0) + + + def autonomousInit(self): + pass + + def autonomousPeriodic(self): + if not self.wallTouchButton.get(): + self.drivetrain.tankDrive(self.autoSpeedControl.get() / 2, self.autoSpeedControl.get() / 2) + else: + self.drivetrain.tankDrive(0, 0) + + def teleopInit(self): + pass + + def teleopPeriodic(self): + self.drivetrain.arcadeDrive(self.primary.getLeftY(), self.primary.getLeftX()) + +if __name__ == "__main__": + wpilib.run(MyRobot) \ No newline at end of file diff --git a/13 - Encoders/README.md b/13 - Encoders/README.md new file mode 100644 index 0000000..e69de29 diff --git a/13 - Encoders/robot.py b/13 - Encoders/robot.py new file mode 100644 index 0000000..1945667 --- /dev/null +++ b/13 - Encoders/robot.py @@ -0,0 +1,47 @@ +import wpilib +import wpilib.drive +import math +import ctre + +class MyRobot(wpilib.TimedRobot): + def robotInit(self): + self.leftFront = ctre.WPI_VictorSPX(0) + self.leftRear = ctre.WPI_VictorSPX(1) + self.rightFront = ctre.WPI_VictorSPX(2) + self.rightRear = ctre.WPI_VictorSPX(3) + + self.left = wpilib.MotorControllerGroup(self.leftFront, self.leftRear) + self.right = wpilib.MotorControllerGroup(self.rightFront, self.rightRear) + self.right.setInverted(True) + + self.drivetrain = wpilib.drive.DifferentialDrive(self.left, self.right) + + self.primary = wpilib.XboxController(0) + + self.PULSES_PER_REVOLUTION = 512 + self.WHEEL_DIAMETER = 6 + self.DISTANCE_PER_PULSE = math.pi * self.WHEEL_DIAMETER / self.PULSES_PER_REVOLUTION + + self.leftDrivetrainEncoder = wpilib.Encoder(0, 1) + self.leftDrivetrainEncoder.setDistancePerPulse(self.DISTANCE_PER_PULSE) + self.rightDrivetrainEncoder = wpilib.Encoder(2, 3) + self.rightDrivetrainEncoder.setDistancePerPulse(self.DISTANCE_PER_PULSE) + + def autonomousInit(self): + self.leftDrivetrainEncoder.reset() + self.rightDrivetrainEncoder.reset() + + def autonomousPeriodic(self): + if (self.leftDrivetrainEncoder.getDistance() + self.rightDrivetrainEncoder.getDistance()) / 2 < 60: + self.drivetrain.tankDrive(.5, .5) + else: + self.drivetrain.tankDrive(0, 0) + + def teleopInit(self): + pass + + def teleopPeriodic(self): + self.drivetrain.arcadeDrive(self.primary.getLeftY(), self.primary.getLeftX()) + +if __name__ == "__main__": + wpilib.run(MyRobot) \ No newline at end of file diff --git a/9 - Robot Program Structure/README.md b/9 - Robot Program Structure/README.md new file mode 100644 index 0000000..e69de29 diff --git a/9 - Robot Program Structure/robot.py b/9 - Robot Program Structure/robot.py new file mode 100644 index 0000000..280fead --- /dev/null +++ b/9 - Robot Program Structure/robot.py @@ -0,0 +1,20 @@ +import wpilib + +class MyRobot(wpilib.TimedRobot): + def robotInit(self): + pass + + def autonomousInit(self): + pass + + def autonomousPeriodic(self): + pass + + def teleopInit(self): + pass + + def teleopPeriodic(self): + pass + +if __name__ == "__main__": + wpilib.run(MyRobot) \ No newline at end of file