Compare commits
12 Commits
branch-bob
...
branch-rc-
Author | SHA1 | Date | |
---|---|---|---|
a793efd2a0 | |||
62b6c16316 | |||
657ec8e624 | |||
c207070b1c | |||
173f934a22 | |||
28d7521ab0 | |||
a122832e76 | |||
1f7b3467c1 | |||
f7aa0c4319 | |||
308f301bd5 | |||
d383e2ca63 | |||
a3f1dfdf68 |
@ -0,0 +1,135 @@
|
|||||||
|
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 = "AsherPathV1", group = "Autonomous Pathing Tuning")
|
||||||
|
public class AsherPathV1 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()
|
||||||
|
/*
|
||||||
|
* Only update this path
|
||||||
|
*/
|
||||||
|
.addPath(
|
||||||
|
// Line 1
|
||||||
|
new BezierCurve(
|
||||||
|
new Point(9.757, 84.983, Point.CARTESIAN),
|
||||||
|
new Point(33.000, 105.000, Point.CARTESIAN),
|
||||||
|
new Point(80.000, 118.000, Point.CARTESIAN),
|
||||||
|
new Point(55.000, 120.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.addPath(
|
||||||
|
// Line 2
|
||||||
|
new BezierCurve(
|
||||||
|
new Point(55.000, 120.000, Point.CARTESIAN),
|
||||||
|
new Point(22.000, 106.000, Point.CARTESIAN),
|
||||||
|
new Point(11.000, 131.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.addPath(
|
||||||
|
// Line 3
|
||||||
|
new BezierCurve(
|
||||||
|
new Point(11.000, 131.000, Point.CARTESIAN),
|
||||||
|
new Point(75.000, 95.000, Point.CARTESIAN),
|
||||||
|
new Point(112.000, 132.000, Point.CARTESIAN),
|
||||||
|
new Point(61.000, 131.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.addPath(
|
||||||
|
// Line 4
|
||||||
|
new BezierLine(
|
||||||
|
new Point(61.000, 131.000, Point.CARTESIAN),
|
||||||
|
new Point(11.000, 131.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.addPath(
|
||||||
|
// Line 5
|
||||||
|
new BezierCurve(
|
||||||
|
new Point(11.000, 131.000, Point.CARTESIAN),
|
||||||
|
new Point(100.000, 118.000, Point.CARTESIAN),
|
||||||
|
new Point(103.000, 135.000, Point.CARTESIAN),
|
||||||
|
new Point(61.000, 135.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.addPath(
|
||||||
|
// Line 6
|
||||||
|
new BezierLine(
|
||||||
|
new Point(61.000, 135.000, Point.CARTESIAN),
|
||||||
|
new Point(11.000, 131.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.addPath(
|
||||||
|
// Line 7
|
||||||
|
new BezierCurve(
|
||||||
|
new Point(11.000, 131.000, Point.CARTESIAN),
|
||||||
|
new Point(113.000, 95.000, Point.CARTESIAN),
|
||||||
|
new Point(67.000, 95.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(90)).build();
|
||||||
|
/*
|
||||||
|
* End of only update this path
|
||||||
|
*/
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -33,7 +33,7 @@ import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Point;
|
|||||||
* @version 1.0, 3/12/2024
|
* @version 1.0, 3/12/2024
|
||||||
*/
|
*/
|
||||||
@Config
|
@Config
|
||||||
@Autonomous(name = "AutoExample", group = "Autonomous Pathing Tuning")
|
@Autonomous(name = "AutoExample - Straight Path", group = "Autonomous Pathing Tuning")
|
||||||
public class AutoExample extends OpMode {
|
public class AutoExample extends OpMode {
|
||||||
private Telemetry telemetryA;
|
private Telemetry telemetryA;
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ public class AutoExample extends OpMode {
|
|||||||
|
|
||||||
private PathChain path;
|
private PathChain path;
|
||||||
|
|
||||||
private final Pose startPose = new Pose(12.0, 11, 90);
|
private final Pose startPose = new Pose(0.0, 20.0, 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
@ -59,46 +59,11 @@ public class AutoExample extends OpMode {
|
|||||||
.addPath(
|
.addPath(
|
||||||
// Line 1
|
// Line 1
|
||||||
new BezierLine(
|
new BezierLine(
|
||||||
new Point(12.804, 11.223, Point.CARTESIAN),
|
new Point(0.000, 20.000, Point.CARTESIAN),
|
||||||
new Point(12.804, 42.362, Point.CARTESIAN)
|
new Point(50.000, 20.000, Point.CARTESIAN)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.setTangentHeadingInterpolation()
|
.setConstantHeadingInterpolation(Math.toRadians(0))
|
||||||
.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();
|
.build();
|
||||||
|
|
||||||
follower.followPath(path);
|
follower.followPath(path);
|
||||||
|
@ -0,0 +1,106 @@
|
|||||||
|
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 = "AutoExample - 2 Curves/2 Lines", group = "Autonomous Pathing Tuning")
|
||||||
|
public class AutoExampleFour extends OpMode {
|
||||||
|
private Telemetry telemetryA;
|
||||||
|
|
||||||
|
private Follower follower;
|
||||||
|
|
||||||
|
private PathChain path;
|
||||||
|
|
||||||
|
private final Pose startPose = new Pose(12,60, 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(.45);
|
||||||
|
|
||||||
|
follower.setStartingPose(startPose);
|
||||||
|
|
||||||
|
path = follower.pathBuilder()
|
||||||
|
.addPath(
|
||||||
|
// Line 1
|
||||||
|
new BezierCurve(
|
||||||
|
new Point(12.000, 60.000, Point.CARTESIAN),
|
||||||
|
new Point(60.000, 60.000, Point.CARTESIAN),
|
||||||
|
new Point(60.000, 12.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setLinearHeadingInterpolation(Math.toRadians(0), Math.toRadians(-90))
|
||||||
|
.addPath(
|
||||||
|
// Line 2
|
||||||
|
new BezierLine(
|
||||||
|
new Point(60.000, 12.000, Point.CARTESIAN),
|
||||||
|
new Point(40.000, 12.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setLinearHeadingInterpolation(Math.toRadians(-90), Math.toRadians(-90))
|
||||||
|
.addPath(
|
||||||
|
// Line 3
|
||||||
|
new BezierCurve(
|
||||||
|
new Point(40.000, 12.000, Point.CARTESIAN),
|
||||||
|
new Point(35.000, 35.000, Point.CARTESIAN),
|
||||||
|
new Point(12.000, 35.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setLinearHeadingInterpolation(Math.toRadians(-90), Math.toRadians(-90))
|
||||||
|
.addPath(
|
||||||
|
// Line 4
|
||||||
|
new BezierLine(
|
||||||
|
new Point(12.000, 35.000, Point.CARTESIAN),
|
||||||
|
new Point(12.000, 60.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setLinearHeadingInterpolation(Math.toRadians(-90), Math.toRadians(0))
|
||||||
|
.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);
|
||||||
|
}
|
||||||
|
}
|
@ -26,7 +26,7 @@ import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Point;
|
|||||||
* @version 1.0, 3/12/2024
|
* @version 1.0, 3/12/2024
|
||||||
*/
|
*/
|
||||||
@Config
|
@Config
|
||||||
@Autonomous(name = "AutoExampleThree", group = "Autonomous Pathing Tuning")
|
@Autonomous(name = "AutoExample - Curve and Line", group = "Autonomous Pathing Tuning")
|
||||||
public class AutoExampleThree extends OpMode {
|
public class AutoExampleThree extends OpMode {
|
||||||
private Telemetry telemetryA;
|
private Telemetry telemetryA;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ public class AutoExampleThree extends OpMode {
|
|||||||
|
|
||||||
private PathChain path;
|
private PathChain path;
|
||||||
|
|
||||||
private final Pose startPose = new Pose(10.0, 40, 90);
|
private final Pose startPose = new Pose(10,45, 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
@ -52,12 +52,21 @@ public class AutoExampleThree extends OpMode {
|
|||||||
.addPath(
|
.addPath(
|
||||||
// Line 1
|
// Line 1
|
||||||
new BezierCurve(
|
new BezierCurve(
|
||||||
new Point(10.000, 20.000, Point.CARTESIAN),
|
new Point(10.000, 45.000, Point.CARTESIAN),
|
||||||
new Point(29.089, 61.232, Point.CARTESIAN),
|
new Point(45.000, 45.000, Point.CARTESIAN),
|
||||||
new Point(48.054, 19.607, Point.CARTESIAN)
|
new Point(50.000, 20.000, Point.CARTESIAN)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(90)).build();
|
.setLinearHeadingInterpolation(Math.toRadians(0), Math.toRadians(-90))
|
||||||
|
.addPath(
|
||||||
|
// Line 2
|
||||||
|
new BezierLine(
|
||||||
|
new Point(50.000, 20.000, Point.CARTESIAN),
|
||||||
|
new Point(10.000, 20.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setLinearHeadingInterpolation(Math.toRadians(-90), Math.toRadians(-90))
|
||||||
|
.build();
|
||||||
|
|
||||||
follower.followPath(path);
|
follower.followPath(path);
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import org.firstinspires.ftc.teamcode.pedroPathing.pathGeneration.Point;
|
|||||||
* @version 1.0, 3/12/2024
|
* @version 1.0, 3/12/2024
|
||||||
*/
|
*/
|
||||||
@Config
|
@Config
|
||||||
@Autonomous(name = "AutoExampleTwo", group = "Autonomous Pathing Tuning")
|
@Autonomous(name = "AutoExample - Simple Curve", group = "Autonomous Pathing Tuning")
|
||||||
public class AutoExampleTwo extends OpMode {
|
public class AutoExampleTwo extends OpMode {
|
||||||
private Telemetry telemetryA;
|
private Telemetry telemetryA;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ public class AutoExampleTwo extends OpMode {
|
|||||||
|
|
||||||
private PathChain path;
|
private PathChain path;
|
||||||
|
|
||||||
private final Pose startPose = new Pose(10.0, 40, 90);
|
private final Pose startPose = new Pose(10.0, 45, 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
@ -51,28 +51,14 @@ public class AutoExampleTwo extends OpMode {
|
|||||||
path = follower.pathBuilder()
|
path = follower.pathBuilder()
|
||||||
.addPath(
|
.addPath(
|
||||||
// Line 1
|
// Line 1
|
||||||
new BezierLine(
|
new BezierCurve(
|
||||||
new Point(10.000, 40.000, Point.CARTESIAN),
|
new Point(10.000, 45.000, Point.CARTESIAN),
|
||||||
new Point(60.000, 40.000, Point.CARTESIAN)
|
new Point(45.000, 45.000, Point.CARTESIAN),
|
||||||
|
new Point(50.000, 20.000, Point.CARTESIAN)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.setConstantHeadingInterpolation(Math.toRadians(90))
|
.setLinearHeadingInterpolation(Math.toRadians(0), Math.toRadians(-90))
|
||||||
.addPath(
|
.build();
|
||||||
// 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);
|
follower.followPath(path);
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
package org.firstinspires.ftc.teamcode;
|
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;
|
||||||
@ -37,7 +39,12 @@ 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.Disabled;
|
||||||
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;
|
||||||
import com.qualcomm.robotcore.hardware.DcMotor;
|
import com.qualcomm.robotcore.hardware.DcMotor;
|
||||||
@ -74,15 +81,12 @@ 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() {
|
||||||
|
|
||||||
@ -93,12 +97,18 @@ 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. !!!!!
|
||||||
// ########################################################################################
|
// ########################################################################################
|
||||||
@ -114,20 +124,11 @@ 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();
|
||||||
@ -186,14 +187,12 @@ 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);
|
telemetry.addData("Status", "Run Time: " + runtime.toString());
|
||||||
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("Encoder Front Left", leftFrontDrive.getDirection() + " : " + leftFrontDrive.getCurrentPosition());
|
telemetry.addData("Left Encoder Value", leftEncoder.getDeltaPosition());
|
||||||
telemetry.addData("Encoder Front Right", rightFrontDrive.getCurrentPosition());
|
telemetry.addData("Right Encoder Value", rightEncoder.getDeltaPosition());
|
||||||
telemetry.addData("Encoder Back Left", leftBackDrive.getCurrentPosition());
|
telemetry.addData("Strafe Encoder Value", strafeEncoder.getDeltaPosition());
|
||||||
telemetry.addData("Encoder Back Right", rightBackDrive.getCurrentPosition());
|
|
||||||
telemetry.update();
|
telemetry.update();
|
||||||
}
|
}
|
||||||
}
|
}}
|
||||||
}
|
|
||||||
|
@ -0,0 +1,147 @@
|
|||||||
|
package org.firstinspires.ftc.teamcode;
|
||||||
|
import static android.os.SystemClock.sleep;
|
||||||
|
|
||||||
|
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
|
||||||
|
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 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 = "BlueBasketAuto", group = "Autonomous Pathing Tuning")
|
||||||
|
public class BlueBasketAuto extends OpMode {
|
||||||
|
private Telemetry telemetryA;
|
||||||
|
|
||||||
|
private Follower follower;
|
||||||
|
|
||||||
|
private PathChain path;
|
||||||
|
|
||||||
|
private final Pose startPose = new Pose(11.25, 95.75);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(.45);
|
||||||
|
|
||||||
|
follower.setStartingPose(startPose);
|
||||||
|
|
||||||
|
path = follower.pathBuilder()
|
||||||
|
.addPath(
|
||||||
|
// Line 1
|
||||||
|
new BezierLine(
|
||||||
|
new Point(11.250, 95.750, Point.CARTESIAN),
|
||||||
|
new Point(37.000, 108.000, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(0))
|
||||||
|
.addPath(
|
||||||
|
// Line 2
|
||||||
|
new BezierCurve(
|
||||||
|
new Point(37.000, 108.000, Point.CARTESIAN),
|
||||||
|
new Point(73.286, 111.536, Point.CARTESIAN),
|
||||||
|
new Point(67.821, 120.536, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(0))
|
||||||
|
.addPath(
|
||||||
|
// Line 3
|
||||||
|
new BezierLine(
|
||||||
|
new Point(67.821, 120.536, Point.CARTESIAN),
|
||||||
|
new Point(28.000, 121.500, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(0))
|
||||||
|
.addPath(
|
||||||
|
// Line 4
|
||||||
|
new BezierLine(
|
||||||
|
new Point(28.000, 121.500, Point.CARTESIAN),
|
||||||
|
new Point(15.750, 126.321, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(0))
|
||||||
|
.addPath(
|
||||||
|
// Line 5
|
||||||
|
new BezierCurve(
|
||||||
|
new Point(15.750, 126.321, Point.CARTESIAN),
|
||||||
|
new Point(59.000, 102.500, Point.CARTESIAN),
|
||||||
|
new Point(68.700, 130.500, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(0))
|
||||||
|
.addPath(
|
||||||
|
// Line 6
|
||||||
|
new BezierLine(
|
||||||
|
new Point(68.700, 130.500, Point.CARTESIAN),
|
||||||
|
new Point(22.661, 130.821, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(0))
|
||||||
|
.addPath(
|
||||||
|
// Line 7
|
||||||
|
new BezierCurve(
|
||||||
|
new Point(22.661, 130.821, Point.CARTESIAN),
|
||||||
|
new Point(49.018, 121.179, Point.CARTESIAN),
|
||||||
|
new Point(63.804, 135.321, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(0))
|
||||||
|
.addPath(
|
||||||
|
// Line 8
|
||||||
|
new BezierLine(
|
||||||
|
new Point(63.804, 135.321, Point.CARTESIAN),
|
||||||
|
new Point(26.679, 135.964, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(0))
|
||||||
|
.addPath(
|
||||||
|
// Line 9
|
||||||
|
new BezierLine(
|
||||||
|
new Point(26.679, 135.964, Point.CARTESIAN),
|
||||||
|
new Point(83.250, 95.464, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setLinearHeadingInterpolation(Math.toRadians(0), Math.toRadians(270)).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);
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,8 @@ public class PedroConstants {
|
|||||||
/*
|
/*
|
||||||
Robot parameters
|
Robot parameters
|
||||||
*/
|
*/
|
||||||
|
// Turn localizer - -0.003
|
||||||
|
|
||||||
|
|
||||||
// Robot motor configurations
|
// Robot motor configurations
|
||||||
public static final String FRONT_LEFT_MOTOR = "Drive front lt";
|
public static final String FRONT_LEFT_MOTOR = "Drive front lt";
|
||||||
@ -20,38 +22,51 @@ public class PedroConstants {
|
|||||||
// 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.REVERSE;
|
public static final Direction FRONT_RIGHT_MOTOR_DIRECTION = Direction.FORWARD;
|
||||||
public static final Direction BACK_RIGHT_MOTOR_DIRECTION = Direction.REVERSE;
|
public static final Direction BACK_RIGHT_MOTOR_DIRECTION = Direction.FORWARD;
|
||||||
|
|
||||||
|
// Robot IMU configuration
|
||||||
|
public static final String IMU = "imu";
|
||||||
|
|
||||||
|
// Robot IMU placement
|
||||||
|
public static final RevHubOrientationOnRobot.LogoFacingDirection IMU_LOGO_FACING_DIRECTION
|
||||||
|
= RevHubOrientationOnRobot.LogoFacingDirection.DOWN;
|
||||||
|
public static final RevHubOrientationOnRobot.UsbFacingDirection IMU_USB_FACING_DIRECTION
|
||||||
|
= RevHubOrientationOnRobot.UsbFacingDirection.LEFT;
|
||||||
|
|
||||||
|
// Robot encoders
|
||||||
|
public static final String LEFT_ENCODER = "encoder left";
|
||||||
|
public static final String RIGHT_ENCODER = "encoder right";
|
||||||
|
public static final String BACK_ENCODER = "encoder back";
|
||||||
|
|
||||||
// Robot encoder direction
|
// Robot encoder direction
|
||||||
public static final double FRONT_LEFT_MOTOR_ENCODER = Encoder.FORWARD;
|
public static final double LEFT_ENCODER_DIRECTION = Encoder.FORWARD;
|
||||||
public static final double BACK_LEFT_MOTOR_ENCODER = Encoder.FORWARD;
|
public static final double RIGHT_ENCODER_DIRECTION = Encoder.FORWARD;
|
||||||
public static final double FRONT_RIGHT_MOTOR_ENCODER = Encoder.FORWARD;
|
public static final double BACK_ENCODER_DIRECTION = Encoder.FORWARD;
|
||||||
public static final double BACK_RIGHT_MOTOR_ENCODER = Encoder.FORWARD;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
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 = 5.15;
|
public static final double ROBOT_WEIGHT_IN_KG = 10.5;
|
||||||
|
|
||||||
// Maximum velocity of the robot going forward
|
// Maximum velocity of the robot going forward
|
||||||
public static final double ROBOT_SPEED_FORWARD = 66.6117;
|
public static final double ROBOT_SPEED_FORWARD = 51.4598;
|
||||||
|
|
||||||
// Maximum velocity of the robot going right
|
// Maximum velocity of the robot going right
|
||||||
public static final double ROBOT_SPEED_LATERAL = 60.0671;
|
public static final double ROBOT_SPEED_LATERAL = 28.7119;
|
||||||
|
|
||||||
// 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 = -71.154;
|
public static final double FORWARD_ZERO_POWER_ACCEL = -59.805;
|
||||||
|
|
||||||
// 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 = -109.5358;
|
public static final double LATERAL_ZERO_POWER_ACCEL = -99.672;
|
||||||
|
|
||||||
// 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 = 4.0;
|
public static final double ZERO_POWER_ACCEL_MULT = 3.5;
|
||||||
|
|
||||||
/* 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.0005;
|
public static final double CENTRIPETAL_SCALING = 0.0004;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,161 @@
|
|||||||
|
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 = "BlueBasketAuto", group = "Autonomous Pathing Tuning")
|
||||||
|
public class RedBasketAuto extends OpMode {
|
||||||
|
private Telemetry telemetryA;
|
||||||
|
|
||||||
|
private Follower follower;
|
||||||
|
|
||||||
|
private PathChain path;
|
||||||
|
|
||||||
|
private final Pose startPose = new Pose(
|
||||||
|
135.6
|
||||||
|
, 48.05);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(.45);
|
||||||
|
|
||||||
|
follower.setStartingPose(startPose);
|
||||||
|
|
||||||
|
path = follower.pathBuilder()
|
||||||
|
.addPath(
|
||||||
|
// Line 1
|
||||||
|
new BezierLine(
|
||||||
|
new Point(136.286, 48.536, Point.CARTESIAN),
|
||||||
|
new Point(102.375, 32.946, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(180))
|
||||||
|
.addPath(
|
||||||
|
// Line 2
|
||||||
|
new BezierLine(
|
||||||
|
new Point(102.375, 32.946, Point.CARTESIAN),
|
||||||
|
new Point(80.679, 31.982, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(180))
|
||||||
|
.addPath(
|
||||||
|
// Line 3
|
||||||
|
new BezierLine(
|
||||||
|
new Point(80.679, 31.982, Point.CARTESIAN),
|
||||||
|
new Point(80.679, 23.304, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(180))
|
||||||
|
.addPath(
|
||||||
|
// Line 4
|
||||||
|
new BezierLine(
|
||||||
|
new Point(80.679, 23.304, Point.CARTESIAN),
|
||||||
|
new Point(131.143, 21.536, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(180))
|
||||||
|
.addPath(
|
||||||
|
// Line 5
|
||||||
|
new BezierLine(
|
||||||
|
new Point(131.143, 21.536, Point.CARTESIAN),
|
||||||
|
new Point(81.000, 23.304, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(180))
|
||||||
|
.addPath(
|
||||||
|
// Line 6
|
||||||
|
new BezierLine(
|
||||||
|
new Point(81.000, 23.304, Point.CARTESIAN),
|
||||||
|
new Point(81.161, 13.179, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(180))
|
||||||
|
.addPath(
|
||||||
|
// Line 7
|
||||||
|
new BezierLine(
|
||||||
|
new Point(81.161, 13.179, Point.CARTESIAN),
|
||||||
|
new Point(124.554, 13.018, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(180))
|
||||||
|
.addPath(
|
||||||
|
// Line 8
|
||||||
|
new BezierLine(
|
||||||
|
new Point(124.554, 13.018, Point.CARTESIAN),
|
||||||
|
new Point(81.000, 13.018, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(180))
|
||||||
|
.addPath(
|
||||||
|
// Line 9
|
||||||
|
new BezierLine(
|
||||||
|
new Point(81.000, 13.018, Point.CARTESIAN),
|
||||||
|
new Point(80.839, 8.800, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(180))
|
||||||
|
.addPath(
|
||||||
|
// Line 10
|
||||||
|
new BezierLine(
|
||||||
|
new Point(80.839, 8.800, Point.CARTESIAN),
|
||||||
|
new Point(120.054, 8.518, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setConstantHeadingInterpolation(Math.toRadians(180))
|
||||||
|
.addPath(
|
||||||
|
// Line 11
|
||||||
|
new BezierCurve(
|
||||||
|
new Point(120.054, 8.518, Point.CARTESIAN),
|
||||||
|
new Point(49.821, 27.643, Point.CARTESIAN),
|
||||||
|
new Point(60.429, 48.214, Point.CARTESIAN)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setLinearHeadingInterpolation(Math.toRadians(0), 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,171 @@
|
|||||||
|
/* Copyright (c) 2022 FIRST. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted (subject to the limitations in the disclaimer below) provided that
|
||||||
|
* the following conditions are met:
|
||||||
|
*
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
* of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer in the documentation and/or
|
||||||
|
* other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* Neither the name of FIRST nor the names of its contributors may be used to endorse or
|
||||||
|
* promote products derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
|
||||||
|
* LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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.IMU_LOGO_FACING_DIRECTION;
|
||||||
|
import static org.firstinspires.ftc.teamcode.PedroConstants.IMU_USB_FACING_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.hardware.rev.RevHubOrientationOnRobot;
|
||||||
|
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
|
||||||
|
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
|
||||||
|
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
|
||||||
|
import com.qualcomm.robotcore.hardware.DcMotorEx;
|
||||||
|
import com.qualcomm.robotcore.hardware.IMU;
|
||||||
|
|
||||||
|
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
|
||||||
|
import org.firstinspires.ftc.robotcore.external.navigation.AngularVelocity;
|
||||||
|
import org.firstinspires.ftc.robotcore.external.navigation.YawPitchRollAngles;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.localization.Encoder;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This OpMode shows how to use the new universal IMU interface. This
|
||||||
|
* interface may be used with the BNO055 IMU or the BHI260 IMU. It assumes that an IMU is configured
|
||||||
|
* on the robot with the name "imu".
|
||||||
|
*
|
||||||
|
* The sample will display the current Yaw, Pitch and Roll of the robot.<br>
|
||||||
|
* With the correct orientation parameters selected, pitch/roll/yaw should act as follows:
|
||||||
|
* Pitch value should INCREASE as the robot is tipped UP at the front. (Rotation about X) <br>
|
||||||
|
* Roll value should INCREASE as the robot is tipped UP at the left side. (Rotation about Y) <br>
|
||||||
|
* Yaw value should INCREASE as the robot is rotated Counter Clockwise. (Rotation about Z) <br>
|
||||||
|
*
|
||||||
|
* The yaw can be reset (to zero) by pressing the Y button on the gamepad (Triangle on a PS4 controller)
|
||||||
|
*
|
||||||
|
* This specific sample assumes that the Hub is mounted on one of the three orthogonal planes
|
||||||
|
* (X/Y, X/Z or Y/Z) and that the Hub has only been rotated in a range of 90 degree increments.
|
||||||
|
*
|
||||||
|
* Note: if your Hub is mounted on a surface angled at some non-90 Degree multiple (like 30) look at
|
||||||
|
* the alternative SensorIMUNonOrthogonal sample in this folder.
|
||||||
|
*
|
||||||
|
* This "Orthogonal" requirement means that:
|
||||||
|
*
|
||||||
|
* 1) The Logo printed on the top of the Hub can ONLY be pointing in one of six directions:
|
||||||
|
* FORWARD, BACKWARD, UP, DOWN, LEFT and RIGHT.
|
||||||
|
*
|
||||||
|
* 2) The USB ports can only be pointing in one of the same six directions:<br>
|
||||||
|
* FORWARD, BACKWARD, UP, DOWN, LEFT and RIGHT.
|
||||||
|
*
|
||||||
|
* So, To fully define how your Hub is mounted to the robot, you must simply specify:<br>
|
||||||
|
* logoFacingDirection<br>
|
||||||
|
* usbFacingDirection
|
||||||
|
*
|
||||||
|
* Use Android Studio to Copy this Class, and Paste it into your team's code folder with a new name.
|
||||||
|
* Remove or comment out the @Disabled line to add this OpMode to the Driver Station OpMode list.
|
||||||
|
*
|
||||||
|
* Finally, choose the two correct parameters to define how your Hub is mounted and edit this OpMode
|
||||||
|
* to use those parameters.
|
||||||
|
*/
|
||||||
|
@TeleOp(name = "Sensor: IMU Orthogonal", group = "Sensor")
|
||||||
|
@Disabled // Comment this out to add to the OpMode list
|
||||||
|
public class SensorIMUOrthogonal extends LinearOpMode {
|
||||||
|
// The IMU sensor object
|
||||||
|
IMU imu;
|
||||||
|
private Encoder leftEncoder;
|
||||||
|
private Encoder rightEncoder;
|
||||||
|
private Encoder strafeEncoder;
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------
|
||||||
|
// Main logic
|
||||||
|
//----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void runOpMode() throws InterruptedException {
|
||||||
|
|
||||||
|
// Retrieve and initialize the IMU.
|
||||||
|
// This sample expects the IMU to be in a REV Hub and named "imu".
|
||||||
|
imu = hardwareMap.get(IMU.class, PedroConstants.IMU);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
/* Define how the hub is mounted on the robot to get the correct Yaw, Pitch and Roll values.
|
||||||
|
*
|
||||||
|
* Two input parameters are required to fully specify the Orientation.
|
||||||
|
* The first parameter specifies the direction the printed logo on the Hub is pointing.
|
||||||
|
* The second parameter specifies the direction the USB connector on the Hub is pointing.
|
||||||
|
* All directions are relative to the robot, and left/right is as-viewed from behind the robot.
|
||||||
|
*
|
||||||
|
* If you are using a REV 9-Axis IMU, you can use the Rev9AxisImuOrientationOnRobot class instead of the
|
||||||
|
* RevHubOrientationOnRobot class, which has an I2cPortFacingDirection instead of a UsbFacingDirection.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* The next two lines define Hub orientation.
|
||||||
|
* The Default Orientation (shown) is when a hub is mounted horizontally with the printed logo pointing UP and the USB port pointing FORWARD.
|
||||||
|
*
|
||||||
|
* To Do: EDIT these two lines to match YOUR mounting configuration.
|
||||||
|
*/
|
||||||
|
RevHubOrientationOnRobot.LogoFacingDirection logoDirection = IMU_LOGO_FACING_DIRECTION;
|
||||||
|
RevHubOrientationOnRobot.UsbFacingDirection usbDirection = IMU_USB_FACING_DIRECTION;
|
||||||
|
|
||||||
|
RevHubOrientationOnRobot orientationOnRobot = new RevHubOrientationOnRobot(logoDirection, usbDirection);
|
||||||
|
|
||||||
|
// Now initialize the IMU with this mounting orientation
|
||||||
|
// Note: if you choose two conflicting directions, this initialization will cause a code exception.
|
||||||
|
imu.initialize(new IMU.Parameters(orientationOnRobot));
|
||||||
|
|
||||||
|
// Loop and update the dashboard
|
||||||
|
while (!isStopRequested()) {
|
||||||
|
|
||||||
|
telemetry.addData("Hub orientation", "Logo=%s USB=%s\n ", logoDirection, usbDirection);
|
||||||
|
|
||||||
|
// Check to see if heading reset is requested
|
||||||
|
if (gamepad1.y) {
|
||||||
|
telemetry.addData("Yaw", "Resetting\n");
|
||||||
|
imu.resetYaw();
|
||||||
|
} else {
|
||||||
|
telemetry.addData("Yaw", "Press Y (triangle) on Gamepad to reset\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve Rotational Angles and Velocities
|
||||||
|
YawPitchRollAngles orientation = imu.getRobotYawPitchRollAngles();
|
||||||
|
AngularVelocity angularVelocity = imu.getRobotAngularVelocity(AngleUnit.DEGREES);
|
||||||
|
|
||||||
|
telemetry.addData("Yaw (Z)", "%.2f Deg. (Heading)", orientation.getYaw(AngleUnit.DEGREES));
|
||||||
|
telemetry.addData("Pitch (X)", "%.2f Deg.", orientation.getPitch(AngleUnit.DEGREES));
|
||||||
|
telemetry.addData("Roll (Y)", "%.2f Deg.\n", orientation.getRoll(AngleUnit.DEGREES));
|
||||||
|
telemetry.addData("Yaw (Z) velocity", "%.2f Deg/Sec", angularVelocity.zRotationRate);
|
||||||
|
telemetry.addData("Pitch (X) velocity", "%.2f Deg/Sec", angularVelocity.xRotationRate);
|
||||||
|
telemetry.addData("Roll (Y) velocity", "%.2f Deg/Sec", angularVelocity.yRotationRate);
|
||||||
|
telemetry.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -71,8 +71,9 @@ measurements will be in centimeters.
|
|||||||
of how fast your robot will coast to a stop. Honestly, this is up to you. I personally used 4, but
|
of how fast your robot will coast to a stop. Honestly, this is up to you. I personally used 4, but
|
||||||
what works best for you is most important. Higher numbers will cause a faster brake, but increase
|
what works best for you is most important. Higher numbers will cause a faster brake, but increase
|
||||||
oscillations at the end. Lower numbers will do the opposite. This can be found on line `107` in
|
oscillations at the end. Lower numbers will do the opposite. This can be found on line `107` in
|
||||||
`FollowerConstants`, named `zeroPowerAccelerationMultiplier`. The drive PID is much, much more
|
`FollowerConstants`, named `zeroPowerAccelerationMultiplier`.
|
||||||
* sensitive than the others. For reference,
|
|
||||||
|
* The drive PID is much, much more sensitive than the others. For reference,
|
||||||
my P values were in the hundredths and thousandths place values, and my D values were in the hundred
|
my P values were in the hundredths and thousandths place values, and my D values were in the hundred
|
||||||
thousandths and millionths place values. To tune this, enable `useDrive`, `useHeading`, and
|
thousandths and millionths place values. To tune this, enable `useDrive`, `useHeading`, and
|
||||||
`useTranslational` in the `Follower` dropdown in FTC Dashboard. Next, run `StraightBackAndForth`
|
`useTranslational` in the `Follower` dropdown in FTC Dashboard. Next, run `StraightBackAndForth`
|
||||||
|
@ -6,6 +6,9 @@ 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.DriveEncoderLocalizer;
|
import org.firstinspires.ftc.teamcode.pedroPathing.localization.localizers.DriveEncoderLocalizer;
|
||||||
|
import org.firstinspires.ftc.teamcode.pedroPathing.localization.localizers.ThreeWheelIMULocalizer;
|
||||||
|
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;
|
||||||
|
|
||||||
@ -67,7 +70,8 @@ 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 DriveEncoderLocalizer(hardwareMap));
|
this(hardwareMap, new ThreeWheelLocalizer(hardwareMap));
|
||||||
|
// this(hardwareMap, new ThreeWheelIMULocalizer(hardwareMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,20 +1,11 @@
|
|||||||
package org.firstinspires.ftc.teamcode.pedroPathing.localization.localizers;
|
package org.firstinspires.ftc.teamcode.pedroPathing.localization.localizers;
|
||||||
|
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_LEFT_MOTOR;
|
import static org.firstinspires.ftc.teamcode.pedroPathing.tuning.FollowerConstants.leftFrontMotorName;
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_LEFT_MOTOR_DIRECTION;
|
import static org.firstinspires.ftc.teamcode.pedroPathing.tuning.FollowerConstants.leftRearMotorName;
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_LEFT_MOTOR_ENCODER;
|
import static org.firstinspires.ftc.teamcode.pedroPathing.tuning.FollowerConstants.rightFrontMotorName;
|
||||||
import static org.firstinspires.ftc.teamcode.PedroConstants.BACK_RIGHT_MOTOR;
|
import static org.firstinspires.ftc.teamcode.pedroPathing.tuning.FollowerConstants.rightRearMotorName;
|
||||||
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;
|
||||||
|
|
||||||
@ -35,21 +26,21 @@ import org.firstinspires.ftc.teamcode.pedroPathing.util.NanoTimer;
|
|||||||
*/
|
*/
|
||||||
@Config
|
@Config
|
||||||
public class DriveEncoderLocalizer extends Localizer {
|
public class DriveEncoderLocalizer extends Localizer {
|
||||||
private final HardwareMap hardwareMap;
|
private 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 final NanoTimer timer;
|
private NanoTimer timer;
|
||||||
private long deltaTimeNano;
|
private long deltaTimeNano;
|
||||||
private final Encoder leftFront;
|
private Encoder leftFront;
|
||||||
private final Encoder rightFront;
|
private Encoder rightFront;
|
||||||
private final Encoder leftRear;
|
private Encoder leftRear;
|
||||||
private final Encoder rightRear;
|
private Encoder rightRear;
|
||||||
private double totalHeading;
|
private double totalHeading;
|
||||||
public static double FORWARD_TICKS_TO_INCHES = -0.0058;
|
public static double FORWARD_TICKS_TO_INCHES = -0.6308;
|
||||||
public static double STRAFE_TICKS_TO_INCHES = -0.0054;
|
public static double STRAFE_TICKS_TO_INCHES = 46.4839;
|
||||||
public static double TURN_TICKS_TO_RADIANS = -0.0009;
|
public static double TURN_TICKS_TO_RADIANS = -0.002;
|
||||||
public static double ROBOT_WIDTH = 1;
|
public static double ROBOT_WIDTH = 1;
|
||||||
public static double ROBOT_LENGTH = 1;
|
public static double ROBOT_LENGTH = 1;
|
||||||
|
|
||||||
@ -73,26 +64,16 @@ public class DriveEncoderLocalizer extends Localizer {
|
|||||||
public DriveEncoderLocalizer(HardwareMap map, Pose setStartPose) {
|
public DriveEncoderLocalizer(HardwareMap map, Pose setStartPose) {
|
||||||
hardwareMap = map;
|
hardwareMap = map;
|
||||||
|
|
||||||
leftFront = new Encoder(hardwareMap.get(DcMotorEx.class, FRONT_LEFT_MOTOR));
|
leftFront = new Encoder(hardwareMap.get(DcMotorEx.class, leftFrontMotorName));
|
||||||
leftRear = new Encoder(hardwareMap.get(DcMotorEx.class, BACK_LEFT_MOTOR));
|
leftRear = new Encoder(hardwareMap.get(DcMotorEx.class, leftRearMotorName));
|
||||||
rightRear = new Encoder(hardwareMap.get(DcMotorEx.class, BACK_RIGHT_MOTOR));
|
rightRear = new Encoder(hardwareMap.get(DcMotorEx.class, rightRearMotorName));
|
||||||
rightFront = new Encoder(hardwareMap.get(DcMotorEx.class, FRONT_RIGHT_MOTOR));
|
rightFront = new Encoder(hardwareMap.get(DcMotorEx.class, rightFrontMotorName));
|
||||||
|
|
||||||
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(FRONT_LEFT_MOTOR_ENCODER);
|
leftFront.setDirection(Encoder.REVERSE);
|
||||||
rightFront.setDirection(FRONT_RIGHT_MOTOR_ENCODER);
|
rightRear.setDirection(Encoder.REVERSE);
|
||||||
leftRear.setDirection(BACK_LEFT_MOTOR_ENCODER);
|
leftRear.setDirection(Encoder.FORWARD);
|
||||||
rightRear.setDirection(BACK_RIGHT_MOTOR_ENCODER);
|
rightRear.setDirection(Encoder.FORWARD);
|
||||||
|
|
||||||
setStartPose(setStartPose);
|
setStartPose(setStartPose);
|
||||||
timer = new NanoTimer();
|
timer = new NanoTimer();
|
||||||
@ -148,7 +129,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));
|
||||||
@ -183,7 +164,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);
|
||||||
@ -233,13 +214,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,317 @@
|
|||||||
|
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.004;//8192 * 1.37795 * 2 * Math.PI * 0.5008239963;
|
||||||
|
public static double STRAFE_TICKS_TO_INCHES = -0.0036;//8192 * 1.37795 * 2 * Math.PI * 0.5018874659;
|
||||||
|
public static double TURN_TICKS_TO_RADIANS = 0.0043;//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(-7.625, 6.19375, 0);
|
||||||
|
rightEncoderPose = new Pose(-7.625, -6.19375, 0);
|
||||||
|
strafeEncoderPose = new Pose(7, 1, 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();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,297 @@
|
|||||||
|
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.00052189;//8192 * 1.37795 * 2 * Math.PI * 0.5008239963;
|
||||||
|
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.00052189;//8192 * 1.37795 * 2 * Math.PI * 0.5018874659;
|
||||||
|
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.00053717;//8192 * 1.37795 * 2 * Math.PI * 0.5;
|
||||||
|
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.19375, 0);
|
||||||
|
rightEncoderPose = new Pose(0, -6.19375, 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() {
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,302 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -58,6 +58,9 @@ 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(DcMotorSimple.Direction.REVERSE);
|
||||||
|
leftRear.setDirection(DcMotorSimple.Direction.REVERSE);
|
||||||
|
|
||||||
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,
|
0.01,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
// Translational Integral
|
// Translational Integral
|
||||||
@ -58,9 +58,9 @@ public class FollowerConstants {
|
|||||||
|
|
||||||
// Heading error PIDF coefficients
|
// Heading error PIDF coefficients
|
||||||
public static CustomPIDFCoefficients headingPIDFCoefficients = new CustomPIDFCoefficients(
|
public static CustomPIDFCoefficients headingPIDFCoefficients = new CustomPIDFCoefficients(
|
||||||
1,
|
2,
|
||||||
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.025,
|
0.006,
|
||||||
0,
|
0,
|
||||||
0.00001,
|
0.00001,
|
||||||
0.6,
|
0.8,
|
||||||
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,
|
||||||
1);
|
3);
|
||||||
|
|
||||||
|
|
||||||
// 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.00315,
|
0.02,
|
||||||
0,
|
0,
|
||||||
0.0001,
|
0.000005,
|
||||||
0.6,
|
0.6,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user