26 |
27 | - Colin Robertson
28 | - GitHub: [Wobblyyyy](https://github.com/Wobblyyyy)
29 | - Discord: `wobblyyyy#6733`
30 | - Email: `wobblyyyy@gmail.com`
31 | - Contributions:
32 | - Primary author of the Pathfinder2 library
33 |
--------------------------------------------------------------------------------
/header.txt:
--------------------------------------------------------------------------------
1 | This file contains copies of the header that should go at the top of every
2 | source file included in the project.
3 |
4 | Normal (without comment marking):
5 | ---
6 | Copyright (c) 2021.
7 |
8 | This file is part of the "Pathfinder2" project, available here:
9 | GitHub
10 |
11 | This project is licensed under the GNU GPL V3 license.
12 | GNU GPL V3
13 | ---
14 |
15 | C-style (with comment marking):
16 | ---
17 | /*
18 | * Copyright (c) 2021.
19 | *
20 | * This file is part of the "Pathfinder2" project, available here:
21 | * GitHub
22 | *
23 | * This project is licensed under the GNU GPL V3 license.
24 | * GNU GPL V3
25 | */
26 | ---
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/main/java/me/wobblyyyy/pathfinder2/utils/Pair.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.utils;
12 |
13 | public class Pair {
14 | private final A a;
15 | private final B b;
16 |
17 | public Pair(A a, B b) {
18 | this.a = a;
19 | this.b = b;
20 | }
21 |
22 | public Pair(Pair pair) {
23 | this(pair.getA(), pair.getB());
24 | }
25 |
26 | public A getA() {
27 | return a;
28 | }
29 |
30 | public B getB() {
31 | return b;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/sensors/AngleEncoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.sensors;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.Angle;
14 |
15 | /**
16 | * An encoder that's capable of supplying the angle the encoder is at.
17 | *
18 | * @author Colin Robertson
19 | * @since 0.5.0
20 | */
21 | public interface AngleEncoder {
22 | /**
23 | * Get the angle the encoder is at.
24 | *
25 | * @return the angle the encoder is at.
26 | */
27 | Angle getAngle();
28 | }
29 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/pathfinder2-frc/src/main/java/me/wobblyyyy/pathfinder2/wpilib/WPIJoystick.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.wpilib;
12 |
13 | import me.wobblyyyy.pathfinder2.utils.Joystick;
14 |
15 | /**
16 | * A {@code wpilib}-specific joystick implementation. It really can't get
17 | * any more simple than this.
18 | *
19 | * @author Colin Robertson
20 | * @since 0.15.0
21 | */
22 | public class WPIJoystick extends Joystick {
23 |
24 | public WPIJoystick(edu.wpi.first.wpilibj.Joystick joystick) {
25 | super(joystick::getX, joystick::getY);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/main/java/me/wobblyyyy/pathfinder2/math/Magnitude.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.math;
12 |
13 | public class Magnitude {
14 |
15 | public static boolean higherMagnitude(double a, double b) {
16 | boolean greaterAbs = Math.abs(a) >= Math.abs(b);
17 | if (greaterAbs) {
18 | return (a <= 0 && b <= 0) || (a >= 0 && b >= 0);
19 | }
20 | return false;
21 | }
22 |
23 | public static boolean lowerMagnitude(double a, double b) {
24 | return !higherMagnitude(a, b);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/sensors/InchesDistanceSensor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.sensors;
12 |
13 | import me.wobblyyyy.pathfinder2.units.Conversions;
14 |
15 | public abstract class InchesDistanceSensor implements DistanceSensor {
16 |
17 | @Override
18 | public double getDistanceCentimeters() {
19 | return Conversions.inchesToCm(getDistanceInches());
20 | }
21 |
22 | @Override
23 | public double getDistanceMeters() {
24 | return Conversions.inchesToM(getDistanceInches());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/pathfinder2-kinematics/src/main/java/me/wobblyyyy/pathfinder2/kinematics/SwerveDriveOdometry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.kinematics;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.Angle;
14 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
15 |
16 | public class SwerveDriveOdometry extends GenericOdometry {
17 |
18 | public SwerveDriveOdometry(
19 | Kinematics kinematics,
20 | Angle gyroAngle,
21 | PointXYZ initialPosition
22 | ) {
23 | super(kinematics, gyroAngle, initialPosition);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/sensors/ThreeAxisGyroscopeMode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.sensors;
12 |
13 | public enum ThreeAxisGyroscopeMode {
14 | /**
15 | * Use ROLL for {@code getAngle()}.
16 | */
17 | USE_ROLL_AS_ANGLE,
18 |
19 | /**
20 | * Use PITCH for {@code getAngle()}.
21 | */
22 | USE_PITCH_AS_ANGLE,
23 |
24 | /**
25 | * Use YAW for {@code getAngle()}.
26 | */
27 | USE_YAW_AS_ANGLE,
28 |
29 | /**
30 | * Use YAW for {@code getAngle()}.
31 | */
32 | DEFAULT
33 | }
34 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/utils/AtomicAngle.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.utils;
12 |
13 | import java.util.concurrent.atomic.AtomicReference;
14 | import me.wobblyyyy.pathfinder2.geometry.Angle;
15 |
16 | /**
17 | * {@code AtomicReference} for {@link Angle}.
18 | *
19 | * @author Colin Robertson
20 | * @since 2.4.0
21 | */
22 | public class AtomicAngle extends AtomicReference {
23 |
24 | public AtomicAngle() {
25 | super();
26 | }
27 |
28 | public AtomicAngle(Angle angle) {
29 | super(angle);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | /**
12 | * Anything related to the actual robot Pathfinder is responsible for.
13 | *
14 | *
15 | * Pathfinder contains many hardware components that are not used anywhere
16 | * in Pathfinder's source code. This is done for standardization purposes -
17 | * a generic sensor, such as {@link me.wobblyyyy.pathfinder2.robot.sensors.Accelerometer},
18 | * can now be used across many different projects without relying on
19 | * vendor-specific classes.
20 | *
21 | */
22 | package me.wobblyyyy.pathfinder2.robot;
23 |
--------------------------------------------------------------------------------
/pathfinder2-OdometryCore/src/main/java/me/wobblyyyy/pathfinder2/odometrycore/TrackableWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.odometrycore;
12 |
13 | import com.tejasmehta.OdometryCore.trackables.OdometryTrackable;
14 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
15 | import me.wobblyyyy.pathfinder2.robot.AbstractOdometry;
16 |
17 | public abstract class TrackableWrapper
18 | extends AbstractOdometry
19 | implements OdometryTrackable {
20 |
21 | @Override
22 | public PointXYZ getRawPosition() {
23 | return OdometryCoreUtils.fromOdometryPosition(getCurrentPosition());
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/pathgen/GridScaling.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.pathgen;
12 |
13 | public class GridScaling {
14 | private final double scaleX;
15 | private final double scaleY;
16 |
17 | public GridScaling(double scale) {
18 | this(scale, scale);
19 | }
20 |
21 | public GridScaling(double scaleX, double scaleY) {
22 | this.scaleX = scaleX;
23 | this.scaleY = scaleY;
24 | }
25 |
26 | public double getScaleX() {
27 | return scaleX;
28 | }
29 |
30 | public double getScaleY() {
31 | return scaleY;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/sensors/MetersDistanceSensor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.sensors;
12 |
13 | import me.wobblyyyy.pathfinder2.units.Conversions;
14 | import me.wobblyyyy.pathfinder2.units.Unit;
15 |
16 | public abstract class MetersDistanceSensor implements DistanceSensor {
17 |
18 | @Override
19 | public double getDistanceInches() {
20 | return Conversions.mToInches(getDistanceMeters());
21 | }
22 |
23 | @Override
24 | public double getDistanceCentimeters() {
25 | return Conversions.convert(Unit.M, Unit.CM, getDistanceMeters());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/led/LedController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.led;
12 |
13 | /**
14 | * An interface for controlling an LED.
15 | *
16 | * @author Colin Robertson
17 | * @since 0.6.1
18 | */
19 | public interface LedController {
20 | /**
21 | * Set the color of the LEDs.
22 | *
23 | * @param color the color to set to the LEDs.
24 | */
25 | void setColor(LedColor color);
26 |
27 | /**
28 | * Set the pattern of the LEDs.
29 | *
30 | * @param pattern the pattern to set to the LEDs.
31 | */
32 | void setPattern(LedPattern pattern);
33 | }
34 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/sensors/CentimetersDistanceSensor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.sensors;
12 |
13 | import me.wobblyyyy.pathfinder2.units.Conversions;
14 | import me.wobblyyyy.pathfinder2.units.Unit;
15 |
16 | public abstract class CentimetersDistanceSensor implements DistanceSensor {
17 |
18 | @Override
19 | public double getDistanceInches() {
20 | return Conversions.cmToInches(getDistanceCentimeters());
21 | }
22 |
23 | @Override
24 | public double getDistanceMeters() {
25 | return Conversions.convert(Unit.CM, Unit.M, getDistanceCentimeters());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/simulated/EmptyOdometry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.simulated;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
14 | import me.wobblyyyy.pathfinder2.robot.AbstractOdometry;
15 |
16 | /**
17 | * An entirely empty odometry implementation. This will always return a
18 | * position of (0, 0, 0) using {@link PointXYZ#zero()}.
19 | *
20 | * @author Colin Robertson
21 | * @since 0.1.0
22 | */
23 | public class EmptyOdometry extends AbstractOdometry {
24 |
25 | @Override
26 | public PointXYZ getRawPosition() {
27 | return PointXYZ.zero();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/main/java/me/wobblyyyy/pathfinder2/utils/Trio.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.utils;
12 |
13 | public class Trio {
14 | private final A a;
15 | private final B b;
16 | private final C c;
17 |
18 | public Trio(A a, B b, C c) {
19 | this.a = a;
20 | this.b = b;
21 | this.c = c;
22 | }
23 |
24 | public Trio(Trio trio) {
25 | this(trio.getA(), trio.getB(), trio.getC());
26 | }
27 |
28 | public A getA() {
29 | return a;
30 | }
31 |
32 | public B getB() {
33 | return b;
34 | }
35 |
36 | public C getC() {
37 | return c;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/pathfinder2-kinematics/src/main/java/me/wobblyyyy/pathfinder2/kinematics/MecanumOdometry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.kinematics;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.Angle;
14 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
15 |
16 | /**
17 | * Odometry for a mecanum chassis.
18 | *
19 | * @author Colin Robertson
20 | * @since 0.5.0
21 | */
22 | public class MecanumOdometry extends GenericOdometry {
23 |
24 | public MecanumOdometry(
25 | Kinematics kinematics,
26 | Angle gyroAngle,
27 | PointXYZ initialPosition
28 | ) {
29 | super(kinematics, gyroAngle, initialPosition);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Java sources
2 | *.java text diff=java
3 | *.kt text diff=java
4 | *.groovy text diff=java
5 | *.scala text diff=java
6 | *.gradle text diff=java
7 | *.gradle.kts text diff=java
8 |
9 | # These files are text and should be normalized (Convert crlf => lf)
10 | *.css text diff=css
11 | *.scss text diff=css
12 | *.sass text
13 | *.df text
14 | *.htm text diff=html
15 | *.html text diff=html
16 | *.js text
17 | *.jsp text
18 | *.jspf text
19 | *.jspx text
20 | *.properties text
21 | *.tld text
22 | *.tag text
23 | *.tagx text
24 | *.xml text
25 |
26 | # These files are binary and should be left untouched
27 | # (binary is a macro for -text -diff)
28 | *.class binary
29 | *.dll binary
30 | *.ear binary
31 | *.jar binary
32 | *.so binary
33 | *.war binary
34 | *.jks binary
35 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/pathfinder2-kinematics/src/main/java/me/wobblyyyy/pathfinder2/kinematics/TankOdometry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.kinematics;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.Angle;
14 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
15 |
16 | /**
17 | * Odometry for a {@code TankDrive}.
18 | *
19 | * @author Colin Robertson
20 | * @since 2.2.0
21 | */
22 | public class TankOdometry extends GenericOdometry {
23 |
24 | public TankOdometry(
25 | Kinematics kinematics,
26 | Angle gyroAngle,
27 | PointXYZ initialPosition,
28 | double updateIntervalMs
29 | ) {
30 | super(kinematics, gyroAngle, initialPosition, updateIntervalMs);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/recording/Recordable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.recording;
12 |
13 | /**
14 | * In order to use Pathfinder's state recording system, anything you'd like
15 | * to record must be a {@link Recordable}.
16 | *
17 | * @author Colin Robertson
18 | * @since 2.4.0
19 | */
20 | public interface Recordable {
21 | /**
22 | * Get the {@code Recordable}'s value.
23 | *
24 | * @return the {@code Recordable}'s value.
25 | */
26 | T getRecordingValue();
27 |
28 | /**
29 | * Set the {@code Recordable}'s value.
30 | *
31 | * @param value the value for the {@code Recordable}.
32 | */
33 | void setRecordingValue(Object value);
34 | }
35 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/utils/AccelerationProfile.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.utils;
12 |
13 | public class AccelerationProfile {
14 | private final double acceleration;
15 |
16 | public AccelerationProfile(double acceleration) {
17 | this.acceleration = acceleration;
18 | }
19 |
20 | public double getAcceleration() {
21 | return acceleration;
22 | }
23 |
24 | public double getDisplacement(double initialVelocity, double time) {
25 | // s = ut + 1/2at^2
26 | return (initialVelocity * time) + (0.5 * time * acceleration);
27 | }
28 |
29 | public double getDisplacement(double time) {
30 | return getDisplacement(0, time);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/pathfinder2-commands/src/main/java/me/wobblyyyy/pathfinder2/exceptions/ScriptingException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.exceptions;
12 |
13 | /**
14 | * When something goes wrong while executing a user script, a
15 | * {@code ScriptingException} will be thrown.
16 | *
17 | * @author Colin Robertson
18 | * @since 3.0.0-alpha
19 | */
20 | public class ScriptingException extends RuntimeException {
21 |
22 | /**
23 | * Create a new {@code ScriptingException}.
24 | *
25 | * @param msg the message the exception should carry. This message should
26 | * clearly explain what what wrong, as well as how to fix it.
27 | */
28 | public ScriptingException(String msg) {
29 | super(msg);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/listening/Tickable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.listening;
12 |
13 | import me.wobblyyyy.pathfinder2.Pathfinder;
14 |
15 | /**
16 | * A {@code Tickable} is something that can be ticked. This is basically
17 | * anything that needs to be regularly updated.
18 | *
19 | * @author Colin Robertson
20 | * @since 0.8.0
21 | */
22 | @FunctionalInterface
23 | public interface Tickable {
24 | /**
25 | * Tick the object once.
26 | *
27 | * @param pathfinder the instance of Pathfinder that is being ticked.
28 | * @return true if the {@code Tickable} should continue being executed.
29 | * Otherwise, false.
30 | */
31 | boolean tick(Pathfinder pathfinder);
32 | }
33 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/led/LedColor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.led;
12 |
13 | /**
14 | * A color, used for LEDs.
15 | *
16 | * @author Colin Robertson
17 | * @since 0.6.1
18 | */
19 | public class LedColor {
20 | private final int red;
21 | private final int green;
22 | private final int blue;
23 |
24 | public LedColor(int red, int green, int blue) {
25 | this.red = red;
26 | this.green = green;
27 | this.blue = blue;
28 | }
29 |
30 | public int red() {
31 | return this.red;
32 | }
33 |
34 | public int green() {
35 | return this.green;
36 | }
37 |
38 | public int blue() {
39 | return this.blue;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/main/java/me/wobblyyyy/pathfinder2/exceptions/NullAngleException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.exceptions;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.Angle;
14 |
15 | /**
16 | * Exception thrown whenever an operation is requested to be performed on
17 | * an angle that is... you guessed it... null!
18 | *
19 | * @author Colin Robertson
20 | * @since 0.0.0
21 | */
22 | public class NullAngleException extends RuntimeException {
23 |
24 | public NullAngleException(String message) {
25 | super(message);
26 | }
27 |
28 | public static void throwIfInvalid(String message, Angle angle) {
29 | if (angle == null) {
30 | throw new NullAngleException(message);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/sensors/Sensor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.sensors;
12 |
13 | /**
14 | * A physical device used to read information from an outside environment.
15 | *
16 | * @param the type of data the sensor reads. Color sensors return ARGB
17 | * values. Distance sensors return distance values (doubles).
18 | * Digital inputs (such as buttons or limit switches) return
19 | * boolean values (true = pressed, false = not pressed).
20 | * @author Colin Robertson
21 | * @since 0.7.1
22 | */
23 | public interface Sensor {
24 | /**
25 | * Read data from the sensor.
26 | *
27 | * @return data, read from the sensor.
28 | */
29 | T read();
30 | }
31 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/main/java/me/wobblyyyy/pathfinder2/math/Equation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.math;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.PointXY;
14 |
15 | public interface Equation {
16 | /**
17 | * Get a Y value at a specific X value according to the equation.
18 | *
19 | * @param x the X value to "look up."
20 | * @return the Y value, according to the inputted X value.
21 | */
22 | double getY(double x);
23 |
24 | /**
25 | * Get a point based on an X value.
26 | *
27 | * @param x the X value to "look up."
28 | * @return the point, according to the inputted X value.
29 | */
30 | default PointXY getPoint(double x) {
31 | return new PointXY(x, getY(x));
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/main/java/me/wobblyyyy/pathfinder2/exceptions/InvalidToleranceException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.exceptions;
12 |
13 | /**
14 | * Exception to be thrown whenever a provided tolerance value is invalid.
15 | * This exception will almost exclusively be thrown when a tolerance value is
16 | * negative - all tolerance values must be positive.
17 | *
18 | * @author Colin Robertson
19 | * @since 0.0.0
20 | */
21 | public class InvalidToleranceException extends RuntimeException {
22 |
23 | public InvalidToleranceException(String s) {
24 | super(s);
25 | }
26 |
27 | public static void throwIfInvalid(String message, double tolerance) {
28 | if (tolerance < 0) throw new InvalidToleranceException(message);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/recording/recordables/RecordableDouble.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.recording.recordables;
12 |
13 | import me.wobblyyyy.pathfinder2.recording.Recordable;
14 |
15 | public class RecordableDouble implements Recordable {
16 | private double value;
17 |
18 | public RecordableDouble(double value) {
19 | this.value = value;
20 | }
21 |
22 | public RecordableDouble() {
23 | this(0.0);
24 | }
25 |
26 | @Override
27 | public Double getRecordingValue() {
28 | return value;
29 | }
30 |
31 | @Override
32 | public void setRecordingValue(Object obj) {
33 | if (obj instanceof Double) {
34 | value = (Double) obj;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/pathfinder2-kinematics/src/main/java/me/wobblyyyy/pathfinder2/control/SplineController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.control;
12 |
13 | import me.wobblyyyy.pathfinder2.math.Spline;
14 |
15 | public class SplineController extends AbstractController {
16 | private final Spline spline;
17 |
18 | public SplineController(Spline spline) {
19 | this.spline = spline;
20 | }
21 |
22 | /**
23 | * OVERRIDE THIS METHOD TO CHANGE INPUTS!
24 | *
25 | * @param value the input.
26 | * @return the output.
27 | */
28 | public double modifyInput(double value) {
29 | return value;
30 | }
31 |
32 | @Override
33 | public double calculate(double value) {
34 | return spline.interpolateY(modifyInput(value));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/recording/recordables/RecordableBoolean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.recording.recordables;
12 |
13 | import me.wobblyyyy.pathfinder2.recording.Recordable;
14 |
15 | public class RecordableBoolean implements Recordable {
16 | private boolean value;
17 |
18 | public RecordableBoolean(boolean value) {
19 | this.value = value;
20 | }
21 |
22 | public RecordableBoolean() {
23 | this(false);
24 | }
25 |
26 | @Override
27 | public Boolean getRecordingValue() {
28 | return value;
29 | }
30 |
31 | @Override
32 | public void setRecordingValue(Object obj) {
33 | if (obj instanceof Boolean) {
34 | value = (Boolean) obj;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/pathfinder2-frc/src/main/java/me/wobblyyyy/pathfinder2/kauailabs/AHRSGyroMode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.kauailabs;
12 |
13 | /**
14 | * Modes the {@link AHRSGyro} can operate in. Unless you have a reason not
15 | * to, you should use {@link AHRSGyroMode#NORMAL}.
16 | *
17 | * @author Colin Robertson
18 | * @since 0.10.8
19 | */
20 | public enum AHRSGyroMode {
21 | /**
22 | * The gyroscope's normal mode of operation. This is the same as YAW.
23 | */
24 | NORMAL,
25 |
26 | /**
27 | * Use the gyroscope's yaw for angle values.
28 | */
29 | YAW,
30 |
31 | /**
32 | * Use the gyroscope's pitch for angle values.
33 | */
34 | PITCH,
35 |
36 | /**
37 | * Use the gyroscope's roll for angle values.
38 | */
39 | ROLL
40 | }
41 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/test/java/me/wobblyyyy/pathfinder2/geometry/TestCircle.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.geometry;
12 |
13 | import org.junit.jupiter.api.Assertions;
14 | import org.junit.jupiter.api.Test;
15 |
16 | public class TestCircle {
17 |
18 | @Test
19 | public void testIsPointInShape() {
20 | PointXY center = new PointXY(0, 0);
21 | double radius = 10;
22 | Circle circle = new Circle(center, radius);
23 |
24 | PointXY test1 = new PointXY(0, 0);
25 | PointXY test2 = new PointXY(10, 10);
26 | PointXY test3 = new PointXY(5, 5);
27 |
28 | Assertions.assertTrue(test1.isInside(circle));
29 | Assertions.assertFalse(test2.isInside(circle));
30 | Assertions.assertTrue(test3.isInside(circle));
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/pathfinder2-commands/src/main/java/me/wobblyyyy/pathfinder2/commands/TimeCommands.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.commands;
12 |
13 | import me.wobblyyyy.pathfinder2.logging.Logger;
14 | import me.wobblyyyy.pathfinder2.time.ElapsedTimer;
15 |
16 | public class TimeCommands {
17 |
18 | private TimeCommands() {}
19 |
20 | public static final Command WAIT_COMMAND = new Command(
21 | "wait",
22 | (pathfinder, args) -> {
23 | double time = Double.parseDouble(args[0]);
24 | Logger.debug(TimeCommands.class, "waiting for <%s> ms", time);
25 | ElapsedTimer.wait(time);
26 | },
27 | 1
28 | );
29 |
30 | public static void addTimeCommands(CommandRegistry registry) {
31 | registry.unsafeAdd(WAIT_COMMAND);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/pathfinder2-OdometryCore/build.gradle:
--------------------------------------------------------------------------------
1 | //file:noinspection GroovyAssignabilityCheck
2 | //file:noinspection GroovyAssignabilityCheck
3 | //file:noinspection GroovyAssignabilityCheck
4 | plugins {
5 | id 'java'
6 | id 'maven-publish'
7 | }
8 |
9 | repositories {
10 | mavenCentral()
11 | }
12 |
13 | java {
14 | toolchain {
15 | languageVersion = JavaLanguageVersion.of(8)
16 | }
17 |
18 | withSourcesJar()
19 | withJavadocJar()
20 | }
21 |
22 | dependencies {
23 | implementation project(':pathfinder2-geometry')
24 | implementation project(':pathfinder2-kinematics')
25 | implementation project(':pathfinder2-core')
26 |
27 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
28 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
29 | }
30 |
31 | test {
32 | useJUnitPlatform()
33 | }
34 |
35 | publishing {
36 | publications {
37 | maven(MavenPublication) {
38 | groupId = project.projectName
39 | version = project.projectVersion
40 | artifactId = 'OdometryCore'
41 | from components.java
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/test/java/me/wobblyyyy/pathfinder2/math/TestMinMax.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.math;
12 |
13 | import org.junit.jupiter.api.Assertions;
14 | import org.junit.jupiter.api.Test;
15 |
16 | public class TestMinMax {
17 |
18 | @Test
19 | public void testSimpleClip() {
20 | Assertions.assertEquals(0.25, MinMax.clip(0.25, 0, 1));
21 | Assertions.assertEquals(0.1, MinMax.clip(0.25, 0, 0.1));
22 | Assertions.assertEquals(0.3, MinMax.clip(0.25, 0.3, 1));
23 | }
24 |
25 | @Test
26 | public void testClipWithMagnitude() {
27 | Assertions.assertEquals(0.25, MinMax.clip(0.25, 0, 0, 1, 1));
28 | Assertions.assertEquals(0.1, MinMax.clip(0.25, 0, 0, 1, 0.1));
29 | Assertions.assertEquals(-0.1, MinMax.clip(-0.25, -1, 0, 1, 0.1));
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/sensors/Gyroscope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.sensors;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.Angle;
14 |
15 | /**
16 | * An interface for a gyroscope.
17 | *
18 | * @author Colin Robertson
19 | * @since 0.6.1
20 | */
21 | public interface Gyroscope {
22 | /**
23 | * Get the angle the gyroscope is currently facing.
24 | *
25 | * @return the angle the gyroscope is currently facing.
26 | */
27 | Angle getAngle();
28 |
29 | /**
30 | * Set the current angle of the gyroscope.
31 | *
32 | * @param angle the angle to set to the gyroscope.
33 | */
34 | void setAngle(Angle angle);
35 |
36 | /**
37 | * Set the angle of the gyroscope to 0 degrees.
38 | */
39 | void reset();
40 | }
41 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/test/java/me/wobblyyyy/pathfinder2/geometry/TestPointSlope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.geometry;
12 |
13 | import org.junit.jupiter.api.Assertions;
14 | import org.junit.jupiter.api.Test;
15 |
16 | public class TestPointSlope {
17 |
18 | @Test
19 | public void testIntersection() {
20 | PointSlope a = new PointSlope(new PointXY(0, 0), 1);
21 | PointSlope b = new PointSlope(new PointXY(0, 10), -1);
22 |
23 | PointXY intersection1 = a.getIntersection(b);
24 | PointXY intersection2 = b.getIntersection(a);
25 |
26 | Assertions.assertEquals(5d, intersection1.x());
27 | Assertions.assertEquals(5d, intersection1.y());
28 | Assertions.assertEquals(5d, intersection2.x());
29 | Assertions.assertEquals(5d, intersection2.y());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/execution/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | /**
12 | * Internal code responsible for managing Pathfinder's actions. The concept
13 | * behind these execution constructs is as follows:
14 | *
15 | *
16 | *
17 | * Individual followers are executed by a {@code FollowerExecutor}.
18 | *
19 | *
20 | * {@code FollowerExecutor}s are executed and managed by a
21 | * {@code ExecutorManager}.
22 | *
23 | *
24 | * Pathfinder's autonomous movement is operated via controlling
25 | * and managing {@code ExecutorManager}s.
26 | *
27 | *
28 | *
29 | *
30 | * Classes in this package are pretty much only useful inside the library.
31 | *
4 | pathfinder2-core
5 | Core code behind Pathfinder. This module depends on both the geometry and
6 | kinematics portion of Pathfinder. This module is needed to actually use Pathfinder,
7 | outside of the geometry and kinematics portions of the library.
8 |
9 |
10 | pathfinder2-geometry
11 | Everything geometry-related in Pathfinder. The library contains quite a few
12 | geometry utilities that may be useful in other projects, so this has been split
13 | into a separate module.
14 |
15 |
16 | pathfinder2-kinematics
17 | Forwards and inverse kinematics. Tank, swerve, meccanum - etc. This module
18 | contains kinematics and odometry for most major types of drivetrains.
19 |
20 |
21 | pathfinder2-OdometryCore
22 | Three-wheel odometry specific algorithm written by Tejas Mehta.
23 |
24 |
25 | pathfinder2-examples
26 | Examples of Pathfinder code - how to use it, etc.
27 |
28 |
29 |
--------------------------------------------------------------------------------
/pathfinder2-kinematics/src/main/java/me/wobblyyyy/pathfinder2/kinematics/SwerveModuleState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.kinematics;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.Angle;
14 |
15 | public class SwerveModuleState {
16 | private final double speed;
17 | private final Angle direction;
18 |
19 | public SwerveModuleState(double speed, Angle direction) {
20 | this.speed = speed;
21 | this.direction = direction;
22 | }
23 |
24 | public double speed() {
25 | return speed;
26 | }
27 |
28 | public Angle direction() {
29 | return direction;
30 | }
31 |
32 | public SwerveModuleState add(SwerveModuleState state) {
33 | return new SwerveModuleState(
34 | speed + state.speed,
35 | direction.add(state.direction)
36 | );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/jmh/java/me/wobblyyyy/pathfinder2/trajectory/BenchmarkFastTrajectory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.trajectory;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
14 | import org.openjdk.jmh.annotations.Benchmark;
15 | import org.openjdk.jmh.annotations.Scope;
16 | import org.openjdk.jmh.annotations.State;
17 | import org.openjdk.jmh.infra.Blackhole;
18 |
19 | @State(Scope.Benchmark)
20 | public class BenchmarkFastTrajectory extends GenericTrajectoryBenchmarker {
21 | private static final double speed = 0.5;
22 |
23 | private static final Trajectory trajectory = new FastTrajectory(
24 | new PointXYZ(0, 0, 0),
25 | new PointXYZ(-10, -10, 45),
26 | speed
27 | );
28 |
29 | @Benchmark
30 | public void benchmark(Blackhole bh) {
31 | followTrajectories(bh, trajectory);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/sensors/AbstractGyroscope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.sensors;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.Angle;
14 |
15 | /**
16 | * An abstract implementation of the {@link Gyroscope} interface.
17 | *
18 | * @author Colin Robertson
19 | * @since 0.6.1
20 | */
21 | public abstract class AbstractGyroscope implements Gyroscope {
22 | private Angle offset = Angle.DEG_0;
23 |
24 | public abstract Angle getRawAngle();
25 |
26 | @Override
27 | public Angle getAngle() {
28 | return getRawAngle().add(offset);
29 | }
30 |
31 | @Override
32 | public void setAngle(Angle angle) {
33 | this.offset = angle.subtract(getAngle());
34 | }
35 |
36 | @Override
37 | public void reset() {
38 | setAngle(Angle.DEG_0);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/sensors/SensorBuffer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.sensors;
12 |
13 | import java.util.function.Supplier;
14 | import me.wobblyyyy.pathfinder2.math.RollingAverage;
15 |
16 | /**
17 | * Wrapper for sensors that supply double values, meant to smoothen results
18 | * by averaging past values.
19 | *
20 | * @author Colin Robertson
21 | * @since 0.7.1
22 | */
23 | public class SensorBuffer implements Supplier {
24 | private final Supplier input;
25 | private final RollingAverage average;
26 |
27 | public SensorBuffer(Supplier input, int size) {
28 | this.input = input;
29 | this.average = new RollingAverage(size);
30 | }
31 |
32 | @Override
33 | public Double get() {
34 | return average.add(input.get());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/main/java/me/wobblyyyy/pathfinder2/geometry/PointSlope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.geometry;
12 |
13 | /**
14 | * Another implementation of the {@link LinearEquation} interface.
15 | * {@code y - y1 = m(x - x1)} or {@code y = m(x - x1) + y1}
16 | *
17 | *
18 | * Internally, this simply converts the point slope into a slope intercept.
19 | * This means you can't get "the point."
20 | *
21 | *
22 | * @author Colin Robertson
23 | * @since 0.1.0
24 | */
25 | public class PointSlope extends SlopeIntercept {
26 |
27 | /**
28 | * Create a new {@code PointSlope} instance.
29 | *
30 | * @param point the point to use.
31 | * @param slope the slope to use.
32 | */
33 | public PointSlope(PointXY point, double slope) {
34 | super(slope, (slope * -point.x()) + point.y());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/pathfinder2-OdometryCore/src/main/java/com/tejasmehta/OdometryCore/trackables/ThreeWheelTrackable.java:
--------------------------------------------------------------------------------
1 | /****
2 | * Made by Tejas Mehta
3 | * Made on Monday, March 29, 2021
4 | * File Name: ThreeWheelTrackable
5 | * Package: com.tejasmehta.OdometryCore.trackables*/
6 | package com.tejasmehta.OdometryCore.trackables;
7 |
8 | import com.tejasmehta.OdometryCore.localization.OdometryPosition;
9 |
10 | public class ThreeWheelTrackable implements OdometryTrackable {
11 | private final double wheelDiameter;
12 | private final double cpr;
13 | private final double leftOffset;
14 | private final double rightOffset;
15 | private final double frontBackOffset;
16 |
17 | ThreeWheelTrackable(
18 | double cpr,
19 | double wheelDiameter,
20 | double leftOffset,
21 | double rightOffset,
22 | double frontBackOffset
23 | ) {
24 | this.wheelDiameter = wheelDiameter;
25 | this.cpr = cpr;
26 | this.leftOffset = leftOffset;
27 | this.rightOffset = rightOffset;
28 | this.frontBackOffset = frontBackOffset;
29 | }
30 |
31 | @Override
32 | public OdometryPosition getCurrentPosition() {
33 | return null;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/sensors/ARGB.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.sensors;
12 |
13 | /**
14 | * A representation of an ARGB color.
15 | *
16 | * @author Colin Robertson
17 | * @since 0.7.1
18 | */
19 | public class ARGB {
20 | private final int alpha;
21 | private final int red;
22 | private final int green;
23 | private final int blue;
24 |
25 | public ARGB(int alpha, int red, int green, int blue) {
26 | this.alpha = alpha;
27 | this.red = red;
28 | this.green = green;
29 | this.blue = blue;
30 | }
31 |
32 | public int alpha() {
33 | return alpha;
34 | }
35 |
36 | public int red() {
37 | return red;
38 | }
39 |
40 | public int green() {
41 | return green;
42 | }
43 |
44 | public int blue() {
45 | return blue;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/exceptions/InvalidSpeedException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.exceptions;
12 |
13 | /**
14 | * Exception to be thrown whenever a speed value is invalid.
15 | *
16 | *
17 | * In most cases, speed values should always fit within the range of 0.0
18 | * to 1.0. If you're getting this exception during program execution, actually,
19 | * it's fairly likely the cause is a speed value outside of that range.
20 | *
21 | *
22 | * @author Colin Robertson
23 | * @since 0.0.0
24 | */
25 | public class InvalidSpeedException extends RuntimeException {
26 |
27 | public InvalidSpeedException(String s) {
28 | super(s);
29 | }
30 |
31 | public static void throwIfInvalid(String message, double speed) {
32 | if (speed < 0 || speed > 1) {
33 | throw new InvalidSpeedException(message);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
25 |
26 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/main/java/me/wobblyyyy/pathfinder2/math/GearRatio.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.math;
12 |
13 | /**
14 | * Gear ratio implementation.
15 | *
16 | * @author Colin Robertson
17 | * @since 0.1.0
18 | */
19 | public class GearRatio {
20 | private final double inOverOut;
21 | private final double outOverIn;
22 |
23 | @SuppressWarnings("RedundantCast")
24 | public GearRatio(int inputTeeth, int outputTeeth) {
25 | this((double) inputTeeth, (double) outputTeeth);
26 | }
27 |
28 | public GearRatio(double howManyIn, double howManyOut) {
29 | this.inOverOut = howManyIn / howManyOut;
30 | this.outOverIn = howManyOut / howManyIn;
31 | }
32 |
33 | public double outputFor(double input) {
34 | return outOverIn * input;
35 | }
36 |
37 | public double inputFor(double output) {
38 | return inOverOut * output;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/utils/NotNull.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.utils;
12 |
13 | /**
14 | * Utility class used for verifying that objects are not null.
15 | *
16 | * @author Colin Robertson
17 | * @since 0.2.3
18 | */
19 | public class NotNull {
20 |
21 | private NotNull() {}
22 |
23 | public static boolean isAnythingNull(Object... objects) {
24 | for (Object obj : objects) {
25 | if (obj == null) {
26 | return true;
27 | }
28 | }
29 |
30 | return false;
31 | }
32 |
33 | public static boolean isNothingNull(Object... objects) {
34 | return !isAnythingNull(objects);
35 | }
36 |
37 | public static void throwExceptionIfNull(String message, Object... objects) {
38 | if (isAnythingNull(objects)) {
39 | throw new NullPointerException(message);
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/pathfinder2-pi/src/main/java/me/wobblyyyy/pathfinder2/pi/PiMotor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.pi;
12 |
13 | import me.wobblyyyy.pathfinder2.arduino.ArduinoInterface;
14 | import me.wobblyyyy.pathfinder2.arduino.ArduinoOutput;
15 | import me.wobblyyyy.pathfinder2.robot.components.Motor;
16 |
17 | /**
18 | * Pi-specific {@code Motor} implementation, reliant on using an Arduino
19 | * to transmit motor power.
20 | *
21 | * @author Colin Robertson
22 | * @since 2.1.1
23 | */
24 | public class PiMotor extends ArduinoOutput implements Motor {
25 | private double power;
26 |
27 | public PiMotor(ArduinoInterface arduino, String id) {
28 | super(arduino, id);
29 | }
30 |
31 | @Override
32 | public void setPower(double power) {
33 | super.write(power);
34 |
35 | this.power = power;
36 | }
37 |
38 | @Override
39 | public double getPower() {
40 | return this.power;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/odometry/SwerveModuleOdometry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.odometry;
12 |
13 | import java.util.function.Supplier;
14 | import me.wobblyyyy.pathfinder2.geometry.Angle;
15 | import me.wobblyyyy.pathfinder2.kinematics.SwerveModuleState;
16 |
17 | public class SwerveModuleOdometry {
18 | private final Supplier getSpeed;
19 | private final Supplier getAngle;
20 |
21 | public SwerveModuleOdometry(
22 | Supplier getSpeed,
23 | Supplier getAngle
24 | ) {
25 | this.getSpeed = getSpeed;
26 | this.getAngle = getAngle;
27 | }
28 |
29 | public double getSpeed() {
30 | return getSpeed.get();
31 | }
32 |
33 | public Angle getAngle() {
34 | return getAngle.get();
35 | }
36 |
37 | public SwerveModuleState getState() {
38 | return new SwerveModuleState(getSpeed(), getAngle());
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/sensors/Accelerometer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.sensors;
12 |
13 | /**
14 | * A basic interface for an accelerometer.
15 | *
16 | * @author Colin Robertson
17 | * @since 0.6.1
18 | */
19 | public interface Accelerometer {
20 | /**
21 | * Get the velocity of the {@code Accelerometer} in units per second.
22 | *
23 | * @return the velocity on the X axis, in units per second.
24 | */
25 | double getVxPerSecond();
26 |
27 | /**
28 | * Get the velocity of the {@code Accelerometer} in units per second.
29 | *
30 | * @return the velocity on the Y axis, in units per second.
31 | */
32 | double getVyPerSecond();
33 |
34 | /**
35 | * Get the velocity of the {@code Accelerometer} in rotations
36 | * per second.
37 | *
38 | * @return how many times the robot is rotating, per second.
39 | */
40 | double getRotationsPerSecond();
41 | }
42 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/readme.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Autonomous motion planning and control library for wheeled mobile robots.
5 |
6 | Successor to Pathfinder.
7 |
8 |
9 | # pathfinder2-geometry
10 |
11 | Geometry! My favorite. It might not be yours, but it's certainly mine. The memories I have of 9th grade geometry
12 | class... man, those were the days, am I right? Of course, I'm right, I always am.
13 |
14 | Anyways. Pathfinder2's geometry package contains some rather extensive classes and methods for anything geometry
15 | related. Well, not anything, actually, but just about. The core concepts of the geometry package revolve around points
16 | and angles - see the PointXY, PointXYZ, and Angle classes to learn more. There's quite a bit of in-code documentation
17 | you can look at if you're confused.
18 |
19 | This package has been designed to be used outside of FIRST robotics environments, hence its separation from
20 | Pathfinder2's core. Because most of this code is just really simple math and trigonometry, there's not very much
21 | extensive test documentation. You can feel free to add some if you'd like.
22 |
23 | ## Dependencies
24 | This module depends on... nothing!
25 |
--------------------------------------------------------------------------------
/pathfinder2-commands/src/test/java/me/wobblyyyy/pathfinder2/commands/TestTimeCommands.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.commands;
12 |
13 | import me.wobblyyyy.pathfinder2.Pathfinder;
14 | import me.wobblyyyy.pathfinder2.logging.Logger;
15 | import me.wobblyyyy.pathfinder2.time.ElapsedTimer;
16 | import org.junit.jupiter.api.Assertions;
17 | import org.junit.jupiter.api.BeforeEach;
18 | import org.junit.jupiter.api.Test;
19 |
20 | public class TestTimeCommands {
21 | private Pathfinder pathfinder;
22 | private CommandRegistry registry;
23 |
24 | @BeforeEach
25 | public void beforeEach() {
26 | pathfinder = Pathfinder.newSimulatedPathfinder(-0.05);
27 | registry = CommandRegistry.createDefaultRegistry(pathfinder);
28 | }
29 |
30 | @Test
31 | public void testWaitCommand() {
32 | ElapsedTimer timer = new ElapsedTimer(true);
33 | registry.execute("wait", "3");
34 | Assertions.assertTrue(timer.elapsedMs() >= 3);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/test/java/me/wobblyyyy/pathfinder2/math/TestRollingAverage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.math;
12 |
13 | import org.junit.jupiter.api.Assertions;
14 | import org.junit.jupiter.api.Test;
15 |
16 | public class TestRollingAverage {
17 |
18 | @Test
19 | public void testWithEmptyValues() {
20 | RollingAverage avg = new RollingAverage(10);
21 |
22 | avg.add(0.0);
23 | avg.add(1.0);
24 |
25 | Assertions.assertEquals(0.5, avg.average());
26 | }
27 |
28 | @Test
29 | public void testWithCoolValues() {
30 | double[] numbers = new double[1_000];
31 |
32 | for (int i = 0; i < numbers.length; i++) {
33 | numbers[i] = i * 17.3;
34 | }
35 |
36 | RollingAverage avg = new RollingAverage(1_000);
37 | for (double number : numbers) {
38 | avg.add(number);
39 | }
40 |
41 | Assertions.assertEquals(Average.of(numbers), avg.average());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/test/java/me/wobblyyyy/pathfinder2/robot/simulated/TestSimulatedDrive.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.simulated;
12 |
13 | import java.util.function.Function;
14 | import me.wobblyyyy.pathfinder2.geometry.Translation;
15 | import org.junit.jupiter.api.Assertions;
16 | import org.junit.jupiter.api.Test;
17 |
18 | public class TestSimulatedDrive {
19 |
20 | @Test
21 | public void testTranslation() {
22 | Translation translation = new Translation(0, 0, 0);
23 | SimulatedDrive drive = new SimulatedDrive();
24 | drive.setTranslation(translation);
25 | Assertions.assertEquals(translation, drive.getTranslation());
26 | }
27 |
28 | @Test
29 | public void testModifier() {
30 | Function modifier = t -> t;
31 | SimulatedDrive drive = new SimulatedDrive();
32 | drive.setDriveModifier(modifier);
33 | Assertions.assertEquals(modifier, drive.getDriveModifier());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/pathfinder2-commands/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | plugins {
12 | id 'java'
13 | id 'maven-publish'
14 | }
15 |
16 | repositories {
17 | mavenCentral()
18 | }
19 |
20 | java {
21 | toolchain {
22 | languageVersion.set(JavaLanguageVersion.of(11))
23 | }
24 |
25 | withSourcesJar()
26 | withJavadocJar()
27 | }
28 |
29 | dependencies {
30 | implementation project(':pathfinder2-core')
31 | implementation project(':pathfinder2-geometry')
32 | implementation project(':pathfinder2-kinematics')
33 |
34 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
35 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
36 | }
37 |
38 | test {
39 | useJUnitPlatform()
40 | }
41 |
42 | publishing {
43 | publications {
44 | maven(MavenPublication) {
45 | groupId = project.projectName
46 | version = project.projectVersion
47 | artifactId = 'commands'
48 | from components.java
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/sensors/DigitalInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.sensors;
12 |
13 | /**
14 | * A {@code DigitalInput} is pretty much a binary sensor - it can either be
15 | * on or off. Usually, this is implemented as something like a button.
16 | *
17 | * @author Colin Robertson
18 | * @since 0.7.1
19 | */
20 | public interface DigitalInput extends Sensor {
21 | /**
22 | * Is the switch currently active?
23 | *
24 | * @return if the switch is currently active, return true. Otherwise,
25 | * return false.
26 | */
27 | boolean isActive();
28 |
29 | /**
30 | * Is the switch currently inactive?
31 | *
32 | * @return if the switch is currently active, return false. Otherwise,
33 | * return true.
34 | */
35 | default boolean isInactive() {
36 | return !isActive();
37 | }
38 |
39 | @Override
40 | default Boolean read() {
41 | return isActive();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/main/java/me/wobblyyyy/pathfinder2/math/ZeroSlopeSpline.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.math;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.PointXY;
14 |
15 | /**
16 | * A spline with a slope of 0.
17 | *
18 | * @author Colin Robertson
19 | * @since 0.6.1
20 | */
21 | public class ZeroSlopeSpline implements Spline {
22 | private final double returnValue;
23 |
24 | public ZeroSlopeSpline(double returnValue) {
25 | this.returnValue = returnValue;
26 | }
27 |
28 | @Override
29 | public double interpolateY(double x) {
30 | return this.returnValue;
31 | }
32 |
33 | @Override
34 | public PointXY interpolate(double x) {
35 | return new PointXY(x, this.returnValue);
36 | }
37 |
38 | @Override
39 | public PointXY getStartPoint() {
40 | return new PointXY(0, returnValue);
41 | }
42 |
43 | @Override
44 | public PointXY getEndPoint() {
45 | return new PointXY(0, returnValue);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/pathfinder2-commands/readme.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Autonomous motion planning and control library for wheeled mobile robots.
5 |
6 | Successor to Pathfinder.
7 |
8 |
9 | # pathfinder2-commands
10 | Pathfinder's built-in command/scripting support! Using the `commands` module,
11 | you can write scripts (conventionally suffixed with `.pf` (for example, take
12 | `coolAutonRoutine.pf`)) that can be executed by Pathfinder. The
13 | `CommandRegistry` class parses `String`s into instructions interpreted by
14 | Pathfinder, essentially creating a rudimentary scripting language. For examples
15 | of the capabilities of this scripting language, check out the following:
16 | - [`testGoTo.pf`](src/test/resources/me/wobblyyyy/pathfinder2/commands/testGoTo.pf)
17 | - [`testSetTranslation.pf`](src/test/resources/me/wobblyyyy/pathfinder2/commands/testSetTranslation.pf)
18 | - [`testSetValuesAndSplineTo.pf`](src/test/resources/me/wobblyyyy/pathfinder2/commands/testSetValuesAndSplineTo.pf)
19 | - [`testSplineTo.pf`](src/test/resources/me/wobblyyyy/pathfinder2/commands/testSplineTo.pf)
20 |
21 | ## Dependencies
22 |
23 | This module depends on...
24 |
25 | - `pathfinder2-kinematics`
26 | - `pathfinder2-geometry`
27 | - `pathfinder2-core`
28 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/pathgen/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | /**
12 | * Ahh. Path generation. This is also the part of Pathfinder that actually
13 | * finds paths. Internally, this uses the A star pathfinding algorithm
14 | * to find paths. This algorithm works based on integer points and a sort
15 | * of two-dimensional data structure ({@link java.util.HashMap} is used for
16 | * performance purposes), so decimal/double points need to be converted to
17 | * integers. How do you do this, you may be asking? I'll tell you how.
18 | * Use {@link me.wobblyyyy.pathfinder2.pathgen.LocalizedPathGen}! A lovely
19 | * class. Truly, just lovely. Fantastic, even. I'm currently in English class
20 | * and trying to kill time until the period ends, so I hope you're enjoying
21 | * this meaningless rambling.
22 | *
23 | *
24 | * Interestingly enough, this code... sucks. If you can rewrite it so it's
25 | * cleaner and/or faster, you're more than welcome to do so.
26 | *
27 | */
28 | package me.wobblyyyy.pathfinder2.pathgen;
29 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/trajectory/EmptyTrajectory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.trajectory;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
14 |
15 | /**
16 | * An {@code EmptyTrajectory} is a trajectory that does absolutely nothing.
17 | * The next marker point is always the current point, the trajectory is never
18 | * done, and the speed is always 0. This should be used when you want
19 | * Pathfinder to do absolutely nothing.
20 | *
21 | * @author Colin Robertson
22 | * @since 0.0.0
23 | */
24 | public class EmptyTrajectory implements Trajectory {
25 |
26 | @Override
27 | public PointXYZ nextMarker(PointXYZ current) {
28 | return current;
29 | }
30 |
31 | @Override
32 | public boolean isDone(PointXYZ current) {
33 | return false;
34 | }
35 |
36 | @Override
37 | public double speed(PointXYZ current) {
38 | return 0;
39 | }
40 |
41 | @Override
42 | public String toString() {
43 | return "EmptyTrajectory";
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/jmh/java/me/wobblyyyy/pathfinder2/trajectory/BenchmarkLinearTrajectory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.trajectory;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.Angle;
14 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
15 | import org.openjdk.jmh.annotations.Benchmark;
16 | import org.openjdk.jmh.annotations.Scope;
17 | import org.openjdk.jmh.annotations.State;
18 | import org.openjdk.jmh.infra.Blackhole;
19 |
20 | @State(Scope.Benchmark)
21 | public class BenchmarkLinearTrajectory extends GenericTrajectoryBenchmarker {
22 | private static final double speed = 0.5;
23 | private static final double tolerance = 2;
24 | private static final Angle angleTolerance = Angle.fromDeg(5);
25 |
26 | private static final Trajectory trajectory = new LinearTrajectory(
27 | new PointXYZ(-10, -10, 45),
28 | speed,
29 | tolerance,
30 | angleTolerance
31 | );
32 |
33 | @Benchmark
34 | public void benchmark(Blackhole bh) {
35 | followTrajectories(bh, trajectory);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/pathgen/AStarPathFinder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.pathgen;
12 |
13 | import java.util.List;
14 | import me.wobblyyyy.pathfinder2.geometry.PointXY;
15 | import me.wobblyyyy.pathfinder2.zones.Zone;
16 |
17 | /**
18 | * I'm not entirely sure why I made this class, to be honest.
19 | *
20 | * @author Colin Robertson
21 | * @since 0.1.0
22 | */
23 | public class AStarPathFinder {
24 | private final LocalizedPathGen pathGen;
25 |
26 | public AStarPathFinder(
27 | GridScaling scale,
28 | double robotWidth,
29 | double robotLength,
30 | List zones
31 | ) {
32 | pathGen =
33 | LocalizedPathGen.withInflatedZones(
34 | zones,
35 | scale.getScaleX(),
36 | scale.getScaleY(),
37 | robotWidth,
38 | robotLength
39 | );
40 | }
41 |
42 | public List getPath(PointXY start, PointXY end) {
43 | return pathGen.getPath(start, end);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/pathfinder2-pi/src/main/java/me/wobblyyyy/pathfinder2/arduino/ArduinoInput.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.arduino;
12 |
13 | /**
14 | * An input (Arduino to Pi) for communicating with an Arduino.
15 | *
16 | * @author Colin Robertson
17 | * @since 2.1.1
18 | */
19 | public class ArduinoInput implements ArduinoBus {
20 | private final ArduinoInterface arduino;
21 | private final String id;
22 | private double value = 0.0;
23 |
24 | public ArduinoInput(ArduinoInterface arduino, String id) {
25 | this.arduino = arduino;
26 | this.id = id;
27 |
28 | arduino.addBus(this);
29 | }
30 |
31 | @Override
32 | public void update() {}
33 |
34 | @Override
35 | public String getId() {
36 | return id;
37 | }
38 |
39 | public double read() {
40 | return value;
41 | }
42 |
43 | @Override
44 | public boolean equals(Object obj) {
45 | return ArduinoBus.equals(this, obj);
46 | }
47 |
48 | @Override
49 | public String toString() {
50 | return id;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/sensors/AbstractEncodedMotor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.sensors;
12 |
13 | import java.util.function.Consumer;
14 | import java.util.function.Supplier;
15 | import me.wobblyyyy.pathfinder2.robot.components.Motor;
16 |
17 | public class AbstractEncodedMotor extends AbstractEncoder implements Motor {
18 | private final Consumer setPower;
19 | private final Supplier getTicks;
20 | private double lastPower;
21 |
22 | public AbstractEncodedMotor(
23 | Consumer setPower,
24 | Supplier getTicks
25 | ) {
26 | this.setPower = setPower;
27 | this.getTicks = getTicks;
28 | }
29 |
30 | @Override
31 | public int getRawTicks() {
32 | return getTicks.get();
33 | }
34 |
35 | @Override
36 | public double getPower() {
37 | return lastPower;
38 | }
39 |
40 | @Override
41 | public void setPower(double power) {
42 | lastPower = power;
43 | setPower.accept(power);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/pathfinder2-frc/src/main/java/me/wobblyyyy/pathfinder2/kauailabs/AHRSSubsystem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.kauailabs;
12 |
13 | import edu.wpi.first.wpilibj2.command.SubsystemBase;
14 | import me.wobblyyyy.pathfinder2.geometry.Angle;
15 |
16 | /**
17 | * A subsystem wrapper for an {@code AHRSGyro}.
18 | *
19 | * @author Colin Robertson
20 | * @since 0.10.8
21 | */
22 | public class AHRSSubsystem extends SubsystemBase {
23 | private final AHRSGyro gyro;
24 | private Angle angle;
25 |
26 | /**
27 | * Create a new {@code AHRSGyro}.
28 | *
29 | * @param gyro the gyroscope.
30 | */
31 | public AHRSSubsystem(AHRSGyro gyro) {
32 | this.gyro = gyro;
33 | }
34 |
35 | /**
36 | * Get the gyroscope's angle.j
37 | *
38 | * @return the gyroscope's angle.
39 | */
40 | public Angle getAngle() {
41 | return angle;
42 | }
43 |
44 | /**
45 | * Occasionally update the gyroscope's angle.
46 | */
47 | @Override
48 | public void periodic() {
49 | angle = gyro.getAngle();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/trajectory/multi/target/TargetPrecision.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.trajectory.multi.target;
12 |
13 | /**
14 | * Types of target precision for the {@link MultiTargetTrajectory}.
15 | *
16 | * @author Colin Robertson
17 | * @since 0.4.0
18 | */
19 | public enum TargetPrecision {
20 | /**
21 | * The target should be precise. The robot will make sure it's within
22 | * the provided tolerance values whenever approaching a precise target. This
23 | * can cause a sort of jitter effect, an effect often responsible for
24 | * slowing the robot down. It may pause in order to compensate for any
25 | * overcorrection.
26 | */
27 | PRECISE,
28 |
29 | /**
30 | * The target does not need to be precise. The robot will not make sure
31 | * it's within the provided tolerance values when approaching a fast
32 | * target. This means the robot doesn't have to adjust and compensate
33 | * for any movement error, making the trajectory able to move more quickly.
34 | */
35 | FAST
36 | }
37 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/test/java/me/wobblyyyy/pathfinder2/recording/TestMovementRecorder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.recording;
12 |
13 | import me.wobblyyyy.pathfinder2.Pathfinder;
14 | import me.wobblyyyy.pathfinder2.geometry.Angle;
15 | import me.wobblyyyy.pathfinder2.geometry.Translation;
16 | import me.wobblyyyy.pathfinder2.robot.simulated.SimulatedOdometry;
17 | import me.wobblyyyy.pathfinder2.time.ElapsedTimer;
18 |
19 | public class TestMovementRecorder {
20 |
21 | public void testMovementRecorder() {
22 | Pathfinder pf = Pathfinder.newSimulatedPathfinder(0.01);
23 | SimulatedOdometry odometry = (SimulatedOdometry) pf.getOdometry();
24 |
25 | Translation translation = new Translation(0.51, 0.51, 0);
26 | odometry.setVelocity(Angle.DEG_45, 0.5);
27 | odometry.setTranslation(translation);
28 | pf.setTranslation(translation);
29 |
30 | pf.getMovementRecorder().start();
31 | pf.tick();
32 |
33 | ElapsedTimer timer = new ElapsedTimer(true);
34 |
35 | while (timer.elapsedSeconds() < 2) pf.tick();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/pathfinder2-kinematics/src/main/java/me/wobblyyyy/pathfinder2/kinematics/RelativeSwerveState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.kinematics;
12 |
13 | public class RelativeSwerveState {
14 | private final RelativeSwerveModuleState fr;
15 | private final RelativeSwerveModuleState fl;
16 | private final RelativeSwerveModuleState br;
17 | private final RelativeSwerveModuleState bl;
18 |
19 | public RelativeSwerveState(
20 | RelativeSwerveModuleState fr,
21 | RelativeSwerveModuleState fl,
22 | RelativeSwerveModuleState br,
23 | RelativeSwerveModuleState bl
24 | ) {
25 | this.fr = fr;
26 | this.fl = fl;
27 | this.br = br;
28 | this.bl = bl;
29 | }
30 |
31 | public RelativeSwerveModuleState fr() {
32 | return this.fr;
33 | }
34 |
35 | public RelativeSwerveModuleState fl() {
36 | return this.fl;
37 | }
38 |
39 | public RelativeSwerveModuleState br() {
40 | return this.br;
41 | }
42 |
43 | public RelativeSwerveModuleState bl() {
44 | return this.bl;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/jmh/java/me/wobblyyyy/pathfinder2/trajectory/GenericTrajectoryBenchmarker.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.trajectory;
12 |
13 | import me.wobblyyyy.pathfinder2.Pathfinder;
14 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
15 | import me.wobblyyyy.pathfinder2.robot.simulated.SimulatedRobot;
16 | import org.openjdk.jmh.infra.Blackhole;
17 |
18 | public class GenericTrajectoryBenchmarker {
19 |
20 | public void followTrajectories(
21 | Blackhole blackhole,
22 | Trajectory... trajectories
23 | ) {
24 | SimulatedRobot robot = new SimulatedRobot();
25 | Pathfinder pathfinder = new Pathfinder(robot, -0.05);
26 | PointXYZ lastPosition = PointXYZ.ZERO;
27 | double distance = 0;
28 |
29 | for (Trajectory trajectory : trajectories) {
30 | robot.setPosition(PointXYZ.ZERO);
31 | pathfinder.followTrajectory(trajectory);
32 |
33 | while (distance < 10) {
34 | pathfinder.tick();
35 | distance += pathfinder.getPosition().absDistance(lastPosition);
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/trajectory/RandomTrajectory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.trajectory;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
14 |
15 | /**
16 | * Completely useless. That's all there is to say. There is absolutely no
17 | * reason to use this, ever. Like. Not even ironically. Are you mad that
18 | * there's just a random class you'll never use sitting on your computer
19 | * now? Does that make you angry? Sorry.
20 | *
21 | * @author Colin Robertson
22 | * @since 1.0.1
23 | */
24 | public class RandomTrajectory implements Trajectory {
25 |
26 | @Override
27 | public PointXYZ nextMarker(PointXYZ current) {
28 | return current.add(
29 | new PointXYZ(
30 | Math.random() * 2,
31 | Math.random() * 2,
32 | Math.random() * 2
33 | )
34 | );
35 | }
36 |
37 | @Override
38 | public boolean isDone(PointXYZ current) {
39 | return false;
40 | }
41 |
42 | @Override
43 | public double speed(PointXYZ current) {
44 | return Math.random();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/trajectory/spline/InterpolationMode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.trajectory.spline;
12 |
13 | import me.wobblyyyy.pathfinder2.math.ApacheSpline;
14 | import me.wobblyyyy.pathfinder2.math.MonotoneCubicSpline;
15 | import me.wobblyyyy.pathfinder2.math.Spline;
16 |
17 | /**
18 | * Modes splines can use. Changing the mode a spline operates in will
19 | * change the underlying {@link Spline} that's being used by the trajectory.
20 | * You can create your own custom spline interpolator generator if you
21 | * so desire by using the {@link #CUSTOM} option.
22 | *
23 | * @author Colin Robertson
24 | * @since 1.0.0
25 | */
26 | public enum InterpolationMode {
27 | /**
28 | * Use {@link MonotoneCubicSpline}.
29 | */
30 | DEFAULT,
31 |
32 | /**
33 | * Use {@link ApacheSpline} with {@code SplineInterpolator}.
34 | */
35 | CUBIC,
36 |
37 | /**
38 | * Use {@link ApacheSpline} with {@code AkimaSplineInterpolator}.
39 | */
40 | AKIMA,
41 |
42 | /**
43 | * Use a custom spline interpolator generator.
44 | */
45 | CUSTOM
46 | }
47 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/trajectory/spline/SpeedSplineTrajectory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.trajectory.spline;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.Angle;
14 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
15 | import me.wobblyyyy.pathfinder2.math.Spline;
16 | import me.wobblyyyy.pathfinder2.trajectory.LinearTrajectory;
17 |
18 | /**
19 | * A wrapper for {@link LinearTrajectory} that uses a spline to determine
20 | * the speed of the robot, allowing for very epic acceleration and deceleration.
21 | *
22 | * @author Colin Robertson
23 | * @since 0.6.1
24 | */
25 | public class SpeedSplineTrajectory extends LinearTrajectory {
26 | private final Spline speedSpline;
27 |
28 | public SpeedSplineTrajectory(
29 | PointXYZ target,
30 | double tolerance,
31 | Angle angleTolerance,
32 | Spline speedSpline
33 | ) {
34 | super(target, 0.5, tolerance, angleTolerance);
35 | this.speedSpline = speedSpline;
36 | }
37 |
38 | @Override
39 | public double speed(PointXYZ current) {
40 | return speedSpline.interpolateY(current.x());
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/pathfinder2-pi/src/main/java/me/wobblyyyy/pathfinder2/arduino/ArduinoInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.arduino;
12 |
13 | import java.util.ArrayList;
14 | import java.util.Collection;
15 |
16 | /**
17 | * Interface for interacting with an Arduino, assuming that Arduino is
18 | * connected via USB and is also running compatible code. Because the Pi,
19 | * although a wonderful piece of technology, is a bit too slow to control
20 | * motors and read sensors as precisely as needed, using an Arduino and
21 | * communicating with it via serial (hopefully) circumvents that issue.
22 | *
23 | * @author Colin Robertson
24 | * @since 2.1.1
25 | */
26 | public class ArduinoInterface {
27 | private final Collection buses = new ArrayList<>();
28 |
29 | public ArduinoInterface() {}
30 |
31 | public Collection getBuses() {
32 | return buses;
33 | }
34 |
35 | public ArduinoInterface addBus(ArduinoBus bus) {
36 | buses.add(bus);
37 |
38 | return this;
39 | }
40 |
41 | public void update() {
42 | for (ArduinoBus bus : buses) {
43 | bus.update();
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/modifiers/ConditionalModifier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.modifiers;
12 |
13 | import java.util.function.Supplier;
14 |
15 | /**
16 | * A modifier which can conditionally be toggled on and off.
17 | *
18 | * @param the type of value the modifier will modify.
19 | * @author Colin Robertson
20 | * @since 0.7.1
21 | */
22 | public class ConditionalModifier implements Modifier {
23 | private final Supplier isActive;
24 | private final Modifier modifier;
25 |
26 | /**
27 | * Create a new {@code ConditionalModifier}.
28 | *
29 | * @param isActive a supplier which indicates whether the modifier should
30 | * modify inputted values.
31 | * @param modifier the modifier that this class will wrap.
32 | */
33 | public ConditionalModifier(
34 | Supplier isActive,
35 | Modifier modifier
36 | ) {
37 | this.isActive = isActive;
38 | this.modifier = modifier;
39 | }
40 |
41 | @Override
42 | public T apply(T t) {
43 | if (!isActive.get()) return t; else return modifier.apply(t);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/main/java/me/wobblyyyy/pathfinder2/math/Max.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.math;
12 |
13 | public class Max {
14 |
15 | private Max() {}
16 |
17 | public static double of(double... values) {
18 | double m = values[0];
19 |
20 | for (int i = 1; i < values.length; i++) {
21 | m = Math.max(values[i], m);
22 | }
23 |
24 | return m;
25 | }
26 |
27 | public static double absoluteOf(double... values) {
28 | double m = Math.abs(values[0]);
29 |
30 | for (int i = 1; i < values.length; i++) {
31 | m = Math.max(Math.abs(values[i]), m);
32 | }
33 |
34 | return m;
35 | }
36 |
37 | @SuppressWarnings("DuplicatedCode")
38 | public static double magnitude(double... values) {
39 | double value = values[0];
40 | double magnitude = Math.abs(values[0]);
41 |
42 | for (int i = 1; i < values.length; i++) {
43 | double val = values[i];
44 | double mag = Math.abs(values[i]);
45 |
46 | if (mag > magnitude) {
47 | value = val;
48 | }
49 | }
50 |
51 | return value;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/main/java/me/wobblyyyy/pathfinder2/math/Min.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.math;
12 |
13 | public class Min {
14 |
15 | private Min() {}
16 |
17 | public static double of(double... values) {
18 | double m = values[0];
19 |
20 | for (int i = 1; i < values.length; i++) {
21 | m = Math.min(values[i], m);
22 | }
23 |
24 | return m;
25 | }
26 |
27 | public static double absoluteOf(double... values) {
28 | double m = Math.abs(values[0]);
29 |
30 | for (int i = 1; i < values.length; i++) {
31 | m = Math.min(Math.abs(values[i]), m);
32 | }
33 |
34 | return m;
35 | }
36 |
37 | @SuppressWarnings("DuplicatedCode")
38 | public static double magnitude(double... values) {
39 | double value = values[0];
40 | double magnitude = Math.abs(values[0]);
41 |
42 | for (int i = 1; i < values.length; i++) {
43 | double val = values[i];
44 | double mag = Math.abs(values[i]);
45 |
46 | if (mag < magnitude) {
47 | value = val;
48 | }
49 | }
50 |
51 | return value;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/pathfinder2-commands/src/main/java/me/wobblyyyy/pathfinder2/commands/TickCommands.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.commands;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.Angle;
14 | import me.wobblyyyy.pathfinder2.geometry.PointXY;
15 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
16 | import me.wobblyyyy.pathfinder2.utils.StringUtils;
17 |
18 | public class TickCommands {
19 |
20 | private TickCommands() {}
21 |
22 | public static final Command TICK_COMMAND = new Command(
23 | "tick",
24 | (pathfinder, args) -> {
25 | pathfinder.tick();
26 | },
27 | 0
28 | );
29 |
30 | public static final Command TICK_UNTIL_COMMAND = new Command(
31 | "tickUntil",
32 | (pathfinder, args) -> {
33 | if (args.length == 0) {
34 | pathfinder.tickUntil();
35 | } else {
36 | pathfinder.tickUntil(Double.parseDouble(args[0]));
37 | }
38 | },
39 | 0,
40 | 1
41 | );
42 |
43 | public static void addTickCommands(CommandRegistry registry) {
44 | registry.unsafeAdd(TICK_COMMAND);
45 | registry.unsafeAdd(TICK_UNTIL_COMMAND);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/pathfinder2-kinematics/src/main/java/me/wobblyyyy/pathfinder2/kinematics/Kinematics.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.kinematics;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.Translation;
14 |
15 | /**
16 | * Based on a translation, calculate a value of type E. Forwards kinematics
17 | * convert a {@code Translation} into some form (of type {@code E}) that the
18 | * robot can then use to interact with the drive train in a matter that
19 | * moves the robot according to the {@code Translation}.
20 | *
21 | * @param
22 | * @author Colin Robertson
23 | * @since 0.0.0
24 | */
25 | public interface Kinematics {
26 | /**
27 | * Calculate a value of type E based on a translation.
28 | *
29 | * @param translation the translation to calculate a value of type E
30 | * based on.
31 | * @return a calculated value based on the provided translation.
32 | */
33 | E calculate(Translation translation);
34 |
35 | /**
36 | * Calculate a translation based on a state.
37 | *
38 | * @param state convert a state into a translation.
39 | * @return the state, as a translation.
40 | */
41 | Translation toTranslation(E state);
42 | }
43 |
--------------------------------------------------------------------------------
/pathfinder2-commands/src/test/java/me/wobblyyyy/pathfinder2/commands/TestScriptingCommands.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.commands;
12 |
13 | import me.wobblyyyy.pathfinder2.Pathfinder;
14 | import org.junit.jupiter.api.BeforeEach;
15 | import org.junit.jupiter.api.Test;
16 |
17 | public class TestScriptingCommands {
18 | private Pathfinder pathfinder;
19 | private CommandRegistry registry;
20 |
21 | @BeforeEach
22 | public void beforeEach() {
23 | pathfinder = Pathfinder.newSimulatedPathfinder(-0.05);
24 | registry = CommandRegistry.createDefaultRegistry(pathfinder);
25 | }
26 |
27 | @Test
28 | public void testDefAndGoTo() {
29 | registry.execute("def", "abc", "10,10,0");
30 | registry.execute("goTo", "$abc");
31 | registry.execute("tickUntil");
32 | }
33 |
34 | @Test
35 | public void testDefAndSplineTo() {
36 | registry.execute("def", "a", "0,0,0");
37 | registry.execute("def", "b", "5,10,0");
38 | registry.execute("def", "c", "10,15,0");
39 | registry.execute("def", "d", "15,25,0");
40 | registry.execute("splineTo", "$a", "$b", "$c", "$d");
41 | registry.execute("tickUntil");
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/time/TimeUnit.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.time;
12 |
13 | /**
14 | * Different units of time. Very cool, right?
15 | *
16 | * @author Colin Robertson
17 | * @since 0.0.0
18 | */
19 | public enum TimeUnit {
20 | /**
21 | * Milliseconds.
22 | */
23 | MS(1),
24 |
25 | /**
26 | * Seconds.
27 | */
28 | S(1000),
29 |
30 | /**
31 | * Minutes.
32 | */
33 | M(60000),
34 |
35 | /**
36 | * Hours.
37 | */
38 | H(3600000);
39 |
40 | /**
41 | * How many milliseconds is this time unit worth?
42 | */
43 | private final double timeInMs;
44 |
45 | /**
46 | * Create a new time unit.
47 | *
48 | * @param timeInMs the amount of time, in milliseconds, that one unit
49 | * of this time represents.
50 | */
51 | TimeUnit(double timeInMs) {
52 | this.timeInMs = timeInMs;
53 | }
54 |
55 | /**
56 | * Get the amount of milliseconds one unit of this time represents.
57 | *
58 | * @return the unit represented in milliseconds.
59 | */
60 | public double getTimeInMs() {
61 | return timeInMs;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/pathfinder2-kinematics/src/test/java/me/wobblyyyy/pathfinder2/control/TestBangBangController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.control;
12 |
13 | import org.junit.jupiter.api.Assertions;
14 | import org.junit.jupiter.api.Test;
15 |
16 | public class TestBangBangController {
17 | private final Controller[] controllers = new BangBangController[] {
18 | new BangBangController(0, 0),
19 | new BangBangController(-1, 1),
20 | new BangBangController(1, -1)
21 | };
22 |
23 | private void runTests(double target, double value, double[] expected) {
24 | for (int i = 0; i < controllers.length; i++) {
25 | Controller controller = controllers[i];
26 | controller.setTarget(target);
27 | Assertions.assertEquals(expected[i], controller.calculate(value));
28 | }
29 | }
30 |
31 | @Test
32 | public void testWhenZero() {
33 | runTests(0, 0, new double[] { 0, 0, 0 });
34 | }
35 |
36 | @Test
37 | public void testWhenPositive() {
38 | runTests(100, 0, new double[] { 0, -1, 1 });
39 | }
40 |
41 | @Test
42 | public void testWhenNegative() {
43 | runTests(-100, 0, new double[] { 0, 1, -1 });
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/pathfinder2-kinematics/src/test/java/me/wobblyyyy/pathfinder2/control/TestProportionalController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.control;
12 |
13 | import org.junit.jupiter.api.Assertions;
14 | import org.junit.jupiter.api.Test;
15 |
16 | public class TestProportionalController {
17 | private Controller controller;
18 |
19 | @Test
20 | public void testPositiveNumber() {
21 | controller = new ProportionalController(10);
22 |
23 | Assertions.assertEquals(10, controller.calculate(0, 1));
24 | Assertions.assertEquals(100, controller.calculate(0, 10));
25 | Assertions.assertEquals(1, controller.calculate(0, 0.1));
26 | }
27 |
28 | @Test
29 | public void testNegativeNumber() {
30 | controller = new ProportionalController(10);
31 |
32 | Assertions.assertEquals(-10, controller.calculate(0, -1));
33 | Assertions.assertEquals(-100, controller.calculate(0, -10));
34 | Assertions.assertEquals(-1, controller.calculate(0, -0.1));
35 | }
36 |
37 | @Test
38 | public void testZeroCoefficient() {
39 | controller = new ProportionalController(0);
40 |
41 | Assertions.assertEquals(0, controller.calculate(0, 100));
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/pathfinder2-pi/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | plugins {
12 | id 'java'
13 | id 'maven-publish'
14 | }
15 |
16 | repositories {
17 | mavenCentral()
18 | }
19 |
20 | java {
21 | toolchain {
22 | languageVersion.set(JavaLanguageVersion.of(11))
23 | }
24 |
25 | withSourcesJar()
26 | withJavadocJar()
27 | }
28 |
29 | dependencies {
30 | implementation project(':pathfinder2-core')
31 | implementation project(':pathfinder2-geometry')
32 | implementation project(':pathfinder2-kinematics')
33 |
34 | implementation 'com.pi4j:pi4j-core:2.1.1'
35 | implementation 'com.pi4j:pi4j-library-pigpio:2.1.1'
36 | implementation 'com.pi4j:pi4j-plugin-pigpio:2.1.1'
37 | implementation 'com.pi4j:pi4j-plugin-raspberrypi:2.1.1'
38 |
39 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
40 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
41 | }
42 |
43 | test {
44 | useJUnitPlatform()
45 | }
46 |
47 | publishing {
48 | publications {
49 | maven(MavenPublication) {
50 | groupId = project.projectName
51 | version = project.projectVersion
52 | artifactId = 'pi'
53 | from components.java
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/sensors/ARGBColorSensor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.sensors;
12 |
13 | /**
14 | * A very lovely and very pleasant color sensor, responsible for, among other
15 | * things, sensing colors.
16 | *
17 | * @author Colin Robertson
18 | * @since 0.7.1
19 | */
20 | public interface ARGBColorSensor extends Sensor {
21 | /**
22 | * Get the RED value from the color sensor.
23 | *
24 | * @return the RED value from the color sensor.
25 | */
26 | int getRed();
27 |
28 | /**
29 | * Get the GREEN value from the color sensor.
30 | *
31 | * @return the GREEN value from the color sensor.
32 | */
33 | int getGreen();
34 |
35 | /**
36 | * Get the BLUE value from the color sensor.
37 | *
38 | * @return the BLUE value from the color sensor.
39 | */
40 | int getBlue();
41 |
42 | /**
43 | * Get the ALPHA value from the color sensor.
44 | *
45 | * @return the ALPHA value from the color sensor.
46 | */
47 | int getAlpha();
48 |
49 | @Override
50 | default ARGB read() {
51 | return new ARGB(getAlpha(), getRed(), getGreen(), getBlue());
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/pathfinder2-examples/src/main/java/me/wobblyyyy/pathfinder2/examples/ExampleFieldNavigation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.examples;
12 |
13 | import me.wobblyyyy.pathfinder2.Pathfinder;
14 | import me.wobblyyyy.pathfinder2.geometry.Angle;
15 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
16 | import me.wobblyyyy.pathfinder2.robot.Robot;
17 | import me.wobblyyyy.pathfinder2.robot.simulated.SimulatedRobot;
18 |
19 | public class ExampleFieldNavigation {
20 | private Robot robot = new SimulatedRobot();
21 | private double coefficient = -0.05;
22 | private Pathfinder pathfinder = new Pathfinder(robot, coefficient);
23 |
24 | public void moveAroundSquare() {
25 | pathfinder.goTo(new PointXYZ(0, 0, Angle.fromDeg(0)));
26 | pathfinder.tickUntil();
27 |
28 | pathfinder.goTo(new PointXYZ(10, 0, Angle.fromDeg(0)));
29 | pathfinder.tickUntil();
30 |
31 | pathfinder.goTo(new PointXYZ(10, 10, Angle.fromDeg(0)));
32 | pathfinder.tickUntil();
33 |
34 | pathfinder.goTo(new PointXYZ(0, 10, Angle.fromDeg(0)));
35 | pathfinder.tickUntil();
36 |
37 | pathfinder.goTo(new PointXYZ(0, 0, Angle.fromDeg(0)));
38 | pathfinder.tickUntil();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/utils/DoubleQueue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.utils;
12 |
13 | import java.util.Arrays;
14 |
15 | public class DoubleQueue {
16 | private final double[] data;
17 | private int maxIndex = 0;
18 |
19 | public DoubleQueue(double[] data) {
20 | this.data = data;
21 | }
22 |
23 | public DoubleQueue(int size) {
24 | this(new double[size]);
25 | }
26 |
27 | public double get(int index) {
28 | return data[index];
29 | }
30 |
31 | public double[] getData() {
32 | double[] d = new double[maxIndex];
33 | System.arraycopy(data, 0, d, 0, d.length);
34 | return d;
35 | }
36 |
37 | public DoubleQueue add(double value) {
38 | System.arraycopy(data, 0, data, 1, data.length - 1);
39 | data[0] = value;
40 |
41 | if (maxIndex < data.length) {
42 | maxIndex++;
43 | }
44 |
45 | return this;
46 | }
47 |
48 | public void set(int index, double value) {
49 | data[index] = value;
50 | }
51 |
52 | public DoubleQueue clear() {
53 | Arrays.fill(data, 0);
54 |
55 | maxIndex = 0;
56 |
57 | return this;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/pathfinder2-OdometryCore/src/main/java/com/tejasmehta/OdometryCore/localization/HeadingUnit.java:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Tejas Mehta
2 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
4 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5 |
6 | package com.tejasmehta.OdometryCore.localization;
7 |
8 | /****
9 | * An enumeration for the heading unit used in the OdometryPosition to allow
10 | * any users to request their degree/heading be given in the following unit(s)
11 | * @author Tejas Mehta
12 | * Made on Wednesday, November 04, 2020
13 | * File Name: OdometryPosition
14 | */
15 | public enum HeadingUnit {
16 | DEGREES,
17 | RADIANS
18 | }
19 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/recording/StateRecord.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.recording;
12 |
13 | import java.io.Serializable;
14 | import java.util.HashMap;
15 | import java.util.Map;
16 |
17 | /**
18 | * A record for the state of an entire robot (or at least all of the parts of
19 | * the robot that are being recorded).
20 | *
21 | * @author Colin Robertson
22 | * @since 2.4.0
23 | */
24 | public class StateRecord implements Serializable {
25 | private final Map map;
26 |
27 | public StateRecord(Map map) {
28 | this.map = map;
29 | }
30 |
31 | public StateRecord(StateRecorder recorder) {
32 | this(new HashMap<>(recorder.getNodes().size()));
33 | }
34 |
35 | public StateRecord() {
36 | this(new HashMap<>());
37 | }
38 |
39 | public Object get(String key) {
40 | return map.get(key);
41 | }
42 |
43 | public Object remove(String key) {
44 | return map.remove(key);
45 | }
46 |
47 | public Map getMap() {
48 | return map;
49 | }
50 |
51 | public StateRecord put(String key, Object value) {
52 | map.put(key, value);
53 |
54 | return this;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/test/java/me/wobblyyyy/pathfinder2/math/TestMonotoneCubicSpline.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.math;
12 |
13 | import org.junit.jupiter.api.Assertions;
14 | import org.junit.jupiter.api.Test;
15 |
16 | public class TestMonotoneCubicSpline {
17 |
18 | @Test
19 | public void testNonReflectedSpline() {
20 | Spline spline = new MonotoneCubicSpline(
21 | new double[] { 0, 5, 10, 15 },
22 | new double[] { 0, 10, 15, 25 }
23 | );
24 |
25 | Assertions.assertEquals(0, spline.interpolateY(0));
26 | Assertions.assertEquals(10, spline.interpolateY(5));
27 | Assertions.assertEquals(15, spline.interpolateY(10));
28 | Assertions.assertEquals(25, spline.interpolateY(15));
29 | }
30 |
31 | @Test
32 | public void testReflectedSpline() {
33 | Spline spline = new MonotoneCubicSpline(
34 | new double[] { 0, -5, -10, -15 },
35 | new double[] { 0, 10, 15, 25 }
36 | );
37 |
38 | Assertions.assertEquals(0, spline.interpolateY(0));
39 | Assertions.assertEquals(10, spline.interpolateY(-5));
40 | Assertions.assertEquals(15, spline.interpolateY(-10));
41 | Assertions.assertEquals(25, spline.interpolateY(-15));
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/test/java/me/wobblyyyy/pathfinder2/utils/TestStringUtils.java:
--------------------------------------------------------------------------------
1 | package me.wobblyyyy.pathfinder2.utils;
2 |
3 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
4 | import org.junit.jupiter.api.Assertions;
5 | import org.junit.jupiter.api.Test;
6 |
7 | public class TestStringUtils {
8 |
9 | @Test
10 | public void testFormatString() {
11 | String template = "(%s, %s, %s deg)";
12 |
13 | Assertions.assertEquals(
14 | "(10, 10, 45 deg)",
15 | StringUtils.format(template, 10, 10, 45)
16 | );
17 |
18 | Assertions.assertEquals(
19 | "(10.0, 10.0, 45.0 deg)",
20 | new PointXYZ(10, 10, 45).toString()
21 | );
22 | }
23 |
24 | @Test
25 | public void testFormatWithMaxLength() {
26 | String template = "(%4s, %4s, %5s, %3s)";
27 |
28 | Assertions.assertEquals(
29 | "(10.0, 10.0, 100.0, 100)",
30 | StringUtils.format(template, 10.0, 10.0, 100.0, 100)
31 | );
32 | }
33 |
34 | @Test
35 | public void testFormatNumber() {
36 | double a = 1_000;
37 | double b = 1_000.56;
38 | double c = 1_234_567.890;
39 | int d = 0;
40 | double e = 100;
41 |
42 | Assertions.assertEquals("1,000.0", StringUtils.formatNumber(a));
43 | Assertions.assertEquals("1,000.56", StringUtils.formatNumber(b));
44 | Assertions.assertEquals("1,234,567.89", StringUtils.formatNumber(c));
45 | Assertions.assertEquals("0.0", StringUtils.formatNumber(d));
46 | Assertions.assertEquals("100.0", StringUtils.formatNumber(e));
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | /**
12 | * Pathfinder's main package - welcome!
13 | *
14 | *
15 | * As you can (probably) see, the Pathfinder project is split up into many
16 | * different packages for organizational purposes. The main
17 | * {@link me.wobblyyyy.pathfinder2.Pathfinder} class is the only class that's
18 | * in the package {@code me.wobblyyyy.pathfinder2} - all other classes are
19 | * in subpackages, such as {@code robot} or {@code geometry}.
20 | *
21 | *
22 | *
23 | * The name of each of the subpackages should describe it's purpose fairly
24 | * well. If you're browsing Pathfinder's source code, you might want to take
25 | * note of the module structure there is - there's {@code pathfinder2-geometry},
26 | * as well as {@code pathfinder2-core} et al.
27 | *
28 | *
29 | *
30 | * There's a lot of content in this library, so I can't exactly list everything
31 | * in one convenient document, but if you'd like to get started learning the
32 | * library, you should check out the {@link me.wobblyyyy.pathfinder2.Pathfinder}
33 | * class and anything associated with it. Another solid idea is to check out
34 | * tutorials linked on the project's GitHub page - those might help.
35 | *
36 | */
37 | package me.wobblyyyy.pathfinder2;
38 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/main/java/me/wobblyyyy/pathfinder2/math/LinearSpline.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.math;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.LinearEquation;
14 | import me.wobblyyyy.pathfinder2.geometry.PointXY;
15 | import me.wobblyyyy.pathfinder2.utils.StringUtils;
16 |
17 | /**
18 | * A spline based on a linear equation.
19 | *
20 | * @author Colin Robertson
21 | * @since 0.6.1
22 | */
23 | public class LinearSpline implements Spline {
24 | private final LinearEquation equation;
25 |
26 | public LinearSpline(LinearEquation equation) {
27 | this.equation = equation;
28 | }
29 |
30 | @Override
31 | public double interpolateY(double x) {
32 | return equation.getY(x);
33 | }
34 |
35 | @Override
36 | public PointXY interpolate(double x) {
37 | return new PointXY(x, this.equation.getY(x));
38 | }
39 |
40 | @Override
41 | public PointXY getStartPoint() {
42 | return interpolate(0);
43 | }
44 |
45 | @Override
46 | public PointXY getEndPoint() {
47 | return interpolate(0);
48 | }
49 |
50 | @Override
51 | public String toString() {
52 | return StringUtils.format(
53 | "LinearSpline (slope: <%s>)",
54 | equation.getSlope()
55 | );
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/pathfinder2-commands/src/main/java/me/wobblyyyy/pathfinder2/commands/ScriptingCommands.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.commands;
12 |
13 | import java.util.Arrays;
14 | import me.wobblyyyy.pathfinder2.logging.Logger;
15 | import me.wobblyyyy.pathfinder2.utils.StringUtils;
16 |
17 | public class ScriptingCommands {
18 | public static final String DEF_PREFIX = "var_";
19 |
20 | private ScriptingCommands() {}
21 |
22 | public static final Command DEF_COMMAND = new Command(
23 | "def",
24 | (pathfinder, args) -> {
25 | String name = args[0];
26 | String[] valueArray = new String[args.length - 1];
27 | System.arraycopy(args, 1, valueArray, 0, valueArray.length);
28 | String value = StringUtils.concat(valueArray);
29 | pathfinder.putData(DEF_PREFIX + name, value);
30 | Logger.debug(
31 | ScriptingCommands.class,
32 | "Defined variable <%s> with value <%s> (args: <%s>)",
33 | DEF_PREFIX + name,
34 | value,
35 | Arrays.toString(args)
36 | );
37 | },
38 | 2,
39 | Integer.MAX_VALUE
40 | );
41 |
42 | public static void addScriptingCommands(CommandRegistry registry) {
43 | registry.unsafeAdd(DEF_COMMAND);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/robot/simulated/SimulatedWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.robot.simulated;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
14 | import me.wobblyyyy.pathfinder2.robot.Robot;
15 |
16 | /**
17 | * A wrapper for instances of {@link SimulatedDrive} and
18 | * {@link SimulatedOdometry}.
19 | *
20 | * @author Colin Robertson
21 | * @since 0.15.0
22 | */
23 | public class SimulatedWrapper {
24 | private final SimulatedDrive drive;
25 | private final SimulatedOdometry odometry;
26 |
27 | public SimulatedWrapper(SimulatedDrive drive, SimulatedOdometry odometry) {
28 | this.drive = drive;
29 | this.odometry = odometry;
30 |
31 | this.drive.setDriveModifier(
32 | translation -> {
33 | PointXYZ pos = odometry.getPosition();
34 |
35 | odometry.setRawPosition(pos.applyTranslation(translation));
36 |
37 | return translation;
38 | }
39 | );
40 | }
41 |
42 | public SimulatedDrive getDrive() {
43 | return drive;
44 | }
45 |
46 | public SimulatedOdometry getOdometry() {
47 | return odometry;
48 | }
49 |
50 | public Robot getRobot() {
51 | return new Robot(drive, odometry);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/main/java/me/wobblyyyy/pathfinder2/geometry/BoundingBox.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.geometry;
12 |
13 | /**
14 | * Utilities for verifying numbers. I'd encourage you to not use this class,
15 | * it's only still here so nothing breaks.
16 | *
17 | * @author Colin Robertson
18 | * @since 0.1.0
19 | */
20 | public class BoundingBox {
21 |
22 | private BoundingBox() {}
23 |
24 | public static boolean validate(double number, double min, double max) {
25 | return (min - 0.01) <= number && number <= (max + 0.01);
26 | }
27 |
28 | public static boolean isPointInBox(
29 | PointXY point,
30 | double minX,
31 | double minY,
32 | double maxX,
33 | double maxY
34 | ) {
35 | if (point == null) return false;
36 |
37 | double x = point.x();
38 | double y = point.y();
39 |
40 | boolean validX = validate(x, minX, maxX);
41 | boolean validY = validate(y, minY, maxY);
42 |
43 | return validX && validY;
44 | }
45 |
46 | public static boolean isPointInLine(PointXY point, Line line) {
47 | return isPointInBox(
48 | point,
49 | line.getMinX(),
50 | line.getMinY(),
51 | line.getMaxX(),
52 | line.getMaxY()
53 | );
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/pathfinder2-frc/src/main/java/me/wobblyyyy/pathfinder2/ctre/TalonFXMotor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.ctre;
12 |
13 | import com.ctre.phoenix.motorcontrol.TalonFXControlMode;
14 | import com.ctre.phoenix.motorcontrol.can.TalonFX;
15 | import me.wobblyyyy.pathfinder2.robot.components.AbstractMotor;
16 |
17 | /**
18 | * Wrapper for {@link TalonFX}.
19 | *
20 | * @author Colin Robertson
21 | * @since 0.10.8
22 | */
23 | public class TalonFXMotor extends AbstractMotor {
24 | private final TalonFX talon;
25 |
26 | /**
27 | * Create a new {@code TalonFXMotor}.
28 | *
29 | * @param talon the {@link TalonFX} to use.
30 | */
31 | public TalonFXMotor(TalonFX talon) {
32 | super(
33 | power -> talon.set(TalonFXControlMode.PercentOutput, power),
34 | talon::getMotorOutputPercent
35 | );
36 | this.talon = talon;
37 | }
38 |
39 | /**
40 | * Create a new {@code TalonFXMotor}.
41 | *
42 | * @param deviceNumber the Talon's device number.
43 | */
44 | public TalonFXMotor(int deviceNumber) {
45 | this(new TalonFX(deviceNumber));
46 | }
47 |
48 | /**
49 | * Get the internal TalonFX.
50 | *
51 | * @return the internal TalonFX.
52 | */
53 | public TalonFX getTalon() {
54 | return talon;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/pathfinder2-kinematics/src/main/java/me/wobblyyyy/pathfinder2/control/SimpleSwerveModuleController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.control;
12 |
13 | /**
14 | * The simplest form of control for a swerve module. This class is an
15 | * extension of the {@link AngleDeltaController} class and only provides
16 | * a single constructor with a single parameter - the coefficient. Higher
17 | * coefficient values will mean the swerve module will turn faster. Lower
18 | * coefficient values will mean the swerve module will turn slower. It
19 | * typically takes some fine tuning to get this right.
20 | *
21 | * @author Colin Robertson
22 | * @since 0.0.0
23 | */
24 | public class SimpleSwerveModuleController extends AngleDeltaController {
25 |
26 | /**
27 | * Create a new {@code SimpleSwerveModuleController}.
28 | *
29 | * @param coefficient the turn speed coefficient. Higher values will
30 | * make the swerve module turn faster, and lower values
31 | * will make the swerve module turn slower. This value
32 | * should almost always be determined experimentally,
33 | * but a decent place to start is around 0.02.
34 | */
35 | public SimpleSwerveModuleController(double coefficient) {
36 | super(coefficient);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/pathfinder2-commands/src/main/java/me/wobblyyyy/pathfinder2/commands/TestCommands.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.commands;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.Angle;
14 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
15 | import me.wobblyyyy.pathfinder2.utils.AssertionUtils;
16 |
17 | public class TestCommands {
18 |
19 | private TestCommands() {}
20 |
21 | public static final Command ASSERT_IS_NEAR_COMMAND = new Command(
22 | "assertIsNear",
23 | (pathfinder, args) -> {
24 | PointXYZ target = PointXYZ.parse(args[0]);
25 | double tolerance = 2;
26 | Angle angleTolerance = Angle.fromDeg(5);
27 | if (args.length > 1) {
28 | tolerance = Double.parseDouble(args[1]);
29 | }
30 | if (args.length > 2) {
31 | angleTolerance = Angle.parse(args[2]);
32 | }
33 | PointXYZ current = pathfinder.getPosition();
34 | AssertionUtils.assertIsNear(
35 | target,
36 | current,
37 | tolerance,
38 | angleTolerance
39 | );
40 | },
41 | 1,
42 | 3
43 | );
44 |
45 | public static void addTestCommands(CommandRegistry registry) {
46 | registry.unsafeAdd(ASSERT_IS_NEAR_COMMAND);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/pathfinder2-frc/src/main/java/me/wobblyyyy/pathfinder2/ctre/TalonSRXMotor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.ctre;
12 |
13 | import com.ctre.phoenix.motorcontrol.TalonSRXControlMode;
14 | import com.ctre.phoenix.motorcontrol.can.TalonSRX;
15 | import me.wobblyyyy.pathfinder2.robot.components.AbstractMotor;
16 |
17 | /**
18 | * Wrapper for {@link TalonSRX}.
19 | *
20 | * @author Colin Robertson
21 | * @since 0.10.8
22 | */
23 | public class TalonSRXMotor extends AbstractMotor {
24 | private final TalonSRX talon;
25 |
26 | /**
27 | * Create a new {@code TalonSRXMotor}.
28 | *
29 | * @param talon the {@link TalonSRX} to use.
30 | */
31 | public TalonSRXMotor(TalonSRX talon) {
32 | super(
33 | power -> talon.set(TalonSRXControlMode.PercentOutput, power),
34 | talon::getMotorOutputPercent
35 | );
36 | this.talon = talon;
37 | }
38 |
39 | /**
40 | * Create a new {@code TalonSRXMotor}.
41 | *
42 | * @param deviceNumber the Talon's device number.
43 | */
44 | public TalonSRXMotor(int deviceNumber) {
45 | this(new TalonSRX(deviceNumber));
46 | }
47 |
48 | /**
49 | * Get the internal Talon SRX.
50 | *
51 | * @return the internal Talon SRX.
52 | */
53 | public TalonSRX getTalon() {
54 | return talon;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/listening/PathfinderListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.listening;
12 |
13 | import java.util.function.Predicate;
14 | import java.util.function.Supplier;
15 | import me.wobblyyyy.pathfinder2.Pathfinder;
16 |
17 | /**
18 | * A listener that accepts {@code Pathfinder} as a parameter.
19 | *
20 | * @author Colin Robertson
21 | * @since 0.7.1
22 | * @deprecated this is some pretty bad code and I wouldn't recommend you make
23 | * use of it...
24 | */
25 | @Deprecated
26 | public class PathfinderListener implements Supplier {
27 | private final Pathfinder pathfinder;
28 | private final Predicate predicate;
29 |
30 | /**
31 | * Create a new {@code PathfinderListener}.
32 | *
33 | * @param pathfinder the {@code Pathfinder} instance that's being operated
34 | * on.
35 | * @param predicate a predicate that determines whether this supplier
36 | * should return true.
37 | */
38 | public PathfinderListener(
39 | Pathfinder pathfinder,
40 | Predicate predicate
41 | ) {
42 | this.pathfinder = pathfinder;
43 | this.predicate = predicate;
44 | }
45 |
46 | @Override
47 | public Boolean get() {
48 | return predicate.test(pathfinder);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/main/java/me/wobblyyyy/pathfinder2/trajectory/spline/FastSplineTrajectory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.trajectory.spline;
12 |
13 | import me.wobblyyyy.pathfinder2.geometry.PointXYZ;
14 | import me.wobblyyyy.pathfinder2.math.Spline;
15 | import me.wobblyyyy.pathfinder2.trajectory.FastTrajectory;
16 |
17 | /**
18 | * A wrapper for {@link FastTrajectory} that uses a spline to determine
19 | * the speed of the robot, allowing for very epic acceleration and deceleration.
20 | *
21 | * @author Colin Robertson
22 | * @since 0.6.1
23 | */
24 | public class FastSplineTrajectory extends FastTrajectory {
25 | private final Spline speedSpline;
26 |
27 | /**
28 | * Create a new {@code FastSplineTrajectory}.
29 | *
30 | * @param start the robot's current position.
31 | * @param end the robot's target position.
32 | * @param speedSpline the spline responsible for controlling the
33 | * robot's speed.
34 | */
35 | public FastSplineTrajectory(
36 | PointXYZ start,
37 | PointXYZ end,
38 | Spline speedSpline
39 | ) {
40 | super(start, end, 0.5);
41 | this.speedSpline = speedSpline;
42 | }
43 |
44 | @Override
45 | public double speed(PointXYZ current) {
46 | return speedSpline.interpolateY(current.x());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/pathfinder2-core/src/test/java/me/wobblyyyy/pathfinder2/time/TestTimeSpan.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.time;
12 |
13 | import org.junit.jupiter.api.Assertions;
14 | import org.junit.jupiter.api.Test;
15 |
16 | public class TestTimeSpan {
17 |
18 | @Test
19 | public void testCreateTimeSpan() {
20 | TimeSpan a = new TimeSpan(0, 0);
21 | TimeSpan b = TimeSpan.elapsed(0, 100);
22 | }
23 |
24 | @Test
25 | public void testCannotCreateInvalidTimeSpan() {
26 | Assertions.assertThrows(
27 | IllegalArgumentException.class,
28 | () -> new TimeSpan(0, -1)
29 | );
30 | }
31 |
32 | @Test
33 | public void testElapsedMethod() {
34 | TimeSpan a = new TimeSpan(100, 200);
35 | TimeSpan b = TimeSpan.elapsed(100, 100);
36 |
37 | Assertions.assertEquals(a, b);
38 | }
39 |
40 | @Test
41 | public void testAdd() {
42 | TimeSpan a = TimeSpan.elapsed(0, 100);
43 | TimeSpan b = TimeSpan.elapsed(100, 100);
44 | TimeSpan c = TimeSpan.elapsed(100, 200);
45 |
46 | Assertions.assertEquals(TimeSpan.elapsed(0, 200), a.add(b));
47 | Assertions.assertEquals(TimeSpan.elapsed(0, 200), a.add(100));
48 |
49 | Assertions.assertEquals(TimeSpan.elapsed(100, 300), b.add(c));
50 | Assertions.assertEquals(TimeSpan.elapsed(100, 400), b.add(300));
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | plugins {
12 | id 'java'
13 | id 'maven-publish'
14 | id 'me.champeau.jmh'
15 | }
16 |
17 | repositories {
18 | mavenCentral()
19 | }
20 |
21 | java {
22 | toolchain {
23 | languageVersion = JavaLanguageVersion.of(8)
24 | }
25 |
26 | withJavadocJar()
27 | withSourcesJar()
28 | }
29 |
30 | dependencies {
31 | compileOnly 'org.apache.commons:commons-math3:3.6.1'
32 | compileOnly 'org.junit.jupiter:junit-jupiter-api:5.8.2'
33 | compileOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
34 |
35 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
36 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
37 | }
38 |
39 | test {
40 | useJUnitPlatform()
41 | }
42 |
43 | publishing {
44 | publications {
45 | maven(MavenPublication) {
46 | groupId = project.projectName
47 | version = project.projectVersion
48 | artifactId = 'geometry'
49 | from components.java
50 | }
51 | }
52 | }
53 |
54 | jmh {
55 | warmup = project.jmhTime
56 | warmupForks = project.jmhWarmupForks
57 | warmupIterations = project.jmhWarmupIterations
58 | iterations = project.jmhIterations
59 | fork = project.jmhForks
60 | timeOnIteration = project.jmhTime
61 | jmhTimeout = project.jmhTime
62 | timeUnit = project.jmhTimeUnit
63 | }
64 |
--------------------------------------------------------------------------------
/pathfinder2-frc/src/main/java/me/wobblyyyy/pathfinder2/revrobotics/REVColorSensor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | package me.wobblyyyy.pathfinder2.revrobotics;
12 |
13 | import com.revrobotics.ColorSensorV3;
14 | import edu.wpi.first.wpilibj.I2C;
15 | import me.wobblyyyy.pathfinder2.robot.sensors.ARGBColorSensor;
16 |
17 | /**
18 | * A wrapper for {@link ColorSensorV3}.
19 | *
20 | * @author Colin Robertson
21 | * @since 0.10.8
22 | */
23 | public class REVColorSensor implements ARGBColorSensor {
24 | private final ColorSensorV3 sensor;
25 |
26 | /**
27 | * Create a new {@code REVColorSensor}.
28 | *
29 | * @param sensor the color sensor.
30 | */
31 | public REVColorSensor(ColorSensorV3 sensor) {
32 | this.sensor = sensor;
33 | }
34 |
35 | /**
36 | * Create a new {@code REVColorSensor}.
37 | *
38 | * @param port the port the color sensor is in.
39 | */
40 | public REVColorSensor(I2C.Port port) {
41 | this(new ColorSensorV3(port));
42 | }
43 |
44 | @Override
45 | public int getRed() {
46 | return sensor.getRed();
47 | }
48 |
49 | @Override
50 | public int getGreen() {
51 | return sensor.getGreen();
52 | }
53 |
54 | @Override
55 | public int getBlue() {
56 | return sensor.getBlue();
57 | }
58 |
59 | @Override
60 | public int getAlpha() {
61 | return sensor.getIR();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/pathfinder2-geometry/src/main/java/me/wobblyyyy/pathfinder2/geometry/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021.
3 | *
4 | * This file is part of the "Pathfinder2" project, available here:
5 | * GitHub
6 | *
7 | * This project is licensed under the GNU GPL V3 license.
8 | * GNU GPL V3
9 | */
10 |
11 | /**
12 | * An expansive set of geometry functionality utilized by Pathfinder. This
13 | * part of Pathfinder can be very challenging to effectively document, because
14 | * there's so many niche methods that do so many niche things. I'd suggest
15 | * you read through the documentation for each of the classes you use, even
16 | * if you just skim over it, so you can get a general idea of what methods
17 | * you have at your disposal.
18 | *
19 | *
20 | * The most commonly-used parts of the geometry package are {@code PointXY},
21 | * {@code PointXYZ}, and {@code Angle}. Rectangles, triangles, and shapes
22 | * in general are made available, but you won't need to use them to get
23 | * the library up and running.
24 | *
25 | *
26 | *
27 | * This is also the only part of the Pathfinder2 project that is not meant
28 | * exclusively for use within Pathfinder2 - none of the code here is very
29 | * specific and can be used just about anywhere.
30 | *
31 | *
32 | *
33 | * This isn't really an API guide or anything, but you're more than welcome
34 | * to add exhaustive tests. In order for this library to function properly,
35 | * the geometry portion has to function perfectly, and adding more tests can
36 | * never hurt, right? Right.
37 | *