Skip to content

Commit 82d8724

Browse files
committed
Functions extends Mathematics
1 parent ca22f93 commit 82d8724

File tree

8 files changed

+18
-17
lines changed

8 files changed

+18
-17
lines changed

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Actions/DriveAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.firstinspires.ftc.teamcode.Utils.Complex;
1818
import org.firstinspires.ftc.teamcode.Utils.Enums.TrajectoryType;
1919
import org.firstinspires.ftc.teamcode.Utils.Enums.driveDirection;
20-
import org.firstinspires.ftc.teamcode.Utils.Mathematics;
20+
import org.firstinspires.ftc.teamcode.Utils.Functions;
2121

2222
public class DriveAction implements DriveOrder {
2323
private final Classic classic;
@@ -48,7 +48,7 @@ public void SetPower(double power) {
4848
@Override
4949
public boolean run(@NonNull TelemetryPacket telemetryPacket) {
5050
BufPower=power;
51-
BufPower= Mathematics.intervalClip(BufPower,-1,1);
51+
BufPower= Functions.intervalClip(BufPower,-1,1);
5252
return false;
5353
}
5454
};

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Actions/DrivingActionsBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.firstinspires.ftc.teamcode.DriveControls.OrderDefinition.DriverProgram;
1010
import org.firstinspires.ftc.teamcode.DriveControls.SimpleMecanumDrive;
1111
import org.firstinspires.ftc.teamcode.Utils.Enums.TrajectoryType;
12-
import org.firstinspires.ftc.teamcode.Utils.Mathematics;
12+
import org.firstinspires.ftc.teamcode.Utils.Functions;
1313

1414
public class DrivingActionsBuilder implements DriveOrderBuilder {
1515
private final DriveActionPackage actionPackage;
@@ -28,7 +28,7 @@ public DrivingActionsBuilder(@NonNull SimpleMecanumDrive drive) {
2828

2929
@Override
3030
public DriveOrderBuilder SetPower(double power) {
31-
power = Mathematics.intervalClip(power, -1f, 1f);
31+
power = Functions.intervalClip(power, -1f, 1f);
3232
cache = new DriveAction(drive.getClassic(), actionPackage.actions.getLast().BufPower, actionPackage.actions.getLast().NEXT());
3333
cache.SetPower(power);
3434
cache.trajectoryType = TrajectoryType.WithoutChangingPosition;
@@ -38,7 +38,7 @@ public DriveOrderBuilder SetPower(double power) {
3838

3939
@Override
4040
public DriveOrderBuilder TurnRadians(double radians) {
41-
radians = Mathematics.intervalClip(radians, -Math.PI, Math.PI);
41+
radians = Functions.intervalClip(radians, -Math.PI, Math.PI);
4242
cache = new DriveAction(drive.getClassic(), actionPackage.actions.getLast().BufPower, actionPackage.actions.getLast().NEXT());
4343
cache.Turn(radians);
4444
cache.trajectoryType = TrajectoryType.TurnOnly;

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Commands/DriveCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.firstinspires.ftc.teamcode.Utils.Complex;
1111
import org.firstinspires.ftc.teamcode.Utils.Enums.TrajectoryType;
1212
import org.firstinspires.ftc.teamcode.Utils.Enums.driveDirection;
13-
import org.firstinspires.ftc.teamcode.Utils.Mathematics;
13+
import org.firstinspires.ftc.teamcode.Utils.Functions;
1414

1515
public class DriveCommand implements DriveOrder {
1616
private final Classic classic;
@@ -45,7 +45,7 @@ public void SetPower(double power) {
4545
@Override
4646
public void runCommand() {
4747
BufPower = power;
48-
BufPower = Mathematics.intervalClip(BufPower, -1f, 1f);
48+
BufPower = Functions.intervalClip(BufPower, -1f, 1f);
4949
}
5050
};
5151
}

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Commands/DrivingCommandsBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.firstinspires.ftc.teamcode.DriveControls.OrderDefinition.DriverProgram;
99
import org.firstinspires.ftc.teamcode.DriveControls.SimpleMecanumDrive;
1010
import org.firstinspires.ftc.teamcode.Utils.Enums.TrajectoryType;
11-
import org.firstinspires.ftc.teamcode.Utils.Mathematics;
11+
import org.firstinspires.ftc.teamcode.Utils.Functions;
1212

1313
public class DrivingCommandsBuilder implements DriveOrderBuilder {
1414
private final DriveCommandPackage commandPackage;
@@ -27,7 +27,7 @@ public DrivingCommandsBuilder(@NonNull SimpleMecanumDrive drive) {
2727
}
2828

2929
public DrivingCommandsBuilder SetPower(double power) {
30-
power = Mathematics.intervalClip(power, -1f, 1f);
30+
power = Functions.intervalClip(power, -1f, 1f);
3131
cache = new DriveCommand(drive.getClassic(), commandPackage.commands.getLast().BufPower, commandPackage.commands.getLast().NEXT());
3232
cache.SetPower(power);
3333
cache.trajectoryType = TrajectoryType.WithoutChangingPosition;
@@ -36,7 +36,7 @@ public DrivingCommandsBuilder SetPower(double power) {
3636
}
3737

3838
public DrivingCommandsBuilder TurnRadians(double radians) {
39-
radians = Mathematics.intervalClip(radians, -Math.PI, Math.PI);
39+
radians = Functions.intervalClip(radians, -Math.PI, Math.PI);
4040
cache = new DriveCommand(drive.getClassic(), commandPackage.commands.getLast().BufPower, commandPackage.commands.getLast().NEXT());
4141
cache.Turn(radians);
4242
cache.trajectoryType = TrajectoryType.TurnOnly;

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/Classic.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.firstinspires.ftc.teamcode.Params;
1212
import org.firstinspires.ftc.teamcode.Utils.Enums.Quadrant;
1313
import org.firstinspires.ftc.teamcode.Utils.Enums.driveDirection;
14-
import org.firstinspires.ftc.teamcode.Utils.Mathematics;
14+
import org.firstinspires.ftc.teamcode.Utils.Functions;
1515

1616
public class Classic {
1717
public Motors motors;
@@ -98,7 +98,7 @@ public void drive(@NonNull driveDirection driveDirection, @NonNull Quadrant quad
9898
* @param angle 相较于机器的正方向,允许为[-180,180]内的实数(不是弧度,不是弧度,不是弧度)
9999
*/
100100
public void SimpleDrive(double power,double angle){
101-
angle= Mathematics.angleRationalize(angle);
101+
angle= Functions.angleRationalize(angle);
102102

103103
if(angle==0){
104104
drive(driveDirection.forward,power);
@@ -122,7 +122,7 @@ public void SimpleDrive(double power,double angle){
122122
}
123123

124124
public void SimpleRadiansDrive(double power,double radians){
125-
radians=Mathematics.radiansRationalize(radians);
125+
radians=Functions.radiansRationalize(radians);
126126

127127
SimpleDrive(power,Math.toDegrees(radians));
128128
}
@@ -138,7 +138,7 @@ public void STOP(){
138138
public void operateThroughGamePad(@NonNull Gamepad gamepad){
139139
if(Params.Configs.useRightStickYToConfigRobotSpeed){
140140
BufPower+=gamepad.right_stick_y*0.6;
141-
BufPower=Mathematics.intervalClip(BufPower,-1,1);
141+
BufPower=Functions.intervalClip(BufPower,-1,1);
142142
motors.simpleMotorPowerController(
143143
gamepad.left_stick_x*BufPower* Params.factorXPower,
144144
gamepad.left_stick_y*BufPower* Params.factorYPower,

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/basic/Motors.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.firstinspires.ftc.teamcode.Hardwares.namespace.DeviceMap;
77
import org.firstinspires.ftc.teamcode.Params;
88
import org.firstinspires.ftc.teamcode.Utils.Complex;
9+
import org.firstinspires.ftc.teamcode.Utils.Functions;
910
import org.firstinspires.ftc.teamcode.Utils.Mathematics;
1011
import org.firstinspires.ftc.teamcode.Hardwares.namespace.HardwareDevices;
1112

@@ -60,7 +61,7 @@ public void clearDriveOptions(){
6061
public void updateDriveOptions(double headingDeg){
6162
if( Params.Configs.driverUsingAxisPowerInsteadOfCurrentPower ){
6263
double currentXPower,currentYPower,currentHeadingPower=headingPower;
63-
headingDeg= Mathematics.angleRationalize(headingDeg);//防止有问题
64+
headingDeg= Functions.angleRationalize(headingDeg);//防止有问题
6465
Complex aim=new Complex(new Vector2d(xAxisPower,yAxisPower)),robotHeading=new Complex(headingDeg);
6566
Complex Counterclockwise=new Complex(robotHeading.angleToYAxis());
6667

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Utils/Functions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.firstinspires.ftc.teamcode.Utils.Annotations.UtilFunctions;
1111
import org.firstinspires.ftc.teamcode.Utils.Enums.State;
1212

13-
public final class Functions {
13+
public final class Functions extends Mathematics{
1414
@UtilFunctions
1515
public static double getCurrentTimeMills(){
1616
return System.nanoTime()/1.0E06;

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Utils/Mathematics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.firstinspires.ftc.teamcode.Utils;
22

3-
public final class Mathematics {
3+
public class Mathematics {
44
public static double intervalClip(double value,double min,double max){
55
return Math.min(Math.max(min,value),max);
66
}

0 commit comments

Comments
 (0)