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

Commit 93926ff

Browse files
committed
new lift setup
made Lift extend PIDSubsystem and implemented the necessary methods for that (need to do spd --> voltage method though) made new command (UpdateLiftPosition) for continuous teleop PID --> default Lift command need to make commands for auto
1 parent ebe418e commit 93926ff

3 files changed

Lines changed: 121 additions & 19 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class Robot extends IterativeRobot {
5959
String[] fmsPossibilities = { "LL", "LR", "RL", "RR" };
6060

6161
public static SmartDashboardInterface sd = new SmartDashboardInterface() {
62+
@Override
6263
public double getConst(String key, double def) {
6364
Preferences pref = Preferences.getInstance();
6465
if (!pref.containsKey("Const/" + key)) {
@@ -71,6 +72,7 @@ public double getConst(String key, double def) {
7172
return pref.getDouble("Const/" + key, def);
7273
}
7374

75+
@Override
7476
public void putConst(String key, double def) {
7577
Preferences pref = Preferences.getInstance();
7678
pref.putDouble("Const/" + key, def);
@@ -79,14 +81,17 @@ public void putConst(String key, double def) {
7981
}
8082
}
8183

84+
@Override
8285
public void putData(String string, PIDController controller) {
8386
SmartDashboard.putData(string, controller);
8487
}
8588

89+
@Override
8690
public void putNumber(String string, double d) {
8791
SmartDashboard.putNumber(string, d);
8892
}
8993

94+
@Override
9095
public void putBoolean(String string, boolean b) {
9196
SmartDashboard.putBoolean(string, b);
9297
}
@@ -130,7 +135,8 @@ public void robotInit() {
130135
climber = new Climber();
131136
climberAssist = new ClimberAssist();
132137
intakeEject = new IntakeEject();
133-
lift = new Lift();
138+
lift = new Lift("Lift", getConst("LiftkP", 0.1), getConst("LiftkI", 0), getConst("LiftkD", 0),
139+
getConst("LiftkF", 0.1));
134140
dt = new Drivetrain(sd);
135141
oi = new OI(this);
136142

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.usfirst.frc.team199.Robot2018.commands;
2+
3+
import org.usfirst.frc.team199.Robot2018.Robot;
4+
import org.usfirst.frc.team199.Robot2018.subsystems.Lift;
5+
6+
import edu.wpi.first.wpilibj.command.Command;
7+
8+
/**
9+
* This command should be the default command for the Lift subsystem
10+
*/
11+
public class UpdateLiftPosition extends Command {
12+
13+
private Lift lift;
14+
private double targ;
15+
16+
public UpdateLiftPosition(Lift lift) {
17+
// Use requires() here to declare subsystem dependencies
18+
// eg. requires(chassis);
19+
this.lift = lift;
20+
targ = 0;
21+
}
22+
23+
// Called just before this Command runs the first time
24+
@Override
25+
protected void initialize() {
26+
/**
27+
* May need to setInputRange(0, maxHeight);
28+
*/
29+
}
30+
31+
// Called repeatedly when this Command is scheduled to run
32+
@Override
33+
protected void execute() {
34+
int angle = Robot.oi.manipulator.getPOV();
35+
/**
36+
* reference AutoLift for how to calculate targ (below) based on the given
37+
* Position enum
38+
*/
39+
if (angle == 0) {
40+
// targ = GROUND
41+
} else {
42+
// targ = SWITCH
43+
}
44+
lift.setSetpoint(targ);
45+
}
46+
47+
// Make this return true when this Command no longer needs to run execute()
48+
@Override
49+
protected boolean isFinished() {
50+
return false;
51+
}
52+
53+
// Called once after isFinished returns true
54+
@Override
55+
protected void end() {
56+
lift.disable();
57+
}
58+
59+
// Called when another command which requires one or more of the same
60+
// subsystems is scheduled to run
61+
@Override
62+
protected void interrupted() {
63+
}
64+
}

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

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
import org.usfirst.frc.team199.Robot2018.Robot;
44
import org.usfirst.frc.team199.Robot2018.RobotMap;
5-
import org.usfirst.frc.team199.Robot2018.commands.AutoLift;
5+
import org.usfirst.frc.team199.Robot2018.commands.UpdateLiftPosition;
66

77
import edu.wpi.first.wpilibj.Encoder;
88
import edu.wpi.first.wpilibj.SpeedControllerGroup;
9-
import edu.wpi.first.wpilibj.command.Command;
10-
import edu.wpi.first.wpilibj.command.Subsystem;
9+
import edu.wpi.first.wpilibj.command.PIDSubsystem;
1110

1211
/**
1312
*
1413
*/
15-
public class Lift extends Subsystem implements LiftInterface {
14+
public class Lift extends PIDSubsystem implements LiftInterface {
1615

1716
private final SpeedControllerGroup liftMotors = RobotMap.liftMotors;
1817
private final Encoder liftEnc = RobotMap.liftEnc;
@@ -21,28 +20,19 @@ public class Lift extends Subsystem implements LiftInterface {
2120
private final int NUM_STAGES;
2221
private final double WIGGLE_ROOM;
2322

24-
public Lift() {
23+
public Lift(String name, double kP, double kI, double kD, double kF) {
24+
super(name, kP, kI, kD, kF);
2525
NUM_STAGES = (int) Robot.getConst("Lift stages", 1);
2626
WIGGLE_ROOM = (int) Robot.getConst("Lift wiggle room", 3.0);
27+
enable();
2728
}
2829

2930
/**
3031
* Set the default command for a subsystem here.
3132
*/
33+
@Override
3234
public void initDefaultCommand() {
33-
// Set the default command for a subsystem here.
34-
// setDefaultCommand(new MySpecialCommand());
35-
int angle = Robot.oi.manipulator.getPOV();
36-
37-
Command com = null;
38-
39-
if (angle == 0) {
40-
com = new AutoLift(Position.GROUND, this);
41-
setDefaultCommand(com);
42-
} else if (angle == 90 || angle == 180 || angle == 270) {
43-
com = new AutoLift(Position.SWITCH, this);
44-
setDefaultCommand(com);
45-
}
35+
setDefaultCommand(new UpdateLiftPosition(this));
4636
}
4737

4838
/**
@@ -51,27 +41,31 @@ public void initDefaultCommand() {
5141
* @param newPosition
5242
* - the new position meant to be set
5343
*/
44+
@Override
5445
public void setCurrPosition(Position newPosition) {
5546
currPosition = newPosition;
5647
}
5748

5849
/**
5950
* Uses (insert sensor here) to detect the current lift position
6051
*/
52+
@Override
6153
public double getHeight() {
6254
return liftEnc.getDistance() * NUM_STAGES;
6355
}
6456

6557
/**
6658
* stops the lift
6759
*/
60+
@Override
6861
public void stopLift() {
6962
liftMotors.stopMotor();
7063
}
7164

7265
/**
7366
* gets current motor values
7467
*/
68+
@Override
7569
public double getLiftSpeed() {
7670
return liftMotors.get();
7771
}
@@ -82,6 +76,7 @@ public double getLiftSpeed() {
8276
* @param speed
8377
* - desired speed to run at
8478
*/
79+
@Override
8580
public void runMotor(double output) {
8681
liftMotors.set(output);
8782
}
@@ -91,28 +86,65 @@ public void runMotor(double output) {
9186
*
9287
* @return pos - current position
9388
*/
89+
@Override
9490
public Position getCurrPos() {
9591
return currPosition;
9692
}
9793

9894
/**
9995
* Resets the encoder
10096
*/
97+
@Override
10198
public void resetEnc() {
10299
liftEnc.reset();
103100
}
104101

105102
/**
106103
* Gets the number of stages variable
107104
*/
105+
@Override
108106
public int getNumStages() {
109107
return NUM_STAGES;
110108
}
111109

112110
/**
113111
* Gets the extra distance above the switch or scale we want to lift in inches
114112
*/
113+
@Override
115114
public double getWiggleRoom() {
116115
return WIGGLE_ROOM;
117116
}
117+
118+
/**
119+
* Uses AMT103 Encoder to detect the current lift height with respect to the
120+
* lift's min height (inches)
121+
*/
122+
@Override
123+
protected double returnPIDInput() {
124+
// return getHeight(); //Use this instead? What's the difference?
125+
return liftEnc.getDistance();
126+
}
127+
128+
/**
129+
* Runs the lift motors at the value that the pid loop calculated. Used
130+
* internally by PIDSubsystem.
131+
*/
132+
@Override
133+
protected void usePIDOutput(double output) {
134+
double out = output;
135+
double spd = liftEnc.getRate();
136+
out += convertSpdToVoltage(spd);
137+
runMotor(out);
138+
}
139+
140+
/**
141+
* Takes a value for the current lift speed and translates it to the amount of
142+
* voltage to motors need to supply.
143+
*
144+
* @param speed
145+
* - the current lift speed (in/s)
146+
*/
147+
public double convertSpdToVoltage(double speed) {
148+
return 0;
149+
}
118150
}

0 commit comments

Comments
 (0)