From ca1b7551e4eaaa989f9addf803fd89d9d493e345 Mon Sep 17 00:00:00 2001 From: WillHescott Date: Sat, 20 Jan 2018 14:26:28 -0500 Subject: [PATCH 1/2] A lot of updates mainly auton handling --- AutonInterpreter.py | 28 ++++++ Auton_Data_Handling.py | 25 +++++ DriveCommand.py | 16 ++++ .../__pycache__/drive.cpython-36.pyc | Bin 0 -> 2370 bytes PracticeDriveCode/autonTesting.py | 38 ++++++++ PracticeDriveCode/drive.py | 8 ++ PracticeDriveCode/operator.py | 89 ------------------ PracticeDriveCode/operatorFunctions.py | 10 +- PracticeDriveCode/robot.py | 12 +-- RobotSide/Auton_Data_Handling.py | 29 ------ RobotSide/DriveCommand.py | 15 --- RobotSide/TurnCommand.py | 15 --- TurnCommand.py | 15 +++ __pycache__/AutonInterpreter.cpython-36.pyc | Bin 0 -> 871 bytes __pycache__/DriveCommand.cpython-36.pyc | Bin 759 -> 816 bytes __pycache__/TurnCommand.cpython-36.pyc | Bin 703 -> 668 bytes 16 files changed, 141 insertions(+), 159 deletions(-) create mode 100644 AutonInterpreter.py create mode 100644 Auton_Data_Handling.py create mode 100644 DriveCommand.py create mode 100644 PracticeDriveCode/__pycache__/drive.cpython-36.pyc create mode 100644 PracticeDriveCode/autonTesting.py delete mode 100644 PracticeDriveCode/operator.py delete mode 100644 RobotSide/Auton_Data_Handling.py delete mode 100644 RobotSide/DriveCommand.py delete mode 100644 RobotSide/TurnCommand.py create mode 100644 TurnCommand.py create mode 100644 __pycache__/AutonInterpreter.cpython-36.pyc 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 0000000000000000000000000000000000000000..b1d37c952c6a2010c8fa5a0f2d052d1e8bd78ca3 GIT binary patch literal 2370 zcmZt{U60#DaJ~MBHY#QFtc{L6CEWvXtvT(I?KD8s;BA%05Qzvo^&T}_%_n2^n_l5~?$sdiqil@CJ!+0Sx&_FK){0hyGUD#CtJ;^w_O_wL^L{O-L6 z_3r*0W=bRfK!qutlwnec5avaw=1_|Y$MYg35jr?QOW2@iRag4icq~B{WtQZ9dJvhd zr$wrSgp^LL21n!xPW=dhWN1B$IC*F2Un-IH*!Tw_(*%AEdpFy;*#j#>WdBZ zLAMHwX$O#GMM`pM(CXma!KoiujFoI+P4I=KwP3N`P~1>XL)nIM8_F@1SGFepf=z6k z&XVKZcEfRzgONZ^P+mg3jWaNG2TyDW*WB+Sw>!DKWO!~9aeHzFt-^1KQAXNXqun*y zTchpCRgAyY+&#lxA7?V&7n6ZEMn73i>3VG^cE zQ6{-6PFm>X6ORBonw^mEfv|(!L2s*a(h_9U`DK>H=D3Dmqs|Ze-^2%WdHDQA)yl`; zkz7O$8w6GyXgD6;&$Gj7YdDiq?5LsymFE)nK+R{Blgn{gxsbg&DuLdQ0#JvlG&xxL zLzT-yWuj{7qikGCsO(p=tS&dyzS0?Ga&#+I#W;I4l(|exDR%Lt!z6t@l!aChb+s&O zbpI&PGP-H#`e?&%1oe33Xqk^uBhune1~*Wrf1d6<9DT1P=+S{prs0?OM}3vfr&um} zw3n67=7*!*=Q}ag;bEktheC@1QwpVge3Kk7osXv*j=_687jy82e*=1dRVS55WFQHdq6UscS@5u1TAoYt*V- zO1+nrXL9dlWXKm)K-{nA)0u>I#oI>8exmh#d{a}GVi=+0t#b;W9!W_-8njYko6vlQ z$O4UeWq=?fkBRN-fMu~yV{LcXw|zoOw2gW1%ZEmquG@rCu8 zH>Yf2Oe$8!>>i*I*GS1N0@n$AgrLW3BR(L;n*Q%2kAAtji+~*NSV2=X7pySBeY@Mq zPqlXcclRnwY~x&`jd5<{*QiYiVR{#~CTdd#UsJLQl6k3$KK(h#WoOB8{hXiA&J22O z>IMb=;N!Ro;&`gWJSV&p$3M-JyxsvyZWCqrkT41*kU!vK0%wjg7*!WgR#Ne4Dnp<9 zw|&oda0X_l*Q#1^EL0lDK<+f%9lP_k(b6~y!3SP8&vyq@!@KslR-Bn%HT@PnwTHi0?@RjI&$vY? zax*1G%+n+n%6O_w6KxuCNgLdF{j^Y`?HgB#^vJk*oQbfN#flzyH&NOkkv!J1acz9) zYLS%&ldmA>ZHXJ5r`-c3r0TvAaklvQQFp88SDDDQ>TW0cW!3Ax*zZJZE2~ese}CYE z@}p@U3vKUdQZltj3ed$l^s$8jw%9zISk@y1cs~D6nn{X18WKN>YzI+fT2Yi0yh^Pd zMA1nVr&l}jE?qJ%{)SqxoE>tHpzL7zZ0wsxQR%YMZ7*zmD3dhlg%16dv`5AV{+rJD U>sJMA*gsTuNPQNt+1mmB1|hK8(EtDd literal 0 HcmV?d00001 diff --git a/__pycache__/DriveCommand.cpython-36.pyc b/__pycache__/DriveCommand.cpython-36.pyc index ac9f7eb7ac926783ec442b9c440259583ad395fe..60f393fbd58a06d53311eb2908ee2640386850af 100644 GIT binary patch delta 449 zcmZvY&q~8U5XN`YY}%wPMeq-ZXgmgc5G#neR!>R}RxeVK&}?fYP0MV&gg_78JV+%^ z;mya%zUn`o-$Ck_0+ENKtTw6kc5+1GCv+gT-FmVl5%FzT`paY JGxHB^`v-UeZAkzC delta 438 zcmZ8dze@u#6i#wUy=!U3#W^}C2TnR!M2CVnbrC5_K}zr02CljCa&;&N9l8s0n~ONQ z`PVq)9}%2Pu2O#_yzk{DFW>v#d#inj=&0GOzr63>JUvDa3r<$cd*-a;%xpU-XhCjC z!5q>eaL5vJNn+ZK11roFAhA)R5Qe$Rv~A>I@=i9H40IB6%MGM=7&sdA#3&rR65Md^ z^Q_bEUl~Bt@2NCO diff --git a/__pycache__/TurnCommand.cpython-36.pyc b/__pycache__/TurnCommand.cpython-36.pyc index bd245d98df92a5226e89e22113613b979393c75f..773c24ebaa4109fab8e8e3743490ea9cfe006f82 100644 GIT binary patch delta 346 zcmdnbI)|0hn3tDpdq-jv^F+?xP$mWl0MQ`q48+A;K%$1Rh9RCIg&~+hlhIF;@fK@h zUV2WdCetmJ;?$h9B4(hHl?+9!KX z;pU0~RhKZNFg7zX0_hrtEHDdf2a{iwOn9n#QK~{oX;EHgUb;eNoc D3{*;G delta 395 zcmYk2K}*9h6vvZvS=Y+c+dx!`D6?lTvV#Z}-Dww*ffQu6aYWj5BG-h?fPGzd)MK@dwz7#a+ypZA_%n!QsD~S zpo)Ov6kVbak3!N=HDfGo=tN927CKE!vFuKoX4wLHMY0X)`y?8~SBgm$k9n2_L#C2K z>-ell%A5(U;tQ^a7y3 wr2fFCTOCvD8!_Kn5x4G>on!0Ucz;jY88mB}DQ(;)B9+E$rO(>9^#j@c1*D!>@Bjb+ From e522bd360e022d9e947e542914e097ebd4206188 Mon Sep 17 00:00:00 2001 From: WillHescott Date: Sat, 20 Jan 2018 14:34:14 -0500 Subject: [PATCH 2/2] njf,jf --- PracticeDriveCode/drive.py | 92 -------------------------- PracticeDriveCode/operatorFunctions.py | 89 ------------------------- PracticeDriveCode/robot.py | 38 ----------- 3 files changed, 219 deletions(-) delete mode 100644 PracticeDriveCode/drive.py delete mode 100644 PracticeDriveCode/operatorFunctions.py delete mode 100644 PracticeDriveCode/robot.py diff --git a/PracticeDriveCode/drive.py b/PracticeDriveCode/drive.py deleted file mode 100644 index 7f00dd3..0000000 --- a/PracticeDriveCode/drive.py +++ /dev/null @@ -1,92 +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 autonDrive(self, leftSpeed, rightSpeed, leftDistance, rightDistance): - if ((self.lfmotor.getSelectedSensorPosition(0)+self.lbMotor.getSelectedSensorPosition(0))/2 != abs(leftDistance-1)): - self.lfmotor.set(leftSpeed) - self.lbmotor.set(leftSpeed) - if((self.rfMotor.getSelectedSensorPosition(0)+self.rbMotor.getSelectedSensorPosition(0))/2 != abs(leftDistance-1)): - self.rfmotor.set(rightSpeed) - self.rbmotor.set(rightSpeed) - - 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/operatorFunctions.py b/PracticeDriveCode/operatorFunctions.py deleted file mode 100644 index 094a7f9..0000000 --- a/PracticeDriveCode/operatorFunctions.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(leftY, leftX, rightY, rightX, aButton, bButton, xButton, yButton, leftY, leftX, rightY, rightX, rightTrigger, rightBumper, leftTrigger, 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/robot.py b/PracticeDriveCode/robot.py deleted file mode 100644 index b85d1b7..0000000 --- a/PracticeDriveCode/robot.py +++ /dev/null @@ -1,38 +0,0 @@ -""" -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)