From 82d8724c944401fde48004745c7b7823f2f4d05c Mon Sep 17 00:00:00 2001 From: BennyLi Date: Tue, 10 Sep 2024 22:04:24 +0800 Subject: [PATCH] Functions extends Mathematics --- .../ftc/teamcode/DriveControls/Actions/DriveAction.java | 4 ++-- .../DriveControls/Actions/DrivingActionsBuilder.java | 6 +++--- .../ftc/teamcode/DriveControls/Commands/DriveCommand.java | 4 ++-- .../DriveControls/Commands/DrivingCommandsBuilder.java | 6 +++--- .../org/firstinspires/ftc/teamcode/Hardwares/Classic.java | 8 ++++---- .../ftc/teamcode/Hardwares/basic/Motors.java | 3 ++- .../org/firstinspires/ftc/teamcode/Utils/Functions.java | 2 +- .../org/firstinspires/ftc/teamcode/Utils/Mathematics.java | 2 +- 8 files changed, 18 insertions(+), 17 deletions(-) diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Actions/DriveAction.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Actions/DriveAction.java index 3eeb630..3f8b878 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Actions/DriveAction.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Actions/DriveAction.java @@ -17,7 +17,7 @@ import org.firstinspires.ftc.teamcode.Utils.Complex; import org.firstinspires.ftc.teamcode.Utils.Enums.TrajectoryType; import org.firstinspires.ftc.teamcode.Utils.Enums.driveDirection; -import org.firstinspires.ftc.teamcode.Utils.Mathematics; +import org.firstinspires.ftc.teamcode.Utils.Functions; public class DriveAction implements DriveOrder { private final Classic classic; @@ -48,7 +48,7 @@ public void SetPower(double power) { @Override public boolean run(@NonNull TelemetryPacket telemetryPacket) { BufPower=power; - BufPower= Mathematics.intervalClip(BufPower,-1,1); + BufPower= Functions.intervalClip(BufPower,-1,1); return false; } }; diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Actions/DrivingActionsBuilder.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Actions/DrivingActionsBuilder.java index adae4bf..e341712 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Actions/DrivingActionsBuilder.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Actions/DrivingActionsBuilder.java @@ -9,7 +9,7 @@ import org.firstinspires.ftc.teamcode.DriveControls.OrderDefinition.DriverProgram; import org.firstinspires.ftc.teamcode.DriveControls.SimpleMecanumDrive; import org.firstinspires.ftc.teamcode.Utils.Enums.TrajectoryType; -import org.firstinspires.ftc.teamcode.Utils.Mathematics; +import org.firstinspires.ftc.teamcode.Utils.Functions; public class DrivingActionsBuilder implements DriveOrderBuilder { private final DriveActionPackage actionPackage; @@ -28,7 +28,7 @@ public DrivingActionsBuilder(@NonNull SimpleMecanumDrive drive) { @Override public DriveOrderBuilder SetPower(double power) { - power = Mathematics.intervalClip(power, -1f, 1f); + power = Functions.intervalClip(power, -1f, 1f); cache = new DriveAction(drive.getClassic(), actionPackage.actions.getLast().BufPower, actionPackage.actions.getLast().NEXT()); cache.SetPower(power); cache.trajectoryType = TrajectoryType.WithoutChangingPosition; @@ -38,7 +38,7 @@ public DriveOrderBuilder SetPower(double power) { @Override public DriveOrderBuilder TurnRadians(double radians) { - radians = Mathematics.intervalClip(radians, -Math.PI, Math.PI); + radians = Functions.intervalClip(radians, -Math.PI, Math.PI); cache = new DriveAction(drive.getClassic(), actionPackage.actions.getLast().BufPower, actionPackage.actions.getLast().NEXT()); cache.Turn(radians); cache.trajectoryType = TrajectoryType.TurnOnly; diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Commands/DriveCommand.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Commands/DriveCommand.java index 0b74b1c..d87358e 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Commands/DriveCommand.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Commands/DriveCommand.java @@ -10,7 +10,7 @@ import org.firstinspires.ftc.teamcode.Utils.Complex; import org.firstinspires.ftc.teamcode.Utils.Enums.TrajectoryType; import org.firstinspires.ftc.teamcode.Utils.Enums.driveDirection; -import org.firstinspires.ftc.teamcode.Utils.Mathematics; +import org.firstinspires.ftc.teamcode.Utils.Functions; public class DriveCommand implements DriveOrder { private final Classic classic; @@ -45,7 +45,7 @@ public void SetPower(double power) { @Override public void runCommand() { BufPower = power; - BufPower = Mathematics.intervalClip(BufPower, -1f, 1f); + BufPower = Functions.intervalClip(BufPower, -1f, 1f); } }; } diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Commands/DrivingCommandsBuilder.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Commands/DrivingCommandsBuilder.java index 41d9c1e..048b399 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Commands/DrivingCommandsBuilder.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Commands/DrivingCommandsBuilder.java @@ -8,7 +8,7 @@ import org.firstinspires.ftc.teamcode.DriveControls.OrderDefinition.DriverProgram; import org.firstinspires.ftc.teamcode.DriveControls.SimpleMecanumDrive; import org.firstinspires.ftc.teamcode.Utils.Enums.TrajectoryType; -import org.firstinspires.ftc.teamcode.Utils.Mathematics; +import org.firstinspires.ftc.teamcode.Utils.Functions; public class DrivingCommandsBuilder implements DriveOrderBuilder { private final DriveCommandPackage commandPackage; @@ -27,7 +27,7 @@ public DrivingCommandsBuilder(@NonNull SimpleMecanumDrive drive) { } public DrivingCommandsBuilder SetPower(double power) { - power = Mathematics.intervalClip(power, -1f, 1f); + power = Functions.intervalClip(power, -1f, 1f); cache = new DriveCommand(drive.getClassic(), commandPackage.commands.getLast().BufPower, commandPackage.commands.getLast().NEXT()); cache.SetPower(power); cache.trajectoryType = TrajectoryType.WithoutChangingPosition; @@ -36,7 +36,7 @@ public DrivingCommandsBuilder SetPower(double power) { } public DrivingCommandsBuilder TurnRadians(double radians) { - radians = Mathematics.intervalClip(radians, -Math.PI, Math.PI); + radians = Functions.intervalClip(radians, -Math.PI, Math.PI); cache = new DriveCommand(drive.getClassic(), commandPackage.commands.getLast().BufPower, commandPackage.commands.getLast().NEXT()); cache.Turn(radians); cache.trajectoryType = TrajectoryType.TurnOnly; diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/Classic.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/Classic.java index 3604404..329ef15 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/Classic.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/Classic.java @@ -11,7 +11,7 @@ import org.firstinspires.ftc.teamcode.Params; import org.firstinspires.ftc.teamcode.Utils.Enums.Quadrant; import org.firstinspires.ftc.teamcode.Utils.Enums.driveDirection; -import org.firstinspires.ftc.teamcode.Utils.Mathematics; +import org.firstinspires.ftc.teamcode.Utils.Functions; public class Classic { public Motors motors; @@ -98,7 +98,7 @@ public void drive(@NonNull driveDirection driveDirection, @NonNull Quadrant quad * @param angle 相较于机器的正方向,允许为[-180,180]内的实数(不是弧度,不是弧度,不是弧度) */ public void SimpleDrive(double power,double angle){ - angle= Mathematics.angleRationalize(angle); + angle= Functions.angleRationalize(angle); if(angle==0){ drive(driveDirection.forward,power); @@ -122,7 +122,7 @@ public void SimpleDrive(double power,double angle){ } public void SimpleRadiansDrive(double power,double radians){ - radians=Mathematics.radiansRationalize(radians); + radians=Functions.radiansRationalize(radians); SimpleDrive(power,Math.toDegrees(radians)); } @@ -138,7 +138,7 @@ public void STOP(){ public void operateThroughGamePad(@NonNull Gamepad gamepad){ if(Params.Configs.useRightStickYToConfigRobotSpeed){ BufPower+=gamepad.right_stick_y*0.6; - BufPower=Mathematics.intervalClip(BufPower,-1,1); + BufPower=Functions.intervalClip(BufPower,-1,1); motors.simpleMotorPowerController( gamepad.left_stick_x*BufPower* Params.factorXPower, gamepad.left_stick_y*BufPower* Params.factorYPower, diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/basic/Motors.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/basic/Motors.java index a10b3ca..2440012 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/basic/Motors.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/basic/Motors.java @@ -6,6 +6,7 @@ import org.firstinspires.ftc.teamcode.Hardwares.namespace.DeviceMap; import org.firstinspires.ftc.teamcode.Params; import org.firstinspires.ftc.teamcode.Utils.Complex; +import org.firstinspires.ftc.teamcode.Utils.Functions; import org.firstinspires.ftc.teamcode.Utils.Mathematics; import org.firstinspires.ftc.teamcode.Hardwares.namespace.HardwareDevices; @@ -60,7 +61,7 @@ public void clearDriveOptions(){ public void updateDriveOptions(double headingDeg){ if( Params.Configs.driverUsingAxisPowerInsteadOfCurrentPower ){ double currentXPower,currentYPower,currentHeadingPower=headingPower; - headingDeg= Mathematics.angleRationalize(headingDeg);//防止有问题 + headingDeg= Functions.angleRationalize(headingDeg);//防止有问题 Complex aim=new Complex(new Vector2d(xAxisPower,yAxisPower)),robotHeading=new Complex(headingDeg); Complex Counterclockwise=new Complex(robotHeading.angleToYAxis()); diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Utils/Functions.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Utils/Functions.java index af68441..4846ed9 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Utils/Functions.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Utils/Functions.java @@ -10,7 +10,7 @@ import org.firstinspires.ftc.teamcode.Utils.Annotations.UtilFunctions; import org.firstinspires.ftc.teamcode.Utils.Enums.State; -public final class Functions { +public final class Functions extends Mathematics{ @UtilFunctions public static double getCurrentTimeMills(){ return System.nanoTime()/1.0E06; diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Utils/Mathematics.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Utils/Mathematics.java index b94d68a..4c7fa10 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Utils/Mathematics.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Utils/Mathematics.java @@ -1,6 +1,6 @@ package org.firstinspires.ftc.teamcode.Utils; -public final class Mathematics { +public class Mathematics { public static double intervalClip(double value,double min,double max){ return Math.min(Math.max(min,value),max); }