-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from STMARobotics/kyen/slide-code
Kyen/slide code
- Loading branch information
Showing
4 changed files
with
194 additions
and
2 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ArmSubsystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package org.firstinspires.ftc.teamcode; | ||
|
||
import com.qualcomm.robotcore.hardware.DcMotor; | ||
import com.qualcomm.robotcore.hardware.DcMotorEx; | ||
import com.qualcomm.robotcore.hardware.HardwareMap; | ||
|
||
import org.firstinspires.ftc.robotcore.external.Telemetry; | ||
import org.firstinspires.ftc.robotcore.external.navigation.CurrentUnit; | ||
|
||
public class ArmSubsystem { | ||
private DcMotor armMotor; | ||
|
||
private HardwareMap hardwareMap; | ||
private Telemetry telemetry; | ||
|
||
public static final String ARM_MOTOR = "arm_motor"; | ||
|
||
final double ARM_TICKS_PER_DEGREE = | ||
28 // number of encoder ticks per rotation of the bare motor | ||
* 250047.0 / 4913.0 // This is the exact gear ratio of the 50.9:1 Yellow Jacket gearbox | ||
* 100.0 / 20.0 // This is the external gear reduction, a 20T pinion gear that drives a 100T hub-mount gear | ||
* 1/360.0; // we want ticks per degree, not per rotation | ||
final double ARM_COLLAPSED_INTO_ROBOT = 0; | ||
final double ARM_COLLECT = 15 * ARM_TICKS_PER_DEGREE; | ||
final double ARM_CLEAR_BARRIER = 15 * ARM_TICKS_PER_DEGREE; | ||
final double ARM_SCORE_SPECIMEN = 90 * ARM_TICKS_PER_DEGREE; | ||
final double ARM_SCORE_SAMPLE_IN_LOW = 90 * ARM_TICKS_PER_DEGREE; | ||
final double ARM_ATTACH_HANGING_HOOK = 110 * ARM_TICKS_PER_DEGREE; | ||
final double ARM_WINCH_ROBOT = 10 * ARM_TICKS_PER_DEGREE; | ||
|
||
static double FUDGE_FACTOR_DEGREES = 15; | ||
|
||
public ArmSubsystem(HardwareMap hm, Telemetry telemetry) { | ||
this.hardwareMap = hm; | ||
this.telemetry = telemetry; | ||
|
||
armMotor=hm.get(DcMotor.class, ARM_MOTOR); | ||
armMotor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE); | ||
((DcMotorEx)armMotor).setCurrentAlert(5, CurrentUnit.AMPS); | ||
armMotor.setTargetPosition(0); | ||
armMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
armMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
|
||
armMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER); | ||
} | ||
|
||
public void moveToArmToCollectPosition(double alteration){ | ||
|
||
setArmPosition(ARM_COLLECT + getAlterationDegrees(alteration)); | ||
} | ||
|
||
private double getAlterationDegrees(double alteration) { | ||
return FUDGE_FACTOR_DEGREES * ARM_TICKS_PER_DEGREE * alteration; | ||
} | ||
|
||
public void moveArmToClearBarrierPosition(double alteration){ | ||
setArmPosition(ARM_CLEAR_BARRIER + (getAlterationDegrees(alteration))); | ||
} | ||
public void moveArmToScoreSampleInLowPosition(double alteration){ | ||
setArmPosition(ARM_SCORE_SAMPLE_IN_LOW + (getAlterationDegrees(alteration))); | ||
} | ||
public void moveArmToCollapsedIntoRobotPosition(double alteration){ | ||
setArmPosition(ARM_COLLAPSED_INTO_ROBOT + (getAlterationDegrees(alteration))); | ||
} | ||
public void moveArmToScoreSpecimenPosition(double alteration){ | ||
setArmPosition(ARM_SCORE_SPECIMEN + (getAlterationDegrees(alteration))); | ||
} | ||
public void moveArmToAttachHangingHookPosition(double alteration){ | ||
setArmPosition(ARM_ATTACH_HANGING_HOOK + (getAlterationDegrees(alteration))); | ||
} | ||
public void moveArmToWinchRobotPosition(double alteration){ | ||
setArmPosition(ARM_WINCH_ROBOT + (getAlterationDegrees(alteration))); | ||
} | ||
private void setArmPosition(double position) { | ||
armMotor.setTargetPosition((int)(position)); | ||
((DcMotorEx) armMotor).setVelocity(2100); | ||
armMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/SlideSubsystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.firstinspires.ftc.teamcode; | ||
|
||
import com.qualcomm.robotcore.hardware.DcMotor; | ||
import com.qualcomm.robotcore.hardware.DcMotorEx; | ||
import com.qualcomm.robotcore.hardware.DcMotorSimple; | ||
import com.qualcomm.robotcore.hardware.HardwareMap; | ||
|
||
import org.firstinspires.ftc.robotcore.external.Telemetry; | ||
|
||
public class SlideSubsystem { | ||
|
||
private DcMotor slideMotor; | ||
public static final String SLIDE_MOTOR="slide-motor"; | ||
|
||
public static final double LIFT_TICKS_PER_MM = (111132.0 / 289.0) / 120.0; | ||
|
||
public static final double LIFT_COLLAPSED = 0 * LIFT_TICKS_PER_MM; | ||
public static final double LIFT_SCORING_IN_LOW_BASKET = 0 * LIFT_TICKS_PER_MM; | ||
public static final double LIFT_SCORING_IN_HIGH_BASKET = 480 * LIFT_TICKS_PER_MM; | ||
|
||
double liftPosition = LIFT_COLLAPSED; | ||
|
||
private HardwareMap hardwareMap; | ||
private Telemetry telemetry; | ||
|
||
public SlideSubsystem (HardwareMap hm, Telemetry telemetry){ | ||
this.hardwareMap = hm; | ||
this.telemetry = telemetry; | ||
|
||
slideMotor = hardwareMap.get(DcMotor.class, SLIDE_MOTOR); | ||
|
||
slideMotor.setDirection(DcMotorSimple.Direction.REVERSE); | ||
slideMotor.setTargetPosition(0); | ||
slideMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
slideMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER); | ||
} | ||
|
||
public void changePosition(int positionDelta){ | ||
this.liftPosition = this.liftPosition + positionDelta; | ||
setPosition(this.liftPosition); | ||
} | ||
|
||
public void setPosition(double liftPosition) { | ||
slideMotor.setTargetPosition((int) (liftPosition)); | ||
|
||
((DcMotorEx) slideMotor).setVelocity(2100); | ||
slideMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/WristSubsystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.firstinspires.ftc.teamcode; | ||
|
||
import com.qualcomm.robotcore.hardware.HardwareMap; | ||
import com.qualcomm.robotcore.hardware.Servo; | ||
|
||
import org.firstinspires.ftc.robotcore.external.Telemetry; | ||
|
||
public class WristSubsystem { | ||
public static final String WRIST_SERVO = "wrist-servo"; | ||
|
||
private HardwareMap hardwareMap; | ||
private Telemetry telemetry; | ||
|
||
private Servo servo; | ||
|
||
public WristSubsystem(HardwareMap hm, Telemetry telemetry){ | ||
this.hardwareMap = hm; | ||
this.telemetry = telemetry; | ||
|
||
servo = hardwareMap.get(Servo.class, WRIST_SERVO); | ||
} | ||
|
||
public void moveToPosition(double position){ | ||
servo.setPosition(position); | ||
} | ||
} |