diff options
Diffstat (limited to 'src/org/usfirst/frc/team4272/robot2016')
5 files changed, 125 insertions, 69 deletions
diff --git a/src/org/usfirst/frc/team4272/robot2016/Autonomous.java b/src/org/usfirst/frc/team4272/robot2016/Autonomous.java index 756c33d..5cba22f 100644 --- a/src/org/usfirst/frc/team4272/robot2016/Autonomous.java +++ b/src/org/usfirst/frc/team4272/robot2016/Autonomous.java @@ -14,18 +14,24 @@ public class Autonomous { } public Control run(Control c) { - if (robot.armL.get()) { - c.arm = -0.5; - } else { - c.arm = 0; - robot.armE.reset(); - } - if (time.get() < 4) { - c.lDrive1 = c.rDrive1 = -0.4; - } else { - c.lDrive1 = c.rDrive1 = 0; +// if (time.get() < 5) { +// c.lDrive1 = c.lDrive2 = 0.2; +// c.rDrive1 =c.rDrive2 = -0.2; +// } else { +// c.lDrive1 = c.rDrive1 = 0; +// c.lDrive2 = c.rDrive2 = 0; +// } + if(Math.abs(robot.driveE.getRaw()) > 1){ + c.lDrive1 = c.lDrive2 = 0; + c.rDrive1 =c.rDrive2 = 0; + } + else + { + c.lDrive1 = c.lDrive2 = 0.2; + c.rDrive1 =c.rDrive2 = 0.2; } + SmartDashboard.putNumber("autoTime", time.get()); return c; diff --git a/src/org/usfirst/frc/team4272/robot2016/Control.java b/src/org/usfirst/frc/team4272/robot2016/Control.java index 40fcb5a..4c9be6f 100644 --- a/src/org/usfirst/frc/team4272/robot2016/Control.java +++ b/src/org/usfirst/frc/team4272/robot2016/Control.java @@ -2,12 +2,14 @@ package org.usfirst.frc.team4272.robot2016; public class Control { double lDrive1 = 0, - lDrive2 = 0, + lDrive2 = 0, rDrive1 = 0, rDrive2 = 0, fBall = 0, bBall = 0, - arm = 0; - + arm = 0, + camRotate = 0, + camTilt = 0; + boolean PCM = false; public Control() {} } diff --git a/src/org/usfirst/frc/team4272/robot2016/HwOI.java b/src/org/usfirst/frc/team4272/robot2016/HwOI.java index fc5cc78..6ae63eb 100644 --- a/src/org/usfirst/frc/team4272/robot2016/HwOI.java +++ b/src/org/usfirst/frc/team4272/robot2016/HwOI.java @@ -5,7 +5,5 @@ import org.usfirst.frc.team4272.robotlib.Xbox360Controller; import edu.wpi.first.wpilibj.Joystick; public class HwOI { - public Joystick lStick = new Joystick(0); - public Joystick rStick = new Joystick(1); - public Xbox360Controller xbox = new Xbox360Controller(2); + public Xbox360Controller xbox = new Xbox360Controller(1); } diff --git a/src/org/usfirst/frc/team4272/robot2016/HwRobot.java b/src/org/usfirst/frc/team4272/robot2016/HwRobot.java index e61d87f..d0108b7 100644 --- a/src/org/usfirst/frc/team4272/robot2016/HwRobot.java +++ b/src/org/usfirst/frc/team4272/robot2016/HwRobot.java @@ -9,8 +9,11 @@ import edu.wpi.first.wpilibj.PIDOutput; import edu.wpi.first.wpilibj.PIDSourceType; import edu.wpi.first.wpilibj.PowerDistributionPanel; import edu.wpi.first.wpilibj.Talon; +import edu.wpi.first.wpilibj.Jaguar; +import edu.wpi.first.wpilibj.Solenoid; import org.usfirst.frc.team4272.robotlib.PIDOutputSplitter; +import org.usfirst.frc.team4272.robotlib.PIDServo; public class HwRobot { /* Relay == a Spike */ @@ -33,27 +36,34 @@ public class HwRobot { // naming convention: {side_letter}{Thing}{E|M (encoder/motor)} private final PIDOutput - rDriveM1 = new Talon(/*PWM*/2), /* PDP 2, 3 */ - rDriveM2 = new Talon(/*PWM*/4), /* PDP 4 */ - lDriveM1 = new Talon(/*PWM*/1), /* PDP 12, 13 */ - lDriveM2 = new Talon(/*PWM*/0), /* PDP 11 */ - armM = new Talon(/*PWM*/8), /* PDP 15 */ - rfBallM = new Talon(/*PWM*/3), /* PDP 0 */ - lfBallM = new Talon(/*PWM*/9), /* PDP 14 */ - fBallM = new PIDOutputSplitter(rfBallM, lfBallM), - bBallM = new Talon(/*PWM*/6); /* PDP 10, 5 */ - - public final Encoder armE = new Encoder(/*DIO*/0, /*DIO*/1, /*DIO*/2, true); + rDriveM1 = new Jaguar(/*PWM*/0), /* PDP 2, 3 */ + rDriveM2 = new Jaguar(/*PWM*/1), /* PDP 4 */ + lDriveM1 = new Jaguar(/*PWM*/2), /* PDP 12, 13 */ + lDriveM2 = new Jaguar(3),/*PWM*/ /* PDP 11 */ + //armM = new Talon(/*PWM*/8), /* PDP 15 */ + //rfBallM = new Talon(/*PWM*/4), /* PDP 0 */ + //lfBallM = new Talon(/*PWM*/9), /* PDP 14 */ + //fBallM = new PIDOutputSplitter(rfBallM, lfBallM), + //bBallM = new Talon(/*PWM*/6),/* PDP 10, 5 */ + camRotate = new PIDServo(8), + camTilt = new PIDServo(9); + + + + //public final Encoder driveE = new Encoder(/*DIO*/0, /*DIO*/1, true); + public final Encoder driveE = new Encoder(2,3,true); public final DigitalInput armL = new DigitalInput(/*DIO*/3); public final DigitalInput ballL = new DigitalInput(/*DIO*/4); public final Encoder rDriveE = new Encoder(/*DIO*/5,/*DIO*/6); public final Encoder lDriveE = new Encoder(/*DIO*/7,/*DIO*/8, true); public final PowerDistributionPanel PDP = new PowerDistributionPanel(); /* via CAN */ + private final Solenoid PCM = new Solenoid(/*PCM*/ 0); + public HwRobot() { - armE.setPIDSourceType(PIDSourceType.kDisplacement); - lDriveE.setPIDSourceType(PIDSourceType.kRate); - rDriveE.setPIDSourceType(PIDSourceType.kRate); + driveE.setPIDSourceType(PIDSourceType.kDisplacement); +// lDriveE.setPIDSourceType(PIDSourceType.kRate); +// rDriveE.setPIDSourceType(PIDSourceType.kRate); PDP.initTable(NetworkTable.getTable("PDP")); } @@ -62,23 +72,30 @@ public class HwRobot { lDriveM2.pidWrite( c.lDrive2); rDriveM1.pidWrite(-c.rDrive1); rDriveM2.pidWrite(-c.rDrive2); - armM.pidWrite(c.arm * 0.5); - fBallM.pidWrite(-c.fBall); - bBallM.pidWrite(-c.bBall); - + //armM.pidWrite(c.arm * 0.5); + //fBallM.pidWrite(-c.fBall); + //bBallM.pidWrite(-c.bBall); + camRotate.pidWrite(c.camRotate); + camTilt.pidWrite(c.camTilt); + PCM.set(c.PCM); SmartDashboard.putNumber("fBall", c.fBall); SmartDashboard.putNumber("bBall", c.bBall); SmartDashboard.putNumber("armM", c.arm); - SmartDashboard.putNumber("armE", armE.pidGet()); - SmartDashboard.putNumber("lDriveE distance", lDriveE.getDistance()); - SmartDashboard.putNumber("lDriveE rate", lDriveE.getRate()); - SmartDashboard.putNumber("rDriveE distance", rDriveE.getDistance()); - SmartDashboard.putNumber("rDriveE rate", rDriveE.getRate()); - SmartDashboard.putBoolean("ballL", ballL.get()); - SmartDashboard.putBoolean("armL", armL.get()); + System.out.println("driveEncoder: " + driveE.getRaw()); + System.out.println("driveEncoder: " + driveE.getRate()); + System.out.println("driveEncoder: " + driveE.pidGet()); + + SmartDashboard.putNumber("armE", driveE.getRaw()); +// SmartDashboard.putNumber("lDriveE distance", lDriveE.getDistance()); +// SmartDashboard.putNumber("lDriveE rate", lDriveE.getRate()); +// SmartDashboard.putNumber("rDriveE distance", rDriveE.getDistance()); +// SmartDashboard.putNumber("rDriveE rate", rDriveE.getRate()); +// SmartDashboard.putBoolean("ballL", ballL.get()); +// SmartDashboard.putBoolean("armL", armL.get()); PDP.updateTable(); SmartDashboard.putData("PDP", PDP); } + } diff --git a/src/org/usfirst/frc/team4272/robot2016/Teleop.java b/src/org/usfirst/frc/team4272/robot2016/Teleop.java index 73b7b60..ed86427 100644 --- a/src/org/usfirst/frc/team4272/robot2016/Teleop.java +++ b/src/org/usfirst/frc/team4272/robot2016/Teleop.java @@ -6,6 +6,7 @@ import org.usfirst.frc.team4272.robotlib.Xbox360Controller.Axis; import org.usfirst.frc.team4272.robotlib.Xbox360Controller.Button; import org.usfirst.frc.team4272.robotlib.PushButton; + public class Teleop { private final HwRobot robot; private final double armSoftStop = 95;//295; @@ -15,49 +16,63 @@ public class Teleop { public Teleop(HwRobot robot) { this.robot = robot; - robot.armE.reset(); +// robot.armE.reset(); } - private static double jsScale(Joystick j) { - double y = -j.getY();/* +:forward; -:backward */ - double z = -j.getZ();/* +:more-sensitive; -:less-sensitive */ - return Math.copySign(Math.pow(Math.abs(y), 2.0-z), y); - } - - private static double bound(double min, double v, double max) { - return Math.min(Math.max(v, min), max); - } +// private static double jsScale(Joystick j) { +// double y = -j.getY();/* +:forward; -:backward */ +// double z = -j.getZ();/* +:more-sensitive; -:less-sensitive */ +// return Math.copySign(Math.pow(Math.abs(y), 2.0-z), y); +// } +// +// private static double bound(double min, double v, double max) { +// return Math.min(Math.max(v, min), max); +// } private static double oneIf(boolean b) { return b ? 1 : 0; } + //boolean DriverControl = true; public Control run(Control control, HwOI oi) { /* Drive */ - control.lDrive1 = jsScale(oi.lStick); - control.rDrive1 = jsScale(oi.rStick); - control.lDrive2 = oi.lStick.getTrigger() ? control.lDrive1 : 0; - control.rDrive2 = oi.rStick.getTrigger() ? control.rDrive1 : 0; - control.arm = -oi.xbox.getAxis(Axis.LY); + /*if (oi.lStick.getButton(Joystick.ButtonType.kTop) || oi.rStick.getButton(Joystick.ButtonType.kTop)) { + DriverControl =! DriverControl; + System.out.println("switched"); + }*/ + if (oi.xbox.getAxis(Axis.LY) > 0.2) { + control.lDrive1 = (oi.xbox.getAxis(Axis.LY)); + control.lDrive2 = (oi.xbox.getAxis(Axis.LY)); + } + if (oi.xbox.getAxis(Axis.RY) > 0.2) { + control.rDrive1 = (oi.xbox.getAxis(Axis.RY)); + control.rDrive2 = (oi.xbox.getAxis(Axis.RY)); + } + //control.arm = -oi.xbox.getAxis(Axis.LY); + /*if (DriverControl == true && Math.abs(oi.lStick.getAxis(Joystick.AxisType.kY)) <= 0.1 && (Math.abs(oi.rStick.getAxis(Joystick.AxisType.kY)) <= 0.1) ){ + control.lDrive1 = 0; + control.rDrive1 = 0; + System.out.println("stopped"); + }*/ if (control.arm < 0) control.arm = control.arm*0.2; - double fBall = oi.xbox.getAxis(Axis.RTrigger) - oi.xbox.getAxis(Axis.LTrigger); - double bBall = bound(-1, fBall, 0) + oneIf(oi.xbox.getButton(Button.A)) - oneIf(oi.xbox.getButton(Button.B)); + //double fBall = oi.xbox.getAxis(Axis.RTrigger) - oi.xbox.getAxis(Axis.LTrigger); + //double bBall = bound(-1, fBall, 0) + oneIf(oi.xbox.getButton(Button.A)) - oneIf(oi.xbox.getButton(Button.B)); - boolean ballL = robot.ballL.get(); - control.fBall = bound(-oneIf(ballL), fBall < 0 ? 0.5*fBall : fBall, 1); - control.bBall = bound(-oneIf(ballL), bBall < 0 ? 0.5*bBall : bBall, 1); + //boolean ballL = robot.ballL.get(); + //control.fBall = bound(-oneIf(ballL), fBall < 0 ? 0.5*fBall : fBall, 1); + //control.bBall = bound(-oneIf(ballL), bBall < 0 ? 0.5*bBall : bBall, 1); /* I'm eyeballing 10 degrees ≈ 50 clicks */ - if (robot.armE.pidGet() < 50 && !robot.armL.get()) { - robot.armE.reset(); - } +// if (robot.armE.pidGet() < 50 && !robot.armL.get()) { +// robot.armE.reset(); +// } - if (oi.xbox.getButton(Button.LBumper)) - control.arm = 1-(robot.armE.pidGet()/armSoftStop); - else if (oi.xbox.getButton(Button.RBumper)) - control.arm = robot.armE.pidGet()/armSoftStop; +// if (oi.xbox.getButton(Button.LBumper)) +// control.arm = 1-(robot.armE.pidGet()/armSoftStop); +// else if (oi.xbox.getButton(Button.RBumper)) +// control.arm = robot.armE.pidGet()/armSoftStop; if (shootButton.update(oi.xbox.getButton(Button.X))) { time.reset(); @@ -74,8 +89,26 @@ public class Teleop { control.fBall = 1; } } + + if(oi.xbox.getAxis(Axis.RTrigger) > 0) + control.camRotate = 1; + else if(oi.xbox.getAxis(Axis.LTrigger) > 0) + control.camRotate = -1; + else + control.camRotate = 0; + +// if(Math.abs(oi.xbox.getAxis(Axis.RY)) > 0.2) +// control.camTilt = oi.xbox.getAxis(Axis.RY); +// else +// control.camTilt = 0; + +// if(oi.xbox.getButton(Button.A)); /* Don't delete me!!*/ +// control.setSolnoid(true) +// else: +// control.PCM. + - //if (robot.armE.pidGet() > armSoftStop && control.arm > 0) + //if (robot.armE.piedGet() > armSoftStop && control.arm > 0) // control.arm = 0; /* Take pictures */ |