44import com .ctre .phoenix .motorcontrol .FeedbackDevice ;
55import com .ctre .phoenix .motorcontrol .can .TalonSRX ;
66import com .ctre .phoenix .motorcontrol .can .VictorSPX ;
7+ import edu .wpi .first .networktables .NetworkTable ;
8+ import edu .wpi .first .networktables .NetworkTableEntry ;
9+ import edu .wpi .first .networktables .NetworkTableInstance ;
710import edu .wpi .first .wpilibj .DriverStation ;
811import edu .wpi .first .wpilibj .Joystick ;
912import edu .wpi .first .wpilibj .Servo ;
13+ import edu .wpi .first .wpilibj .shuffleboard .Shuffleboard ;
14+ import edu .wpi .first .wpilibj .smartdashboard .SmartDashboard ;
1015import edu .wpi .first .wpilibj2 .command .SubsystemBase ;
1116import frc .team5115 .Auto .DriveBase ;
17+ import frc .team5115 .Auto .Loc2D ;
1218import frc .team5115 .Robot .Robot ;
1319import frc .team5115 .Robot .RobotContainer ;
1420import io .github .oblarg .oblog .Loggable ;
21+ import io .github .oblarg .oblog .annotations .Log ;
1522
1623import static frc .team5115 .Configuration .Constants .*;
1724
1825public class Drivetrain extends SubsystemBase implements DriveBase , Loggable {
1926 private Locationator locationator ;
2027
21- private DriverStation driverStation = DriverStation .getInstance ();
22-
2328 //instances of the speed controllers
2429 private VictorSPX frontLeft ;
2530 private VictorSPX frontRight ;
2631 private TalonSRX backLeft ;
2732 private TalonSRX backRight ;
2833
34+
35+ NetworkTable networkTable = NetworkTableInstance .getDefault ().getTable ("SmartDashboard" );
36+ NetworkTableEntry t ;
37+ NetworkTableEntry l ;
38+
2939 Servo servo ;
3040
41+
3142 private double targetAngle ; //during regular operation, the drive train keeps control of the drive. This is the angle that it targets.
3243
3344 private double rightSpd ;
@@ -37,10 +48,13 @@ public class Drivetrain extends SubsystemBase implements DriveBase, Loggable {
3748
3849 double throttle = .7 ;
3950
51+ Loc2D targetLocation ;
52+
4053 private RobotContainer robotContainer ;
4154
4255 public Drivetrain (RobotContainer x ) {
4356 //this.locationator = x.locationator;
57+
4458 robotContainer = x ;
4559
4660 servo = new Servo (1 );
@@ -51,6 +65,7 @@ public Drivetrain(RobotContainer x) {
5165 backLeft = new TalonSRX (BACK_LEFT_MOTOR_ID );
5266 backRight = new TalonSRX (BACK_RIGHT_MOTOR_ID );
5367
68+
5469 //backRight.setInverted(true);
5570
5671 //back motors are master
@@ -60,6 +75,17 @@ public Drivetrain(RobotContainer x) {
6075 backLeft .configSelectedFeedbackSensor (FeedbackDevice .CTRE_MagEncoder_Relative );
6176 backRight .configSelectedFeedbackSensor (FeedbackDevice .CTRE_MagEncoder_Relative );
6277 lastAngle = locationator .getAngle ();
78+
79+ targetLocation = new Loc2D (
80+ locationator .getCurrentLocation ().getX (), //goes strait forward.
81+ 90 );
82+
83+
84+ t = networkTable .getEntry ("Throttle" );
85+ l = networkTable .getEntry ("Target Location" );
86+
87+ t .setDouble (throttle );
88+ l .setDouble (locationator .getCurrentLocation ().distanceFrom (targetLocation ));
6389 }
6490
6591 @ Override
@@ -86,6 +112,7 @@ public void drive(double x, double y, double throttle) { //Change the drive outp
86112 backRight .set (ControlMode .PercentOutput , rightSpd );
87113
88114 //System.out.println("servo.get() = " + servo.get());
115+
89116 }
90117
91118 public double throttle (double increase , double decrease ) {
@@ -240,6 +267,19 @@ public void debug() {
240267 System .out .println ("getSpeed() = " + 15 *getSpeed ());
241268 }
242269
270+ public void printThrottle () {
271+ System .out .println ("throttle = " + throttle );
272+ }
273+
274+ public void resetCameraAngle () {
275+ servo .setAngle (DRIVING_CAM_MIN_ANGLE );
276+ }
277+
278+ public void update () {
279+ t .setValue (throttle );
280+ l .setDouble (locationator .getCurrentLocation ().distanceFrom (targetLocation ));
281+ }
282+
243283}
244284
245285
0 commit comments