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

Commit 344904a

Browse files
committed
cleaned imports in oi and added update pid constants functionality
1 parent ae89def commit 344904a

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.usfirst.frc.team199.Robot2018.commands.ShiftDriveType;
1111
import org.usfirst.frc.team199.Robot2018.commands.ShiftLowGear;
12+
import org.usfirst.frc.team199.Robot2018.commands.UpdatePIDConstants;
1213

1314
import edu.wpi.first.wpilibj.Joystick;
1415
import edu.wpi.first.wpilibj.buttons.JoystickButton;
@@ -51,6 +52,7 @@ public class OI {
5152
private JoystickButton shiftDrive;
5253
private JoystickButton shiftDriveType;
5354
public Joystick rightJoy;
55+
private JoystickButton updatePidConstants;
5456
public Joystick manipulator;
5557

5658
public int getButton(String key, int def) {
@@ -66,7 +68,11 @@ public OI() {
6668
shiftDrive.whenPressed(new ShiftLowGear());
6769
shiftDriveType = new JoystickButton(leftJoy, getButton("Shift Drive Type", 2));
6870
shiftDriveType.whenPressed(new ShiftDriveType());
71+
6972
rightJoy = new Joystick(1);
73+
updatePidConstants = new JoystickButton(rightJoy, getButton("Get PID Constants", 8));
74+
updatePidConstants.whenPressed(new UpdatePIDConstants());
75+
7076
manipulator = new Joystick(2);
7177
}
7278
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.usfirst.frc.team199.Robot2018.commands;
2+
3+
import org.usfirst.frc.team199.Robot2018.Robot;
4+
5+
import edu.wpi.first.wpilibj.Timer;
6+
import edu.wpi.first.wpilibj.command.Command;
7+
8+
/**
9+
*
10+
*/
11+
public class UpdatePIDConstants extends Command {
12+
13+
Timer tim;
14+
15+
public UpdatePIDConstants() {
16+
// Use requires() here to declare subsystem dependencies
17+
// eg. requires(chassis);
18+
}
19+
20+
// Called just before this Command runs the first time
21+
protected void initialize() {
22+
tim = new Timer();
23+
tim.reset();
24+
tim.start();
25+
}
26+
27+
// Called repeatedly when this Command is scheduled to run
28+
protected void execute() {
29+
Robot.dt.updatePidConstants();
30+
}
31+
32+
// Make this return true when this Command no longer needs to run execute()
33+
protected boolean isFinished() {
34+
return tim.get() > Robot.getConst("Update Constants Time", 0.1);
35+
}
36+
37+
// Called once after isFinished returns true
38+
protected void end() {
39+
}
40+
41+
// Called when another command which requires one or more of the same
42+
// subsystems is scheduled to run
43+
protected void interrupted() {
44+
end();
45+
}
46+
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ public class Drivetrain extends Subsystem implements PIDOutput, PIDSource {
4242

4343
private double pidOut = 0;
4444

45+
/**
46+
* Updates the PIDControllers' PIDConstants based on SmartDashboard values
47+
*/
48+
public void updatePidConstants() {
49+
turnController.setPID(Robot.getConst("TurnkP", 1), Robot.getConst("TurnkI", 0), Robot.getConst("TurnkD", 0));
50+
moveController.setPID(Robot.getConst("MovekP", 1), Robot.getConst("MovekI", 0), Robot.getConst("MovekD", 0));
51+
}
52+
4553
/**
4654
* Activates the solenoid to push the drivetrain into low or high gear
4755
*

0 commit comments

Comments
 (0)