Skip to content

Commit 17a9dd3

Browse files
authored
1.0.9
1.0.9
2 parents c1c4aa4 + fad3290 commit 17a9dd3

24 files changed

+298
-504
lines changed

build.gradle.kts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,7 @@ dependencies {
7979
compileOnly("org.firstinspires.ftc:FtcCommon:10.2.0")
8080
compileOnly("org.firstinspires.ftc:RobotServer:10.2.0")
8181
compileOnly("org.firstinspires.ftc:OnBotJava:10.2.0")
82-
83-
84-
85-
implementation("com.acmerobotics.dashboard:dashboard:0.4.16") {
86-
exclude(group = "org.firstinspires.ftc")
87-
}
82+
compileOnly("com.acmerobotics.dashboard:dashboard:0.4.16")
8883

8984
implementation("org.apache.commons:commons-math3:3.6.1")
9085
dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.9.20")
@@ -98,7 +93,7 @@ publishing {
9893
register<MavenPublication>("release") {
9994
groupId = "com.pedropathing"
10095
artifactId = "pedro"
101-
version = "1.0.8"
96+
version = "1.0.9"
10297

10398
afterEvaluate {
10499
from(components["release"])

maven.pedropathing.com

src/main/java/com/pedropathing/follower/Follower.java

Lines changed: 155 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333
import com.acmerobotics.dashboard.config.Config;
3434
import com.acmerobotics.dashboard.telemetry.MultipleTelemetry;
35+
import com.pedropathing.util.Constants;
36+
import com.pedropathing.util.CustomFilteredPIDFCoefficients;
37+
import com.pedropathing.util.CustomPIDFCoefficients;
3538
import com.qualcomm.robotcore.hardware.DcMotor;
3639
import com.qualcomm.robotcore.hardware.DcMotorEx;
3740
import com.qualcomm.robotcore.hardware.HardwareMap;
@@ -91,25 +94,25 @@ public class Follower {
9194

9295
private PathChain currentPathChain;
9396

94-
private final int BEZIER_CURVE_SEARCH_LIMIT = FollowerConstants.BEZIER_CURVE_SEARCH_LIMIT;
95-
private final int AVERAGED_VELOCITY_SAMPLE_NUMBER = FollowerConstants.AVERAGED_VELOCITY_SAMPLE_NUMBER;
97+
private int BEZIER_CURVE_SEARCH_LIMIT;
98+
private int AVERAGED_VELOCITY_SAMPLE_NUMBER;
9699

97100
private int chainIndex;
98101

99102
private long[] pathStartTimes;
100103

101104
private boolean followingPathChain;
102105
private boolean holdingPosition;
103-
private boolean isBusy;
106+
private boolean isBusy, isTurning;
104107
private boolean reachedParametricPathEnd;
105108
private boolean holdPositionAtEnd;
106109
private boolean teleopDrive;
107110

108111
private double globalMaxPower = 1;
109112
private double previousSecondaryTranslationalIntegral;
110113
private double previousTranslationalIntegral;
111-
private double holdPointTranslationalScaling = FollowerConstants.holdPointTranslationalScaling;
112-
private double holdPointHeadingScaling = FollowerConstants.holdPointHeadingScaling;
114+
private double holdPointTranslationalScaling;
115+
private double holdPointHeadingScaling;
113116
public double driveError;
114117
public double headingError;
115118

@@ -134,21 +137,22 @@ public class Follower {
134137
public Vector centripetalVector;
135138
public Vector correctiveVector;
136139

137-
private double centripetalScaling = FollowerConstants.centripetalScaling;
140+
private double centripetalScaling;
138141

139-
private PIDFController secondaryTranslationalPIDF = new PIDFController(FollowerConstants.secondaryTranslationalPIDFCoefficients);
140-
private PIDFController secondaryTranslationalIntegral = new PIDFController(FollowerConstants.secondaryTranslationalIntegral);
141-
private PIDFController translationalPIDF = new PIDFController(FollowerConstants.translationalPIDFCoefficients);
142-
private PIDFController translationalIntegral = new PIDFController(FollowerConstants.translationalIntegral);
143-
private PIDFController secondaryHeadingPIDF = new PIDFController(FollowerConstants.secondaryHeadingPIDFCoefficients);
144-
private PIDFController headingPIDF = new PIDFController(FollowerConstants.headingPIDFCoefficients);
145-
private FilteredPIDFController secondaryDrivePIDF = new FilteredPIDFController(FollowerConstants.secondaryDrivePIDFCoefficients);
146-
private FilteredPIDFController drivePIDF = new FilteredPIDFController(FollowerConstants.drivePIDFCoefficients);
142+
private PIDFController secondaryTranslationalPIDF;
143+
private PIDFController secondaryTranslationalIntegral;
144+
private PIDFController translationalPIDF;
145+
private PIDFController translationalIntegral;
146+
private PIDFController secondaryHeadingPIDF;
147+
private PIDFController headingPIDF;
148+
private FilteredPIDFController secondaryDrivePIDF;
149+
private FilteredPIDFController drivePIDF;
147150

148-
private KalmanFilter driveKalmanFilter = new KalmanFilter(FollowerConstants.driveKalmanFilterParameters);
151+
private KalmanFilter driveKalmanFilter;
149152
private double[] driveErrors;
150153
private double rawDriveError;
151154
private double previousRawDriveError;
155+
private double turnHeadingErrorThreshold;
152156

153157
public static boolean drawOnDashboard = true;
154158
public static boolean useTranslational = true;
@@ -175,8 +179,9 @@ public class Follower {
175179
* This creates a new Follower given a HardwareMap.
176180
* @param hardwareMap HardwareMap required
177181
*/
178-
public Follower(HardwareMap hardwareMap) {
182+
public Follower(HardwareMap hardwareMap, Class<?> FConstants, Class<?> LConstants) {
179183
this.hardwareMap = hardwareMap;
184+
setupConstants(FConstants, LConstants);
180185
initialize();
181186
}
182187

@@ -185,11 +190,36 @@ public Follower(HardwareMap hardwareMap) {
185190
* @param hardwareMap HardwareMap required
186191
* @param localizer the localizer you wish to use
187192
*/
188-
public Follower(HardwareMap hardwareMap, Localizer localizer) {
193+
public Follower(HardwareMap hardwareMap, Localizer localizer, Class<?> FConstants, Class<?> LConstants) {
189194
this.hardwareMap = hardwareMap;
195+
setupConstants(FConstants, LConstants);
190196
initialize(localizer);
191197
}
192198

199+
/**
200+
* Setup constants for the Follower.
201+
* @param FConstants the constants for the Follower
202+
* @param LConstants the constants for the Localizer
203+
*/
204+
public void setupConstants(Class<?> FConstants, Class<?> LConstants) {
205+
Constants.setConstants(FConstants, LConstants);
206+
BEZIER_CURVE_SEARCH_LIMIT = FollowerConstants.BEZIER_CURVE_SEARCH_LIMIT;
207+
AVERAGED_VELOCITY_SAMPLE_NUMBER = FollowerConstants.AVERAGED_VELOCITY_SAMPLE_NUMBER;
208+
holdPointTranslationalScaling = FollowerConstants.holdPointTranslationalScaling;
209+
holdPointHeadingScaling = FollowerConstants.holdPointHeadingScaling;
210+
centripetalScaling = FollowerConstants.centripetalScaling;
211+
secondaryTranslationalPIDF = new PIDFController(FollowerConstants.secondaryTranslationalPIDFCoefficients);
212+
secondaryTranslationalIntegral = new PIDFController(FollowerConstants.secondaryTranslationalIntegral);
213+
translationalPIDF = new PIDFController(FollowerConstants.translationalPIDFCoefficients);
214+
translationalIntegral = new PIDFController(FollowerConstants.translationalIntegral);
215+
secondaryHeadingPIDF = new PIDFController(FollowerConstants.secondaryHeadingPIDFCoefficients);
216+
headingPIDF = new PIDFController(FollowerConstants.headingPIDFCoefficients);
217+
secondaryDrivePIDF = new FilteredPIDFController(FollowerConstants.secondaryDrivePIDFCoefficients);
218+
drivePIDF = new FilteredPIDFController(FollowerConstants.drivePIDFCoefficients);
219+
driveKalmanFilter = new KalmanFilter(FollowerConstants.driveKalmanFilterParameters);
220+
turnHeadingErrorThreshold = FollowerConstants.turnHeadingErrorThreshold;
221+
}
222+
193223
/**
194224
* This initializes the follower.
195225
* In this, the DriveVectorScaler and PoseUpdater is instantiated, the drive motors are
@@ -601,6 +631,11 @@ public void update() {
601631
}
602632
}
603633
}
634+
635+
if(headingError < turnHeadingErrorThreshold && isTurning) {
636+
isTurning = false;
637+
isBusy = false;
638+
}
604639
} else {
605640
if (isBusy) {
606641
closestPose = currentPath.getClosestPoint(poseUpdater.getPose(), BEZIER_CURVE_SEARCH_LIMIT);
@@ -1277,13 +1312,17 @@ public void refreshVoltage() {
12771312
public void turn(double radians, boolean isLeft) {
12781313
Pose temp = new Pose(getPose().getX(), getPose().getY(), getPose().getHeading() + (isLeft ? radians : -radians));
12791314
holdPoint(temp);
1315+
isTurning = true;
1316+
isBusy = true;
12801317
}
12811318

12821319
/** Turns to a specific heading
12831320
* @param radians the heading in radians to turn to
12841321
*/
12851322
public void turnTo(double radians) {
12861323
holdPoint(new Pose(getPose().getX(), getPose().getY(), Math.toRadians(radians)));
1324+
isTurning = true;
1325+
isBusy = true;
12871326
}
12881327

12891328
/** Turns to a specific heading in degrees
@@ -1300,4 +1339,103 @@ public void turnToDegrees(double degrees) {
13001339
public void turnDegrees(double degrees, boolean isLeft) {
13011340
turn(Math.toRadians(degrees), isLeft);
13021341
}
1342+
1343+
public boolean isTurning() {
1344+
return isTurning;
1345+
}
1346+
1347+
/**
1348+
* This will update the PIDF coefficients for primary Heading PIDF mid run
1349+
* can be used between paths
1350+
*
1351+
* @param set PIDF coefficients you would like to set.
1352+
*/
1353+
public void setHeadingPIDF(CustomPIDFCoefficients set){
1354+
headingPIDF.setCoefficients(set);
1355+
}
1356+
1357+
/**
1358+
* This will update the PIDF coefficients for primary Translational PIDF mid run
1359+
* can be used between paths
1360+
*
1361+
* @param set PIDF coefficients you would like to set.
1362+
*/
1363+
public void setTranslationalPIDF(CustomPIDFCoefficients set){
1364+
translationalPIDF.setCoefficients(set);
1365+
}
1366+
1367+
/**
1368+
* This will update the PIDF coefficients for primary Drive PIDF mid run
1369+
* can be used between paths
1370+
*
1371+
* @param set PIDF coefficients you would like to set.
1372+
*/
1373+
public void setDrivePIDF(CustomFilteredPIDFCoefficients set){
1374+
drivePIDF.setCoefficients(set);
1375+
}
1376+
1377+
/**
1378+
* This will update the PIDF coefficients for secondary Heading PIDF mid run
1379+
* can be used between paths
1380+
*
1381+
* @param set PIDF coefficients you would like to set.
1382+
*/
1383+
public void setSecondaryHeadingPIDF(CustomPIDFCoefficients set){
1384+
secondaryHeadingPIDF.setCoefficients(set);
1385+
}
1386+
1387+
/**
1388+
* This will update the PIDF coefficients for secondary Translational PIDF mid run
1389+
* can be used between paths
1390+
*
1391+
* @param set PIDF coefficients you would like to set.
1392+
*/
1393+
public void setSecondaryTranslationalPIDF(CustomPIDFCoefficients set){
1394+
secondaryTranslationalPIDF.setCoefficients(set);
1395+
}
1396+
1397+
/**
1398+
* This will update the PIDF coefficients for secondary Drive PIDF mid run
1399+
* can be used between paths
1400+
*
1401+
* @param set PIDF coefficients you would like to set.
1402+
*/
1403+
public void setSecondaryDrivePIDF(CustomFilteredPIDFCoefficients set){
1404+
secondaryDrivePIDF.setCoefficients(set);
1405+
}
1406+
1407+
/**
1408+
* Checks if the robot is at a certain point within certain tolerances
1409+
* @param point Point to compare with the current point
1410+
* @param xTolerance Tolerance for the x position
1411+
* @param yTolerance Tolerance for the y position
1412+
*/
1413+
public boolean atPoint(Point point, double xTolerance, double yTolerance) {
1414+
return Math.abs(point.getX() - getPose().getX()) < xTolerance && Math.abs(point.getY() - getPose().getY()) < yTolerance;
1415+
}
1416+
1417+
/**
1418+
* Checks if the robot is at a certain pose within certain tolerances
1419+
* @param pose Pose to compare with the current pose
1420+
* @param xTolerance Tolerance for the x position
1421+
* @param yTolerance Tolerance for the y position
1422+
* @param headingTolerance Tolerance for the heading
1423+
*/
1424+
public boolean atPose(Pose pose, double xTolerance, double yTolerance, double headingTolerance) {
1425+
return Math.abs(pose.getX() - getPose().getX()) < xTolerance && Math.abs(pose.getY() - getPose().getY()) < yTolerance && Math.abs(pose.getHeading() - getPose().getHeading()) < headingTolerance;
1426+
}
1427+
1428+
/**
1429+
* Checks if the robot is at a certain pose within certain tolerances
1430+
* @param pose Pose to compare with the current pose
1431+
* @param xTolerance Tolerance for the x position
1432+
* @param yTolerance Tolerance for the y position
1433+
*/
1434+
public boolean atPose(Pose pose, double xTolerance, double yTolerance) {
1435+
return Math.abs(pose.getX() - getPose().getX()) < xTolerance && Math.abs(pose.getY() - getPose().getY()) < yTolerance;
1436+
}
1437+
1438+
public double getHeadingError() {
1439+
return headingError;
1440+
}
13031441
}

src/main/java/com/pedropathing/follower/FollowerConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,9 @@ public class FollowerConstants {
345345
* Will only read voltage if useVoltageCompensation is true.
346346
* Default Value: 0.5 */
347347
public static double cacheInvalidateSeconds = 0.5;
348+
349+
/** Threshold that the turn and turnTo methods will be considered to be finished
350+
* In Radians
351+
* Default Value: 0.01 */
352+
public static double turnHeadingErrorThreshold = 0.01;
348353
}

0 commit comments

Comments
 (0)