diff --git a/AutonInterpreter.py b/AutonInterpreter.py new file mode 100644 index 0000000..92e6fa6 --- /dev/null +++ b/AutonInterpreter.py @@ -0,0 +1,28 @@ +import wpilib +#from PracticeDriveCode import drive, operatorFunctions, robot +from GUI import convert + +class AutonInterpreter(): + + def getList(self, name): + masterList = [] + with open("GUI/convert/" + name, "r") as f: + data = f.readlines() + for line in data: + line = line[:-1] + temp = line.split(",") + #temp.remove("\n") + masterList.append(temp) + #print(masterList) + f.close() + for i in masterList: + if i[0] == "0": + i[0] = "driveCommand" + elif i[0] == "1": + i[0] = "turnCommand" + elif i[0] == "2": + i[0] = "genericCommand" + return(masterList) + +AutonInterpreter.getList(None, "output") +pass diff --git a/Auton_Data_Handling.py b/Auton_Data_Handling.py new file mode 100644 index 0000000..c40f2b8 --- /dev/null +++ b/Auton_Data_Handling.py @@ -0,0 +1,25 @@ + +speed="None" +direction="None" +angle="None" +testCommand ="None" +import DriveCommand, TurnCommand, AutonInterpreter +from PracticeDriveCode import driveTrain, operatorFunctions + +class AutonHandling(): + + def readCommandList(self, alist): + i = 0 #Sets up iterator variable + cmdList = AutonInterpreter.AutonInterpreter.getList(None, alist) + for i in cmdList: #Basically, 'While i is less than or equal to the number or items in the list;' + if i[0] == "driveCommand":#Checking first item in list to see if it's a drive command + DriveCommand.DriveCommand(i[1], i[2], i[3], i[4]).runCommand()#It was a drive command! now it pulls all + #of the data from the list and plugs it into the DriveCommand function + elif i[0] == "turnCommand":#Repeat above process, just checking for a different variable + TurnCommand.TurnCommand(i[1]).runCommand() + +AutonHandling.readCommandList(None, "haha") +''' # Used to work with runCommands, need to update in order to test out readCommandList +commands = DriveCommand.DriveCommand("Fast","Forward","Test"), TurnCommand.TurnCommand("Slow","Left"), DriveCommand.DriveCommand("Slow", "Backwards", "Test") +AutonHandling().runCommands(commands) +''' diff --git a/DriveCommand.py b/DriveCommand.py new file mode 100644 index 0000000..410d082 --- /dev/null +++ b/DriveCommand.py @@ -0,0 +1,16 @@ + +speed="None" +direction="None" +angle="None" +testCommand ="None" + + +class DriveCommand(): + + def __init__(self, lspeed, ldistance, rspeed, rdistance): + self.lspeed = lspeed + self.ldistance = ldistance + self.rspeed = rspeed + self.rdistance = rdistance + def runCommand(self): + print ("LeftSpeed: " + self.lspeed + ", LeftDistance " + self.ldistance + "RightSpeed: " + self.rspeed + ", RightDistance: " + self.rdistance) diff --git a/PracticeDriveCode/__pycache__/drive.cpython-36.pyc b/PracticeDriveCode/__pycache__/drive.cpython-36.pyc new file mode 100644 index 0000000..b1d37c9 Binary files /dev/null and b/PracticeDriveCode/__pycache__/drive.cpython-36.pyc differ diff --git a/PracticeDriveCode/robot.py b/PracticeDriveCode/autonTesting.py similarity index 79% rename from PracticeDriveCode/robot.py rename to PracticeDriveCode/autonTesting.py index 86a4068..d4624f9 100644 --- a/PracticeDriveCode/robot.py +++ b/PracticeDriveCode/autonTesting.py @@ -1,40 +1,38 @@ -""" -File Author: Jacob Harrelson -File Name: robot.py -File Creation Date: 1/8/2018 -File Purpose: To create our drive functions -""" -import wpilib -from xbox import XboxController -from wpilib.drive import DifferentialDrive -from drive import driveTrain -#from operatorFunctions import operatorControl -from wpilib import RobotDrive - -class MyRobot(wpilib.IterativeRobot): - - def robotInit(self): - self.drive = driveTrain(self) - self.controllerOne = XboxController(0) - self.controllerTwo = XboxController(1) - #self.speedLimiter = 1 #1 = standard speed, greater than 1 to slow down, less than 1 to speed up - - self.dashTimer = wpilib.Timer()# Timer for SmartDashboard updating - self.dashTimer.start() - - def autonomousInit(self): - self.auto_loop_counter = 0 - gameData = DriverStation.getInstance().getGameSpecificMessage() - print (gameData) - - def autonomousPeriodic(self): - if self.auto_loop_counter < 100:#~50 loops a second - self.drive.autonDrive(.5, -.5) # Drive forwards at half speed - self.auto_loop_counter += 1 - else: - self.robot_drive.drive(0, 0) - def teleopPeriodic(self): - self.drive.drivePass(self.controllerOne.getLeftY(), self.controllerOne.getRightY(), self.controllerOne.getLeftX(), self.controllerOne.getLeftBumper()) - #self.operatorControl.operate(self.controllerTwo.getLeftY, self.controllerTwo.getLeftX(), self.controllerTwo.getRightY(), self.controllerTwo.getRightX(), self.controllerTwo.getButtonA(),self.controllerTwo.getButtonB(), self.controllerTwo.getButtonX(), self.controllerTwo.getButtonY(), self.controllerTwo.getRightTrigger(), self.controllerTwo.getRightBumper(), self.controllerTwo.getLeftTrigger(), self.controllerTwo.getLeftBumper()) -if __name__ == "__main__": - wpilib.run(MyRobot) +""" +File Author: Jacob Harrelson +File Name: robot.py +File Creation Date: 1/8/2018 +File Purpose: To create our drive functions +""" +import wpilib +from xbox import XboxController +from wpilib.drive import DifferentialDrive +from drive import driveTrain +from operatorFunctions import operatorControl +from wpilib import RobotDrive + +class MyRobot(wpilib.IterativeRobot): + + def robotInit(self): + self.drive = driveTrain(self) + self.controllerOne = XboxController(0) + self.controllerTwo = XboxController(1) + #self.speedLimiter = 1 #1 = standard speed, greater than 1 to slow down, less than 1 to speed up + + self.dashTimer = wpilib.Timer()# Timer for SmartDashboard updating + self.dashTimer.start() + + def autonomousInit(self): + self.gameData = DriverStation.getInstance().getGameSpecificMessage() + print (self.gameData) + + def autonomousPeriodic(self): + if self.lfMotor.getSelectedSensorPosition(0) < 16000: + self.drive.autonDrive(1, 1) + else: + self.robot_drive.drive(0, 0) + def teleopPeriodic(self): + self.drive.drivePass(self.controllerOne.getLeftY(), self.controllerOne.getRightY(), self.controllerOne.getLeftX(), self.controllerOne.getLeftBumper()) + #self.operatorControl.operate(self.controllerTwo.getLeftY, self.controllerTwo.getLeftX(), self.controllerTwo.getRightY(), self.controllerTwo.getRightX(), self.controllerTwo.getButtonA(),self.controllerTwo.getButtonB(), self.controllerTwo.getButtonX(), self.controllerTwo.getButtonY(), self.controllerTwo.getRightTrigger(), self.controllerTwo.getRightBumper(), self.controllerTwo.getLeftTrigger(), self.controllerTwo.getLeftBumper()) +if __name__ == "__main__": + wpilib.run(MyRobot) diff --git a/PracticeDriveCode/drive.py b/PracticeDriveCode/drive.py deleted file mode 100644 index 5df9453..0000000 --- a/PracticeDriveCode/drive.py +++ /dev/null @@ -1,84 +0,0 @@ -""" -File Author: Jacob Harrelson -File Name: drive.py -File Creation Date: 1/10/2018 -File Purpose: To create and run our drive functions -""" - -import wpilib -from wpilib.drive import DifferentialDrive -from wpilib import Encoder -import ctre - -class driveTrain(): - - def __init__(self, robot): - """Sets drive motors to a cantalon""" - self.lfMotor = ctre.wpi_talonsrx.WPI_TalonSRX(7) - self.lbMotor = ctre.wpi_talonsrx.WPI_TalonSRX(6) - self.rfMotor = ctre.wpi_talonsrx.WPI_TalonSRX(1) - self.rbMotor = ctre.wpi_talonsrx.WPI_TalonSRX(2) - - self.left = wpilib.SpeedControllerGroup(self.lfMotor, self.lbMotor) - self.right = wpilib.SpeedControllerGroup(self.rfMotor, self.rbMotor) - - self.robotDrive = DifferentialDrive(self.left, self.right) - - self.shifter = wpilib.Solenoid(0)#Initilizes the shifter's solenoid and sets it to read fron digital output 0 - self.shifterPosition = self.shifter.get() - - - self.lfMotor.configSelectedFeedbackSensor(0, 0, 0) - self.lbMotor.configSelectedFeedbackSensor(0, 0, 0) - self.rfMotor.configSelectedFeedbackSensor(0, 0, 0) - self.rbMotor.configSelectedFeedbackSensor(0, 0, 0) - - self.lfMotor.setSensorPhase(True) - self.lbMotor.setSensorPhase(True) - self.rfMotor.setSensorPhase(False) - self.rbMotor.setSensorPhase(False) - - self.lfMotor.setSelectedSensorPosition(0, 0, 0) - self.lbMotor.setSelectedSensorPosition(0, 0, 0) - self.rfMotor.setSelectedSensorPosition(0, 0, 0) - self.rbMotor.setSelectedSensorPosition(0, 0, 0) - - def printEncoders(self): - print(self.lfMotor.getSelectedSensorPosition(0)) - print(self.lbMotor.getSelectedSensorPosition(0)) - print(self.rfMotor.getSelectedSensorPosition(0)) - print(self.rbMotor.getSelectedSensorPosition(0)) - - def drivePass(self, leftY, rightY, leftX, leftBumper): - self.drive(leftY, rightY) - self.shift(leftBumper) - - def drive(self, leftY, rightY): - leftY = leftY*-1 - self.left.set(leftY) - self.right.set(rightY) - self.printEncoders() - - def shift(self, leftBumper): - self.shifterPosition = self.shifter.get() - if leftBumper:#When left bumper is pressed we shift gears - if self.shifter.get():#Checks to see what gear we are in and shifts accordingly - self.shifter.set(False) - elif self.shifter.get() == False: - self.shifter.set(True) - else: - pass - - def autonDrive(self, leftSpeed, rightSpeed): - self.left.set(leftSpeed) - self.right.set(rightSpeed) -""" - def autonTurn(self, turnAngle):#Angle is in degrees - ROBOT_WIDTH = 24.3 - - def getSpeeds(angle, radius, speed=1): - return [speed, speed*(lambda x: x[1]/x[0])(getDistances(angle, radius)) - - def getDistances(angle, radius): - return [(radius + ROBOT_WIDTH/2)*math.radians(angle), (radius - ROBOT_WIDTH/2)*math.radians(angle) ] -""" diff --git a/PracticeDriveCode/operator.py b/PracticeDriveCode/operator.py deleted file mode 100644 index 59b4c28..0000000 --- a/PracticeDriveCode/operator.py +++ /dev/null @@ -1,89 +0,0 @@ -""" -File Author: Jacob Harrelson -File Name: operator.py -File Creation Date: 1/11/2018 -File Purpose: To create and run our operator functions -""" -import wpilib -from wpilib import RobotDrive - -class operatorControl(): - - def __init__(self, robot, drive): - - self.drive = drive - #Set each motor to a talon - #Note that these are theoretical and subject to change as of 1-13-2018 - self.liftMotorOne = ctre.wpi_talonsrx.WPI_TalonSRX(4) - self.liftMotorTwo = ctre.wpi_talonsrx.WPI_TalonSRX(5) - - self.liftRotationMotor = ctre.wpi_talonsrx.WPI_TalonSRX(6) - - self.leftWinchMotorOne = ctre.wpi_talonsrx.WPI_TalonSRX(7) - self.leftWinchMotorTwo = ctre.wpi_talonsrx.WPI_TalonSRX(8) - - self.rightWinchMotorOne = ctre.wpi_talonsrx.WPI_TalonSRX(9) - self.rightWinchMotorTwo = ctre.wpi_talonsrx.WPI_TalonSRX(10) - - self.leftManipulatorMotor = ctre.wpi_talonsrx.WPI_TalonSRX(11) - self.rightManipulatorMotor = ctre.wpi_talonsrx.WPI_TalonSRX(12) - - self.leftPlatformDeployMotor = ctre.wpi_talonsrx.WPI_TalonSRX(13) - self.rightPlatformDeployMotor = ctre.wpi_talonsrx.WPI_TalonSRX(14) - - self.manipulatorFoldUpDownMotor = ctre.wpi_talonsrx.WPI_TalonSRX(15) - - self.manipulatorPowerCubeReleaseMotor = ctre.wpi_talonsrx.WPI_TalonSRX(16) - - self.doWeHaveACube = wpilib.DigitalInput(0)#Initilizes a proximity sensor used to see if we have a cube secured in the manipulator, sets it to read from digital input 0 - - self.aToggle = False#Initilizes the A toggle to an off state - #Set motors that are apired to do the same task to a control group - #Note that these are theoretical and subject to change as of 1-13-2018 - - self.liftMotorControlGroup = wpilib.SpeedControllerGroup(self.liftMotorOne, self.liftMotorTwo) - - self.leftWinchMotorControlGroup = wpilib.SpeedControllerGroup(self.leftWinchMotorOne, self.leftWinchMotorTwo) - - self.rightWinchMotorControlGroup = wpilib.SpeedControllerGroup(self.rightWinchMotorOne, self.rightWinchMotorTwo) - - def operate(aButton, bButton, xButton, yButton, leftY, leftX, rightY, rightX, rightTrigger, leftTrigger, rightBumper, leftBumper): - self.raiseLowerLift(leftY) - self.liftRotation(leftX) - self.winchUp(rightY) - self.manipulatorCubeRelease(whateverButtonThisEndsUpBeingInstanceOne) - self.platformDeploy(whateverButtonThisEndsUpBeingInstanceTwo) - self.manipulatorFold(whateverButtonThisEndsUpBeingInstanceThree) - self.manipulatorIntake(aButton) - - def raiseLowerLift(self, leftY): - self.liftMotorControlGroup.set(leftY) - - def liftRotation(self, leftX): - self.liftRotationMotor.set(leftX) - - def winchUp(self, rightY):#Operator can use right stick to raise the winch for climbing - #if rightY <= 0:#Allows for only positive values to be passed to the motors - #rightY = rightY*-1 - self.leftWinchMotorControlGroup.set(rightY) - self.rightWinchMotorControlGroup.set(rightY) - - def manipulatorCubeRelease(self, whateverButtonThisEndsUpBeingInstanceOne): - pass - - def platformDeploy(self, whateverButtonThisEndsUpBeingInstanceTwo): - pass - - def manipulatorFold(self, whateverButtonThisEndsUpBeingInstanceThree): - pass - - def manipulatorIntake(self, aButton):#operator can toggle the intake using A, the intake will run until it detects that it has a cube, or the operator can toggle if off using A - self.cubeInManinpulator = self.doWeHaveACube.get()#Gets input from proximity sensor and setes it to self.cubeInManinpulator - if self.aButton:#Runs when a is pressed - if self.aToggle:#If a has been toggled, it untoggles A - self.aToggle = False - else:#If a has not been toggled, it toggles A - self.aToggle = True - if self.aToggle and not self.cubeInManinpulator:#If A has been toggled and we have no cube, it will intake cubes - self.leftManipulatorMotor.set(1) - self.rightManipulatorMotor.set(-1) diff --git a/PracticeDriveCode/operatorFunctions.py b/PracticeDriveCode/operatorFunctions.py deleted file mode 100644 index 8242665..0000000 --- a/PracticeDriveCode/operatorFunctions.py +++ /dev/null @@ -1,87 +0,0 @@ -""" -File Author: Jacob Harrelson -File Name: operator.py -File Creation Date: 1/11/2018 -File Purpose: To create and run our operator functions -""" -"""import wpilib -from wpilib import Encoder, RobotDrive - -class operatorControl(): - - def __init__(self, robot, drive): - - self.drive = drive - #Set each motor to a talon - #Note that these are theoretical and subject to change as of 1-13-2018 - self.liftMotorOne = ctre.wpi_talonsrx.WPI_TalonSRX(4) - self.liftMotorTwo = ctre.wpi_talonsrx.WPI_TalonSRX(5) - - self.liftRotationMotor = ctre.wpi_talonsrx.WPI_TalonSRX(6) - - self.leftWinchMotorOne = ctre.wpi_talonsrx.WPI_TalonSRX(7) - self.leftWinchMotorTwo = ctre.wpi_talonsrx.WPI_TalonSRX(8) - - self.rightWinchMotorOne = ctre.wpi_talonsrx.WPI_TalonSRX(9) - self.rightWinchMotorTwo = ctre.wpi_talonsrx.WPI_TalonSRX(10) - - self.leftManipulatorMotor = ctre.wpi_talonsrx.WPI_TalonSRX(11) - self.rightManipulatorMotor = ctre.wpi_talonsrx.WPI_TalonSRX(12) - - self.leftPlatformDeployMotor = ctre.wpi_talonsrx.WPI_TalonSRX(13) - self.rightPlatformDeployMotor = ctre.wpi_talonsrx.WPI_TalonSRX(14) - - self.manipulatorFoldUpDownMotor = ctre.wpi_talonsrx.WPI_TalonSRX(15) - - self.manipulatorPowerCubeReleaseMotor = ctre.wpi_talonsrx.WPI_TalonSRX(16) - - self.doWeHaveACube = wpilib.DigitalInput(0)#Initilizes a proximity sensor used to see if we have a cube secured in the manipulator, sets it to read from digital input 0 - - self.aToggle = False#Initilizes the A toggle to an off state - #Set motors that are apired to do the same task to a control group - #Note that these are theoretical and subject to change as of 1-13-2018 - - self.liftMotorControlGroup = wpilib.SpeedControllerGroup(self.liftMotorOne, self.liftMotorTwo) - - self.leftWinchMotorControlGroup = wpilib.SpeedControllerGroup(self.leftWinchMotorOne, self.leftWinchMotorTwo) - - self.rightWinchMotorControlGroup = wpilib.SpeedControllerGroup(self.rightWinchMotorOne, self.rightWinchMotorTwo) - - def operate(aButton, bButton, xButton, yButton, leftY, leftX, rightY, rightX, rightTrigger, leftTrigger, rightBumper, leftBumper): - self.raiseLowerLift(leftY) - self.liftRotation(leftX) - self.winchUp(rightY) - self.manipulatorCubeRelease(whateverButtonThisEndsUpBeingInstanceOne) - self.platformDeploy(whateverButtonThisEndsUpBeingInstanceTwo) - self.manipulatorFold(whateverButtonThisEndsUpBeingInstanceThree) - self.manipulatorIntake(aButton) - - def raiseLowerLift(self, leftY): - self.liftMotorControlGroup.set(leftY) - - def liftRotation(self, leftX): - self.liftRotationMotor.set(leftX) - - def winchUp(self, rightY):#Operator can use right stick to raise the winch for climbing - #if rightY <= 0:#Allows for only positive values to be passed to the motors - #rightY = rightY*-1 - self.leftWinchMotorControlGroup.set(rightY) - self.rightWinchMotorControlGroup.set(rightY) - - def manipulatorCubeRelease(self, whateverButtonThisEndsUpBeingInstanceOne): - - def platformDeploy(self, whateverButtonThisEndsUpBeingInstanceTwo): - - def manipulatorFold(self, whateverButtonThisEndsUpBeingInstanceThree): - - def manipulatorIntake(self, aButton):#operator can toggle the intake using A, the intake will run until it detects that it has a cube, or the operator can toggle if off using A - self.cubeInManinpulator = self.doWeHaveACube.get()#Gets input from proximity sensor and setes it to self.cubeInManinpulator - if self.aButton:#Runs when a is pressed - if self.aToggle:#If a has been toggled, it untoggles A - self.aToggle = False - else:#If a has not been toggled, it toggles A - self.aToggle = True - if self.aToggle and not self.cubeInManinpulator:#If A has been toggled and we have no cube, it will intake cubes - self.leftManipulatorMotor.set(1) - self.rightManipulatorMotor.set(-1) -""" diff --git a/RobotSide/Auton_Data_Handling.py b/RobotSide/Auton_Data_Handling.py deleted file mode 100644 index e6869d5..0000000 --- a/RobotSide/Auton_Data_Handling.py +++ /dev/null @@ -1,29 +0,0 @@ - -speed="None" -direction="None" -angle="None" -testCommand ="None" -import DriveCommand, TurnCommand# also need to import data from Jacobs classes, just don't know how to quantify that yet - -class AutonHandling(): -''' - def runCommands(self, commandList):# Just a testing function, proof of concept - for command in commandList: - command.runCommand() -''' - def readCommandList(self, jacobsList): - counter = 0 #Sets up iterator variable (posibly an unnessicary holdout from java) - for counter in '''define class here''' jacobsList: #Basically, 'While counter is less than or equal to the number or items in the list;' - if jacobsList[counter[1]] == "driveCommand":#Checking first item in list to see if it's a drive command - DriveCommand.DriveCommand(jacobsList[counter[2]], jacobsList[counter[3]], jacobsList[counter[4]]):#It was a drive command! now it pulls all - #of the data from the list and plugs it into the DriveCommand function - elif jacobsList[counter[1]] == "turnCommand":#Repeat above process, just checking for a different variable - TurnCommand.TurnCommand(jacobsList[counter[2]], jacobsList[counter[3]]):#Note how it only pulls 2 items from the list instead of 3, - #because TurnCommand only needs 2 variables - counter+=1#once it finishes this check, add another number to the counter and check that location (we just checked location 0, now - #we add 1 to it and check location 1 next. This goes on until you've searched the whole list) - -''' # Used to work with runCommands, need to update in order to test out readCommandList -commands = DriveCommand.DriveCommand("Fast","Forward","Test"), TurnCommand.TurnCommand("Slow","Left"), DriveCommand.DriveCommand("Slow", "Backwards", "Test") -AutonHandling().runCommands(commands) -''' diff --git a/RobotSide/DriveCommand.py b/RobotSide/DriveCommand.py deleted file mode 100644 index dbbb01d..0000000 --- a/RobotSide/DriveCommand.py +++ /dev/null @@ -1,15 +0,0 @@ - -speed="None" -direction="None" -angle="None" -testCommand ="None" - - -class DriveCommand(): - - def __init__(self, speed, direction, testCommand): - self.speed = speed - self.direction = direction - self.testCommand = testCommand - def runCommand(self): - print ("We're driving " + self.speed + " in direction: " + self.direction + " heres the test: " + self.testCommand) diff --git a/RobotSide/TurnCommand.py b/RobotSide/TurnCommand.py deleted file mode 100644 index 14e319e..0000000 --- a/RobotSide/TurnCommand.py +++ /dev/null @@ -1,15 +0,0 @@ - -speed="None" -direction="None" -angle="None" -testCommand ="None" - - -class TurnCommand(): - def __init__(self, speed, angle): - self.speed = speed - self.angle=angle - - def runCommand(self): - - print ("We're turning " + self.speed + " in direction: " + self.angle) diff --git a/TurnCommand.py b/TurnCommand.py new file mode 100644 index 0000000..a6d2d97 --- /dev/null +++ b/TurnCommand.py @@ -0,0 +1,15 @@ + +speed="None" +direction="None" +angle="None" +testCommand ="None" + + +class TurnCommand(): + def __init__(self, angle): + self.angle=angle + + def runCommand(self): + + print ("We're turning in direction: ") + print(self.angle) diff --git a/__pycache__/AutonInterpreter.cpython-36.pyc b/__pycache__/AutonInterpreter.cpython-36.pyc new file mode 100644 index 0000000..ed47120 Binary files /dev/null and b/__pycache__/AutonInterpreter.cpython-36.pyc differ diff --git a/__pycache__/DriveCommand.cpython-36.pyc b/__pycache__/DriveCommand.cpython-36.pyc index ac9f7eb..60f393f 100644 Binary files a/__pycache__/DriveCommand.cpython-36.pyc and b/__pycache__/DriveCommand.cpython-36.pyc differ diff --git a/__pycache__/TurnCommand.cpython-36.pyc b/__pycache__/TurnCommand.cpython-36.pyc index bd245d9..773c24e 100644 Binary files a/__pycache__/TurnCommand.cpython-36.pyc and b/__pycache__/TurnCommand.cpython-36.pyc differ