elevator code fix

changed last years elevator code to work with this years desine, no closed loop control implemented other than limit switches.
This commit is contained in:
lukesta182
2019-01-19 10:03:34 -07:00
parent 3615e5c257
commit 75f1aea29d
15 changed files with 274 additions and 81 deletions
Binary file not shown.
Binary file not shown.
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
#Fri Jan 18 21:28:34 MST 2019
gradle.version=5.0
View File
+3 -2
View File
@@ -1,6 +1,6 @@
plugins {
id "java"
id "edu.wpi.first.GradleRIO" version "2019.1.1"
id "edu.wpi.first.GradleRIO" version "2019.2.1"
}
def ROBOT_MAIN_CLASS = "org.usfirst.frc4388.robot.Main"
@@ -50,7 +50,8 @@ dependencies {
nativeZip wpi.deps.vendor.jni(wpi.platforms.roborio)
nativeDesktopZip wpi.deps.vendor.jni(wpi.platforms.desktop)
testCompile 'junit:junit:4.12'
compile pathfinder()
//compile Pathfinder()
compile 'jaci.jniloader:JNILoader:1.0.1'
}
// Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar')
+1 -1
View File
@@ -1,3 +1,3 @@
Files placed in this directory will be deployed to the RoboRIO into the
'deploy' directory in the home folder. Use the 'FileUtilities.getFilePath' wpilib function
to get a proper path relative to the deploy directory.
to get a proper path relative to the deploy directory.
@@ -34,31 +34,8 @@ import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
public class Elevator extends Subsystem implements ControlLoopable
{
//PID encoder and motor
private CANTalonEncoder elevatorRight;
private WPI_TalonSRX elevatorLeft;
//PID controller Max Scale
private SoftwarePIDPositionController pidPositionControllerMaxScale;
//private PIDParams PositionPIDParamsMaxScale = new PIDParams(2.0, 0.0, 0.0);
private PIDParams PositionPMaxScale;
private CANTalonEncoder elevatorMain;
//PID controller Max Scale
private SoftwarePIDPositionController pidPositionControllerLowScale;
//private PIDParams PositionPIDParamsLowScale = new PIDParams(2.0, 0.0, 0.0);
private PIDParams PositionPLowScale;
//PID controller Max Scale
private SoftwarePIDPositionController pidPositionControllerSwitch;
//private PIDParams PositionPIDParamsSwitch = new PIDParams(2.0, 0.0, 0.0);
private PIDParams PositionPSwitch;
//PID controller Max Scale
private SoftwarePIDPositionController pidPositionControllerLowest;
//private PIDParams PositionPIDParamsLowest = new PIDParams(2.0, 0.0, 0.0);
private PIDParams PositionPLowest;
//PID target
private double targetPPosition;
//Encoder ticks to inches for encoders
public static final double ENCODER_TICKS_TO_INCHES = Constants.kElevatorEncoderTicksPerInch;
@@ -93,37 +70,34 @@ public class Elevator extends Subsystem implements ControlLoopable
try
{
//PID elevator encoder and talon
elevatorRight = new CANTalonEncoder(RobotMap.ELEVATOR_MOTOR1_ID, ENCODER_TICKS_TO_INCHES, FeedbackDevice.QuadEncoder);
elevatorLeft = new WPI_TalonSRX(RobotMap.ELEVATOR_MOTOR2_ID);
elevatorMain = new CANTalonEncoder(RobotMap.ELEVATOR_MOTOR1_ID, ENCODER_TICKS_TO_INCHES, FeedbackDevice.QuadEncoder);
elevatorRight.setInverted(false);
elevatorMain.setInverted(false);
//Setting left elevator motor as follower
elevatorLeft.set(ControlMode.Follower, elevatorRight.getDeviceID());
elevatorLeft.setInverted(false);
elevatorLeft.setNeutralMode(NeutralMode.Brake);
elevatorRight.setNeutralMode(NeutralMode.Brake);
elevatorRight.setSensorPhase(true);
elevatorMain.setNeutralMode(NeutralMode.Brake);
elevatorMain.setSensorPhase(true);
//Limit Switch Left
//elevatorLeft.overrideLimitSwitchesEnable(true);
elevatorLeft.configForwardLimitSwitchSource(limitSwitchSource, LimitSwitchNormal.NormallyOpen, 0);
elevatorLeft.configReverseLimitSwitchSource(limitSwitchSource, LimitSwitchNormal.NormallyOpen, 0);
elevatorMain.configForwardLimitSwitchSource(limitSwitchSource, LimitSwitchNormal.NormallyOpen, 0);
elevatorMain.configReverseLimitSwitchSource(limitSwitchSource, LimitSwitchNormal.NormallyOpen, 0);
//Limit Switch Right
//elevatorRight.overrideLimitSwitchesEnable(true);
//elevatorRight.configForwardLimitSwitchSource(limitSwitchSource, LimitSwitchNormal.NormallyOpen, 0);
//elevatorRight.configReverseLimitSwitchSource(limitSwitchSource, LimitSwitchNormal.NormallyOpen, 0);
//elevatorMain.overrideLimitSwitchesEnable(true);
//elevatorMain.configForwardLimitSwitchSource(limitSwitchSource, LimitSwitchNormal.NormallyOpen, 0);
//elevatorMain.configReverseLimitSwitchSource(limitSwitchSource, LimitSwitchNormal.NormallyOpen, 0);
//Change This boi
// elevatorRight.configForwardSoftLimitThreshold(10000, 0); //right here
//elevatorRight.configReverseSoftLimitThreshold(5, 0);
//elevatorRight.configForwardSoftLimitEnable(true, 0);
//elevatorRight.configReverseSoftLimitEnable(true, 0);
// elevatorMain.configForwardSoftLimitThreshold(10000, 0); //right here
//elevatorMain.configReverseSoftLimitThreshold(5, 0);
//elevatorMain.configForwardSoftLimitEnable(true, 0);
//elevatorMain.configReverseSoftLimitEnable(true, 0);
//sos
//elevatorRight.enableLimitSwitch(true, true);
//elevatorMain.enableLimitSwitch(true, true);
@@ -207,7 +181,7 @@ public class Elevator extends Subsystem implements ControlLoopable
public void resetElevatorEncoder()
{
elevatorRight.setSelectedSensorPosition(0, 0, 0);
elevatorMain.setSelectedSensorPosition(0, 0, 0);
}
public void moveElevatorXbox()
@@ -226,37 +200,37 @@ public class Elevator extends Subsystem implements ControlLoopable
if(elevatorTuningPressed == true)
{
elevatorRight.set(moveElevatorInput * 0.5);
elevatorMain.set(moveElevatorInput * 0.5);
}
else if(elevatorTuningPressed == false)
{
elevatorRight.set(moveElevatorInput);
elevatorMain.set(moveElevatorInput);
}
/*
if(elevatorPos <= elevatorSafeZone && elevatorPos >= 0)
{
elevatorRight.set(moveElevatorInput);
elevatorMain.set(moveElevatorInput);
}
else if(elevatorPos > elevatorSafeZone)
{
elevatorRight.set(moveElevatorInput * 0.65);
elevatorMain.set(moveElevatorInput * 0.65);
if(holdButtonPressed == true)
{
elevatorRight.set(-0.43 * (0.2));
elevatorMain.set(-0.43 * (0.2));
}
else if(holdButtonPressed == false)
{
elevatorRight.set(moveElevatorInput * 0.75);
elevatorMain.set(moveElevatorInput * 0.75);
}
}
else if(elevatorPos < 0)
{
elevatorRight.set(moveElevatorInput * 0.75);
elevatorMain.set(moveElevatorInput * 0.75);
}
*/
}
@@ -268,12 +242,12 @@ public class Elevator extends Subsystem implements ControlLoopable
//PID encoder position
public double getEncoderElevatorPosition()
{
return elevatorRight.getPositionWorld();
return elevatorMain.getPositionWorld();
}
public double getElevatorHeightInchesAboveFloor()
{
return elevatorRight.getPositionWorld();
return elevatorMain.getPositionWorld();
}
public synchronized void setControlMode(DriveControlMode controlMode)
@@ -316,23 +290,23 @@ public class Elevator extends Subsystem implements ControlLoopable
}
*/
public void rawSetOutput(double output){
elevatorRight.set(/*ControlMode.PercentOutput,*/ output);
elevatorMain.set(/*ControlMode.PercentOutput,*/ output);
}
public void holdInPos()
{
elevatorRight.set(-0.43 * 0.2);
elevatorMain.set(-0.43 * 0.2);
}
public void stopMotors()
{
elevatorRight.set(0);
elevatorMain.set(0);
}
public void isSwitchPressed()
{
pressed = false;
isPressed = elevatorRight.getSensorCollection();
isPressed = elevatorMain.getSensorCollection();
if(isPressed.isFwdLimitSwitchClosed() == true)
{
@@ -370,22 +344,6 @@ public class Elevator extends Subsystem implements ControlLoopable
else if (!isFinished)
{
//PID control mode
if(controlMode == DriveControlMode.MOVE_POSITION_MAX_SCALE)
{
isFinished = pidPositionControllerMaxScale.controlLoopUpdate(getEncoderElevatorPosition());
}
else if(controlMode == DriveControlMode.MOVE_POSITION_LOW_SCALE)
{
isFinished = pidPositionControllerLowScale.controlLoopUpdate(getEncoderElevatorPosition());
}
else if(controlMode == DriveControlMode.MOVE_POSITION_SWITCH)
{
isFinished = pidPositionControllerSwitch.controlLoopUpdate(getEncoderElevatorPosition());
}
else if(controlMode == DriveControlMode.MOVE_POSITION_LOWEST)
{
isFinished = pidPositionControllerLowest.controlLoopUpdate(getEncoderElevatorPosition());
}
/*
else if(controlMode == DriveControlMode.RAW)
{
@@ -410,11 +368,6 @@ public class Elevator extends Subsystem implements ControlLoopable
public void setPeriodMs(long periodMs)
{
//PID controller
pidPositionControllerMaxScale = new SoftwarePIDPositionController(PositionPMaxScale, elevatorRight);
pidPositionControllerLowScale = new SoftwarePIDPositionController(PositionPLowScale, elevatorRight);
pidPositionControllerSwitch = new SoftwarePIDPositionController(PositionPSwitch, elevatorRight);
pidPositionControllerLowest = new SoftwarePIDPositionController(PositionPLowest, elevatorRight);
this.periodMs = periodMs;
}
@@ -434,7 +387,7 @@ public class Elevator extends Subsystem implements ControlLoopable
{
try
{
SmartDashboard.putNumber("Elevator Pos Ticks", elevatorRight.getSelectedSensorPosition(0));
SmartDashboard.putNumber("Elevator Pos Ticks", elevatorMain.getSelectedSensorPosition(0));
SmartDashboard.putNumber("Elevator Pos Inches", getElevatorHeightInchesAboveFloor());
//SmartDashboard.putData(pressed);
}
+85
View File
@@ -0,0 +1,85 @@
{
"fileName": "PathfinderOLD.json",
"name": "PathfinderOld",
"version": "2019.1.11",
"uuid": "7194a2d4-2860-4bcc-86c0-97879737d875",
"mavenUrls": [
"https://dev.imjac.in/maven"
],
"jsonUrl": "https://dev.imjac.in/maven/jaci/pathfinder/PathfinderOLD-latest.json",
"cppDependencies": [
{
"groupId": "jaci.pathfinder",
"artifactId": "Pathfinder-Core",
"version": "2019.1.11",
"libName": "pathfinder",
"configuration": "native_pathfinder_old",
"headerClassifier": "headers",
"sharedLibrary": true,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"linuxx86-64",
"windowsx86-64",
"osxx86-64",
"linuxathena",
"linuxraspbian"
]
},
{
"groupId": "jaci.pathfinder",
"artifactId": "Pathfinder-FRCSupport",
"version": "2019.1.11",
"libName": "pathfinder_frc",
"configuration": "native_pathfinder_old",
"headerClassifier": "headers",
"binaryPlatforms": []
}
],
"javaDependencies": [
{
"groupId": "jaci.pathfinder",
"artifactId": "Pathfinder-Java",
"version": "2019.1.11"
},
{
"groupId": "jaci.jniloader",
"artifactId": "JNILoader",
"version": "1.0.1"
},
{
"groupId": "jaci.pathfinder",
"artifactId": "Pathfinder-FRCSupport",
"version": "2019.1.11"
}
],
"jniDependencies": [
{
"groupId": "jaci.pathfinder",
"artifactId": "Pathfinder-JNI",
"version": "2019.1.11",
"isJar": true,
"skipInvalidPlatforms": true,
"validPlatforms": [
"linuxx86-64",
"windowsx86-64",
"osxx86-64",
"linuxathena",
"linuxraspbian"
]
},
{
"groupId": "jaci.pathfinder",
"artifactId": "Pathfinder-CoreJNI",
"version": "2019.1.11",
"isJar": true,
"skipInvalidPlatforms": true,
"validPlatforms": [
"linuxx86-64",
"windowsx86-64",
"osxx86-64",
"linuxathena",
"linuxraspbian"
]
}
]
}
+87
View File
@@ -0,0 +1,87 @@
{
"fileName": "Phoenix.json",
"name": "CTRE-Phoenix",
"version": "5.12.1",
"uuid": "ab676553-b602-441f-a38d-f1296eff6537",
"mavenUrls": [
"http://devsite.ctr-electronics.com/maven/release/"
],
"jsonUrl": "http://devsite.ctr-electronics.com/maven/release/com/ctre/phoenix/Phoenix-latest.json",
"javaDependencies": [
{
"groupId": "com.ctre.phoenix",
"artifactId": "api-java",
"version": "5.12.1"
},
{
"groupId": "com.ctre.phoenix",
"artifactId": "wpiapi-java",
"version": "5.12.1"
}
],
"jniDependencies": [
{
"groupId": "com.ctre.phoenix",
"artifactId": "cci",
"version": "5.12.1",
"isJar": false,
"skipInvalidPlatforms": true,
"validPlatforms": [
"linuxathena",
"windowsx86-64",
"linuxx86-64"
]
}
],
"cppDependencies": [
{
"groupId": "com.ctre.phoenix",
"artifactId": "wpiapi-cpp",
"version": "5.12.1",
"libName": "CTRE_Phoenix_WPI",
"headerClassifier": "headers",
"sharedLibrary": false,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"linuxathena",
"windowsx86-64",
"linuxx86-64"
]
},
{
"groupId": "com.ctre.phoenix",
"artifactId": "api-cpp",
"version": "5.12.1",
"libName": "CTRE_Phoenix",
"headerClassifier": "headers",
"sharedLibrary": false,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"linuxathena",
"windowsx86-64",
"linuxx86-64"
]
},
{
"groupId": "com.ctre.phoenix",
"artifactId": "cci",
"version": "5.12.1",
"libName": "CTRE_PhoenixCCI",
"headerClassifier": "headers",
"sharedLibrary": false,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"linuxathena",
"windowsx86-64",
"linuxx86-64"
]
},
{
"groupId": "com.ctre.phoenix",
"artifactId": "core",
"version": "5.12.1",
"libName": "CTRE_PhoenixCore",
"headerClassifier": "headers"
}
]
}
+32
View File
@@ -0,0 +1,32 @@
{
"fileName": "REVRobotics.json",
"name": "REVRobotics",
"version": "1.0.26",
"uuid": "c16ed09f-23df-4beb-87e8-460bd7fa9924",
"mavenUrls": [
"http://www.revrobotics.com/content/sw/max/sdk/maven/"
],
"jsonUrl": "http://www.revrobotics.com/content/sw/max/sdk/REVRobotics.json",
"javaDependencies": [
{
"groupId": "com.revrobotics.frc",
"artifactId": "SparkMax-java",
"version": "1.0.26"
}
],
"jniDependencies": [],
"cppDependencies": [
{
"groupId": "com.revrobotics.frc",
"artifactId": "SparkMax-cpp",
"version": "1.0.26",
"libName": "libSparkMax",
"headerClassifier": "headers",
"sharedLibrary": false,
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"linuxathena"
]
}
]
}
+33
View File
@@ -0,0 +1,33 @@
{
"fileName": "navx_frc.json",
"name": "KauaiLabs_navX_FRC",
"version": "3.1.344",
"uuid": "cb311d09-36e9-4143-a032-55bb2b94443b",
"mavenUrls": [
"https://repo1.maven.org/maven2/"
],
"jsonUrl": "https://www.kauailabs.com/dist/frc/2019/navx_frc.json",
"javaDependencies": [
{
"groupId": "com.kauailabs.navx.frc",
"artifactId": "navx-java",
"version": "3.1.344"
}
],
"jniDependencies": [],
"cppDependencies": [
{
"groupId": "com.kauailabs.navx.frc",
"artifactId": "navx-cpp",
"version": "3.1.344",
"headerClassifier": "headers",
"sourcesClassifier": "sources",
"sharedLibrary": false,
"libName": "navx_frc",
"skipInvalidPlatforms": true,
"binaryPlatforms": [
"linuxathena"
]
}
]
}