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

Commit df84a71

Browse files
caengineerscaengineers
authored andcommitted
Merge remote-tracking branch 'dadavid/master'
2 parents 6d823a3 + f840cef commit df84a71

4 files changed

Lines changed: 90 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.usfirst.frc.team199.Robot2018.commands.Autonomous;
1616
import org.usfirst.frc.team199.Robot2018.commands.Autonomous.Position;
1717
import org.usfirst.frc.team199.Robot2018.commands.Autonomous.Strategy;
18+
import org.usfirst.frc.team199.Robot2018.commands.ShiftLowGear;
1819
import org.usfirst.frc.team199.Robot2018.subsystems.Climber;
1920
import org.usfirst.frc.team199.Robot2018.subsystems.ClimberAssist;
2021
import org.usfirst.frc.team199.Robot2018.subsystems.Drivetrain;
@@ -108,6 +109,7 @@ public void robotInit() {
108109
// auto delay chooser
109110
SmartDashboard.putNumber("Auto Delay", 0);
110111

112+
111113
// parse scripts from Preferences, which maintains values throughout
112114
// reboots
113115
autoScripts = AutoUtils.parseScriptFile(Preferences.getInstance().getString("autoscripts", ""));
@@ -137,6 +139,7 @@ public void disabledPeriodic() {
137139
*/
138140
@Override
139141
public void autonomousInit() {
142+
Scheduler.getInstance().add(new ShiftLowGear());
140143
String fmsInput = DriverStation.getInstance().getGameSpecificMessage();
141144
Position startPos = posChooser.getSelected();
142145
double autoDelay = SmartDashboard.getNumber("Auto Delay", 0);

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public RobotMap() {
122122
dtLeft = new SpeedControllerGroup(dtLeftMaster, dtLeftSlave);
123123

124124
leftVelocityController = new VelocityPIDController(Robot.getConst("VelocityLeftkP", 1),
125-
Robot.getConst("VelocityLeftkI", 0), Robot.getConst("VelocityLeftkD", 0),
125+
Robot.getConst("VelocityLeftkI", 0), Robot.getConst("VelocityLeftkD", calcDefkD()),
126126
1 / Robot.getConst("Max Low Speed", 84), leftEncRate, dtLeft);
127127
leftVelocityController.enable();
128128
leftVelocityController.setInputRange(-Robot.getConst("Max High Speed", 204),
@@ -144,7 +144,7 @@ public RobotMap() {
144144
dtRight = new SpeedControllerGroup(dtRightMaster, dtRightSlave);
145145

146146
rightVelocityController = new VelocityPIDController(Robot.getConst("VelocityRightkP", 1),
147-
Robot.getConst("VelocityRightkI", 0), Robot.getConst("VelocityRightkD", 0),
147+
Robot.getConst("VelocityRightkI", 0), Robot.getConst("VelocityRightkD", calcDefkD()),
148148
1 / Robot.getConst("Max Low Speed", 84), rightEncRate, dtRight);
149149
rightVelocityController.enable();
150150
rightVelocityController.setInputRange(-Robot.getConst("Max High Speed", 204),
@@ -181,4 +181,15 @@ public int getPort(String key, int def) {
181181
return (int) SmartDashboard.getNumber("Port/" + key, def);
182182
}
183183

184+
/**
185+
* Uses SmartDashboard and math to calculate a *great* default kD
186+
*/
187+
public double calcDefkD() {
188+
double timeConstant = Robot.getConst("Omega Max", 5330) * Robot.getConst("Mass of Robot", 54.4311)
189+
* Robot.getConst("Radius of Drivetrain Wheel", 0.0635)
190+
* Robot.getConst("Radius of Drivetrain Wheel", 0.0635) / Robot.getConst("Stall Torque", 2.41);
191+
double cycleTime = Robot.getConst("Code cycle time", 0.1);
192+
double denominator = 1 - Math.pow(Math.E, -1 * cycleTime / timeConstant);
193+
return 1 / denominator;
194+
}
184195
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.usfirst.frc.team199.Robot2018.commands;
2+
3+
import org.usfirst.frc.team199.Robot2018.Robot;
4+
5+
import edu.wpi.first.wpilibj.command.Command;
6+
7+
/**
8+
*
9+
*/
10+
public class TalonDrive extends Command {
11+
12+
public TalonDrive() {
13+
// Use requires() here to declare subsystem dependencies
14+
// eg. requires(chassis);
15+
}
16+
17+
// Called just before this Command runs the first time
18+
protected void initialize() {
19+
}
20+
21+
// Called repeatedly when this Command is scheduled to run
22+
protected void execute() {
23+
Robot.dt.dtRightPIDDrive(Robot.oi.leftJoy.getY());
24+
Robot.dt.dtLeftPIDDrive(Robot.oi.rightJoy.getY());
25+
}
26+
27+
// Make this return true when this Command no longer needs to run execute()
28+
protected boolean isFinished() {
29+
return false;
30+
}
31+
32+
// Called once after isFinished returns true
33+
protected void end() {
34+
}
35+
36+
// Called when another command which requires one or more of the same
37+
// subsystems is scheduled to run
38+
protected void interrupted() {
39+
end();
40+
}
41+
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import org.usfirst.frc.team199.Robot2018.autonomous.VelocityPIDController;
1414
import org.usfirst.frc.team199.Robot2018.commands.TeleopDrive;
1515

16+
import com.ctre.phoenix.motorcontrol.ControlMode;
17+
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
18+
import com.ctre.phoenix.motorcontrol.can.WPI_VictorSPX;
1619
import com.kauailabs.navx.frc.AHRS;
1720

1821
import edu.wpi.first.wpilibj.DoubleSolenoid;
@@ -25,6 +28,10 @@ public class Drivetrain extends Subsystem implements DrivetrainInterface {
2528
// Put methods for controlling this subsystem
2629
// here. Call these from Commands.
2730

31+
private final WPI_TalonSRX dtLeftMaster = RobotMap.dtLeftMaster;
32+
private final WPI_VictorSPX dtLeftSlave = RobotMap.dtLeftSlave;
33+
private final WPI_TalonSRX dtRightMaster = RobotMap.dtRightMaster;
34+
private final WPI_VictorSPX dtRightSlave = RobotMap.dtRightSlave;
2835
private final Encoder leftEncDist = RobotMap.leftEncDist;
2936
private final Encoder rightEncDist = RobotMap.rightEncDist;
3037
private final PIDSourceAverage distEncAvg = RobotMap.distEncAvg;
@@ -42,6 +49,32 @@ public void initDefaultCommand() {
4249
setDefaultCommand(new TeleopDrive());
4350
}
4451

52+
/**
53+
* Sets the left side of the drivetrain to use the talons' pids to run at the
54+
* specified speed.
55+
*
56+
* @param value
57+
* The speed to run at
58+
*/
59+
public void dtLeftPIDDrive(double value) {
60+
double setValue = value * Robot.getConst("Units per 100ms", 3413);
61+
dtLeftMaster.set(ControlMode.Velocity, setValue);
62+
dtLeftSlave.set(ControlMode.Velocity, setValue);
63+
}
64+
65+
/**
66+
* Sets the right side of the drivetrain to use the talons' pids to run at the
67+
* specified speed.
68+
*
69+
* @param value
70+
* The speed to run at
71+
*/
72+
public void dtRightPIDDrive(double value) {
73+
double setValue = value * Robot.getConst("Units per 100ms", 3413);
74+
dtRightMaster.set(ControlMode.Velocity, setValue);
75+
dtRightSlave.set(ControlMode.Velocity, setValue);
76+
}
77+
4578
/**
4679
* Drives based on joystick input and SmartDashboard values
4780
*/

0 commit comments

Comments
 (0)