Skip to content

Commit

Permalink
合并 RuntimeOption.java 和 Params
Browse files Browse the repository at this point in the history
  • Loading branch information
6-BennyLi-9 committed Aug 24, 2024
1 parent 08fefc9 commit c366889
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -41,15 +41,15 @@ private void openClips(){
OpenFrontClip();
OpenRearClip();

if( RuntimeOption.runUpdateWhenAnyNewOptionsAdded ){
if( Params.runUpdateWhenAnyNewOptionsAdded ){
servos.update();
}
}
private void closeClips(){
CloseFrontClip();
CloseRearClip();

if( RuntimeOption.runUpdateWhenAnyNewOptionsAdded ){
if( Params.runUpdateWhenAnyNewOptionsAdded ){
servos.update();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -98,15 +98,15 @@ 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);
try{
updateStructureOptions();
}catch (Exception ignored){}

if(RuntimeOption.autoPrepareForNextOptionWhenUpdate){
if(Params.autoPrepareForNextOptionWhenUpdate){
clearDriveOptions();
}
}
Expand All @@ -116,7 +116,7 @@ public void update(){
updateStructureOptions();
}catch (Exception ignored){}

if(RuntimeOption.autoPrepareForNextOptionWhenUpdate){
if(Params.autoPrepareForNextOptionWhenUpdate){
clearDriveOptions();
}
}
Expand Down
16 changes: 16 additions & 0 deletions TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Params.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,20 @@ public final class Params {
* 在执行手动程序时,由Structure下达的SuspensionArmPower命令的倍率因数
*/
public static double factorSuspensionArmPower;
/**让机器自动在运行<code>update()</code>时,自动清除所有电机的<code>power</code>*/
public static boolean autoPrepareForNextOptionWhenUpdate = true;
/**让机器自动在执行提供的操作时,自动在更改任何<code>power</code>变量后执行<code>update()</code>*/
public static boolean runUpdateWhenAnyNewOptionsAdded = false;
/**在对舵机下达命令时,自动等待舵机到位*/
public static boolean waitForServoUntilThePositionIsInPlace = false;
/**让机器即使在不调用<code>pid</code>时,依然执行<code>pid.update()</code>*/
public static boolean alwaysRunPIDInAutonomous = false;
/**在自动程序中使用<code>pid</code>*/
public static boolean usePIDInAutonomous = true;
/**必须在自动程序中保持改变量为<code>true</code>*/
public static boolean driverUsingAxisPowerInsteadOfCurrentPower=true;
/**在手动程序中,使用<code>gamepad1</code>的<code>right_stick_y</code>来控制底盘速度*/
public static boolean useRightStickYToConfigRobotSpeed = true;
/**启用超时保护器*/
public static boolean useOutTimeProtection = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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));
}
Expand Down

This file was deleted.

0 comments on commit c366889

Please sign in to comment.