Compare commits
18 Commits
0ab402af0f
...
branch-bob
Author | SHA1 | Date | |
---|---|---|---|
bee78d7d71 | |||
b442008fb6 | |||
4e8c37e01b | |||
6a125ff247 | |||
1c4b3723c3 | |||
7a028835f8 | |||
cd10d3a01b | |||
89f4c1b9a0 | |||
6f784936d2 | |||
945a77ca49 | |||
43c505e292 | |||
5cec300e58 | |||
00146b2e40 | |||
ba5e1e6fe4 | |||
a64a558f2f | |||
99099bf78f | |||
efd3302645 | |||
a7f060c3eb |
@ -0,0 +1,122 @@
|
|||||||
|
package org.firstinspires.ftc.teamcode;
|
||||||
|
|
||||||
|
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_LEFT_MOTOR;
|
||||||
|
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_RIGHT_MOTOR;
|
||||||
|
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_LEFT_MOTOR;
|
||||||
|
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_RIGHT_MOTOR;
|
||||||
|
|
||||||
|
import com.acmerobotics.dashboard.FtcDashboard;
|
||||||
|
import com.acmerobotics.dashboard.config.Config;
|
||||||
|
import com.acmerobotics.dashboard.telemetry.MultipleTelemetry;
|
||||||
|
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
|
||||||
|
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
|
||||||
|
import com.qualcomm.robotcore.hardware.DcMotor;
|
||||||
|
import com.qualcomm.robotcore.hardware.DcMotorEx;
|
||||||
|
|
||||||
|
import org.firstinspires.ftc.robotcore.external.Telemetry;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.follower.Follower;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Pose;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierCurve;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierLine;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.PathChain;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Point;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the Circle autonomous OpMode. It runs the robot in a PathChain that's actually not quite
|
||||||
|
* a circle, but some Bezier curves that have control points set essentially in a square. However,
|
||||||
|
* it turns enough to tune your centripetal force correction and some of your heading. Some lag in
|
||||||
|
* heading is to be expected.
|
||||||
|
*
|
||||||
|
* @author Anyi Lin - 10158 Scott's Bots
|
||||||
|
* @author Aaron Yang - 10158 Scott's Bots
|
||||||
|
* @author Harrison Womack - 10158 Scott's Bots
|
||||||
|
* @version 1.0, 3/12/2024
|
||||||
|
*/
|
||||||
|
@Config
|
||||||
|
@Autonomous(name = "AutoExample", group = "Autonomous Pathing Tuning")
|
||||||
|
public class AutoExample extends OpMode {
|
||||||
|
private Telemetry telemetryA;
|
||||||
|
|
||||||
|
private Follower follower;
|
||||||
|
|
||||||
|
private PathChain path;
|
||||||
|
|
||||||
|
private final Pose startPose = new Pose(12.0, 11, 90);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This initializes the Follower and creates the PathChain for the "circle". Additionally, this
|
||||||
|
* initializes the FTC Dashboard telemetry.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
follower = new Follower(hardwareMap);
|
||||||
|
|
||||||
|
follower.setMaxPower(.6);
|
||||||
|
|
||||||
|
follower.setStartingPose(startPose);
|
||||||
|
|
||||||
|
path = follower.pathBuilder()
|
||||||
|
.addPath(
|
||||||
|
// Line 1
|
||||||
|
new BezierLine(
|
||||||
|
new Point(12.804, 11.223, Point.CARTESIAN),
|
||||||
|
new Point(12.804, 42.362, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setTangentHeadingInterpolation()
|
||||||
|
.addPath(
|
||||||
|
// Line 2
|
||||||
|
new BezierCurve(
|
||||||
|
new Point(12.804, 42.362, Point.CARTESIAN),
|
||||||
|
new Point(11.381, 57.379, Point.CARTESIAN),
|
||||||
|
new Point(31.614, 56.588, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setTangentHeadingInterpolation()
|
||||||
|
.addPath(
|
||||||
|
// Line 3
|
||||||
|
new BezierLine(
|
||||||
|
new Point(31.614, 56.588, Point.CARTESIAN),
|
||||||
|
new Point(51.214, 56.746, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setTangentHeadingInterpolation()
|
||||||
|
.addPath(
|
||||||
|
// Line 4
|
||||||
|
new BezierCurve(
|
||||||
|
new Point(51.214, 56.746, Point.CARTESIAN),
|
||||||
|
new Point(64.334, 58.643, Point.CARTESIAN),
|
||||||
|
new Point(61.172, 45.524, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setTangentHeadingInterpolation()
|
||||||
|
.addPath(
|
||||||
|
// Line 5
|
||||||
|
new BezierCurve(
|
||||||
|
new Point(61.172, 45.524, Point.CARTESIAN),
|
||||||
|
new Point(36.198, 26.239, Point.CARTESIAN),
|
||||||
|
new Point(19.759, 11.065, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setTangentHeadingInterpolation()
|
||||||
|
.build();
|
||||||
|
|
||||||
|
follower.followPath(path);
|
||||||
|
|
||||||
|
telemetryA = new MultipleTelemetry(this.telemetry, FtcDashboard.getInstance().getTelemetry());
|
||||||
|
telemetryA.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This runs the OpMode, updating the Follower as well as printing out the debug statements to
|
||||||
|
* the Telemetry, as well as the FTC Dashboard.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void loop() {
|
||||||
|
follower.update();
|
||||||
|
if (follower.atParametricEnd()) {
|
||||||
|
follower.followPath(path);
|
||||||
|
}
|
||||||
|
follower.telemetryDebug(telemetryA);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package org.firstinspires.ftc.teamcode.cometbots;
|
package org.firstinspires.ftc.teamcode;
|
||||||
|
|
||||||
import com.acmerobotics.dashboard.FtcDashboard;
|
import com.acmerobotics.dashboard.FtcDashboard;
|
||||||
import com.acmerobotics.dashboard.config.Config;
|
import com.acmerobotics.dashboard.config.Config;
|
||||||
@ -9,7 +9,6 @@ import com.qualcomm.robotcore.eventloop.opmode.OpMode;
|
|||||||
import org.firstinspires.ftc.robotcore.external.Telemetry;
|
import org.firstinspires.ftc.robotcore.external.Telemetry;
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.follower.Follower;
|
import org.firstinspires.ftc.teamcode.pedroPathing.follower.Follower;
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Pose;
|
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Pose;
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierCurve;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierLine;
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierLine;
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.PathChain;
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.PathChain;
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Point;
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Point;
|
||||||
@ -26,15 +25,15 @@ import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Point;
|
|||||||
* @version 1.0, 3/12/2024
|
* @version 1.0, 3/12/2024
|
||||||
*/
|
*/
|
||||||
@Config
|
@Config
|
||||||
@Autonomous(name = "BlueNonBasketAuto", group = "Autonomous Pathing Tuning")
|
@Autonomous(name = "AutoExampleSeason2025V1", group = "Autonomous Pathing Tuning")
|
||||||
public class BlueNonBasketAuto extends OpMode {
|
public class AutoExampleSeason2025V1 extends OpMode {
|
||||||
private Telemetry telemetryA;
|
private Telemetry telemetryA;
|
||||||
|
|
||||||
private Follower follower;
|
private Follower follower;
|
||||||
|
|
||||||
private PathChain path;
|
private PathChain path;
|
||||||
|
|
||||||
private final Pose startPose = new Pose(10.929, 55.446, 0);
|
private final Pose startPose = new Pose(15.0, 35, 90);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This initializes the Follower and creates the PathChain for the "circle". Additionally, this
|
* This initializes the Follower and creates the PathChain for the "circle". Additionally, this
|
||||||
@ -44,93 +43,85 @@ public class BlueNonBasketAuto extends OpMode {
|
|||||||
public void init() {
|
public void init() {
|
||||||
follower = new Follower(hardwareMap);
|
follower = new Follower(hardwareMap);
|
||||||
|
|
||||||
follower.setMaxPower(.45);
|
follower.setMaxPower(.375);
|
||||||
|
|
||||||
follower.setStartingPose(startPose);
|
follower.setStartingPose(startPose);
|
||||||
|
|
||||||
path = follower.pathBuilder()
|
path = follower.pathBuilder()
|
||||||
.addPath(
|
.addPath(
|
||||||
// Line 1
|
// Line 1
|
||||||
new BezierCurve(
|
new BezierLine(
|
||||||
new Point(10.929, 55.446, Point.CARTESIAN),
|
new Point(15.000, 35.000, Point.CARTESIAN),
|
||||||
new Point(42.429, 46.446, Point.CARTESIAN),
|
new Point(60.000, 35.000, Point.CARTESIAN)
|
||||||
new Point(36.321, 38.089, Point.CARTESIAN)
|
)
|
||||||
)
|
)
|
||||||
)
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
|
||||||
.addPath(
|
.addPath(
|
||||||
// Line 2
|
// Line 2
|
||||||
new BezierLine(
|
new BezierLine(
|
||||||
new Point(36.321, 38.089, Point.CARTESIAN),
|
new Point(60.000, 35.000, Point.CARTESIAN),
|
||||||
new Point(59.786, 36.643, Point.CARTESIAN)
|
new Point(60.000, 25.000, Point.CARTESIAN)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
.addPath(
|
.addPath(
|
||||||
// Line 3
|
// Line 3
|
||||||
new BezierLine(
|
new BezierLine(
|
||||||
new Point(59.786, 36.643, Point.CARTESIAN),
|
new Point(60.000, 25.000, Point.CARTESIAN),
|
||||||
new Point(59.304, 24.750, Point.CARTESIAN)
|
new Point(15.000, 25.000, Point.CARTESIAN)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
.addPath(
|
.addPath(
|
||||||
// Line 4
|
// Line 4
|
||||||
new BezierLine(
|
new BezierLine(
|
||||||
new Point(59.304, 24.750, Point.CARTESIAN),
|
new Point(15.000, 25.000, Point.CARTESIAN),
|
||||||
new Point(13.982, 23.946, Point.CARTESIAN)
|
new Point(60.000, 25.000, Point.CARTESIAN)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
.addPath(
|
.addPath(
|
||||||
// Line 5
|
// Line 5
|
||||||
new BezierLine(
|
new BezierLine(
|
||||||
new Point(13.982, 23.946, Point.CARTESIAN),
|
new Point(60.000, 25.000, Point.CARTESIAN),
|
||||||
new Point(59.464, 24.429, Point.CARTESIAN)
|
new Point(60.000, 15.000, Point.CARTESIAN)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
.addPath(
|
.addPath(
|
||||||
// Line 6
|
// Line 6
|
||||||
new BezierLine(
|
new BezierLine(
|
||||||
new Point(59.464, 24.429, Point.CARTESIAN),
|
new Point(60.000, 15.000, Point.CARTESIAN),
|
||||||
new Point(58.982, 15.268, Point.CARTESIAN)
|
new Point(15.000, 15.000, Point.CARTESIAN)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
.addPath(
|
.addPath(
|
||||||
// Line 7
|
// Line 7
|
||||||
new BezierLine(
|
new BezierLine(
|
||||||
new Point(58.982, 15.268, Point.CARTESIAN),
|
new Point(15.000, 15.000, Point.CARTESIAN),
|
||||||
new Point(13.821, 14.464, Point.CARTESIAN)
|
new Point(60.000, 15.000, Point.CARTESIAN)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
.addPath(
|
.addPath(
|
||||||
// Line 8
|
// Line 8
|
||||||
new BezierLine(
|
new BezierLine(
|
||||||
new Point(13.821, 14.464, Point.CARTESIAN),
|
new Point(60.000, 15.000, Point.CARTESIAN),
|
||||||
new Point(58.661, 13.500, Point.CARTESIAN)
|
new Point(60.000, 8.000, Point.CARTESIAN)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
.addPath(
|
.addPath(
|
||||||
// Line 9
|
// Line 9
|
||||||
new BezierLine(
|
new BezierLine(
|
||||||
new Point(58.661, 13.500, Point.CARTESIAN),
|
new Point(60.000, 8.000, Point.CARTESIAN),
|
||||||
new Point(58.339, 8.679, Point.CARTESIAN)
|
new Point(15.000, 8.000, Point.CARTESIAN)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
.setConstantHeadingInterpolation(Math.toRadians(90)).build();
|
||||||
.addPath(
|
|
||||||
// Line 10
|
follower.followPath(path);
|
||||||
new BezierLine(
|
|
||||||
new Point(58.339, 8.679, Point.CARTESIAN),
|
|
||||||
new Point(14.625, 8.518, Point.CARTESIAN)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0)).build();
|
|
||||||
follower.followPath(path, true);
|
|
||||||
|
|
||||||
telemetryA = new MultipleTelemetry(this.telemetry, FtcDashboard.getInstance().getTelemetry());
|
telemetryA = new MultipleTelemetry(this.telemetry, FtcDashboard.getInstance().getTelemetry());
|
||||||
telemetryA.update();
|
telemetryA.update();
|
||||||
@ -144,7 +135,7 @@ public class BlueNonBasketAuto extends OpMode {
|
|||||||
public void loop() {
|
public void loop() {
|
||||||
follower.update();
|
follower.update();
|
||||||
if (follower.atParametricEnd()) {
|
if (follower.atParametricEnd()) {
|
||||||
follower.followPath(path, true);
|
follower.followPath(path);
|
||||||
}
|
}
|
||||||
follower.telemetryDebug(telemetryA);
|
follower.telemetryDebug(telemetryA);
|
||||||
}
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
package org.firstinspires.ftc.teamcode;
|
||||||
|
|
||||||
|
import com.acmerobotics.dashboard.FtcDashboard;
|
||||||
|
import com.acmerobotics.dashboard.config.Config;
|
||||||
|
import com.acmerobotics.dashboard.telemetry.MultipleTelemetry;
|
||||||
|
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
|
||||||
|
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
|
||||||
|
|
||||||
|
import org.firstinspires.ftc.robotcore.external.Telemetry;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.follower.Follower;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Pose;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierCurve;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierLine;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.PathChain;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Point;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the Circle autonomous OpMode. It runs the robot in a PathChain that's actually not quite
|
||||||
|
* a circle, but some Bezier curves that have control points set essentially in a square. However,
|
||||||
|
* it turns enough to tune your centripetal force correction and some of your heading. Some lag in
|
||||||
|
* heading is to be expected.
|
||||||
|
*
|
||||||
|
* @author Anyi Lin - 10158 Scott's Bots
|
||||||
|
* @author Aaron Yang - 10158 Scott's Bots
|
||||||
|
* @author Harrison Womack - 10158 Scott's Bots
|
||||||
|
* @version 1.0, 3/12/2024
|
||||||
|
*/
|
||||||
|
@Config
|
||||||
|
@Autonomous(name = "AutoExampleThree", group = "Autonomous Pathing Tuning")
|
||||||
|
public class AutoExampleThree extends OpMode {
|
||||||
|
private Telemetry telemetryA;
|
||||||
|
|
||||||
|
private Follower follower;
|
||||||
|
|
||||||
|
private PathChain path;
|
||||||
|
|
||||||
|
private final Pose startPose = new Pose(10.0, 40, 90);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This initializes the Follower and creates the PathChain for the "circle". Additionally, this
|
||||||
|
* initializes the FTC Dashboard telemetry.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
follower = new Follower(hardwareMap);
|
||||||
|
|
||||||
|
follower.setMaxPower(.4);
|
||||||
|
|
||||||
|
follower.setStartingPose(startPose);
|
||||||
|
|
||||||
|
path = follower.pathBuilder()
|
||||||
|
.addPath(
|
||||||
|
// Line 1
|
||||||
|
new BezierCurve(
|
||||||
|
new Point(10.000, 20.000, Point.CARTESIAN),
|
||||||
|
new Point(29.089, 61.232, Point.CARTESIAN),
|
||||||
|
new Point(48.054, 19.607, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90)).build();
|
||||||
|
|
||||||
|
follower.followPath(path);
|
||||||
|
|
||||||
|
telemetryA = new MultipleTelemetry(this.telemetry, FtcDashboard.getInstance().getTelemetry());
|
||||||
|
telemetryA.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This runs the OpMode, updating the Follower as well as printing out the debug statements to
|
||||||
|
* the Telemetry, as well as the FTC Dashboard.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void loop() {
|
||||||
|
follower.update();
|
||||||
|
if (follower.atParametricEnd()) {
|
||||||
|
follower.followPath(path);
|
||||||
|
}
|
||||||
|
follower.telemetryDebug(telemetryA);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
package org.firstinspires.ftc.teamcode;
|
||||||
|
|
||||||
|
import com.acmerobotics.dashboard.FtcDashboard;
|
||||||
|
import com.acmerobotics.dashboard.config.Config;
|
||||||
|
import com.acmerobotics.dashboard.telemetry.MultipleTelemetry;
|
||||||
|
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
|
||||||
|
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
|
||||||
|
|
||||||
|
import org.firstinspires.ftc.robotcore.external.Telemetry;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.follower.Follower;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Pose;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierCurve;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierLine;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.PathChain;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Point;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the Circle autonomous OpMode. It runs the robot in a PathChain that's actually not quite
|
||||||
|
* a circle, but some Bezier curves that have control points set essentially in a square. However,
|
||||||
|
* it turns enough to tune your centripetal force correction and some of your heading. Some lag in
|
||||||
|
* heading is to be expected.
|
||||||
|
*
|
||||||
|
* @author Anyi Lin - 10158 Scott's Bots
|
||||||
|
* @author Aaron Yang - 10158 Scott's Bots
|
||||||
|
* @author Harrison Womack - 10158 Scott's Bots
|
||||||
|
* @version 1.0, 3/12/2024
|
||||||
|
*/
|
||||||
|
@Config
|
||||||
|
@Autonomous(name = "AutoExampleTwo", group = "Autonomous Pathing Tuning")
|
||||||
|
public class AutoExampleTwo extends OpMode {
|
||||||
|
private Telemetry telemetryA;
|
||||||
|
|
||||||
|
private Follower follower;
|
||||||
|
|
||||||
|
private PathChain path;
|
||||||
|
|
||||||
|
private final Pose startPose = new Pose(10.0, 40, 90);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This initializes the Follower and creates the PathChain for the "circle". Additionally, this
|
||||||
|
* initializes the FTC Dashboard telemetry.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
follower = new Follower(hardwareMap);
|
||||||
|
|
||||||
|
follower.setMaxPower(.4);
|
||||||
|
|
||||||
|
follower.setStartingPose(startPose);
|
||||||
|
|
||||||
|
path = follower.pathBuilder()
|
||||||
|
.addPath(
|
||||||
|
// Line 1
|
||||||
|
new BezierLine(
|
||||||
|
new Point(10.000, 40.000, Point.CARTESIAN),
|
||||||
|
new Point(60.000, 40.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 2
|
||||||
|
new BezierLine(
|
||||||
|
new Point(60.000, 40.000, Point.CARTESIAN),
|
||||||
|
new Point(60.000, 25.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 3
|
||||||
|
new BezierLine(
|
||||||
|
new Point(60.000, 25.000, Point.CARTESIAN),
|
||||||
|
new Point(10.000, 25.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90)).build();
|
||||||
|
|
||||||
|
follower.followPath(path);
|
||||||
|
|
||||||
|
telemetryA = new MultipleTelemetry(this.telemetry, FtcDashboard.getInstance().getTelemetry());
|
||||||
|
telemetryA.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This runs the OpMode, updating the Follower as well as printing out the debug statements to
|
||||||
|
* the Telemetry, as well as the FTC Dashboard.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void loop() {
|
||||||
|
follower.update();
|
||||||
|
if (follower.atParametricEnd()) {
|
||||||
|
follower.followPath(path);
|
||||||
|
}
|
||||||
|
follower.telemetryDebug(telemetryA);
|
||||||
|
}
|
||||||
|
}
|
@ -27,10 +27,8 @@
|
|||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.firstinspires.ftc.teamcode.cometbots.projects;
|
package org.firstinspires.ftc.teamcode;
|
||||||
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_ENCODER;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_ENCODER_DIRECTION;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_LEFT_MOTOR;
|
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_LEFT_MOTOR;
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_LEFT_MOTOR_DIRECTION;
|
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_LEFT_MOTOR_DIRECTION;
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_RIGHT_MOTOR;
|
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_RIGHT_MOTOR;
|
||||||
@ -39,10 +37,6 @@ import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_LEFT_MOTOR;
|
|||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_LEFT_MOTOR_DIRECTION;
|
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_LEFT_MOTOR_DIRECTION;
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_RIGHT_MOTOR;
|
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_RIGHT_MOTOR;
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_RIGHT_MOTOR_DIRECTION;
|
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_RIGHT_MOTOR_DIRECTION;
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.LEFT_ENCODER;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.LEFT_ENCODER_DIRECTION;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.RIGHT_ENCODER;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.RIGHT_ENCODER_DIRECTION;
|
|
||||||
|
|
||||||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
|
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
|
||||||
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
|
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
|
||||||
@ -80,12 +74,15 @@ import org.firstinspires.ftc.teamcode.pedroPathing.localization.Encoder;
|
|||||||
* Remove or comment out the @Disabled line to add this OpMode to the Driver Station OpMode list
|
* Remove or comment out the @Disabled line to add this OpMode to the Driver Station OpMode list
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@TeleOp(name="Basic: Omni Linear OpMode", group="Linear OpMode")
|
@TeleOp(name = "Basic: Omni Linear OpMode", group = "Linear OpMode")
|
||||||
public class BasicOmniOpMode_Linear extends LinearOpMode {
|
public class BasicOmniOpMode_Linear extends LinearOpMode {
|
||||||
|
|
||||||
// Declare OpMode members for each of the 4 motors.
|
// Declare OpMode members for each of the 4 motors.
|
||||||
private final ElapsedTime runtime = new ElapsedTime();
|
private final ElapsedTime runtime = new ElapsedTime();
|
||||||
|
private Encoder leftFront;
|
||||||
|
private Encoder rightFront;
|
||||||
|
private Encoder leftRear;
|
||||||
|
private Encoder rightRear;
|
||||||
@Override
|
@Override
|
||||||
public void runOpMode() {
|
public void runOpMode() {
|
||||||
|
|
||||||
@ -96,18 +93,12 @@ public class BasicOmniOpMode_Linear extends LinearOpMode {
|
|||||||
DcMotor rightFrontDrive = hardwareMap.get(DcMotor.class, FRONT_RIGHT_MOTOR);
|
DcMotor rightFrontDrive = hardwareMap.get(DcMotor.class, FRONT_RIGHT_MOTOR);
|
||||||
DcMotor rightBackDrive = hardwareMap.get(DcMotor.class, BACK_RIGHT_MOTOR);
|
DcMotor rightBackDrive = hardwareMap.get(DcMotor.class, BACK_RIGHT_MOTOR);
|
||||||
|
|
||||||
|
leftFront = new Encoder(hardwareMap.get(DcMotorEx.class, FRONT_LEFT_MOTOR));
|
||||||
|
leftRear = new Encoder(hardwareMap.get(DcMotorEx.class, BACK_LEFT_MOTOR));
|
||||||
|
rightRear = new Encoder(hardwareMap.get(DcMotorEx.class, BACK_RIGHT_MOTOR));
|
||||||
|
rightFront = new Encoder(hardwareMap.get(DcMotorEx.class, FRONT_RIGHT_MOTOR));
|
||||||
|
|
||||||
|
|
||||||
// TODO: replace these with your encoder ports
|
|
||||||
Encoder leftEncoder = new Encoder(hardwareMap.get(DcMotorEx.class, LEFT_ENCODER));
|
|
||||||
Encoder rightEncoder = new Encoder(hardwareMap.get(DcMotorEx.class, RIGHT_ENCODER));
|
|
||||||
Encoder strafeEncoder = new Encoder(hardwareMap.get(DcMotorEx.class, BACK_ENCODER));
|
|
||||||
|
|
||||||
// TODO: reverse any encoders necessary
|
|
||||||
leftEncoder.setDirection(LEFT_ENCODER_DIRECTION);
|
|
||||||
rightEncoder.setDirection(RIGHT_ENCODER_DIRECTION);
|
|
||||||
strafeEncoder.setDirection(BACK_ENCODER_DIRECTION);
|
|
||||||
|
|
||||||
// ########################################################################################
|
// ########################################################################################
|
||||||
// !!! IMPORTANT Drive Information. Test your motor directions. !!!!!
|
// !!! IMPORTANT Drive Information. Test your motor directions. !!!!!
|
||||||
// ########################################################################################
|
// ########################################################################################
|
||||||
@ -123,11 +114,20 @@ public class BasicOmniOpMode_Linear extends LinearOpMode {
|
|||||||
rightFrontDrive.setDirection(FRONT_RIGHT_MOTOR_DIRECTION);
|
rightFrontDrive.setDirection(FRONT_RIGHT_MOTOR_DIRECTION);
|
||||||
rightBackDrive.setDirection(BACK_RIGHT_MOTOR_DIRECTION);
|
rightBackDrive.setDirection(BACK_RIGHT_MOTOR_DIRECTION);
|
||||||
|
|
||||||
|
leftFrontDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
|
||||||
|
leftBackDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
|
||||||
|
rightFrontDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
|
||||||
|
rightBackDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
|
||||||
|
|
||||||
|
leftFrontDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||||
|
leftBackDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||||
|
rightFrontDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||||
|
rightBackDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Wait for the game to start (driver presses START)
|
// Wait for the game to start (driver presses START)
|
||||||
telemetry.addData("Status", "Initialized");
|
telemetry.addData("Status", "Initialized");
|
||||||
telemetry.addData("Left Encoder Value", leftEncoder.getDeltaPosition());
|
|
||||||
telemetry.addData("Right Encoder Value", rightEncoder.getDeltaPosition());
|
|
||||||
telemetry.addData("Strafe Encoder Value", strafeEncoder.getDeltaPosition());
|
|
||||||
telemetry.update();
|
telemetry.update();
|
||||||
|
|
||||||
waitForStart();
|
waitForStart();
|
||||||
@ -138,16 +138,16 @@ public class BasicOmniOpMode_Linear extends LinearOpMode {
|
|||||||
double max;
|
double max;
|
||||||
|
|
||||||
// POV Mode uses left joystick to go forward & strafe, and right joystick to rotate.
|
// POV Mode uses left joystick to go forward & strafe, and right joystick to rotate.
|
||||||
double axial = -gamepad1.left_stick_y; // Note: pushing stick forward gives negative value
|
double axial = -gamepad1.left_stick_y; // Note: pushing stick forward gives negative value
|
||||||
double lateral = gamepad1.left_stick_x;
|
double lateral = gamepad1.left_stick_x;
|
||||||
double yaw = gamepad1.right_stick_x;
|
double yaw = gamepad1.right_stick_x;
|
||||||
|
|
||||||
// Combine the joystick requests for each axis-motion to determine each wheel's power.
|
// Combine the joystick requests for each axis-motion to determine each wheel's power.
|
||||||
// Set up a variable for each drive wheel to save the power level for telemetry.
|
// Set up a variable for each drive wheel to save the power level for telemetry.
|
||||||
double leftFrontPower = axial + lateral + yaw;
|
double leftFrontPower = axial + lateral + yaw;
|
||||||
double rightFrontPower = axial - lateral - yaw;
|
double rightFrontPower = axial - lateral - yaw;
|
||||||
double leftBackPower = axial - lateral + yaw;
|
double leftBackPower = axial - lateral + yaw;
|
||||||
double rightBackPower = axial + lateral - yaw;
|
double rightBackPower = axial + lateral - yaw;
|
||||||
|
|
||||||
// Normalize the values so no wheel power exceeds 100%
|
// Normalize the values so no wheel power exceeds 100%
|
||||||
// This ensures that the robot maintains the desired motion.
|
// This ensures that the robot maintains the desired motion.
|
||||||
@ -156,10 +156,10 @@ public class BasicOmniOpMode_Linear extends LinearOpMode {
|
|||||||
max = Math.max(max, Math.abs(rightBackPower));
|
max = Math.max(max, Math.abs(rightBackPower));
|
||||||
|
|
||||||
if (max > 1.0) {
|
if (max > 1.0) {
|
||||||
leftFrontPower /= max;
|
leftFrontPower /= max;
|
||||||
rightFrontPower /= max;
|
rightFrontPower /= max;
|
||||||
leftBackPower /= max;
|
leftBackPower /= max;
|
||||||
rightBackPower /= max;
|
rightBackPower /= max;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is test code:
|
// This is test code:
|
||||||
@ -186,12 +186,14 @@ public class BasicOmniOpMode_Linear extends LinearOpMode {
|
|||||||
rightBackDrive.setPower(rightBackPower);
|
rightBackDrive.setPower(rightBackPower);
|
||||||
|
|
||||||
// Show the elapsed game time and wheel power.
|
// Show the elapsed game time and wheel power.
|
||||||
telemetry.addData("Status", "Run Time: " + runtime.toString());
|
telemetry.addData("Status", "Run Time: " + runtime);
|
||||||
telemetry.addData("Front left/Right", "%4.2f, %4.2f", leftFrontPower, rightFrontPower);
|
telemetry.addData("Front left/Right", "%4.2f, %4.2f", leftFrontPower, rightFrontPower);
|
||||||
telemetry.addData("Back left/Right", "%4.2f, %4.2f", leftBackPower, rightBackPower);
|
telemetry.addData("Back left/Right", "%4.2f, %4.2f", leftBackPower, rightBackPower);
|
||||||
telemetry.addData("Left Encoder Value", leftEncoder.getDeltaPosition());
|
telemetry.addData("Encoder Front Left", leftFrontDrive.getDirection() + " : " + leftFrontDrive.getCurrentPosition());
|
||||||
telemetry.addData("Right Encoder Value", rightEncoder.getDeltaPosition());
|
telemetry.addData("Encoder Front Right", rightFrontDrive.getCurrentPosition());
|
||||||
telemetry.addData("Strafe Encoder Value", strafeEncoder.getDeltaPosition());
|
telemetry.addData("Encoder Back Left", leftBackDrive.getCurrentPosition());
|
||||||
|
telemetry.addData("Encoder Back Right", rightBackDrive.getCurrentPosition());
|
||||||
telemetry.update();
|
telemetry.update();
|
||||||
}
|
}
|
||||||
}}
|
}
|
||||||
|
}
|
@ -0,0 +1,247 @@
|
|||||||
|
package org.firstinspires.ftc.teamcode;
|
||||||
|
|
||||||
|
import com.acmerobotics.dashboard.FtcDashboard;
|
||||||
|
import com.acmerobotics.dashboard.config.Config;
|
||||||
|
import com.acmerobotics.dashboard.telemetry.MultipleTelemetry;
|
||||||
|
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
|
||||||
|
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
|
||||||
|
|
||||||
|
import org.firstinspires.ftc.robotcore.external.Telemetry;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.follower.Follower;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Pose;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierCurve;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierLine;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.PathChain;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Point;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the Circle autonomous OpMode. It runs the robot in a PathChain that's actually not quite
|
||||||
|
* a circle, but some Bezier curves that have control points set essentially in a square. However,
|
||||||
|
* it turns enough to tune your centripetal force correction and some of your heading. Some lag in
|
||||||
|
* heading is to be expected.
|
||||||
|
*
|
||||||
|
* @author Anyi Lin - 10158 Scott's Bots
|
||||||
|
* @author Aaron Yang - 10158 Scott's Bots
|
||||||
|
* @author Harrison Womack - 10158 Scott's Bots
|
||||||
|
* @version 1.0, 3/12/2024
|
||||||
|
*/
|
||||||
|
@Config
|
||||||
|
@Autonomous(name = "BluebAutoV1", group = "Autonomous Pathing Tuning")
|
||||||
|
public class BluebAutoV1 extends OpMode {
|
||||||
|
private Telemetry telemetryA;
|
||||||
|
|
||||||
|
private Follower follower;
|
||||||
|
|
||||||
|
private PathChain path;
|
||||||
|
|
||||||
|
private final Pose startPose = new Pose(7.5, 72, 90);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This initializes the Follower and creates the PathChain for the "circle". Additionally, this
|
||||||
|
* initializes the FTC Dashboard telemetry.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
follower = new Follower(hardwareMap);
|
||||||
|
|
||||||
|
follower.setMaxPower(.4);
|
||||||
|
|
||||||
|
follower.setStartingPose(startPose);
|
||||||
|
|
||||||
|
path = follower.pathBuilder()
|
||||||
|
.addPath(
|
||||||
|
// Line 1
|
||||||
|
new BezierLine(
|
||||||
|
new Point(7.5, 72, Point.CARTESIAN),
|
||||||
|
new Point(29.893, 38.250, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 2
|
||||||
|
new BezierLine(
|
||||||
|
new Point(29.893, 38.250, Point.CARTESIAN),
|
||||||
|
new Point(65.250, 32.143, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 3
|
||||||
|
new BezierLine(
|
||||||
|
new Point(65.250, 32.143, Point.CARTESIAN),
|
||||||
|
new Point(61.714, 24.429, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 4
|
||||||
|
new BezierLine(
|
||||||
|
new Point(61.714, 24.429, Point.CARTESIAN),
|
||||||
|
new Point(13.821, 22.821, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 5
|
||||||
|
new BezierLine(
|
||||||
|
new Point(13.821, 22.821, Point.CARTESIAN),
|
||||||
|
new Point(61.714, 24.429, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 6
|
||||||
|
new BezierLine(
|
||||||
|
new Point(61.714, 24.429, Point.CARTESIAN),
|
||||||
|
new Point(60.750, 12.696, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 7
|
||||||
|
new BezierLine(
|
||||||
|
new Point(60.750, 12.696, Point.CARTESIAN),
|
||||||
|
new Point(12.375, 13.179, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 8
|
||||||
|
new BezierLine(
|
||||||
|
new Point(12.375, 13.179, Point.CARTESIAN),
|
||||||
|
new Point(60.750, 12.536, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 9
|
||||||
|
new BezierLine(
|
||||||
|
new Point(60.750, 12.536, Point.CARTESIAN),
|
||||||
|
new Point(60.589, 9.321, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 10
|
||||||
|
new BezierLine(
|
||||||
|
new Point(60.589, 9.321, Point.CARTESIAN),
|
||||||
|
new Point(12.536, 8.357, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 11
|
||||||
|
new BezierLine(
|
||||||
|
new Point(12.536, 8.357, Point.CARTESIAN),
|
||||||
|
new Point(26.679, 8.679, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 12
|
||||||
|
new BezierLine(
|
||||||
|
new Point(26.679, 8.679, Point.CARTESIAN),
|
||||||
|
new Point(22.821, 109.446, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 13
|
||||||
|
new BezierLine(
|
||||||
|
new Point(22.821, 109.446, Point.CARTESIAN),
|
||||||
|
new Point(70.714, 109.446, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 14
|
||||||
|
new BezierLine(
|
||||||
|
new Point(70.714, 109.446, Point.CARTESIAN),
|
||||||
|
new Point(71.036, 120.214, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 15
|
||||||
|
new BezierLine(
|
||||||
|
new Point(71.036, 120.214, Point.CARTESIAN),
|
||||||
|
new Point(22.179, 120.214, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 16
|
||||||
|
new BezierLine(
|
||||||
|
new Point(22.179, 120.214, Point.CARTESIAN),
|
||||||
|
new Point(11.089, 130.821, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 17
|
||||||
|
new BezierLine(
|
||||||
|
new Point(11.089, 130.821, Point.CARTESIAN),
|
||||||
|
new Point(70.714, 112.018, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 18
|
||||||
|
new BezierLine(
|
||||||
|
new Point(70.714, 112.018, Point.CARTESIAN),
|
||||||
|
new Point(70.714, 128.250, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 19
|
||||||
|
new BezierLine(
|
||||||
|
new Point(70.714, 128.250, Point.CARTESIAN),
|
||||||
|
new Point(9.964, 130.018, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 20
|
||||||
|
new BezierLine(
|
||||||
|
new Point(9.964, 130.018, Point.CARTESIAN),
|
||||||
|
new Point(70.554, 130.500, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 21
|
||||||
|
new BezierLine(
|
||||||
|
new Point(70.554, 130.500, Point.CARTESIAN),
|
||||||
|
new Point(70.393, 135.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90))
|
||||||
|
.addPath(
|
||||||
|
// Line 22
|
||||||
|
new BezierLine(
|
||||||
|
new Point(70.393, 135.000, Point.CARTESIAN),
|
||||||
|
new Point(13.821, 134.839, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90)).build();
|
||||||
|
|
||||||
|
follower.followPath(path);
|
||||||
|
telemetryA = new MultipleTelemetry(this.telemetry, FtcDashboard.getInstance().getTelemetry());
|
||||||
|
telemetryA.update();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This runs the OpMode, updating the Follower as well as printing out the debug statements to
|
||||||
|
* the Telemetry, as well as the FTC Dashboard.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void loop() {
|
||||||
|
follower.update();
|
||||||
|
if (follower.atParametricEnd()) {
|
||||||
|
follower.followPath(path);
|
||||||
|
}
|
||||||
|
follower.telemetryDebug(telemetryA);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package org.firstinspires.ftc.teamcode;
|
||||||
|
|
||||||
|
public class BluenbAutov1 {
|
||||||
|
}
|
@ -1,24 +0,0 @@
|
|||||||
package org.firstinspires.ftc.teamcode;
|
|
||||||
|
|
||||||
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
|
|
||||||
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
|
|
||||||
|
|
||||||
import org.firstinspires.ftc.teamcode.cometbots.CometBotAutoDevelopment;
|
|
||||||
|
|
||||||
@TeleOp(name = "CometBot Auto", group = "Development")
|
|
||||||
public class CometBotDevAuto extends OpMode {
|
|
||||||
|
|
||||||
public CometBotAutoDevelopment runMode;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init() {
|
|
||||||
this.runMode = new CometBotAutoDevelopment(hardwareMap, telemetry, gamepad1, gamepad2);
|
|
||||||
this.runMode.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loop() {
|
|
||||||
this.runMode.update();
|
|
||||||
telemetry.update();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
package org.firstinspires.ftc.teamcode;
|
|
||||||
import com.acmerobotics.roadrunner.Action;
|
|
||||||
import com.acmerobotics.roadrunner.SleepAction;
|
|
||||||
import com.acmerobotics.roadrunner.ftc.Actions;
|
|
||||||
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
|
|
||||||
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
|
|
||||||
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.follower.Follower;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Pose;
|
|
||||||
import org.firstinspires.ftc.teamcode.subsystem.AutoLine1;
|
|
||||||
import org.firstinspires.ftc.teamcode.subsystem.AutoLine2;
|
|
||||||
import org.firstinspires.ftc.teamcode.subsystem.AutoLine3;
|
|
||||||
|
|
||||||
@Autonomous(name = "BlueNetAuto", group = "Dev")
|
|
||||||
public class NetAuto extends OpMode {
|
|
||||||
|
|
||||||
public Follower follower;
|
|
||||||
|
|
||||||
public AutoLine1 myFirstPath = new AutoLine1();
|
|
||||||
public AutoLine2 mySecondPath = new AutoLine2();
|
|
||||||
public int pathState = 0;
|
|
||||||
@Override
|
|
||||||
public void init() {
|
|
||||||
follower = new Follower(hardwareMap);
|
|
||||||
follower.setMaxPower(0.65);
|
|
||||||
myFirstPath.moveToAutoLine1(follower);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loop() {
|
|
||||||
follower.update();
|
|
||||||
switch(pathState) {
|
|
||||||
case 0:
|
|
||||||
if (!follower.isBusy()) {
|
|
||||||
pathState = 1;
|
|
||||||
mySecondPath.moveToAutoLine2(follower);
|
|
||||||
}
|
|
||||||
case 1:
|
|
||||||
if (!follower.isBusy()) {
|
|
||||||
System.out.println("Finished");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// switch(pathState) {
|
|
||||||
// case 0:
|
|
||||||
// if (!follower.isBusy()) {
|
|
||||||
// mySecondPath.moveToAutoLine2(follower);
|
|
||||||
// pathState = 1;
|
|
||||||
// }
|
|
||||||
// case 1:
|
|
||||||
// if (!follower.isBusy()) {
|
|
||||||
// pathState = 2;
|
|
||||||
// }
|
|
||||||
// case 2:
|
|
||||||
// // set path 3
|
|
||||||
// // as if busy, if not, set path 4 and so on.
|
|
||||||
// System.out.print("we're at the end");
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
follower.telemetryDebug(telemetry);
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,71 +12,46 @@ public class PedroConstants {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Robot motor configurations
|
// Robot motor configurations
|
||||||
public static final String FRONT_LEFT_MOTOR = "front-left";
|
public static final String FRONT_LEFT_MOTOR = "Drive front lt";
|
||||||
public static final String BACK_LEFT_MOTOR = "back-left";
|
public static final String BACK_LEFT_MOTOR = "Drive back lt";
|
||||||
public static final String FRONT_RIGHT_MOTOR = "front-right";
|
public static final String FRONT_RIGHT_MOTOR = "Drive front rt";
|
||||||
public static final String BACK_RIGHT_MOTOR = "back-right";
|
public static final String BACK_RIGHT_MOTOR = "Drive back rt";
|
||||||
|
|
||||||
// Robot motor direction
|
// Robot motor direction
|
||||||
public static final Direction FRONT_LEFT_MOTOR_DIRECTION = Direction.REVERSE;
|
public static final Direction FRONT_LEFT_MOTOR_DIRECTION = Direction.REVERSE;
|
||||||
public static final Direction BACK_LEFT_MOTOR_DIRECTION = Direction.REVERSE;
|
public static final Direction BACK_LEFT_MOTOR_DIRECTION = Direction.REVERSE;
|
||||||
public static final Direction FRONT_RIGHT_MOTOR_DIRECTION = Direction.FORWARD;
|
public static final Direction FRONT_RIGHT_MOTOR_DIRECTION = Direction.REVERSE;
|
||||||
public static final Direction BACK_RIGHT_MOTOR_DIRECTION = Direction.FORWARD;
|
public static final Direction BACK_RIGHT_MOTOR_DIRECTION = Direction.REVERSE;
|
||||||
|
|
||||||
/*
|
|
||||||
Motor Max Power
|
|
||||||
*/
|
|
||||||
public static final double MAX_POWER = .75;
|
|
||||||
|
|
||||||
// Robot IMU configuration
|
|
||||||
public static final String IMU = "imu";
|
|
||||||
|
|
||||||
// Robot IMU placement
|
|
||||||
public static final RevHubOrientationOnRobot.LogoFacingDirection IMU_LOGO_FACING_DIRECTION
|
|
||||||
= RevHubOrientationOnRobot.LogoFacingDirection.LEFT;
|
|
||||||
public static final RevHubOrientationOnRobot.UsbFacingDirection IMU_USB_FACING_DIRECTION
|
|
||||||
= RevHubOrientationOnRobot.UsbFacingDirection.UP;
|
|
||||||
|
|
||||||
// Robot encoders
|
|
||||||
// NOTE: Encoders are plugged into the same ports as motors hence the weird names
|
|
||||||
public static final String RIGHT_ENCODER = "front-left"; //2
|
|
||||||
public static final String BACK_ENCODER = "front-right"; //1
|
|
||||||
public static final String LEFT_ENCODER = "back-right"; //0
|
|
||||||
|
|
||||||
// Robot encoder direction
|
// Robot encoder direction
|
||||||
public static final double LEFT_ENCODER_DIRECTION = Encoder.FORWARD;
|
public static final double FRONT_LEFT_MOTOR_ENCODER = Encoder.FORWARD;
|
||||||
public static final double RIGHT_ENCODER_DIRECTION = Encoder.REVERSE;
|
public static final double BACK_LEFT_MOTOR_ENCODER = Encoder.FORWARD;
|
||||||
public static final double BACK_ENCODER_DIRECTION = Encoder.FORWARD;
|
public static final double FRONT_RIGHT_MOTOR_ENCODER = Encoder.FORWARD;
|
||||||
|
public static final double BACK_RIGHT_MOTOR_ENCODER = Encoder.FORWARD;
|
||||||
// Arm config
|
|
||||||
public static final String SLIDE_MOTOR = "SlideMotor";
|
|
||||||
public static final String Claw_Servo = "ClawServo";
|
|
||||||
public static final String Wrist_Servo = "WristServo";
|
|
||||||
public static final String Arm_Servo = "ArmServo";
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Pedro's parameters
|
Pedro's parameters
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// The weight of the robot in Kilograms
|
// The weight of the robot in Kilograms
|
||||||
public static final double ROBOT_WEIGHT_IN_KG = 9;
|
public static final double ROBOT_WEIGHT_IN_KG = 5.15;
|
||||||
|
|
||||||
// Maximum velocity of the robot going forward
|
// Maximum velocity of the robot going forward
|
||||||
public static final double ROBOT_SPEED_FORWARD = 51.5;
|
public static final double ROBOT_SPEED_FORWARD = 66.6117;
|
||||||
|
|
||||||
// Maximum velocity of the robot going right
|
// Maximum velocity of the robot going right
|
||||||
public static final double ROBOT_SPEED_LATERAL = 28.7;
|
public static final double ROBOT_SPEED_LATERAL = 60.0671;
|
||||||
|
|
||||||
// Rate of deceleration when power is cut-off when the robot is moving forward
|
// Rate of deceleration when power is cut-off when the robot is moving forward
|
||||||
public static final double FORWARD_ZERO_POWER_ACCEL = -59.8;
|
public static final double FORWARD_ZERO_POWER_ACCEL = -71.154;
|
||||||
|
|
||||||
// Rate of deceleration when power is cut-off when the robot is moving to the right
|
// Rate of deceleration when power is cut-off when the robot is moving to the right
|
||||||
public static final double LATERAL_ZERO_POWER_ACCEL = -99.7;
|
public static final double LATERAL_ZERO_POWER_ACCEL = -109.5358;
|
||||||
|
|
||||||
// Determines how fast your robot will decelerate as a factor of how fast your robot will coast to a stop
|
// Determines how fast your robot will decelerate as a factor of how fast your robot will coast to a stop
|
||||||
public static final double ZERO_POWER_ACCEL_MULT = 3.5;
|
public static final double ZERO_POWER_ACCEL_MULT = 4.0;
|
||||||
|
|
||||||
/* Centripetal force correction - increase if robot is correcting into the path
|
/* Centripetal force correction - increase if robot is correcting into the path
|
||||||
- decrease if robot is correcting away from the path */
|
- decrease if robot is correcting away from the path */
|
||||||
public static final double CENTRIPETAL_SCALING = 0.0004;
|
public static final double CENTRIPETAL_SCALING = 0.0005;
|
||||||
}
|
}
|
||||||
|
@ -1,122 +0,0 @@
|
|||||||
package org.firstinspires.ftc.teamcode;
|
|
||||||
|
|
||||||
import com.acmerobotics.dashboard.FtcDashboard;
|
|
||||||
import com.acmerobotics.dashboard.telemetry.MultipleTelemetry;
|
|
||||||
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
|
|
||||||
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
|
|
||||||
|
|
||||||
import org.firstinspires.ftc.robotcore.external.Telemetry;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.follower.Follower;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Pose;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierCurve;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierLine;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.PathChain;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Point;
|
|
||||||
|
|
||||||
@Autonomous(name = "Pre Loaded Blue Basket Auto", group = "Competition")
|
|
||||||
public class PreLoadedBlueBasketAuto extends OpMode {
|
|
||||||
private Telemetry telemetryA;
|
|
||||||
|
|
||||||
private Follower follower;
|
|
||||||
|
|
||||||
private PathChain path;
|
|
||||||
|
|
||||||
private final Pose startPose = new Pose(7.875, 89.357);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init() {
|
|
||||||
follower = new Follower(hardwareMap);
|
|
||||||
|
|
||||||
follower.setMaxPower(.45);
|
|
||||||
|
|
||||||
follower.setStartingPose(startPose);
|
|
||||||
|
|
||||||
path = follower.pathBuilder()
|
|
||||||
.addPath(
|
|
||||||
// Line 1
|
|
||||||
new BezierLine(
|
|
||||||
new Point(8.036, 89.196, Point.CARTESIAN),
|
|
||||||
new Point(10.125, 126.804, Point.CARTESIAN)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
|
||||||
.addPath(
|
|
||||||
// Line 2
|
|
||||||
new BezierCurve(
|
|
||||||
new Point(10.125, 126.804, Point.CARTESIAN),
|
|
||||||
new Point(37.607, 90.000, Point.CARTESIAN),
|
|
||||||
new Point(62.357, 119.893, Point.CARTESIAN)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
|
||||||
.addPath(
|
|
||||||
// Line 3
|
|
||||||
new BezierCurve(
|
|
||||||
new Point(62.357, 119.893, Point.CARTESIAN),
|
|
||||||
new Point(33.750, 112.500, Point.CARTESIAN),
|
|
||||||
new Point(15.107, 130.661, Point.CARTESIAN)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
|
||||||
.addPath(
|
|
||||||
// Line 4
|
|
||||||
new BezierCurve(
|
|
||||||
new Point(15.107, 130.661, Point.CARTESIAN),
|
|
||||||
new Point(58.821, 103.018, Point.CARTESIAN),
|
|
||||||
new Point(59.625, 126.964, Point.CARTESIAN)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
|
||||||
.addPath(
|
|
||||||
// Line 5
|
|
||||||
new BezierLine(
|
|
||||||
new Point(59.625, 126.964, Point.CARTESIAN),
|
|
||||||
new Point(15.107, 130.339, Point.CARTESIAN)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
|
||||||
.addPath(
|
|
||||||
// Line 6
|
|
||||||
new BezierLine(
|
|
||||||
new Point(15.107, 130.339, Point.CARTESIAN),
|
|
||||||
new Point(59.625, 126.964, Point.CARTESIAN)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
|
||||||
.addPath(
|
|
||||||
// Line 7
|
|
||||||
new BezierLine(
|
|
||||||
new Point(59.625, 126.964, Point.CARTESIAN),
|
|
||||||
new Point(57.857, 133.071, Point.CARTESIAN)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
|
||||||
.addPath(
|
|
||||||
// Line 8
|
|
||||||
new BezierLine(
|
|
||||||
new Point(57.857, 133.071, Point.CARTESIAN),
|
|
||||||
new Point(18.964, 134.679, Point.CARTESIAN)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
|
||||||
.addPath(
|
|
||||||
// Line 9
|
|
||||||
new BezierCurve(
|
|
||||||
new Point(18.964, 134.679, Point.CARTESIAN),
|
|
||||||
new Point(84.536, 131.786, Point.CARTESIAN),
|
|
||||||
new Point(80.036, 96.429, Point.CARTESIAN)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setLinearHeadingInterpolation(Math.toRadians(0), Math.toRadians(270)).build();
|
|
||||||
follower.followPath(path);
|
|
||||||
|
|
||||||
telemetryA = new MultipleTelemetry(this.telemetry, FtcDashboard.getInstance().getTelemetry());
|
|
||||||
telemetryA.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loop() {
|
|
||||||
follower.update();
|
|
||||||
follower.telemetryDebug(telemetryA);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,142 +0,0 @@
|
|||||||
package org.firstinspires.ftc.teamcode.cometbots;
|
|
||||||
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.MAX_POWER;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import com.acmerobotics.dashboard.telemetry.TelemetryPacket;
|
|
||||||
import com.acmerobotics.roadrunner.Action;
|
|
||||||
import com.acmerobotics.roadrunner.SequentialAction;
|
|
||||||
import com.acmerobotics.roadrunner.SleepAction;
|
|
||||||
import com.acmerobotics.roadrunner.ftc.Actions;
|
|
||||||
import com.qualcomm.robotcore.hardware.Gamepad;
|
|
||||||
import com.qualcomm.robotcore.hardware.HardwareMap;
|
|
||||||
|
|
||||||
import org.firstinspires.ftc.robotcore.external.Telemetry;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.follower.Follower;
|
|
||||||
import org.firstinspires.ftc.teamcode.states.FieldStates;
|
|
||||||
import org.firstinspires.ftc.teamcode.subsystem.MotorsSubsystem;
|
|
||||||
|
|
||||||
public class CometBotAutoDevelopment {
|
|
||||||
|
|
||||||
/*
|
|
||||||
Subsystems
|
|
||||||
*/
|
|
||||||
private MotorsSubsystem motors;
|
|
||||||
|
|
||||||
/*
|
|
||||||
Controllers
|
|
||||||
*/
|
|
||||||
public Gamepad GP1;
|
|
||||||
public Gamepad GP2;
|
|
||||||
public Gamepad currentGP1;
|
|
||||||
public Gamepad previousGP1;
|
|
||||||
public Gamepad currentGP2;
|
|
||||||
public Gamepad previousGP2;
|
|
||||||
private Telemetry telemetry;
|
|
||||||
|
|
||||||
public FieldStates fieldStates;
|
|
||||||
private boolean centricity = false;
|
|
||||||
|
|
||||||
private Follower follower;
|
|
||||||
private HardwareMap hardwareMap;
|
|
||||||
|
|
||||||
public CometBotAutoDevelopment(HardwareMap hardwareMap, Telemetry telemetry, Gamepad gp1, Gamepad gp2) {
|
|
||||||
this.motors = new MotorsSubsystem(hardwareMap, telemetry);
|
|
||||||
this.GP1 = gp1;
|
|
||||||
this.GP2 = gp2;
|
|
||||||
this.hardwareMap = hardwareMap;
|
|
||||||
this.telemetry = telemetry;
|
|
||||||
this.currentGP1 = new Gamepad();
|
|
||||||
this.currentGP2 = new Gamepad();
|
|
||||||
this.previousGP1 = new Gamepad();
|
|
||||||
this.previousGP2 = new Gamepad();
|
|
||||||
this.fieldStates = new FieldStates();
|
|
||||||
this.follower = new Follower(hardwareMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ZeroOutPower implements Action {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean run(@NonNull TelemetryPacket telemetryPacket) {
|
|
||||||
follower = new Follower(hardwareMap);
|
|
||||||
follower.setMaxPower(0);
|
|
||||||
System.out.println("Running ZeroOutPower");
|
|
||||||
return follower.isBusy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ReturnToMaxPower implements Action {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean run(@NonNull TelemetryPacket telemetryPacket) {
|
|
||||||
follower = new Follower(hardwareMap);
|
|
||||||
follower.setMaxPower(MAX_POWER);
|
|
||||||
follower.startTeleopDrive();
|
|
||||||
System.out.println("Running ReturnToMaxPower");
|
|
||||||
return follower.isBusy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Action zeroOutPower() {
|
|
||||||
return new ZeroOutPower();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Action returnToMaxPower() {
|
|
||||||
return new ReturnToMaxPower();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init() {
|
|
||||||
this.motors.init();
|
|
||||||
this.fieldStates.setFieldLocation(FieldStates.FieldLocation.TRAVELING);
|
|
||||||
follower.setMaxPower(MAX_POWER);
|
|
||||||
follower.startTeleopDrive();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update() {
|
|
||||||
this.previousGP1.copy(currentGP1);
|
|
||||||
this.currentGP1.copy(this.GP1);
|
|
||||||
this.previousGP2.copy(currentGP2);
|
|
||||||
this.currentGP2.copy(this.GP2);
|
|
||||||
|
|
||||||
this.toFixMotorBlockingIssueFirstMethod();
|
|
||||||
this.toFixMotorBlockingIssueSecondMethod();
|
|
||||||
this.changeCentricity();
|
|
||||||
|
|
||||||
follower.setTeleOpMovementVectors(-this.GP1.left_stick_y, -this.GP1.left_stick_x, -this.GP1.right_stick_x, centricity);
|
|
||||||
follower.update();
|
|
||||||
this.telemetry.addData("Field State", this.fieldStates.getFieldLocation());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void changeCentricity() {
|
|
||||||
if (this.currentGP1.left_bumper && !this.previousGP1.left_bumper) {
|
|
||||||
this.centricity = !centricity;
|
|
||||||
this.follower.breakFollowing();
|
|
||||||
this.follower.startTeleopDrive();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toFixMotorBlockingIssueFirstMethod() {
|
|
||||||
if (this.currentGP1.cross && !this.previousGP1.cross) {
|
|
||||||
fieldStates.setFieldLocation(FieldStates.FieldLocation.BUCKET);
|
|
||||||
Actions.runBlocking(new SequentialAction(
|
|
||||||
this.zeroOutPower(),
|
|
||||||
new SleepAction(3),
|
|
||||||
this.returnToMaxPower()
|
|
||||||
));
|
|
||||||
fieldStates.setFieldLocation(FieldStates.FieldLocation.TRAVELING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toFixMotorBlockingIssueSecondMethod() {
|
|
||||||
if (this.currentGP1.circle && !this.previousGP1.circle) {
|
|
||||||
this.follower.breakFollowing();
|
|
||||||
fieldStates.setFieldLocation(FieldStates.FieldLocation.BUCKET);
|
|
||||||
Actions.runBlocking(new SequentialAction(
|
|
||||||
new SleepAction(3)
|
|
||||||
));
|
|
||||||
fieldStates.setFieldLocation(FieldStates.FieldLocation.TRAVELING);
|
|
||||||
this.follower.startTeleopDrive();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,9 +5,7 @@ import com.qualcomm.robotcore.hardware.HardwareMap;
|
|||||||
import com.qualcomm.robotcore.hardware.IMU;
|
import com.qualcomm.robotcore.hardware.IMU;
|
||||||
|
|
||||||
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
|
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.localizers.ThreeWheelIMULocalizer;
|
import org.firstinspires.ftc.teamcode.pedroPathing.localization.localizers.DriveEncoderLocalizer;
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.localizers.ThreeWheelLocalizer;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.localizers.TwoWheelLocalizer;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.MathFunctions;
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.MathFunctions;
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Vector;
|
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Vector;
|
||||||
|
|
||||||
@ -69,7 +67,7 @@ public class PoseUpdater {
|
|||||||
*/
|
*/
|
||||||
public PoseUpdater(HardwareMap hardwareMap) {
|
public PoseUpdater(HardwareMap hardwareMap) {
|
||||||
// TODO: replace the second argument with your preferred localizer
|
// TODO: replace the second argument with your preferred localizer
|
||||||
this(hardwareMap, new ThreeWheelLocalizer(hardwareMap));
|
this(hardwareMap, new DriveEncoderLocalizer(hardwareMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,11 +1,20 @@
|
|||||||
package org.firstinspires.ftc.teamcode.pedroPathing.localization.localizers;
|
package org.firstinspires.ftc.teamcode.pedroPathing.localization.localizers;
|
||||||
|
|
||||||
import static org.firstinspires.ftc.teamcode.pedroPathing.tuning.FollowerConstants.leftFrontMotorName;
|
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_LEFT_MOTOR;
|
||||||
import static org.firstinspires.ftc.teamcode.pedroPathing.tuning.FollowerConstants.leftRearMotorName;
|
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_LEFT_MOTOR_DIRECTION;
|
||||||
import static org.firstinspires.ftc.teamcode.pedroPathing.tuning.FollowerConstants.rightFrontMotorName;
|
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_LEFT_MOTOR_ENCODER;
|
||||||
import static org.firstinspires.ftc.teamcode.pedroPathing.tuning.FollowerConstants.rightRearMotorName;
|
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_RIGHT_MOTOR;
|
||||||
|
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_RIGHT_MOTOR_DIRECTION;
|
||||||
|
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_RIGHT_MOTOR_ENCODER;
|
||||||
|
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_LEFT_MOTOR;
|
||||||
|
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_LEFT_MOTOR_DIRECTION;
|
||||||
|
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_LEFT_MOTOR_ENCODER;
|
||||||
|
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_RIGHT_MOTOR;
|
||||||
|
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_RIGHT_MOTOR_DIRECTION;
|
||||||
|
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_RIGHT_MOTOR_ENCODER;
|
||||||
|
|
||||||
import com.acmerobotics.dashboard.config.Config;
|
import com.acmerobotics.dashboard.config.Config;
|
||||||
|
import com.qualcomm.robotcore.hardware.DcMotor;
|
||||||
import com.qualcomm.robotcore.hardware.DcMotorEx;
|
import com.qualcomm.robotcore.hardware.DcMotorEx;
|
||||||
import com.qualcomm.robotcore.hardware.HardwareMap;
|
import com.qualcomm.robotcore.hardware.HardwareMap;
|
||||||
|
|
||||||
@ -26,21 +35,21 @@ import org.firstinspires.ftc.teamcode.pedroPathing.util.NanoTimer;
|
|||||||
*/
|
*/
|
||||||
@Config
|
@Config
|
||||||
public class DriveEncoderLocalizer extends Localizer {
|
public class DriveEncoderLocalizer extends Localizer {
|
||||||
private HardwareMap hardwareMap;
|
private final HardwareMap hardwareMap;
|
||||||
private Pose startPose;
|
private Pose startPose;
|
||||||
private Pose displacementPose;
|
private Pose displacementPose;
|
||||||
private Pose currentVelocity;
|
private Pose currentVelocity;
|
||||||
private Matrix prevRotationMatrix;
|
private Matrix prevRotationMatrix;
|
||||||
private NanoTimer timer;
|
private final NanoTimer timer;
|
||||||
private long deltaTimeNano;
|
private long deltaTimeNano;
|
||||||
private Encoder leftFront;
|
private final Encoder leftFront;
|
||||||
private Encoder rightFront;
|
private final Encoder rightFront;
|
||||||
private Encoder leftRear;
|
private final Encoder leftRear;
|
||||||
private Encoder rightRear;
|
private final Encoder rightRear;
|
||||||
private double totalHeading;
|
private double totalHeading;
|
||||||
public static double FORWARD_TICKS_TO_INCHES = 1;
|
public static double FORWARD_TICKS_TO_INCHES = -0.0058;
|
||||||
public static double STRAFE_TICKS_TO_INCHES = 1;
|
public static double STRAFE_TICKS_TO_INCHES = -0.0054;
|
||||||
public static double TURN_TICKS_TO_RADIANS = 1;
|
public static double TURN_TICKS_TO_RADIANS = -0.0009;
|
||||||
public static double ROBOT_WIDTH = 1;
|
public static double ROBOT_WIDTH = 1;
|
||||||
public static double ROBOT_LENGTH = 1;
|
public static double ROBOT_LENGTH = 1;
|
||||||
|
|
||||||
@ -58,22 +67,32 @@ public class DriveEncoderLocalizer extends Localizer {
|
|||||||
* This creates a new DriveEncoderLocalizer from a HardwareMap and a Pose, with the Pose
|
* This creates a new DriveEncoderLocalizer from a HardwareMap and a Pose, with the Pose
|
||||||
* specifying the starting pose of the localizer.
|
* specifying the starting pose of the localizer.
|
||||||
*
|
*
|
||||||
* @param map the HardwareMap
|
* @param map the HardwareMap
|
||||||
* @param setStartPose the Pose to start from
|
* @param setStartPose the Pose to start from
|
||||||
*/
|
*/
|
||||||
public DriveEncoderLocalizer(HardwareMap map, Pose setStartPose) {
|
public DriveEncoderLocalizer(HardwareMap map, Pose setStartPose) {
|
||||||
hardwareMap = map;
|
hardwareMap = map;
|
||||||
|
|
||||||
leftFront = new Encoder(hardwareMap.get(DcMotorEx.class, leftFrontMotorName));
|
leftFront = new Encoder(hardwareMap.get(DcMotorEx.class, FRONT_LEFT_MOTOR));
|
||||||
leftRear = new Encoder(hardwareMap.get(DcMotorEx.class, leftRearMotorName));
|
leftRear = new Encoder(hardwareMap.get(DcMotorEx.class, BACK_LEFT_MOTOR));
|
||||||
rightRear = new Encoder(hardwareMap.get(DcMotorEx.class, rightRearMotorName));
|
rightRear = new Encoder(hardwareMap.get(DcMotorEx.class, BACK_RIGHT_MOTOR));
|
||||||
rightFront = new Encoder(hardwareMap.get(DcMotorEx.class, rightFrontMotorName));
|
rightFront = new Encoder(hardwareMap.get(DcMotorEx.class, FRONT_RIGHT_MOTOR));
|
||||||
|
|
||||||
|
DcMotor leftFrontDrive = hardwareMap.get(DcMotor.class, FRONT_LEFT_MOTOR);
|
||||||
|
DcMotor leftBackDrive = hardwareMap.get(DcMotor.class, BACK_LEFT_MOTOR);
|
||||||
|
DcMotor rightFrontDrive = hardwareMap.get(DcMotor.class, FRONT_RIGHT_MOTOR);
|
||||||
|
DcMotor rightBackDrive = hardwareMap.get(DcMotor.class, BACK_RIGHT_MOTOR);
|
||||||
|
|
||||||
|
leftFrontDrive.setDirection(FRONT_LEFT_MOTOR_DIRECTION);
|
||||||
|
leftBackDrive.setDirection(BACK_LEFT_MOTOR_DIRECTION);
|
||||||
|
rightFrontDrive.setDirection(FRONT_RIGHT_MOTOR_DIRECTION);
|
||||||
|
rightBackDrive.setDirection(BACK_RIGHT_MOTOR_DIRECTION);
|
||||||
|
|
||||||
// TODO: reverse any encoders necessary
|
// TODO: reverse any encoders necessary
|
||||||
leftFront.setDirection(Encoder.REVERSE);
|
leftFront.setDirection(FRONT_LEFT_MOTOR_ENCODER);
|
||||||
rightRear.setDirection(Encoder.REVERSE);
|
rightFront.setDirection(FRONT_RIGHT_MOTOR_ENCODER);
|
||||||
leftRear.setDirection(Encoder.FORWARD);
|
leftRear.setDirection(BACK_LEFT_MOTOR_ENCODER);
|
||||||
rightRear.setDirection(Encoder.FORWARD);
|
rightRear.setDirection(BACK_RIGHT_MOTOR_ENCODER);
|
||||||
|
|
||||||
setStartPose(setStartPose);
|
setStartPose(setStartPose);
|
||||||
timer = new NanoTimer();
|
timer = new NanoTimer();
|
||||||
@ -129,7 +148,7 @@ public class DriveEncoderLocalizer extends Localizer {
|
|||||||
* @param heading the rotation of the Matrix
|
* @param heading the rotation of the Matrix
|
||||||
*/
|
*/
|
||||||
public void setPrevRotationMatrix(double heading) {
|
public void setPrevRotationMatrix(double heading) {
|
||||||
prevRotationMatrix = new Matrix(3,3);
|
prevRotationMatrix = new Matrix(3, 3);
|
||||||
prevRotationMatrix.set(0, 0, Math.cos(heading));
|
prevRotationMatrix.set(0, 0, Math.cos(heading));
|
||||||
prevRotationMatrix.set(0, 1, -Math.sin(heading));
|
prevRotationMatrix.set(0, 1, -Math.sin(heading));
|
||||||
prevRotationMatrix.set(1, 0, Math.sin(heading));
|
prevRotationMatrix.set(1, 0, Math.sin(heading));
|
||||||
@ -164,7 +183,7 @@ public class DriveEncoderLocalizer extends Localizer {
|
|||||||
Matrix globalDeltas;
|
Matrix globalDeltas;
|
||||||
setPrevRotationMatrix(getPose().getHeading());
|
setPrevRotationMatrix(getPose().getHeading());
|
||||||
|
|
||||||
Matrix transformation = new Matrix(3,3);
|
Matrix transformation = new Matrix(3, 3);
|
||||||
if (Math.abs(robotDeltas.get(2, 0)) < 0.001) {
|
if (Math.abs(robotDeltas.get(2, 0)) < 0.001) {
|
||||||
transformation.set(0, 0, 1.0 - (Math.pow(robotDeltas.get(2, 0), 2) / 6.0));
|
transformation.set(0, 0, 1.0 - (Math.pow(robotDeltas.get(2, 0), 2) / 6.0));
|
||||||
transformation.set(0, 1, -robotDeltas.get(2, 0) / 2.0);
|
transformation.set(0, 1, -robotDeltas.get(2, 0) / 2.0);
|
||||||
@ -214,13 +233,13 @@ public class DriveEncoderLocalizer extends Localizer {
|
|||||||
* @return returns a Matrix containing the robot relative movement.
|
* @return returns a Matrix containing the robot relative movement.
|
||||||
*/
|
*/
|
||||||
public Matrix getRobotDeltas() {
|
public Matrix getRobotDeltas() {
|
||||||
Matrix returnMatrix = new Matrix(3,1);
|
Matrix returnMatrix = new Matrix(3, 1);
|
||||||
// x/forward movement
|
// x/forward movement
|
||||||
returnMatrix.set(0,0, FORWARD_TICKS_TO_INCHES * (leftFront.getDeltaPosition() + rightFront.getDeltaPosition() + leftRear.getDeltaPosition() + rightRear.getDeltaPosition()));
|
returnMatrix.set(0, 0, FORWARD_TICKS_TO_INCHES * (leftFront.getDeltaPosition() + rightFront.getDeltaPosition() + leftRear.getDeltaPosition() + rightRear.getDeltaPosition()));
|
||||||
//y/strafe movement
|
//y/strafe movement
|
||||||
returnMatrix.set(1,0, STRAFE_TICKS_TO_INCHES * (-leftFront.getDeltaPosition() + rightFront.getDeltaPosition() + leftRear.getDeltaPosition() - rightRear.getDeltaPosition()));
|
returnMatrix.set(1, 0, STRAFE_TICKS_TO_INCHES * (-leftFront.getDeltaPosition() + rightFront.getDeltaPosition() + leftRear.getDeltaPosition() - rightRear.getDeltaPosition()));
|
||||||
// theta/turning
|
// theta/turning
|
||||||
returnMatrix.set(2,0, TURN_TICKS_TO_RADIANS * ((-leftFront.getDeltaPosition() + rightFront.getDeltaPosition() - leftRear.getDeltaPosition() + rightRear.getDeltaPosition()) / (ROBOT_WIDTH + ROBOT_LENGTH)));
|
returnMatrix.set(2, 0, TURN_TICKS_TO_RADIANS * ((-leftFront.getDeltaPosition() + rightFront.getDeltaPosition() - leftRear.getDeltaPosition() + rightRear.getDeltaPosition()) / (ROBOT_WIDTH + ROBOT_LENGTH)));
|
||||||
return returnMatrix;
|
return returnMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,317 +0,0 @@
|
|||||||
package org.firstinspires.ftc.teamcode.pedroPathing.localization.localizers;
|
|
||||||
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.*;
|
|
||||||
|
|
||||||
import com.acmerobotics.dashboard.config.Config;
|
|
||||||
import com.qualcomm.hardware.rev.RevHubOrientationOnRobot;
|
|
||||||
import com.qualcomm.robotcore.hardware.DcMotorEx;
|
|
||||||
import com.qualcomm.robotcore.hardware.HardwareMap;
|
|
||||||
import com.qualcomm.robotcore.hardware.IMU;
|
|
||||||
|
|
||||||
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Encoder;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Localizer;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Matrix;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Pose;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.MathFunctions;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Vector;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.util.NanoTimer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the ThreeWheelIMULocalizer class. This class extends the Localizer superclass and is a
|
|
||||||
* localizer that uses the three wheel odometry set up with the IMU to have more accurate heading
|
|
||||||
* readings. The diagram below, which is modified from Road Runner, shows a typical set up.
|
|
||||||
*
|
|
||||||
* The view is from the top of the robot looking downwards.
|
|
||||||
*
|
|
||||||
* left on robot is the y positive direction
|
|
||||||
*
|
|
||||||
* forward on robot is the x positive direction
|
|
||||||
*
|
|
||||||
* /--------------\
|
|
||||||
* | ____ |
|
|
||||||
* | ---- |
|
|
||||||
* | || || |
|
|
||||||
* | || || | ----> left (y positive)
|
|
||||||
* | |
|
|
||||||
* | |
|
|
||||||
* \--------------/
|
|
||||||
* |
|
|
||||||
* |
|
|
||||||
* V
|
|
||||||
* forward (x positive)
|
|
||||||
*
|
|
||||||
* @author Logan Nash
|
|
||||||
* @author Anyi Lin - 10158 Scott's Bots
|
|
||||||
* @version 1.0, 7/9/2024
|
|
||||||
*/
|
|
||||||
@Config
|
|
||||||
public class ThreeWheelIMULocalizer extends Localizer {
|
|
||||||
private HardwareMap hardwareMap;
|
|
||||||
private Pose startPose;
|
|
||||||
private Pose displacementPose;
|
|
||||||
private Pose currentVelocity;
|
|
||||||
private Matrix prevRotationMatrix;
|
|
||||||
private NanoTimer timer;
|
|
||||||
private long deltaTimeNano;
|
|
||||||
private Encoder leftEncoder;
|
|
||||||
private Encoder rightEncoder;
|
|
||||||
private Encoder strafeEncoder;
|
|
||||||
private Pose leftEncoderPose;
|
|
||||||
private Pose rightEncoderPose;
|
|
||||||
private Pose strafeEncoderPose;
|
|
||||||
|
|
||||||
public final IMU imu;
|
|
||||||
private double previousIMUOrientation;
|
|
||||||
private double deltaRadians;
|
|
||||||
private double totalHeading;
|
|
||||||
public static double FORWARD_TICKS_TO_INCHES = 0.0029;//8192 * 1.37795 * 2 * Math.PI * 0.5008239963;
|
|
||||||
public static double STRAFE_TICKS_TO_INCHES = 0.0029;//8192 * 1.37795 * 2 * Math.PI * 0.5018874659;
|
|
||||||
public static double TURN_TICKS_TO_RADIANS = 0.0022;//8192 * 1.37795 * 2 * Math.PI * 0.5;
|
|
||||||
|
|
||||||
public static boolean useIMU = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This creates a new ThreeWheelIMULocalizer from a HardwareMap, with a starting Pose at (0,0)
|
|
||||||
* facing 0 heading.
|
|
||||||
*
|
|
||||||
* @param map the HardwareMap
|
|
||||||
*/
|
|
||||||
public ThreeWheelIMULocalizer(HardwareMap map) {
|
|
||||||
this(map, new Pose());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This creates a new ThreeWheelIMULocalizer from a HardwareMap and a Pose, with the Pose
|
|
||||||
* specifying the starting pose of the localizer.
|
|
||||||
*
|
|
||||||
* @param map the HardwareMap
|
|
||||||
* @param setStartPose the Pose to start from
|
|
||||||
*/
|
|
||||||
public ThreeWheelIMULocalizer(HardwareMap map, Pose setStartPose) {
|
|
||||||
hardwareMap = map;
|
|
||||||
imu = hardwareMap.get(IMU.class, IMU);
|
|
||||||
|
|
||||||
// TODO: replace this with your IMU's orientation
|
|
||||||
imu.initialize(new IMU.Parameters(new RevHubOrientationOnRobot(IMU_LOGO_FACING_DIRECTION, IMU_USB_FACING_DIRECTION)));
|
|
||||||
|
|
||||||
// TODO: replace these with your encoder positions
|
|
||||||
leftEncoderPose = new Pose(0, 6.19375, 0);
|
|
||||||
rightEncoderPose = new Pose(0, -6.19375, 0);
|
|
||||||
strafeEncoderPose = new Pose(-7, 0, Math.toRadians(90));
|
|
||||||
|
|
||||||
// TODO: replace these with your encoder ports
|
|
||||||
leftEncoder = new Encoder(hardwareMap.get(DcMotorEx.class, LEFT_ENCODER));
|
|
||||||
rightEncoder = new Encoder(hardwareMap.get(DcMotorEx.class, RIGHT_ENCODER));
|
|
||||||
strafeEncoder = new Encoder(hardwareMap.get(DcMotorEx.class, BACK_ENCODER));
|
|
||||||
|
|
||||||
// TODO: reverse any encoders necessary
|
|
||||||
leftEncoder.setDirection(LEFT_ENCODER_DIRECTION);
|
|
||||||
rightEncoder.setDirection(RIGHT_ENCODER_DIRECTION);
|
|
||||||
strafeEncoder.setDirection(BACK_ENCODER_DIRECTION);
|
|
||||||
|
|
||||||
setStartPose(setStartPose);
|
|
||||||
timer = new NanoTimer();
|
|
||||||
deltaTimeNano = 1;
|
|
||||||
displacementPose = new Pose();
|
|
||||||
currentVelocity = new Pose();
|
|
||||||
totalHeading = 0;
|
|
||||||
|
|
||||||
resetEncoders();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the current pose estimate.
|
|
||||||
*
|
|
||||||
* @return returns the current pose estimate as a Pose
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Pose getPose() {
|
|
||||||
return MathFunctions.addPoses(startPose, displacementPose);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the current velocity estimate.
|
|
||||||
*
|
|
||||||
* @return returns the current velocity estimate as a Pose
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Pose getVelocity() {
|
|
||||||
return currentVelocity.copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the current velocity estimate.
|
|
||||||
*
|
|
||||||
* @return returns the current velocity estimate as a Vector
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Vector getVelocityVector() {
|
|
||||||
return currentVelocity.getVector();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This sets the start pose. Changing the start pose should move the robot as if all its
|
|
||||||
* previous movements were displacing it from its new start pose.
|
|
||||||
*
|
|
||||||
* @param setStart the new start pose
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setStartPose(Pose setStart) {
|
|
||||||
startPose = setStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This sets the Matrix that contains the previous pose's heading rotation.
|
|
||||||
*
|
|
||||||
* @param heading the rotation of the Matrix
|
|
||||||
*/
|
|
||||||
public void setPrevRotationMatrix(double heading) {
|
|
||||||
prevRotationMatrix = new Matrix(3,3);
|
|
||||||
prevRotationMatrix.set(0, 0, Math.cos(heading));
|
|
||||||
prevRotationMatrix.set(0, 1, -Math.sin(heading));
|
|
||||||
prevRotationMatrix.set(1, 0, Math.sin(heading));
|
|
||||||
prevRotationMatrix.set(1, 1, Math.cos(heading));
|
|
||||||
prevRotationMatrix.set(2, 2, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This sets the current pose estimate. Changing this should just change the robot's current
|
|
||||||
* pose estimate, not anything to do with the start pose.
|
|
||||||
*
|
|
||||||
* @param setPose the new current pose estimate
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setPose(Pose setPose) {
|
|
||||||
displacementPose = MathFunctions.subtractPoses(setPose, startPose);
|
|
||||||
resetEncoders();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This updates the elapsed time timer that keeps track of time between updates, as well as the
|
|
||||||
* change position of the Encoders. Then, the robot's global change in position is calculated
|
|
||||||
* using the pose exponential method.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void update() {
|
|
||||||
deltaTimeNano = timer.getElapsedTime();
|
|
||||||
timer.resetTimer();
|
|
||||||
|
|
||||||
updateEncoders();
|
|
||||||
Matrix robotDeltas = getRobotDeltas();
|
|
||||||
Matrix globalDeltas;
|
|
||||||
setPrevRotationMatrix(getPose().getHeading());
|
|
||||||
|
|
||||||
Matrix transformation = new Matrix(3,3);
|
|
||||||
if (Math.abs(robotDeltas.get(2, 0)) < 0.001) {
|
|
||||||
transformation.set(0, 0, 1.0 - (Math.pow(robotDeltas.get(2, 0), 2) / 6.0));
|
|
||||||
transformation.set(0, 1, -robotDeltas.get(2, 0) / 2.0);
|
|
||||||
transformation.set(1, 0, robotDeltas.get(2, 0) / 2.0);
|
|
||||||
transformation.set(1, 1, 1.0 - (Math.pow(robotDeltas.get(2, 0), 2) / 6.0));
|
|
||||||
transformation.set(2, 2, 1.0);
|
|
||||||
} else {
|
|
||||||
transformation.set(0, 0, Math.sin(robotDeltas.get(2, 0)) / robotDeltas.get(2, 0));
|
|
||||||
transformation.set(0, 1, (Math.cos(robotDeltas.get(2, 0)) - 1.0) / robotDeltas.get(2, 0));
|
|
||||||
transformation.set(1, 0, (1.0 - Math.cos(robotDeltas.get(2, 0))) / robotDeltas.get(2, 0));
|
|
||||||
transformation.set(1, 1, Math.sin(robotDeltas.get(2, 0)) / robotDeltas.get(2, 0));
|
|
||||||
transformation.set(2, 2, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
globalDeltas = Matrix.multiply(Matrix.multiply(prevRotationMatrix, transformation), robotDeltas);
|
|
||||||
|
|
||||||
displacementPose.add(new Pose(globalDeltas.get(0, 0), globalDeltas.get(1, 0), globalDeltas.get(2, 0)));
|
|
||||||
currentVelocity = new Pose(globalDeltas.get(0, 0) / (deltaTimeNano * Math.pow(10.0, 9)), globalDeltas.get(1, 0) / (deltaTimeNano * Math.pow(10.0, 9)), globalDeltas.get(2, 0) / (deltaTimeNano * Math.pow(10.0, 9)));
|
|
||||||
|
|
||||||
totalHeading += globalDeltas.get(2, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This updates the Encoders.
|
|
||||||
*/
|
|
||||||
public void updateEncoders() {
|
|
||||||
leftEncoder.update();
|
|
||||||
rightEncoder.update();
|
|
||||||
strafeEncoder.update();
|
|
||||||
|
|
||||||
double currentIMUOrientation = MathFunctions.normalizeAngle(imu.getRobotYawPitchRollAngles().getYaw(AngleUnit.RADIANS));
|
|
||||||
deltaRadians = MathFunctions.getTurnDirection(previousIMUOrientation, currentIMUOrientation) * MathFunctions.getSmallestAngleDifference(currentIMUOrientation, previousIMUOrientation);
|
|
||||||
previousIMUOrientation = currentIMUOrientation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This resets the Encoders.
|
|
||||||
*/
|
|
||||||
public void resetEncoders() {
|
|
||||||
leftEncoder.reset();
|
|
||||||
rightEncoder.reset();
|
|
||||||
strafeEncoder.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This calculates the change in position from the perspective of the robot using information
|
|
||||||
* from the Encoders.
|
|
||||||
*
|
|
||||||
* @return returns a Matrix containing the robot relative movement.
|
|
||||||
*/
|
|
||||||
public Matrix getRobotDeltas() {
|
|
||||||
Matrix returnMatrix = new Matrix(3,1);
|
|
||||||
// x/forward movement
|
|
||||||
returnMatrix.set(0,0, FORWARD_TICKS_TO_INCHES * ((rightEncoder.getDeltaPosition() * leftEncoderPose.getY() - leftEncoder.getDeltaPosition() * rightEncoderPose.getY()) / (leftEncoderPose.getY() - rightEncoderPose.getY())));
|
|
||||||
//y/strafe movement
|
|
||||||
returnMatrix.set(1,0, STRAFE_TICKS_TO_INCHES * (strafeEncoder.getDeltaPosition() - strafeEncoderPose.getX() * ((rightEncoder.getDeltaPosition() - leftEncoder.getDeltaPosition()) / (leftEncoderPose.getY() - rightEncoderPose.getY()))));
|
|
||||||
// theta/turning
|
|
||||||
if (MathFunctions.getSmallestAngleDifference(0, deltaRadians) > 0.00005 && useIMU) {
|
|
||||||
returnMatrix.set(2, 0, deltaRadians);
|
|
||||||
} else {
|
|
||||||
returnMatrix.set(2,0, TURN_TICKS_TO_RADIANS * ((rightEncoder.getDeltaPosition() - leftEncoder.getDeltaPosition()) / (leftEncoderPose.getY() - rightEncoderPose.getY())));
|
|
||||||
}
|
|
||||||
return returnMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns how far the robot has turned in radians, in a number not clamped between 0 and
|
|
||||||
* 2 * pi radians. This is used for some tuning things and nothing actually within the following.
|
|
||||||
*
|
|
||||||
* @return returns how far the robot has turned in total, in radians.
|
|
||||||
*/
|
|
||||||
public double getTotalHeading() {
|
|
||||||
return totalHeading;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the multiplier applied to forward movement measurement to convert from encoder
|
|
||||||
* ticks to inches. This is found empirically through a tuner.
|
|
||||||
*
|
|
||||||
* @return returns the forward ticks to inches multiplier
|
|
||||||
*/
|
|
||||||
public double getForwardMultiplier() {
|
|
||||||
return FORWARD_TICKS_TO_INCHES;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the multiplier applied to lateral/strafe movement measurement to convert from
|
|
||||||
* encoder ticks to inches. This is found empirically through a tuner.
|
|
||||||
*
|
|
||||||
* @return returns the lateral/strafe ticks to inches multiplier
|
|
||||||
*/
|
|
||||||
public double getLateralMultiplier() {
|
|
||||||
return STRAFE_TICKS_TO_INCHES;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the multiplier applied to turning movement measurement to convert from encoder
|
|
||||||
* ticks to radians. This is found empirically through a tuner.
|
|
||||||
*
|
|
||||||
* @return returns the turning ticks to radians multiplier
|
|
||||||
*/
|
|
||||||
public double getTurningMultiplier() {
|
|
||||||
return TURN_TICKS_TO_RADIANS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This resets the IMU.
|
|
||||||
*/
|
|
||||||
public void resetIMU() {
|
|
||||||
imu.resetYaw();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,294 +0,0 @@
|
|||||||
package org.firstinspires.ftc.teamcode.pedroPathing.localization.localizers;
|
|
||||||
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.*;
|
|
||||||
|
|
||||||
import com.acmerobotics.dashboard.config.Config;
|
|
||||||
import com.qualcomm.robotcore.hardware.DcMotorEx;
|
|
||||||
import com.qualcomm.robotcore.hardware.HardwareMap;
|
|
||||||
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Encoder;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Localizer;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Matrix;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Pose;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.MathFunctions;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Vector;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.util.NanoTimer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the ThreeWheelLocalizer class. This class extends the Localizer superclass and is a
|
|
||||||
* localizer that uses the three wheel odometry set up. The diagram below, which is modified from
|
|
||||||
* Road Runner, shows a typical set up.
|
|
||||||
*
|
|
||||||
* The view is from the top of the robot looking downwards.
|
|
||||||
*
|
|
||||||
* left on robot is the y positive direction
|
|
||||||
*
|
|
||||||
* forward on robot is the x positive direction
|
|
||||||
*
|
|
||||||
* /--------------\
|
|
||||||
* | ____ |
|
|
||||||
* | ---- |
|
|
||||||
* | || || |
|
|
||||||
* | || || | ----> left (y positive)
|
|
||||||
* | |
|
|
||||||
* | |
|
|
||||||
* \--------------/
|
|
||||||
* |
|
|
||||||
* |
|
|
||||||
* V
|
|
||||||
* forward (x positive)
|
|
||||||
*
|
|
||||||
* @author Anyi Lin - 10158 Scott's Bots
|
|
||||||
* @version 1.0, 4/2/2024
|
|
||||||
*/
|
|
||||||
@Config
|
|
||||||
public class ThreeWheelLocalizer extends Localizer {
|
|
||||||
private HardwareMap hardwareMap;
|
|
||||||
private Pose startPose;
|
|
||||||
private Pose displacementPose;
|
|
||||||
private Pose currentVelocity;
|
|
||||||
private Matrix prevRotationMatrix;
|
|
||||||
private NanoTimer timer;
|
|
||||||
private long deltaTimeNano;
|
|
||||||
private Encoder leftEncoder;
|
|
||||||
private Encoder rightEncoder;
|
|
||||||
private Encoder strafeEncoder;
|
|
||||||
private Pose leftEncoderPose;
|
|
||||||
private Pose rightEncoderPose;
|
|
||||||
private Pose strafeEncoderPose;
|
|
||||||
private double totalHeading;
|
|
||||||
public static double FORWARD_TICKS_TO_INCHES = 0.0029;//8192 * 1.37795 * 2 * Math.PI * 0.5008239963;
|
|
||||||
public static double STRAFE_TICKS_TO_INCHES = 0.0029;//8192 * 1.37795 * 2 * Math.PI * 0.5018874659;
|
|
||||||
public static double TURN_TICKS_TO_RADIANS = 0.003;//8192 * 1.37795 * 2 * Math.PI * 0.5;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This creates a new ThreeWheelLocalizer from a HardwareMap, with a starting Pose at (0,0)
|
|
||||||
* facing 0 heading.
|
|
||||||
*
|
|
||||||
* @param map the HardwareMap
|
|
||||||
*/
|
|
||||||
public ThreeWheelLocalizer(HardwareMap map) {
|
|
||||||
this(map, new Pose());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This creates a new ThreeWheelLocalizer from a HardwareMap and a Pose, with the Pose
|
|
||||||
* specifying the starting pose of the localizer.
|
|
||||||
*
|
|
||||||
* @param map the HardwareMap
|
|
||||||
* @param setStartPose the Pose to start from
|
|
||||||
*/
|
|
||||||
public ThreeWheelLocalizer(HardwareMap map, Pose setStartPose) {
|
|
||||||
// TODO: replace these with your encoder positions
|
|
||||||
leftEncoderPose = new Pose(0, 6.25, 0);
|
|
||||||
rightEncoderPose = new Pose(0, -6.25, 0);
|
|
||||||
strafeEncoderPose = new Pose(-7, 0, Math.toRadians(90));
|
|
||||||
|
|
||||||
hardwareMap = map;
|
|
||||||
|
|
||||||
// TODO: replace these with your encoder ports
|
|
||||||
leftEncoder = new Encoder(hardwareMap.get(DcMotorEx.class, LEFT_ENCODER));
|
|
||||||
rightEncoder = new Encoder(hardwareMap.get(DcMotorEx.class, RIGHT_ENCODER));
|
|
||||||
strafeEncoder = new Encoder(hardwareMap.get(DcMotorEx.class, BACK_ENCODER));
|
|
||||||
|
|
||||||
// TODO: reverse any encoders necessary
|
|
||||||
leftEncoder.setDirection(LEFT_ENCODER_DIRECTION);
|
|
||||||
rightEncoder.setDirection(RIGHT_ENCODER_DIRECTION);
|
|
||||||
strafeEncoder.setDirection(BACK_ENCODER_DIRECTION);
|
|
||||||
|
|
||||||
setStartPose(setStartPose);
|
|
||||||
timer = new NanoTimer();
|
|
||||||
deltaTimeNano = 1;
|
|
||||||
displacementPose = new Pose();
|
|
||||||
currentVelocity = new Pose();
|
|
||||||
totalHeading = 0;
|
|
||||||
|
|
||||||
resetEncoders();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the current pose estimate.
|
|
||||||
*
|
|
||||||
* @return returns the current pose estimate as a Pose
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Pose getPose() {
|
|
||||||
return MathFunctions.addPoses(startPose, displacementPose);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the current velocity estimate.
|
|
||||||
*
|
|
||||||
* @return returns the current velocity estimate as a Pose
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Pose getVelocity() {
|
|
||||||
return currentVelocity.copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the current velocity estimate.
|
|
||||||
*
|
|
||||||
* @return returns the current velocity estimate as a Vector
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Vector getVelocityVector() {
|
|
||||||
return currentVelocity.getVector();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This sets the start pose. Changing the start pose should move the robot as if all its
|
|
||||||
* previous movements were displacing it from its new start pose.
|
|
||||||
*
|
|
||||||
* @param setStart the new start pose
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setStartPose(Pose setStart) {
|
|
||||||
startPose = setStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This sets the Matrix that contains the previous pose's heading rotation.
|
|
||||||
*
|
|
||||||
* @param heading the rotation of the Matrix
|
|
||||||
*/
|
|
||||||
public void setPrevRotationMatrix(double heading) {
|
|
||||||
prevRotationMatrix = new Matrix(3,3);
|
|
||||||
prevRotationMatrix.set(0, 0, Math.cos(heading));
|
|
||||||
prevRotationMatrix.set(0, 1, -Math.sin(heading));
|
|
||||||
prevRotationMatrix.set(1, 0, Math.sin(heading));
|
|
||||||
prevRotationMatrix.set(1, 1, Math.cos(heading));
|
|
||||||
prevRotationMatrix.set(2, 2, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This sets the current pose estimate. Changing this should just change the robot's current
|
|
||||||
* pose estimate, not anything to do with the start pose.
|
|
||||||
*
|
|
||||||
* @param setPose the new current pose estimate
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setPose(Pose setPose) {
|
|
||||||
displacementPose = MathFunctions.subtractPoses(setPose, startPose);
|
|
||||||
resetEncoders();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This updates the elapsed time timer that keeps track of time between updates, as well as the
|
|
||||||
* change position of the Encoders. Then, the robot's global change in position is calculated
|
|
||||||
* using the pose exponential method.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void update() {
|
|
||||||
deltaTimeNano = timer.getElapsedTime();
|
|
||||||
timer.resetTimer();
|
|
||||||
|
|
||||||
updateEncoders();
|
|
||||||
Matrix robotDeltas = getRobotDeltas();
|
|
||||||
Matrix globalDeltas;
|
|
||||||
setPrevRotationMatrix(getPose().getHeading());
|
|
||||||
|
|
||||||
Matrix transformation = new Matrix(3,3);
|
|
||||||
if (Math.abs(robotDeltas.get(2, 0)) < 0.001) {
|
|
||||||
transformation.set(0, 0, 1.0 - (Math.pow(robotDeltas.get(2, 0), 2) / 6.0));
|
|
||||||
transformation.set(0, 1, -robotDeltas.get(2, 0) / 2.0);
|
|
||||||
transformation.set(1, 0, robotDeltas.get(2, 0) / 2.0);
|
|
||||||
transformation.set(1, 1, 1.0 - (Math.pow(robotDeltas.get(2, 0), 2) / 6.0));
|
|
||||||
transformation.set(2, 2, 1.0);
|
|
||||||
} else {
|
|
||||||
transformation.set(0, 0, Math.sin(robotDeltas.get(2, 0)) / robotDeltas.get(2, 0));
|
|
||||||
transformation.set(0, 1, (Math.cos(robotDeltas.get(2, 0)) - 1.0) / robotDeltas.get(2, 0));
|
|
||||||
transformation.set(1, 0, (1.0 - Math.cos(robotDeltas.get(2, 0))) / robotDeltas.get(2, 0));
|
|
||||||
transformation.set(1, 1, Math.sin(robotDeltas.get(2, 0)) / robotDeltas.get(2, 0));
|
|
||||||
transformation.set(2, 2, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
globalDeltas = Matrix.multiply(Matrix.multiply(prevRotationMatrix, transformation), robotDeltas);
|
|
||||||
|
|
||||||
displacementPose.add(new Pose(globalDeltas.get(0, 0), globalDeltas.get(1, 0), globalDeltas.get(2, 0)));
|
|
||||||
currentVelocity = new Pose(globalDeltas.get(0, 0) / (deltaTimeNano * Math.pow(10.0, 9)), globalDeltas.get(1, 0) / (deltaTimeNano * Math.pow(10.0, 9)), globalDeltas.get(2, 0) / (deltaTimeNano * Math.pow(10.0, 9)));
|
|
||||||
|
|
||||||
totalHeading += globalDeltas.get(2, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This updates the Encoders.
|
|
||||||
*/
|
|
||||||
public void updateEncoders() {
|
|
||||||
leftEncoder.update();
|
|
||||||
rightEncoder.update();
|
|
||||||
strafeEncoder.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This resets the Encoders.
|
|
||||||
*/
|
|
||||||
public void resetEncoders() {
|
|
||||||
leftEncoder.reset();
|
|
||||||
rightEncoder.reset();
|
|
||||||
strafeEncoder.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This calculates the change in position from the perspective of the robot using information
|
|
||||||
* from the Encoders.
|
|
||||||
*
|
|
||||||
* @return returns a Matrix containing the robot relative movement.
|
|
||||||
*/
|
|
||||||
public Matrix getRobotDeltas() {
|
|
||||||
Matrix returnMatrix = new Matrix(3,1);
|
|
||||||
// x/forward movement
|
|
||||||
returnMatrix.set(0,0, FORWARD_TICKS_TO_INCHES * ((rightEncoder.getDeltaPosition() * leftEncoderPose.getY() - leftEncoder.getDeltaPosition() * rightEncoderPose.getY()) / (leftEncoderPose.getY() - rightEncoderPose.getY())));
|
|
||||||
//y/strafe movement
|
|
||||||
returnMatrix.set(1,0, STRAFE_TICKS_TO_INCHES * (strafeEncoder.getDeltaPosition() - strafeEncoderPose.getX() * ((rightEncoder.getDeltaPosition() - leftEncoder.getDeltaPosition()) / (leftEncoderPose.getY() - rightEncoderPose.getY()))));
|
|
||||||
// theta/turning
|
|
||||||
returnMatrix.set(2,0, TURN_TICKS_TO_RADIANS * ((rightEncoder.getDeltaPosition() - leftEncoder.getDeltaPosition()) / (leftEncoderPose.getY() - rightEncoderPose.getY())));
|
|
||||||
return returnMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns how far the robot has turned in radians, in a number not clamped between 0 and
|
|
||||||
* 2 * pi radians. This is used for some tuning things and nothing actually within the following.
|
|
||||||
*
|
|
||||||
* @return returns how far the robot has turned in total, in radians.
|
|
||||||
*/
|
|
||||||
public double getTotalHeading() {
|
|
||||||
return totalHeading;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the multiplier applied to forward movement measurement to convert from encoder
|
|
||||||
* ticks to inches. This is found empirically through a tuner.
|
|
||||||
*
|
|
||||||
* @return returns the forward ticks to inches multiplier
|
|
||||||
*/
|
|
||||||
public double getForwardMultiplier() {
|
|
||||||
return FORWARD_TICKS_TO_INCHES;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the multiplier applied to lateral/strafe movement measurement to convert from
|
|
||||||
* encoder ticks to inches. This is found empirically through a tuner.
|
|
||||||
*
|
|
||||||
* @return returns the lateral/strafe ticks to inches multiplier
|
|
||||||
*/
|
|
||||||
public double getLateralMultiplier() {
|
|
||||||
return STRAFE_TICKS_TO_INCHES;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the multiplier applied to turning movement measurement to convert from encoder
|
|
||||||
* ticks to radians. This is found empirically through a tuner.
|
|
||||||
*
|
|
||||||
* @return returns the turning ticks to radians multiplier
|
|
||||||
*/
|
|
||||||
public double getTurningMultiplier() {
|
|
||||||
return TURN_TICKS_TO_RADIANS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This does nothing since this localizer does not use the IMU.
|
|
||||||
*/
|
|
||||||
public void resetIMU() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,302 +0,0 @@
|
|||||||
package org.firstinspires.ftc.teamcode.pedroPathing.localization.localizers;
|
|
||||||
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_ENCODER;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.LEFT_ENCODER;
|
|
||||||
|
|
||||||
import com.acmerobotics.dashboard.config.Config;
|
|
||||||
import com.qualcomm.hardware.rev.RevHubOrientationOnRobot;
|
|
||||||
import com.qualcomm.robotcore.hardware.DcMotorEx;
|
|
||||||
import com.qualcomm.robotcore.hardware.HardwareMap;
|
|
||||||
import com.qualcomm.robotcore.hardware.IMU;
|
|
||||||
|
|
||||||
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Encoder;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Localizer;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Matrix;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Pose;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.MathFunctions;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Vector;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.util.NanoTimer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is the TwoWheelLocalizer class. This class extends the Localizer superclass and is a
|
|
||||||
* localizer that uses the two wheel odometry with IMU set up. The diagram below, which is modified from
|
|
||||||
* Road Runner, shows a typical set up.
|
|
||||||
*
|
|
||||||
* The view is from the top of the robot looking downwards.
|
|
||||||
*
|
|
||||||
* left on robot is the y positive direction
|
|
||||||
*
|
|
||||||
* forward on robot is the x positive direction
|
|
||||||
*
|
|
||||||
* /--------------\
|
|
||||||
* | ____ |
|
|
||||||
* | ---- |
|
|
||||||
* | || || |
|
|
||||||
* | || || | ----> left (y positive)
|
|
||||||
* | |
|
|
||||||
* | |
|
|
||||||
* \--------------/
|
|
||||||
* |
|
|
||||||
* |
|
|
||||||
* V
|
|
||||||
* forward (x positive)
|
|
||||||
*
|
|
||||||
* @author Anyi Lin - 10158 Scott's Bots
|
|
||||||
* @version 1.0, 4/2/2024
|
|
||||||
*/
|
|
||||||
@Config
|
|
||||||
public class TwoWheelLocalizer extends Localizer { // todo: make two wheel odo work
|
|
||||||
private HardwareMap hardwareMap;
|
|
||||||
private IMU imu;
|
|
||||||
private Pose startPose;
|
|
||||||
private Pose displacementPose;
|
|
||||||
private Pose currentVelocity;
|
|
||||||
private Matrix prevRotationMatrix;
|
|
||||||
private NanoTimer timer;
|
|
||||||
private long deltaTimeNano;
|
|
||||||
private Encoder forwardEncoder;
|
|
||||||
private Encoder strafeEncoder;
|
|
||||||
private Pose forwardEncoderPose;
|
|
||||||
private Pose strafeEncoderPose;
|
|
||||||
private double previousIMUOrientation;
|
|
||||||
private double deltaRadians;
|
|
||||||
private double totalHeading;
|
|
||||||
public static double FORWARD_TICKS_TO_INCHES = 8192 * 1.37795 * 2 * Math.PI * 0.5008239963;
|
|
||||||
public static double STRAFE_TICKS_TO_INCHES = 8192 * 1.37795 * 2 * Math.PI * 0.5018874659;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This creates a new TwoWheelLocalizer from a HardwareMap, with a starting Pose at (0,0)
|
|
||||||
* facing 0 heading.
|
|
||||||
*
|
|
||||||
* @param map the HardwareMap
|
|
||||||
*/
|
|
||||||
public TwoWheelLocalizer(HardwareMap map) {
|
|
||||||
this(map, new Pose());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This creates a new TwoWheelLocalizer from a HardwareMap and a Pose, with the Pose
|
|
||||||
* specifying the starting pose of the localizer.
|
|
||||||
*
|
|
||||||
* @param map the HardwareMap
|
|
||||||
* @param setStartPose the Pose to start from
|
|
||||||
*/
|
|
||||||
public TwoWheelLocalizer(HardwareMap map, Pose setStartPose) {
|
|
||||||
// TODO: replace these with your encoder positions
|
|
||||||
forwardEncoderPose = new Pose(-18.5/25.4 - 0.1, 164.4/25.4, 0);
|
|
||||||
strafeEncoderPose = new Pose(-107.9/25.4+0.25, -1.1/25.4-0.23, Math.toRadians(90));
|
|
||||||
|
|
||||||
hardwareMap = map;
|
|
||||||
|
|
||||||
imu = hardwareMap.get(IMU.class, "imu");
|
|
||||||
// TODO: replace this with your IMU's orientation
|
|
||||||
imu.initialize(new IMU.Parameters(new RevHubOrientationOnRobot(RevHubOrientationOnRobot.LogoFacingDirection.UP, RevHubOrientationOnRobot.UsbFacingDirection.LEFT)));
|
|
||||||
|
|
||||||
// TODO: replace these with your encoder ports
|
|
||||||
forwardEncoder = new Encoder(hardwareMap.get(DcMotorEx.class, LEFT_ENCODER));
|
|
||||||
strafeEncoder = new Encoder(hardwareMap.get(DcMotorEx.class, BACK_ENCODER));
|
|
||||||
|
|
||||||
// TODO: reverse any encoders necessary
|
|
||||||
forwardEncoder.setDirection(Encoder.REVERSE);
|
|
||||||
strafeEncoder.setDirection(Encoder.FORWARD);
|
|
||||||
|
|
||||||
setStartPose(setStartPose);
|
|
||||||
timer = new NanoTimer();
|
|
||||||
deltaTimeNano = 1;
|
|
||||||
displacementPose = new Pose();
|
|
||||||
currentVelocity = new Pose();
|
|
||||||
|
|
||||||
previousIMUOrientation = MathFunctions.normalizeAngle(imu.getRobotYawPitchRollAngles().getYaw(AngleUnit.RADIANS));
|
|
||||||
deltaRadians = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the current pose estimate.
|
|
||||||
*
|
|
||||||
* @return returns the current pose estimate as a Pose
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Pose getPose() {
|
|
||||||
return MathFunctions.addPoses(startPose, displacementPose);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the current velocity estimate.
|
|
||||||
*
|
|
||||||
* @return returns the current velocity estimate as a Pose
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Pose getVelocity() {
|
|
||||||
return currentVelocity.copy();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the current velocity estimate.
|
|
||||||
*
|
|
||||||
* @return returns the current velocity estimate as a Vector
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Vector getVelocityVector() {
|
|
||||||
return currentVelocity.getVector();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This sets the start pose. Changing the start pose should move the robot as if all its
|
|
||||||
* previous movements were displacing it from its new start pose.
|
|
||||||
*
|
|
||||||
* @param setStart the new start pose
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setStartPose(Pose setStart) {
|
|
||||||
startPose = setStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This sets the Matrix that contains the previous pose's heading rotation.
|
|
||||||
*
|
|
||||||
* @param heading the rotation of the Matrix
|
|
||||||
*/
|
|
||||||
public void setPrevRotationMatrix(double heading) {
|
|
||||||
prevRotationMatrix = new Matrix(3,3);
|
|
||||||
prevRotationMatrix.set(0, 0, Math.cos(heading));
|
|
||||||
prevRotationMatrix.set(0, 1, -Math.sin(heading));
|
|
||||||
prevRotationMatrix.set(1, 0, Math.sin(heading));
|
|
||||||
prevRotationMatrix.set(1, 1, Math.cos(heading));
|
|
||||||
prevRotationMatrix.set(2, 2, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This sets the current pose estimate. Changing this should just change the robot's current
|
|
||||||
* pose estimate, not anything to do with the start pose.
|
|
||||||
*
|
|
||||||
* @param setPose the new current pose estimate
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setPose(Pose setPose) {
|
|
||||||
displacementPose = MathFunctions.subtractPoses(setPose, startPose);
|
|
||||||
resetEncoders();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This updates the elapsed time timer that keeps track of time between updates, as well as the
|
|
||||||
* change position of the Encoders and the IMU readings. Then, the robot's global change in
|
|
||||||
* position is calculated using the pose exponential method.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void update() {
|
|
||||||
deltaTimeNano = timer.getElapsedTime();
|
|
||||||
timer.resetTimer();
|
|
||||||
|
|
||||||
updateEncoders();
|
|
||||||
Matrix robotDeltas = getRobotDeltas();
|
|
||||||
Matrix globalDeltas;
|
|
||||||
setPrevRotationMatrix(getPose().getHeading());
|
|
||||||
|
|
||||||
Matrix transformation = new Matrix(3,3);
|
|
||||||
if (Math.abs(robotDeltas.get(2, 0)) < 0.001) {
|
|
||||||
transformation.set(0, 0, 1.0 - (Math.pow(robotDeltas.get(2, 0), 2) / 6.0));
|
|
||||||
transformation.set(0, 1, -robotDeltas.get(2, 0) / 2.0);
|
|
||||||
transformation.set(1, 0, robotDeltas.get(2, 0) / 2.0);
|
|
||||||
transformation.set(1, 1, 1.0 - (Math.pow(robotDeltas.get(2, 0), 2) / 6.0));
|
|
||||||
transformation.set(2, 2, 1.0);
|
|
||||||
} else {
|
|
||||||
transformation.set(0, 0, Math.sin(robotDeltas.get(2, 0)) / robotDeltas.get(2, 0));
|
|
||||||
transformation.set(0, 1, (Math.cos(robotDeltas.get(2, 0)) - 1.0) / robotDeltas.get(2, 0));
|
|
||||||
transformation.set(1, 0, (1.0 - Math.cos(robotDeltas.get(2, 0))) / robotDeltas.get(2, 0));
|
|
||||||
transformation.set(1, 1, Math.sin(robotDeltas.get(2, 0)) / robotDeltas.get(2, 0));
|
|
||||||
transformation.set(2, 2, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
globalDeltas = Matrix.multiply(Matrix.multiply(prevRotationMatrix, transformation), robotDeltas);
|
|
||||||
|
|
||||||
displacementPose.add(new Pose(globalDeltas.get(0, 0), globalDeltas.get(1, 0), globalDeltas.get(2, 0)));
|
|
||||||
currentVelocity = new Pose(globalDeltas.get(0, 0) / (deltaTimeNano * Math.pow(10.0, 9)), globalDeltas.get(1, 0) / (deltaTimeNano * Math.pow(10.0, 9)), globalDeltas.get(2, 0) / (deltaTimeNano * Math.pow(10.0, 9)));
|
|
||||||
|
|
||||||
totalHeading += globalDeltas.get(2, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This updates the Encoders as well as the IMU.
|
|
||||||
*/
|
|
||||||
public void updateEncoders() {
|
|
||||||
forwardEncoder.update();
|
|
||||||
strafeEncoder.update();
|
|
||||||
|
|
||||||
double currentIMUOrientation = MathFunctions.normalizeAngle(imu.getRobotYawPitchRollAngles().getYaw(AngleUnit.RADIANS));
|
|
||||||
deltaRadians = MathFunctions.getTurnDirection(previousIMUOrientation, currentIMUOrientation) * MathFunctions.getSmallestAngleDifference(currentIMUOrientation, previousIMUOrientation);
|
|
||||||
previousIMUOrientation = currentIMUOrientation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This resets the Encoders.
|
|
||||||
*/
|
|
||||||
public void resetEncoders() {
|
|
||||||
forwardEncoder.reset();
|
|
||||||
strafeEncoder.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This calculates the change in position from the perspective of the robot using information
|
|
||||||
* from the Encoders and IMU.
|
|
||||||
*
|
|
||||||
* @return returns a Matrix containing the robot relative movement.
|
|
||||||
*/
|
|
||||||
public Matrix getRobotDeltas() {
|
|
||||||
Matrix returnMatrix = new Matrix(3,1);
|
|
||||||
// x/forward movement
|
|
||||||
returnMatrix.set(0,0, FORWARD_TICKS_TO_INCHES * (forwardEncoder.getDeltaPosition() - forwardEncoderPose.getY() * deltaRadians));
|
|
||||||
//y/strafe movement
|
|
||||||
returnMatrix.set(1,0, STRAFE_TICKS_TO_INCHES * (strafeEncoder.getDeltaPosition() - strafeEncoderPose.getX() * deltaRadians));
|
|
||||||
// theta/turning
|
|
||||||
returnMatrix.set(2,0, deltaRadians);
|
|
||||||
return returnMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns how far the robot has turned in radians, in a number not clamped between 0 and
|
|
||||||
* 2 * pi radians. This is used for some tuning things and nothing actually within the following.
|
|
||||||
*
|
|
||||||
* @return returns how far the robot has turned in total, in radians.
|
|
||||||
*/
|
|
||||||
public double getTotalHeading() {
|
|
||||||
return totalHeading;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the multiplier applied to forward movement measurement to convert from encoder
|
|
||||||
* ticks to inches. This is found empirically through a tuner.
|
|
||||||
*
|
|
||||||
* @return returns the forward ticks to inches multiplier
|
|
||||||
*/
|
|
||||||
public double getForwardMultiplier() {
|
|
||||||
return FORWARD_TICKS_TO_INCHES;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the multiplier applied to lateral/strafe movement measurement to convert from
|
|
||||||
* encoder ticks to inches. This is found empirically through a tuner.
|
|
||||||
*
|
|
||||||
* @return returns the lateral/strafe ticks to inches multiplier
|
|
||||||
*/
|
|
||||||
public double getLateralMultiplier() {
|
|
||||||
return STRAFE_TICKS_TO_INCHES;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This returns the multiplier applied to turning movement measurement to convert from encoder
|
|
||||||
* ticks to radians. This is found empirically through a tuner.
|
|
||||||
*
|
|
||||||
* @return returns the turning ticks to radians multiplier
|
|
||||||
*/
|
|
||||||
public double getTurningMultiplier() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This resets the IMU.
|
|
||||||
*/
|
|
||||||
public void resetIMU() {
|
|
||||||
imu.resetYaw();
|
|
||||||
}
|
|
||||||
}
|
|
@ -63,6 +63,7 @@ public class LateralTuner extends OpMode {
|
|||||||
telemetryA.addData("distance moved", poseUpdater.getPose().getY());
|
telemetryA.addData("distance moved", poseUpdater.getPose().getY());
|
||||||
telemetryA.addLine("The multiplier will display what your strafe ticks to inches should be to scale your current distance to " + DISTANCE + " inches.");
|
telemetryA.addLine("The multiplier will display what your strafe ticks to inches should be to scale your current distance to " + DISTANCE + " inches.");
|
||||||
telemetryA.addData("multiplier", DISTANCE / (poseUpdater.getPose().getY() / poseUpdater.getLocalizer().getLateralMultiplier()));
|
telemetryA.addData("multiplier", DISTANCE / (poseUpdater.getPose().getY() / poseUpdater.getLocalizer().getLateralMultiplier()));
|
||||||
|
|
||||||
telemetryA.update();
|
telemetryA.update();
|
||||||
|
|
||||||
Drawing.drawPoseHistory(dashboardPoseTracker, "#4CAF50");
|
Drawing.drawPoseHistory(dashboardPoseTracker, "#4CAF50");
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package org.firstinspires.ftc.teamcode.pedroPathing.localization.tuning;
|
package org.firstinspires.ftc.teamcode.pedroPathing.localization.tuning;
|
||||||
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_LEFT_MOTOR_DIRECTION;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_RIGHT_MOTOR_DIRECTION;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_LEFT_MOTOR_DIRECTION;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_RIGHT_MOTOR_DIRECTION;
|
|
||||||
import static org.firstinspires.ftc.teamcode.pedroPathing.tuning.FollowerConstants.leftFrontMotorName;
|
import static org.firstinspires.ftc.teamcode.pedroPathing.tuning.FollowerConstants.leftFrontMotorName;
|
||||||
import static org.firstinspires.ftc.teamcode.pedroPathing.tuning.FollowerConstants.leftRearMotorName;
|
import static org.firstinspires.ftc.teamcode.pedroPathing.tuning.FollowerConstants.leftRearMotorName;
|
||||||
import static org.firstinspires.ftc.teamcode.pedroPathing.tuning.FollowerConstants.rightFrontMotorName;
|
import static org.firstinspires.ftc.teamcode.pedroPathing.tuning.FollowerConstants.rightFrontMotorName;
|
||||||
@ -62,11 +58,6 @@ public class LocalizationTest extends OpMode {
|
|||||||
rightRear = hardwareMap.get(DcMotorEx.class, rightRearMotorName);
|
rightRear = hardwareMap.get(DcMotorEx.class, rightRearMotorName);
|
||||||
rightFront = hardwareMap.get(DcMotorEx.class, rightFrontMotorName);
|
rightFront = hardwareMap.get(DcMotorEx.class, rightFrontMotorName);
|
||||||
|
|
||||||
leftFront.setDirection(FRONT_LEFT_MOTOR_DIRECTION);
|
|
||||||
leftRear.setDirection(BACK_LEFT_MOTOR_DIRECTION);
|
|
||||||
rightFront.setDirection(FRONT_RIGHT_MOTOR_DIRECTION);
|
|
||||||
rightRear.setDirection(BACK_RIGHT_MOTOR_DIRECTION);
|
|
||||||
|
|
||||||
motors = Arrays.asList(leftFront, leftRear, rightFront, rightRear);
|
motors = Arrays.asList(leftFront, leftRear, rightFront, rightRear);
|
||||||
|
|
||||||
for (DcMotorEx motor : motors) {
|
for (DcMotorEx motor : motors) {
|
||||||
|
@ -42,7 +42,7 @@ public class FollowerConstants {
|
|||||||
public static CustomPIDFCoefficients translationalPIDFCoefficients = new CustomPIDFCoefficients(
|
public static CustomPIDFCoefficients translationalPIDFCoefficients = new CustomPIDFCoefficients(
|
||||||
0.1,
|
0.1,
|
||||||
0,
|
0,
|
||||||
0.01,
|
0,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
// Translational Integral
|
// Translational Integral
|
||||||
@ -53,14 +53,14 @@ public class FollowerConstants {
|
|||||||
0);
|
0);
|
||||||
|
|
||||||
// Feed forward constant added on to the translational PIDF
|
// Feed forward constant added on to the translational PIDF
|
||||||
public static double translationalPIDFFeedForward = 0.00;
|
public static double translationalPIDFFeedForward = 0.015;
|
||||||
|
|
||||||
|
|
||||||
// Heading error PIDF coefficients
|
// Heading error PIDF coefficients
|
||||||
public static CustomPIDFCoefficients headingPIDFCoefficients = new CustomPIDFCoefficients(
|
public static CustomPIDFCoefficients headingPIDFCoefficients = new CustomPIDFCoefficients(
|
||||||
2,
|
1,
|
||||||
|
0,
|
||||||
0,
|
0,
|
||||||
0.025,
|
|
||||||
0);
|
0);
|
||||||
|
|
||||||
// Feed forward constant added on to the heading PIDF
|
// Feed forward constant added on to the heading PIDF
|
||||||
@ -69,10 +69,10 @@ public class FollowerConstants {
|
|||||||
|
|
||||||
// Drive PIDF coefficients
|
// Drive PIDF coefficients
|
||||||
public static CustomFilteredPIDFCoefficients drivePIDFCoefficients = new CustomFilteredPIDFCoefficients(
|
public static CustomFilteredPIDFCoefficients drivePIDFCoefficients = new CustomFilteredPIDFCoefficients(
|
||||||
0.006,
|
0.025,
|
||||||
0,
|
0,
|
||||||
0.00001,
|
0.00001,
|
||||||
0.8,
|
0.6,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
// Feed forward constant added on to the drive PIDF
|
// Feed forward constant added on to the drive PIDF
|
||||||
@ -81,7 +81,7 @@ public class FollowerConstants {
|
|||||||
// Kalman filter parameters for the drive error Kalman filter
|
// Kalman filter parameters for the drive error Kalman filter
|
||||||
public static KalmanFilterParameters driveKalmanFilterParameters = new KalmanFilterParameters(
|
public static KalmanFilterParameters driveKalmanFilterParameters = new KalmanFilterParameters(
|
||||||
6,
|
6,
|
||||||
3);
|
1);
|
||||||
|
|
||||||
|
|
||||||
// Mass of robot in kilograms
|
// Mass of robot in kilograms
|
||||||
@ -202,9 +202,9 @@ public class FollowerConstants {
|
|||||||
|
|
||||||
// Secondary drive PIDF coefficients
|
// Secondary drive PIDF coefficients
|
||||||
public static CustomFilteredPIDFCoefficients secondaryDrivePIDFCoefficients = new CustomFilteredPIDFCoefficients(
|
public static CustomFilteredPIDFCoefficients secondaryDrivePIDFCoefficients = new CustomFilteredPIDFCoefficients(
|
||||||
0.02,
|
0.00315,
|
||||||
0,
|
0,
|
||||||
0.000005,
|
0.0001,
|
||||||
0.6,
|
0.6,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
|
@ -93,13 +93,11 @@ public class ForwardVelocityTuner extends OpMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
telemetryA = new MultipleTelemetry(this.telemetry, FtcDashboard.getInstance().getTelemetry());
|
telemetryA = new MultipleTelemetry(this.telemetry, FtcDashboard.getInstance().getTelemetry());
|
||||||
// telemetryA.addLine("The robot will run at 1 power until it reaches " + DISTANCE + " inches forward.");
|
telemetryA.addLine("The robot will run at 1 power until it reaches " + DISTANCE + " inches forward.");
|
||||||
// telemetryA.addLine("Make sure you have enough room, since the robot has inertia after cutting power.");
|
telemetryA.addLine("Make sure you have enough room, since the robot has inertia after cutting power.");
|
||||||
// telemetryA.addLine("After running the distance, the robot will cut power from the drivetrain and display the forward velocity.");
|
telemetryA.addLine("After running the distance, the robot will cut power from the drivetrain and display the forward velocity.");
|
||||||
// telemetryA.addLine("Press CROSS or A on game pad 1 to stop.");
|
telemetryA.addLine("Press CROSS or A on game pad 1 to stop.");
|
||||||
//
|
telemetryA.update();
|
||||||
//
|
|
||||||
// telemetryA.update();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,13 +138,6 @@ public class ForwardVelocityTuner extends OpMode {
|
|||||||
velocities.add(currentVelocity);
|
velocities.add(currentVelocity);
|
||||||
velocities.remove(0);
|
velocities.remove(0);
|
||||||
}
|
}
|
||||||
telemetryA.addData("x", poseUpdater.getPose().getX());
|
|
||||||
telemetryA.addData("y", poseUpdater.getPose().getY());
|
|
||||||
telemetryA.addData("heading", poseUpdater.getPose().getHeading());
|
|
||||||
telemetryA.addData("velo mag", poseUpdater.getVelocity().getMagnitude());
|
|
||||||
telemetryA.addData("velo ", poseUpdater.getVelocity().getTheta());
|
|
||||||
telemetryA.update();
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
double average = 0;
|
double average = 0;
|
||||||
for (Double velocity : velocities) {
|
for (Double velocity : velocities) {
|
||||||
@ -155,12 +146,7 @@ public class ForwardVelocityTuner extends OpMode {
|
|||||||
average /= (double) velocities.size();
|
average /= (double) velocities.size();
|
||||||
|
|
||||||
telemetryA.addData("forward velocity:", average);
|
telemetryA.addData("forward velocity:", average);
|
||||||
// telemetryA.addData("x", poseUpdater.getPose().getX());
|
telemetryA.update();
|
||||||
// telemetryA.addData("y", poseUpdater.getPose().getY());
|
|
||||||
// telemetryA.addData("heading", poseUpdater.getPose().getHeading());
|
|
||||||
// telemetryA.addData("velo mag", poseUpdater.getVelocity().getMagnitude());
|
|
||||||
// telemetryA.addData("velo ", poseUpdater.getVelocity().getTheta());
|
|
||||||
// telemetryA.update();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,6 +119,13 @@ public class LateralZeroPowerAccelerationTuner extends OpMode {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void loop() {
|
public void loop() {
|
||||||
|
|
||||||
|
telemetry.addData("x",poseUpdater.getPose().getX());
|
||||||
|
telemetry.addData("y",poseUpdater.getPose().getY());
|
||||||
|
telemetry.addData("heading",poseUpdater.getPose().getHeading());
|
||||||
|
telemetry.addData("velo mag", poseUpdater.getVelocity().getMagnitude());
|
||||||
|
telemetry.addData("velo theta", poseUpdater.getVelocity().getTheta());
|
||||||
|
|
||||||
if (gamepad1.cross || gamepad1.a) {
|
if (gamepad1.cross || gamepad1.a) {
|
||||||
requestOpModeStop();
|
requestOpModeStop();
|
||||||
}
|
}
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package org.firstinspires.ftc.teamcode.states;
|
|
||||||
|
|
||||||
public class FieldStates {
|
|
||||||
|
|
||||||
public enum FieldLocation {
|
|
||||||
BUCKET, SUBMARINE, FLOATING, TRAVELING
|
|
||||||
}
|
|
||||||
|
|
||||||
private FieldLocation fieldLocation;
|
|
||||||
|
|
||||||
public FieldLocation getFieldLocation() {
|
|
||||||
return fieldLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFieldLocation(FieldLocation fieldLocation) {
|
|
||||||
this.fieldLocation = fieldLocation;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
package org.firstinspires.ftc.teamcode.subsystem;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import com.acmerobotics.dashboard.telemetry.TelemetryPacket;
|
|
||||||
import com.acmerobotics.roadrunner.Action;
|
|
||||||
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.follower.Follower;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Pose;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierCurve;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierLine;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.PathBuilder;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.PathChain;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Point;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
AutoLine# - This file does something of a path......
|
|
||||||
|
|
||||||
*/
|
|
||||||
public class AutoLine1 {
|
|
||||||
|
|
||||||
private PathChain pathChain;
|
|
||||||
private Pose autoLin1StartPose = new Pose(8,65);
|
|
||||||
|
|
||||||
public void moveToAutoLine1(Follower robot) {
|
|
||||||
PathBuilder builder = new PathBuilder();
|
|
||||||
builder
|
|
||||||
.addPath(
|
|
||||||
// Line 1
|
|
||||||
new BezierLine(
|
|
||||||
new Point(8.000, 65.000, Point.CARTESIAN),
|
|
||||||
new Point(30.000, 72.000, Point.CARTESIAN)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0));
|
|
||||||
pathChain = builder.build();
|
|
||||||
robot.setStartingPose(autoLin1StartPose);
|
|
||||||
robot.followPath(pathChain);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
|||||||
package org.firstinspires.ftc.teamcode.subsystem;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import com.acmerobotics.dashboard.telemetry.TelemetryPacket;
|
|
||||||
import com.acmerobotics.roadrunner.Action;
|
|
||||||
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.follower.Follower;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Pose;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierCurve;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierLine;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.PathBuilder;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.PathChain;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Point;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
AutoLine# - This file does something of a path......
|
|
||||||
|
|
||||||
*/
|
|
||||||
public class AutoLine2 {
|
|
||||||
private PathChain pathChain;
|
|
||||||
public void moveToAutoLine2(Follower robot) {
|
|
||||||
PathBuilder builder = new PathBuilder();
|
|
||||||
builder
|
|
||||||
.addPath(
|
|
||||||
// Line 2
|
|
||||||
new BezierCurve(
|
|
||||||
new Point(36.000, 72.000, Point.CARTESIAN),
|
|
||||||
new Point(24.000, 24.000, Point.CARTESIAN),
|
|
||||||
new Point(72.000, 36.000, Point.CARTESIAN),
|
|
||||||
new Point(56.000, 24.000, Point.CARTESIAN)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setLinearHeadingInterpolation(Math.toRadians(0), Math.toRadians(180));
|
|
||||||
pathChain = builder.build();
|
|
||||||
robot.followPath(pathChain);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,73 +0,0 @@
|
|||||||
package org.firstinspires.ftc.teamcode.subsystem;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import com.acmerobotics.dashboard.telemetry.TelemetryPacket;
|
|
||||||
import com.acmerobotics.roadrunner.Action;
|
|
||||||
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.follower.Follower;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Pose;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierCurve;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.BezierLine;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.PathBuilder;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.PathChain;
|
|
||||||
import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Point;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
AutoLine# - This file does something of a path......
|
|
||||||
|
|
||||||
*/
|
|
||||||
public class AutoLine3 implements Action {
|
|
||||||
|
|
||||||
private Follower actionRobot;
|
|
||||||
private PathChain pathChain;
|
|
||||||
|
|
||||||
private Pose startPose = new Pose(56,24);
|
|
||||||
|
|
||||||
public AutoLine3(Follower robot) {
|
|
||||||
this.actionRobot = robot;
|
|
||||||
this.actionRobot.setStartingPose(startPose);
|
|
||||||
|
|
||||||
PathBuilder builder = new PathBuilder();
|
|
||||||
builder
|
|
||||||
/* .addPath(
|
|
||||||
// Line 1
|
|
||||||
new BezierLine(
|
|
||||||
new Point(8.000, 65.000, Point.CARTESIAN),
|
|
||||||
new Point(30.000, 72.000, Point.CARTESIAN)
|
|
||||||
// This is the origional new Point(36.000, 72.000, Point.CARTESIAN)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(0))
|
|
||||||
.addPath(
|
|
||||||
// Line 2
|
|
||||||
new BezierCurve(
|
|
||||||
new Point(36.000, 72.000, Point.CARTESIAN),
|
|
||||||
new Point(24.000, 24.000, Point.CARTESIAN),
|
|
||||||
new Point(72.000, 36.000, Point.CARTESIAN),
|
|
||||||
new Point(56.000, 24.000, Point.CARTESIAN)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setLinearHeadingInterpolation(Math.toRadians(0), Math.toRadians(180)) */
|
|
||||||
.addPath(
|
|
||||||
// Line 3
|
|
||||||
new BezierLine(
|
|
||||||
new Point(56.000, 24.000, Point.CARTESIAN),
|
|
||||||
new Point(18.000, 24.000, Point.CARTESIAN)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.setTangentHeadingInterpolation();
|
|
||||||
|
|
||||||
pathChain = builder.build();
|
|
||||||
|
|
||||||
this.actionRobot.followPath(this.pathChain);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean run(@NonNull TelemetryPacket telemetryPacket) {
|
|
||||||
this.actionRobot.update();
|
|
||||||
return this.actionRobot.isBusy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,105 +0,0 @@
|
|||||||
package org.firstinspires.ftc.teamcode.subsystem;
|
|
||||||
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_LEFT_MOTOR;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_LEFT_MOTOR_DIRECTION;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_RIGHT_MOTOR;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_RIGHT_MOTOR_DIRECTION;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_LEFT_MOTOR;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_LEFT_MOTOR_DIRECTION;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_RIGHT_MOTOR;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.FRONT_RIGHT_MOTOR_DIRECTION;
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.MAX_POWER;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import com.acmerobotics.dashboard.telemetry.TelemetryPacket;
|
|
||||||
import com.acmerobotics.roadrunner.Action;
|
|
||||||
import com.qualcomm.robotcore.hardware.DcMotor;
|
|
||||||
import com.qualcomm.robotcore.hardware.Gamepad;
|
|
||||||
import com.qualcomm.robotcore.hardware.HardwareMap;
|
|
||||||
|
|
||||||
import org.firstinspires.ftc.robotcore.external.Telemetry;
|
|
||||||
|
|
||||||
public class MotorsSubsystem {
|
|
||||||
|
|
||||||
public HardwareMap hardwareMap;
|
|
||||||
public Telemetry telemetry;
|
|
||||||
|
|
||||||
public DcMotor frontLeftMotor;
|
|
||||||
public DcMotor backLeftMotor;
|
|
||||||
public DcMotor frontRightMotor;
|
|
||||||
public DcMotor backRightMotor;
|
|
||||||
|
|
||||||
public enum TravelState {
|
|
||||||
STOPPED, MOVING
|
|
||||||
}
|
|
||||||
|
|
||||||
public TravelState travelState;
|
|
||||||
|
|
||||||
public double power;
|
|
||||||
|
|
||||||
public MotorsSubsystem(HardwareMap hardwareMap, Telemetry telemetry) {
|
|
||||||
this.hardwareMap = hardwareMap;
|
|
||||||
this.telemetry = telemetry;
|
|
||||||
this.power = MAX_POWER;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MotorsSubsystem(HardwareMap hardwareMap, Telemetry telemetry, double power) {
|
|
||||||
this.hardwareMap = hardwareMap;
|
|
||||||
this.telemetry = telemetry;
|
|
||||||
this.power = power;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init() {
|
|
||||||
frontLeftMotor = hardwareMap.get(DcMotor.class, FRONT_LEFT_MOTOR);
|
|
||||||
backLeftMotor = hardwareMap.get(DcMotor.class, BACK_LEFT_MOTOR);
|
|
||||||
frontRightMotor = hardwareMap.get(DcMotor.class, FRONT_RIGHT_MOTOR);
|
|
||||||
backRightMotor = hardwareMap.get(DcMotor.class, BACK_RIGHT_MOTOR);
|
|
||||||
|
|
||||||
frontLeftMotor.setDirection(FRONT_LEFT_MOTOR_DIRECTION);
|
|
||||||
backLeftMotor.setDirection(BACK_LEFT_MOTOR_DIRECTION);
|
|
||||||
frontRightMotor.setDirection(FRONT_RIGHT_MOTOR_DIRECTION);
|
|
||||||
backRightMotor.setDirection(BACK_RIGHT_MOTOR_DIRECTION);
|
|
||||||
|
|
||||||
frontLeftMotor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
|
|
||||||
backLeftMotor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
|
|
||||||
frontRightMotor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
|
|
||||||
backRightMotor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
|
|
||||||
|
|
||||||
this.setState(TravelState.STOPPED);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFrontLeftMotorPower(double power) {
|
|
||||||
frontLeftMotor.setPower(power);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBackLeftMotorPower(double power) {
|
|
||||||
backLeftMotor.setPower(power);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFrontRightMotorPower(double power) {
|
|
||||||
frontRightMotor.setPower(power);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBackRightMotorPower(double power) {
|
|
||||||
backRightMotor.setPower(power);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setState(TravelState travelState) {
|
|
||||||
this.travelState = travelState;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TravelState getState() {
|
|
||||||
return this.travelState;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPower(DcMotor motor, double power) {
|
|
||||||
motor.setPower(power);
|
|
||||||
if (power < 0.05) {
|
|
||||||
this.setState(TravelState.MOVING);
|
|
||||||
} else {
|
|
||||||
this.setState(TravelState.STOPPED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,9 +16,6 @@ dependencies {
|
|||||||
implementation 'org.firstinspires.ftc:Vision:10.1.0'
|
implementation 'org.firstinspires.ftc:Vision:10.1.0'
|
||||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||||
|
|
||||||
implementation "com.acmerobotics.roadrunner:ftc:0.1.14"
|
implementation 'com.acmerobotics.dashboard:dashboard:0.4.5'
|
||||||
implementation "com.acmerobotics.roadrunner:core:1.0.0"
|
|
||||||
implementation "com.acmerobotics.roadrunner:actions:1.0.0"
|
|
||||||
implementation "com.acmerobotics.dashboard:dashboard:0.4.16"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user