Skip to content

Commit

Permalink
Functions extends Mathematics
Browse files Browse the repository at this point in the history
  • Loading branch information
6-BennyLi-9 committed Sep 10, 2024
1 parent ca22f93 commit 82d8724
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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));
}
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down

0 comments on commit 82d8724

Please sign in to comment.