Skip to content

Commit af9cfa8

Browse files
committed
work please
1 parent c15d9b0 commit af9cfa8

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

src/main/java/frc/team5115/Subsystems/Drivetrain.java

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
public class Drivetrain extends SubsystemBase implements DriveBase {
1515
private Locationator locationator;
16+
1617
//instances of the speed controllers
1718
private VictorSPX frontLeft;
1819
private VictorSPX frontRight;
@@ -36,9 +37,6 @@ public Drivetrain(RobotContainer x) {
3637

3738
backRight.setInverted(true);
3839

39-
frontLeft.set(ControlMode.Follower, backLeft.getDeviceID());
40-
frontRight.set(ControlMode.Follower, backRight.getDeviceID());
41-
4240
//back motors are master
4341

4442
frontLeft.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative);
@@ -58,36 +56,36 @@ public void drive(double x, double y, double throttle) { //Change the drive outp
5856
//called lots of times per seconds.
5957
//System.out.println("Driving with X:" + x + " Y: " + y + " throttle: " + throttle);
6058
//Math.sqrt(3.4* Math.log(x + y + 1));
61-
62-
leftSpd = (x + y) * throttle;
63-
rightSpd = (x - y) * throttle;
64-
59+
//todome
60+
//System.out.println("x = " + x);
61+
//System.out.println("y = " + y);
62+
leftSpd = (x-y) * throttle;
63+
rightSpd = (x+y) * throttle;
6564
// System.out.println("Setting Right Pair to :" + (int) rightSpd * 100);
6665
// System.out.println("Setting Left Pair to :" + (int) leftSpd * 100);
6766

67+
frontLeft.set(ControlMode.PercentOutput, leftSpd);
68+
frontRight.set(ControlMode.PercentOutput, rightSpd);
6869
backLeft.set(ControlMode.PercentOutput, leftSpd);
69-
backRight.set(ControlMode.PercentOutput, -rightSpd);
70+
backRight.set(ControlMode.PercentOutput, rightSpd);
7071
}
7172

7273
public void XBoxDrive(Joystick joy) {
7374
double x = joy.getRawAxis(XBOX_X_AXIS_ID);
7475
double y = -joy.getRawAxis(XBOX_Y_AXIS_ID);
75-
System.out.println("y = " + y);
76+
7677
double throttle1 = joy.getRawAxis(XBOX_THROTTLE_1_ID);
7778
double throttle2 = joy.getRawAxis(XBOX_THROTTLE_2_ID);
7879

7980
//throttle is between 0.5 and 1
80-
double throttle = (1-throttle1) + (1-throttle2);
81+
double throttle = (1 - throttle1) + (1 - throttle2);
8182
throttle /= 2;
8283
//throttle is between 0 (dont move) and 1, (full move)
83-
throttle = ((1-MIN_XBOX_THROTTLE) * throttle) + MIN_XBOX_THROTTLE;
84+
throttle = ((1 - MIN_XBOX_THROTTLE) * throttle) + MIN_XBOX_THROTTLE;
8485
//new Throttle is now max 1 and min 0.2
8586
//System.out.println("throttle = " + throttle);
86-
x*=0.5;
87-
y*=0.4;
8887
//drive(x,y,throttle);
8988

90-
System.out.println("Remove me if working!");
9189
driveByWire(x, y, throttle);
9290
}
9391

@@ -101,54 +99,51 @@ public static double clamp(double d, double max) {
10199
}
102100

103101
@Override
104-
public void resetTargetAngle() { //set the current target angle to where we currently are.
102+
public void resetTargetAngle() { //set the current txarget angle to where we currently are.
105103
targetAngle = locationator.getAngle();
106104
System.out.println("RESET RBW: Target Angle: " + targetAngle + " Current Angle: " + locationator.getAngle());
107105
}
108106

109107
double I = 0;
110-
double lastAngle = 0;
108+
double lastAngle;
111109

112110
public void relativeAngleHold(double targetAngle, double y) {
113111
this.targetAngle = targetAngle;
114-
double kP = 0.025;
115112
double kI = 0.0;
116113
double kD = 0.1;
117114
double currentAngle = 0;
118115
// System.out.println("currentAngle = " + currentAngle);
119116
// System.out.println("lastAngle = " + lastAngle);
120117
double P = kP * (currentAngle - targetAngle);
121-
if(P < 0.2 && P > -0.2) {
118+
if (P < 0.2 && P > -0.2) {
122119
I = I + (P * kI);
123120
}
124121
double D = -kD * (lastAngle - currentAngle); //finds the difference in the last tick.
125122
double output = P + I + D;
126123
output = clamp(output, 0.5);
127-
128124
// System.out.println("P = " + P);
129125
// System.out.println("I = " + I);
130126
// System.out.println("D = " + D);
131127
// System.out.println("output = " + output);
132128
this.drive(-output, y, 1);
133129
lastAngle = currentAngle;
134130
}
135-
136-
131+
double kP = 0.1;
137132
public void angleHold(double targetAngle, double y, double throttle) {
138133
this.targetAngle = targetAngle;
139-
double kP = 0.025;
140134
double kI = 0.0;
141-
double kD = 0.1;// Hey if you are implementing a d part, use the navx.getRate
135+
double kD = .1;// Hey if you are implementing a d part, use the navx.getRate
142136
double currentAngle = locationator.getAngle();
143137
// System.out.println("currentAngle = " + currentAngle);
144138
// System.out.println("lastAngle = " + lastAngle);
145139
double P = kP * (currentAngle - targetAngle);
146-
if(P < 0.2 && P > -0.2) {
140+
if (P < 0.2 && P > -0.2) {
147141
I = I + (P * kI);
148142
}
143+
P *= (1.5-Math.abs(y));
144+
149145
double D = -kD * (lastAngle - currentAngle); //finds the difference in the last tick.
150146
double output = P + I + D;
151-
output = clamp(output, 0.5);
152147
// System.out.println("P = " + P);
153148
// System.out.println("I = " + I);
154149
// System.out.println("D = " + D);
@@ -162,10 +157,10 @@ public void angleHold(double targetAngle, double y) {
162157
}
163158

164159
public void driveByWire(double x, double y, double throttle) { //rotate by wire
165-
System.out.println("x = " + x);
166-
System.out.println("throttle = " + throttle);
167-
targetAngle += x * 2.5; //at 50 ticks a second, this is 50 degrees a second because the max x is 1.
168-
if(Math.abs(targetAngle - locationator.getAngle()) > 30) {
160+
if (Math.abs(x) < XBOX_X_DEADZONE) x = 0;
161+
targetAngle += x; //at 50 ticks a second, this is 50 degrees a second because the max x is 1.
162+
163+
if (Math.abs(targetAngle - locationator.getAngle()) > 30) {
169164
targetAngle = locationator.getAngle();
170165
}
171166
angleHold(targetAngle, y, throttle);
@@ -191,3 +186,4 @@ public double getSpeedInchesPerSecond() {
191186

192187
}
193188

189+

0 commit comments

Comments
 (0)