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

Commit 7e88dbd

Browse files
committed
added basic velocityPID functionality to the drivetrain using the talons. Not implemented yet
1 parent 4937c90 commit 7e88dbd

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

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)