Skip to content
This repository was archived by the owner on Sep 14, 2019. It is now read-only.

Commit f2a2bec

Browse files
committed
Mapped 4 stages of lift to manipulator POV for tele, also minor tweaks
The 4 stages of lift are now mapped to POV for teleop. Also did tweaks like motor ports, slaves, etc. Also note that manipulator in OI is static now for default command in lift.
1 parent 5bfb1c5 commit f2a2bec

7 files changed

Lines changed: 66 additions & 69 deletions

File tree

Robot2018/src/org/usfirst/frc/team199/Robot2018/OI.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class OI {
4343
public Joystick rightJoy;
4444
private JoystickButton updatePIDConstantsButton;
4545
private JoystickButton updateEncoderDPPButton;
46-
public Joystick manipulator;
46+
public static Joystick manipulator;
4747
private JoystickButton closeIntake;
4848
private JoystickButton openIntake;
4949
private JoystickButton raiseIntake;
@@ -85,10 +85,6 @@ public OI() {
8585
updatePIDConstantsButton.whenPressed(new UpdatePIDConstants());
8686
updateEncoderDPPButton = new JoystickButton(rightJoy, getButton("Get Encoder Dist Per Pulse", 9));
8787
updateEncoderDPPButton.whenPressed(new SetDistancePerPulse());
88-
MoveLiftUpButton = new JoystickButton(rightJoy, getButton("Run Lift Motor Up", 10));
89-
MoveLiftDownButton = new JoystickButton(rightJoy, getButton("Run Lift Motor Down", 11));
90-
MoveLiftUpButton.whileHeld(new RunLift(Robot.lift, true));
91-
MoveLiftDownButton.whileHeld(new RunLift(Robot.lift, false));
9288

9389
// manipulator = new Joystick(2);
9490
// closeIntake = new JoystickButton(manipulator, getButton("Close Intake
@@ -107,5 +103,10 @@ public OI() {
107103
// intake.whenPressed(new IntakeCube());
108104
// outake = new JoystickButton(manipulator, getButton("Outake Button", 6));
109105
// outake.whenPressed(new OutakeCube());
106+
107+
/*MoveLiftUpButton = new JoystickButton(manipulator, getButton("Run Lift Motor Up", 7));
108+
MoveLiftDownButton = new JoystickButton(manipulator, getButton("Run Lift Motor Down", 8));
109+
MoveLiftUpButton.whileHeld(new RunLift(Robot.lift, true));
110+
MoveLiftDownButton.whileHeld(new RunLift(Robot.lift, false));*/
110111
}
111112
}

Robot2018/src/org/usfirst/frc/team199/Robot2018/RobotMap.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ public class RobotMap {
3636

3737
public static PowerDistributionPanel pdp;
3838

39-
public static WPI_TalonSRX liftMotor;
39+
public static WPI_VictorSPX liftMotorA;
40+
public static WPI_TalonSRX liftMotorB;
41+
public static WPI_TalonSRX liftMotorC;
42+
public static SpeedControllerGroup liftMotors;
4043
public static Encoder liftEnc;
4144
public static DigitalSource liftEncPort1;
4245
public static DigitalSource liftEncPort2;
4346

44-
public static WPI_TalonSRX climberMotor;
47+
//public static WPI_TalonSRX climberMotor;
4548

4649
public static VictorSP leftIntakeMotor;
4750
public static VictorSP rightIntakeMotor;
@@ -118,15 +121,18 @@ private void configSPX(WPI_VictorSPX mc) {
118121

119122
public RobotMap() {
120123
pdp = new PowerDistributionPanel();
121-
122-
liftMotor = new WPI_TalonSRX(getPort("LiftTalonSRX", 7));
123-
configSRX(liftMotor);
124+
125+
liftMotorA = new WPI_VictorSPX(getPort("LiftVictorSPX", 5));
126+
configSPX(liftMotorA);
127+
liftMotorB = new WPI_TalonSRX(getPort("1LiftTalonSRX", 6));
128+
configSRX(liftMotorB);
129+
liftMotorC = new WPI_TalonSRX(getPort("2LiftTalonSRX", 7));
130+
configSRX(liftMotorC);
131+
liftMotors = new SpeedControllerGroup(liftMotorB, liftMotorA, liftMotorC);
124132
liftEncPort1 = new DigitalInput(getPort("1LiftEnc", 4));
125133
liftEncPort2 = new DigitalInput(getPort("2LiftEnc", 5));
126134
liftEnc = new Encoder(liftEncPort1, liftEncPort2);
127135
liftEnc.setPIDSourceType(PIDSourceType.kDisplacement);
128-
climberMotor = new WPI_TalonSRX(getPort("ClimberTalonSRX", 6));
129-
configSRX(climberMotor);
130136

131137
leftIntakeMotor = new VictorSP(getPort("IntakeLeftVictorSP", 9));
132138
rightIntakeMotor = new VictorSP(getPort("IntakeRightVictorSP", 8));

Robot2018/src/org/usfirst/frc/team199/Robot2018/commands/AutoLift.java

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,40 @@
1414
*/
1515
public class AutoLift extends Command implements PIDOutput{
1616
/**
17-
* All distances are - 1 foot for initial height of intake and + 3 inches for wiggle room for dropping cubes
18-
* Also, acutal distances are divided by 3 because according to cad, the lift will have a 1:3 ratio from winch
17+
* All distances are measured from bottom of cube and + 3 inches for wiggle room for dropping cubes
18+
* Also, actual distances are divided by 3 because according to cad, the lift will have a 1:3 ratio from winch
1919
* to actual height.
2020
*/
2121

2222
/**
2323
* Distance to switch
2424
* 18.75 inches in starting position (this measurement is the fence that surrounds the switch)
25-
* 9.75 / 3 for ratio = 3.25
25+
* 21.75 / 3 for ratio = 7.25
2626
*/
27-
private final double SWITCH_DIST = 3.25;
27+
private final double SWITCH_DIST = 7.25;
2828
/**
2929
* Distance to scale
3030
* 5 feet starting
31-
* 51 / 3 = 17
31+
* 63 / 3 = 21
3232
*/
33-
private final double SCALE_DIST = 17;
33+
private final double SCALE_DIST = 21;
3434
/**
3535
* Distance to bar
36-
* 72 / 3 = 24
36+
* 87 / 3 = 29
3737
* 7 feet starting; bar distance should be changed because I'm not aware how climber mech will be positioned
3838
*/
39-
private final double BAR_DIST = 24;
39+
private final double BAR_DIST = 29;
4040
private double desiredDist = 0;
41-
private double currDist = 0;
41+
private double currDist;
4242
private LiftInterface lift;
4343
private Position desiredPos;
4444

4545
private PIDController liftController;
4646

4747
public AutoLift(Position stage, LiftInterface lift) {
48-
// Use requires() here to declare subsystem dependencies
49-
// eg. requires(chassis);
5048
this.lift = lift;
5149
requires(Robot.lift);
52-
switch(lift.getCurrPos()) {
53-
case GROUND:
54-
currDist = 0;
55-
break;
56-
case SWITCH:
57-
currDist = SWITCH_DIST;
58-
break;
59-
case SCALE:
60-
currDist = SCALE_DIST;
61-
break;
62-
case BAR:
63-
currDist = BAR_DIST;
64-
break;
65-
}
50+
currDist = lift.getHeight();
6651
switch(stage) {
6752
case GROUND:
6853
desiredDist = -currDist;
@@ -86,7 +71,6 @@ public AutoLift(Position stage, LiftInterface lift) {
8671

8772
// Called just before this Command runs the first time
8873
protected void initialize() {
89-
lift.resetEnc();
9074
// input is in inches
9175
//liftController.setInputRange(-Robot.getConst("Max High Speed", 204), Robot.getConst("Max High Speed", 204));
9276
// output in "motor units" (arcade and tank only accept values [-1, 1]
@@ -104,7 +88,7 @@ protected void execute() {
10488
// Make this return true when this Command no longer needs to run execute()
10589
protected boolean isFinished() {
10690
if(liftController.onTarget()) {
107-
lift.setTargetPosition(desiredPos);
91+
lift.setCurrPosition(desiredPos);
10892
return true;
10993
}
11094
return false;

Robot2018/src/org/usfirst/frc/team199/Robot2018/subsystems/Climber.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
public class Climber extends Subsystem implements ClimberInterface {
1313

14-
private final WPI_TalonSRX climberMotor = RobotMap.climberMotor;
14+
//private final WPI_TalonSRX climberMotor = RobotMap.climberMotor;
1515

1616

1717
/**
@@ -52,7 +52,7 @@ public void attachToBar() {
5252
* stops the climber
5353
*/
5454
public void stopClimber() {
55-
climberMotor.stopMotor();
55+
//climberMotor.stopMotor();
5656
}
5757

5858

Robot2018/src/org/usfirst/frc/team199/Robot2018/subsystems/Lift.java

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,89 @@
11
package org.usfirst.frc.team199.Robot2018.subsystems;
22

3+
import org.usfirst.frc.team199.Robot2018.OI;
34
import org.usfirst.frc.team199.Robot2018.RobotMap;
5+
import org.usfirst.frc.team199.Robot2018.commands.AutoLift;
46
import org.usfirst.frc.team199.Robot2018.subsystems.LiftInterface.Position;
57

68
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
79

810
import edu.wpi.first.wpilibj.Encoder;
11+
import edu.wpi.first.wpilibj.SpeedControllerGroup;
12+
import edu.wpi.first.wpilibj.command.Command;
913
import edu.wpi.first.wpilibj.command.Subsystem;
1014

1115
/**
1216
*
1317
*/
1418
public class Lift extends Subsystem implements LiftInterface {
1519

16-
private final WPI_TalonSRX liftMotor = RobotMap.liftMotor;
20+
private final SpeedControllerGroup liftMotors = RobotMap.liftMotors;
1721
private final Encoder liftEnc = RobotMap.liftEnc;
18-
private Position targetPosition = Position.GROUND;
22+
private Position currPosition = Position.GROUND;
1923

2024
/**
2125
* Set the default command for a subsystem here.
2226
* */
2327
public void initDefaultCommand() {
2428
// Set the default command for a subsystem here.
2529
//setDefaultCommand(new MySpecialCommand());
30+
int ang = OI.manipulator.getPOV();
31+
Command com = null;
32+
if(ang == 0)
33+
com = new AutoLift(Position.GROUND, this);
34+
else if(ang == 90)
35+
com = new AutoLift(Position.SWITCH, this);
36+
else if(ang == 180)
37+
com = new AutoLift(Position.SWITCH, this);
38+
else if(ang == 270)
39+
com = new AutoLift(Position.SWITCH, this);
40+
if(com != null)
41+
setDefaultCommand(com);
2642
}
2743

28-
public void setTargetPosition(Position newPosition) {
29-
targetPosition = newPosition;
44+
/**
45+
* Sets the current position in the lift subsystem
46+
* @param newPosition - the new position meant to be set
47+
*/
48+
public void setCurrPosition(Position newPosition) {
49+
currPosition = newPosition;
3050
}
3151

3252
/**
3353
* Uses (insert sensor here) to detect the current lift position
3454
*/
3555
public double getHeight() {
36-
return -1;
56+
return liftEnc.getDistance() * 3;
3757
}
3858

3959
/**
4060
* stops the lift
4161
*/
4262
public void stopLift() {
43-
liftMotor.stopMotor();
63+
liftMotors.stopMotor();
4464
}
4565

4666
/**
4767
* gets current motor values
4868
*/
4969
public double getLiftSpeed() {
50-
return liftMotor.get();
70+
return liftMotors.get();
5171
}
5272

5373
/**
54-
* Goes to specified height
55-
* @param position - ground, switch, scale, bar
56-
* @param offset - distance up or down from the position
57-
*/
58-
public void goToPosition(Position position, double offset) {
59-
60-
}
61-
/**
62-
* Runs lift motor at specified speed
74+
* Runs lift motors at specified speed
6375
* @param speed - desired speed to run at
6476
*/
6577
public void runMotor(double output) {
66-
liftMotor.set(output);
78+
liftMotors.set(output);
6779
}
6880

6981
/**
7082
* Returns the position the lift is currently at
7183
* @return pos - current position
7284
*/
7385
public Position getCurrPos() {
74-
return targetPosition;
86+
return currPosition;
7587
}
7688
/**
7789
* Resets the encoder

Robot2018/src/org/usfirst/frc/team199/Robot2018/subsystems/LiftInterface.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,8 @@ public enum Position {
3131
*/
3232
public double getLiftSpeed();
3333

34-
35-
/**
36-
* Goes to specified height
37-
* @param position - ground, switch, scale, bar
38-
* @param offset - distance up or down from position
39-
*/
40-
public void goToPosition(Position position, double offset);
41-
4234
/**
43-
* Runs lift motor at specified speed
35+
* Runs lift motors at specified speed
4436
* @param speed - desired speed to run at
4537
*/
4638
public void runMotor(double speed);
@@ -60,5 +52,7 @@ public enum Position {
6052
* Sets the current position in the lift subsystem
6153
* @param newPosition - the new position meant to be set
6254
*/
63-
public void setTargetPosition(Position newPosition);
55+
public void setCurrPosition(Position newPosition);
56+
57+
6458
}

Robot2018/test/org/usfirst/frc/team199/Robot2018/LiftTester.java

Whitespace-only changes.

0 commit comments

Comments
 (0)