From c3668897bbb2cb98c3c8ed9e81d1d639c19957c1 Mon Sep 17 00:00:00 2001 From: Benny0Li Date: Sat, 24 Aug 2024 13:51:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=20RuntimeOption.java=20?= =?UTF-8?q?=E5=92=8C=20Params?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DriveControls/SimpleMecanumDrive.java | 8 +++---- .../ftc/teamcode/Hardwares/Classic.java | 7 +++--- .../ftc/teamcode/Hardwares/Structure.java | 6 ++--- .../teamcode/Hardwares/basic/DeviceMap.java | 2 +- .../ftc/teamcode/Hardwares/basic/Motors.java | 12 +++++----- .../firstinspires/ftc/teamcode/Params.java | 16 +++++++++++++ .../org/firstinspires/ftc/teamcode/Robot.java | 8 +++---- .../ftc/teamcode/RuntimeOption.java | 23 ------------------- 8 files changed, 37 insertions(+), 45 deletions(-) delete mode 100644 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/RuntimeOption.java diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/SimpleMecanumDrive.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/SimpleMecanumDrive.java index 95f351b..965bc7e 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/SimpleMecanumDrive.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/SimpleMecanumDrive.java @@ -16,8 +16,8 @@ import org.firstinspires.ftc.teamcode.DriveControls.Localizers.definition.Localizer; import org.firstinspires.ftc.teamcode.Hardwares.Classic; import org.firstinspires.ftc.teamcode.Hardwares.basic.Motors; +import org.firstinspires.ftc.teamcode.Params; import org.firstinspires.ftc.teamcode.Robot; -import org.firstinspires.ftc.teamcode.RuntimeOption; import org.firstinspires.ftc.teamcode.utils.Client; import org.firstinspires.ftc.teamcode.utils.Complex; import org.firstinspires.ftc.teamcode.utils.Mathematics; @@ -299,17 +299,17 @@ public void runDriveCommands(@NonNull LinkedList < DriveCommand > commands){ client.changeDate("progress", progress +"%"); Pose2d aim=getAimPositionThroughTrajectory(singleCommand,progress); - if(et>st+estimatedTime+ timeOutProtectionMills&&RuntimeOption.useOutTimeProtection){//保护机制 + if(et>st+estimatedTime+ timeOutProtectionMills&& Params.useOutTimeProtection){//保护机制 state=State.BrakeDown; motors.updateDriveOptions(); break; } - if(RuntimeOption.usePIDInAutonomous){ + if(Params.usePIDInAutonomous){ if(Math.abs(aim.position.x- RobotPosition.position.x)> pem || Math.abs(aim.position.y- RobotPosition.position.y)> pem || Math.abs(aim.heading.toDouble()- RobotPosition.heading.toDouble())> aem - || RuntimeOption.alwaysRunPIDInAutonomous ){ + || Params.alwaysRunPIDInAutonomous ){ //间断地调用pid可能会导致pid的效果不佳 pidProcessor.inaccuracies[0]=aim.position.x- RobotPosition.position.x; pidProcessor.inaccuracies[1]=aim.position.y- RobotPosition.position.y; 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 51821ce..aea42f5 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 @@ -10,7 +10,6 @@ import org.firstinspires.ftc.teamcode.Hardwares.basic.Motors; import org.firstinspires.ftc.teamcode.Hardwares.basic.Sensors; import org.firstinspires.ftc.teamcode.Params; -import org.firstinspires.ftc.teamcode.RuntimeOption; import org.firstinspires.ftc.teamcode.utils.Mathematics; import org.firstinspires.ftc.teamcode.utils.Enums.driveDirection; import org.firstinspires.ftc.teamcode.utils.Enums.Quadrant; @@ -52,7 +51,7 @@ public void drive(@NonNull driveDirection driveDirection, double power) { Log.e("UnExpectingCode","ErrorCode#1"); } - if( RuntimeOption.runUpdateWhenAnyNewOptionsAdded ){ + if( Params.runUpdateWhenAnyNewOptionsAdded ){ sensors.update(); motors.update(sensors.FirstAngle); } @@ -92,7 +91,7 @@ public void drive(@NonNull driveDirection driveDirection, @NonNull Quadrant quad break; } - if( RuntimeOption.runUpdateWhenAnyNewOptionsAdded ){ + if( Params.runUpdateWhenAnyNewOptionsAdded ){ sensors.update(); motors.update(sensors.FirstAngle); } @@ -140,7 +139,7 @@ public void STOP(){ motors.updateDriveOptions(sensors.FirstAngle); } public void operateThroughGamePad(@NonNull Gamepad gamepad){ - if(RuntimeOption.useRightStickYToConfigRobotSpeed){ + if(Params.useRightStickYToConfigRobotSpeed){ BufPower+=gamepad.right_stick_y*0.6; BufPower=Mathematics.intervalClip(BufPower,-1,1); motors.simpleMotorPowerController( diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/Structure.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/Structure.java index 4699f1c..50163ee 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/Structure.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/Structure.java @@ -9,7 +9,7 @@ import org.firstinspires.ftc.teamcode.Hardwares.basic.Motors; import org.firstinspires.ftc.teamcode.Hardwares.basic.Servos; -import org.firstinspires.ftc.teamcode.RuntimeOption; +import org.firstinspires.ftc.teamcode.Params; import org.firstinspires.ftc.teamcode.utils.Enums.ClipPosition; import org.firstinspires.ftc.teamcode.utils.Exceptions.UnKnownErrorsException; @@ -41,7 +41,7 @@ private void openClips(){ OpenFrontClip(); OpenRearClip(); - if( RuntimeOption.runUpdateWhenAnyNewOptionsAdded ){ + if( Params.runUpdateWhenAnyNewOptionsAdded ){ servos.update(); } } @@ -49,7 +49,7 @@ private void closeClips(){ CloseFrontClip(); CloseRearClip(); - if( RuntimeOption.runUpdateWhenAnyNewOptionsAdded ){ + if( Params.runUpdateWhenAnyNewOptionsAdded ){ servos.update(); } } diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/basic/DeviceMap.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/basic/DeviceMap.java index 2af8891..58217a5 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/basic/DeviceMap.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/basic/DeviceMap.java @@ -44,7 +44,7 @@ public HardwareDevice getDevice(@NonNull HardwareDevices hardwareDevices){ if(devices.containsKey(hardwareDevices)){ return devices.get(hardwareDevices); }else{ - throw new NullPointerException("Device Not Found:"+ hardwareDevices.toString()); + throw new NullPointerException("Device Not Found:"+ hardwareDevices); } } public void setDirection(@NonNull HardwareDevices hardwareDevices, DcMotorSimple.Direction direction){ 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 eb8bb3e..4149aa3 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 @@ -3,7 +3,7 @@ import com.acmerobotics.roadrunner.Vector2d; import com.qualcomm.robotcore.hardware.DcMotorSimple; -import org.firstinspires.ftc.teamcode.RuntimeOption; +import org.firstinspires.ftc.teamcode.Params; import org.firstinspires.ftc.teamcode.utils.Complex; import org.firstinspires.ftc.teamcode.utils.Mathematics; import org.firstinspires.ftc.teamcode.Hardwares.namespace.HardwareDevices; @@ -54,10 +54,10 @@ public void clearDriveOptions(){ /** * @param headingDeg 必须在使用driverUsingAxisPowerInsteadOfCurrentPower时给出,其他状态下给出是无效的 - * @see org.firstinspires.ftc.teamcode.RuntimeOption + * @see org.firstinspires.ftc.teamcode.Params */ public void updateDriveOptions(double headingDeg){ - if( RuntimeOption.driverUsingAxisPowerInsteadOfCurrentPower ){ + if( Params.driverUsingAxisPowerInsteadOfCurrentPower ){ double currentXPower,currentYPower,currentHeadingPower=headingPower; headingDeg= Mathematics.angleRationalize(headingDeg);//防止有问题 Complex aim=new Complex(new Vector2d(xAxisPower,yAxisPower)),robotHeading=new Complex(headingDeg); @@ -98,7 +98,7 @@ public void updateStructureOptions(){ } /** * @param headingDeg 必须在使用driverUsingAxisPowerInsteadOfCurrentPower时给出,其他状态下给出是无效的 - * @see org.firstinspires.ftc.teamcode.RuntimeOption + * @see org.firstinspires.ftc.teamcode.Params */ public void update(double headingDeg){ updateDriveOptions(headingDeg); @@ -106,7 +106,7 @@ public void update(double headingDeg){ updateStructureOptions(); }catch (Exception ignored){} - if(RuntimeOption.autoPrepareForNextOptionWhenUpdate){ + if(Params.autoPrepareForNextOptionWhenUpdate){ clearDriveOptions(); } } @@ -116,7 +116,7 @@ public void update(){ updateStructureOptions(); }catch (Exception ignored){} - if(RuntimeOption.autoPrepareForNextOptionWhenUpdate){ + if(Params.autoPrepareForNextOptionWhenUpdate){ clearDriveOptions(); } } diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Params.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Params.java index 3ecf30f..aa02e74 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Params.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Params.java @@ -70,4 +70,20 @@ public final class Params { * 在执行手动程序时,由Structure下达的SuspensionArmPower命令的倍率因数 */ public static double factorSuspensionArmPower; + /**让机器自动在运行update()时,自动清除所有电机的power*/ + public static boolean autoPrepareForNextOptionWhenUpdate = true; + /**让机器自动在执行提供的操作时,自动在更改任何power变量后执行update()*/ + public static boolean runUpdateWhenAnyNewOptionsAdded = false; + /**在对舵机下达命令时,自动等待舵机到位*/ + public static boolean waitForServoUntilThePositionIsInPlace = false; + /**让机器即使在不调用pid时,依然执行pid.update()*/ + public static boolean alwaysRunPIDInAutonomous = false; + /**在自动程序中使用pid*/ + public static boolean usePIDInAutonomous = true; + /**必须在自动程序中保持改变量为true*/ + public static boolean driverUsingAxisPowerInsteadOfCurrentPower=true; + /**在手动程序中,使用gamepad1right_stick_y来控制底盘速度*/ + public static boolean useRightStickYToConfigRobotSpeed = true; + /**启用超时保护器*/ + public static boolean useOutTimeProtection = true; } diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Robot.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Robot.java index 3233d7f..fd74ed5 100644 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Robot.java +++ b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Robot.java @@ -71,8 +71,8 @@ public Robot(@NonNull HardwareMap hardwareMap, @NonNull runningState state, @Non if (Objects.requireNonNull(state) == runningState.Autonomous) { InitInAutonomous(); } else if (state == runningState.ManualDrive) { - RuntimeOption.runUpdateWhenAnyNewOptionsAdded=true; - RuntimeOption.driverUsingAxisPowerInsteadOfCurrentPower=false; + Params.runUpdateWhenAnyNewOptionsAdded=true; + Params.driverUsingAxisPowerInsteadOfCurrentPower=false; InitInManualDrive(); } else { @@ -113,14 +113,14 @@ public void update() { sensors.update(); servos.update(); encoders.update(); - if(RuntimeOption.driverUsingAxisPowerInsteadOfCurrentPower) { + if(Params.driverUsingAxisPowerInsteadOfCurrentPower) { motors.update(sensors.FirstAngle); }else{ motors.update(); } client.changeDate("State",state.name()); - while(RuntimeOption.waitForServoUntilThePositionIsInPlace && servos.InPlace()){ + while(Params.waitForServoUntilThePositionIsInPlace && servos.InPlace()){ //当前最方便的Sleep方案 Actions.runBlocking(new SleepAction(0.1)); } diff --git a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/RuntimeOption.java b/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/RuntimeOption.java deleted file mode 100644 index 434f014..0000000 --- a/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/RuntimeOption.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.firstinspires.ftc.teamcode; - -/** - * 要修改其中的值请勿直接在这里修改,而是在Robot中修改 - */ -public final class RuntimeOption { - /**让机器自动在运行update()时,自动清除所有电机的power*/ - public static boolean autoPrepareForNextOptionWhenUpdate = true; - /**让机器自动在执行提供的操作时,自动在更改任何power变量后执行update()*/ - public static boolean runUpdateWhenAnyNewOptionsAdded = false; - /**在对舵机下达命令时,自动等待舵机到位*/ - public static boolean waitForServoUntilThePositionIsInPlace = false; - /**让机器即使在不调用pid时,依然执行pid.update()*/ - public static boolean alwaysRunPIDInAutonomous = false; - /**在自动程序中使用pid*/ - public static boolean usePIDInAutonomous = true; - /**必须在自动程序中保持改变量为true*/ - public static boolean driverUsingAxisPowerInsteadOfCurrentPower=true; - /**在手动程序中,使用gamepad1right_stick_y来控制底盘速度*/ - public static boolean useRightStickYToConfigRobotSpeed = true; - /**启用超时保护器*/ - public static boolean useOutTimeProtection = true; -}