Skip to content

Commit

Permalink
Merge pull request #39 from GearUp12499-org/new_lifts
Browse files Browse the repository at this point in the history
january 17 hotfix patches
  • Loading branch information
penguinencounter authored Jan 18, 2025
2 parents 19b8d9c + ceb3bd1 commit 9af2c29
Show file tree
Hide file tree
Showing 15 changed files with 753 additions and 183 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
package org.firstinspires.ftc.teamcode;

import static java.lang.Math.abs;

import android.annotation.SuppressLint;

import com.qualcomm.hardware.kauailabs.NavxMicroNavigationSensor;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.ElapsedTime;

import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
import org.firstinspires.ftc.robotcore.external.navigation.AxesOrder;
import org.firstinspires.ftc.robotcore.external.navigation.AxesReference;
import org.firstinspires.ftc.robotcore.external.navigation.Orientation;
import org.firstinspires.ftc.teamcode.Hardware.Locks;
import org.firstinspires.ftc.teamcode.hardware.HClawProxy;
import org.firstinspires.ftc.teamcode.hardware.HSlideProxy;
import org.firstinspires.ftc.teamcode.hardware.VLiftProxy;
import org.firstinspires.ftc.teamcode.mmooover.EncoderTracking;
import org.firstinspires.ftc.teamcode.mmooover.Pose;
import org.firstinspires.ftc.teamcode.mmooover.Ramps;
import org.firstinspires.ftc.teamcode.mmooover.Speed2Power;
import org.firstinspires.ftc.teamcode.mmooover.tasks.MoveRelTask;
import org.firstinspires.ftc.teamcode.utilities.LoopStopwatch;

import java.util.function.Consumer;

import dev.aether.collaborative_multitasking.ITask;
import dev.aether.collaborative_multitasking.ITaskWithResult;
import dev.aether.collaborative_multitasking.MultitaskScheduler;
import dev.aether.collaborative_multitasking.OneShot;
import dev.aether.collaborative_multitasking.Scheduler;
import dev.aether.collaborative_multitasking.SharedResource;
import dev.aether.collaborative_multitasking.TaskGroup;
import dev.aether.collaborative_multitasking.ext.Pause;
import dev.aether.collaborative_multitasking.ext.While;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;

import com.qualcomm.robotcore.eventloop.opmode.TeleOp;

@TeleOp

public class FixStuffTeleOp extends LinearOpMode {

private Hardware hardware;
private MultitaskScheduler scheduler;
private VLiftProxy vLiftProxy;
private HSlideProxy hSlideProxy;
private HClawProxy hClawProxy;

private ITask run(Runnable it) {
return new OneShot(scheduler, it);
}

private ITask wait(double seconds) {
return new Pause(scheduler, seconds);
}

private ITask await(double milliseconds) {
return wait(milliseconds / 1000);
}

private TaskGroup groupOf(Consumer<Scheduler> contents) {
return new TaskGroup(scheduler).with(contents);
}

private void hardwareInit() {

hardware.backLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
hardware.frontLeft.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
hardware.backRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
hardware.frontRight.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
hardware.clawFlip.setPosition(Hardware.FLIP_UP);
hardware.clawFront.setPosition(Hardware.FRONT_CLOSE);

hardware.arm.setTargetPosition(0);
hardware.arm.setMode(DcMotor.RunMode.RUN_TO_POSITION);
hardware.arm.setPower(0.3);
hardware.wrist.setPosition(Hardware.WRIST_BACK);
hardware.claw.setPosition(Hardware.CLAW_CLOSE);
hardware.clawTwist.setPosition(Hardware.CLAW_TWIST_INIT);
// we don't have the proxy object to handle this for us
// so manually implement the inversion
hardware.horizontalSlide.setPosition(Hardware.RIGHT_SLIDE_IN);
hardware.horizontalLeft.setPosition(1.05 - Hardware.RIGHT_SLIDE_IN);

hardware.lightLeft.setPosition(Hardware.LAMP_PURPLE);
hardware.lightRight.setPosition(Hardware.LAMP_PURPLE);

}

public void runOpMode() {
scheduler = new MultitaskScheduler();
hardware = new Hardware(hardwareMap);
hardwareInit();

vLiftProxy = scheduler.add(new VLiftProxy(scheduler, hardware.verticalLift));
hSlideProxy = scheduler.add(new HSlideProxy(scheduler, hardware));
hClawProxy = scheduler.add(new HClawProxy(scheduler, hardware));

waitForStart();
if (isStopRequested()) return;

boolean wasX = false;

while (opModeIsActive()) {
if (gamepad1.a) {
SlideOut();
}
if (gamepad1.b) {
SlideIn();
}
boolean isX = gamepad1.x;
if (isX && !wasX) {
scheduler.add(GetSpec());
}
wasX = isX;

if (gamepad1.y) {
transfer();
}

telemetry.addData("slidePos", hardware.horizontalLeft.getPosition());
telemetry.addData("slidePos2", hardware.horizontalSlide.getPosition());
telemetry.update();
scheduler.tick();
}
}

public ITask GetSpec() {
return groupOf(it -> it.add(run(() -> hardware.claw.setPosition(Hardware.CLAW_OPEN)))
.then(await(200))
.then(run(() -> hardware.wrist.setPosition(Hardware.WRIST_UP)))
.then(await(200))
.then(run(() -> hardware.arm.setTargetPosition(65)))
.then(await(500))
.then(run(() -> hardware.claw.setPosition(Hardware.CLAW_CLOSE)))
.then(await(200))
.then(vLiftProxy.moveTo(50, 3, 0.4))
.then(run(() -> hardware.wrist.setPosition(Hardware.WRIST_BACK)))
// .then(await(200))
.then(run(() -> hardware.arm.setTargetPosition(Hardware.deg2arm(10))))
.then(await(200))
.then(vLiftProxy.moveTo(0, 5, 0))
);
}

public void SlideOut() {
hardware.clawFront.setPosition(Hardware.FRONT_OPEN);
sleep(500);
hardware.horizontalSlide.setPosition(Hardware.RIGHT_SLIDE_OUT);
hardware.horizontalLeft.setPosition(1.05 - Hardware.RIGHT_SLIDE_OUT);
sleep(500);
hardware.clawFlip.setPosition(Hardware.FLIP_DOWN);

}

public void SlideIn() {
hardware.clawFront.setPosition(Hardware.FRONT_CLOSE);
sleep(500);
hardware.clawFlip.setPosition(Hardware.FLIP_ONE_THIRD);
sleep(500);
hardware.horizontalSlide.setPosition(Hardware.SLIDE_OVERSHOOT);
hardware.horizontalLeft.setPosition(1.05 - Hardware.SLIDE_OVERSHOOT);
sleep(500);
hardware.horizontalSlide.setPosition(Hardware.RIGHT_SLIDE_IN);
hardware.horizontalLeft.setPosition(1.05 - Hardware.RIGHT_SLIDE_IN);
hardware.clawFlip.setPosition(Hardware.FLIP_UP);
}

public void FourthSample() {
hardware.clawFront.setPosition(Hardware.FRONT_OPEN);
sleep(500);
double PartialFlip = 0.167;
hardware.clawFlip.setPosition(PartialFlip);
sleep(500);
hardware.clawTwist.setPosition(0.26);
sleep(500);
hardware.horizontalSlide.setPosition(Hardware.RIGHT_SLIDE_OUT);
hardware.horizontalLeft.setPosition(1.05 - Hardware.RIGHT_SLIDE_OUT);
sleep(500);
hardware.clawFlip.setPosition(Hardware.FLIP_DOWN);
sleep(500);
hardware.clawFront.setPosition(Hardware.FRONT_CLOSE);
sleep(500);
hardware.clawTwist.setPosition(Hardware.CLAW_TWIST_INIT);
sleep(500);
hardware.horizontalSlide.setPosition(Hardware.SLIDE_OVERSHOOT);
hardware.horizontalLeft.setPosition(1.05 - Hardware.SLIDE_OVERSHOOT);
sleep(500);
hardware.horizontalSlide.setPosition(Hardware.RIGHT_SLIDE_IN);
hardware.horizontalLeft.setPosition(1.05 - Hardware.RIGHT_SLIDE_IN);
sleep(500);
hardware.clawFlip.setPosition(Hardware.FLIP_UP);
}

public void transfer() {
hardware.clawFront.setPosition(Hardware.FRONT_CLOSE);
hardware.claw.setPosition(Hardware.CLAW_OPEN);
hardware.arm.setTargetPosition(Hardware.ARM_TRANSFER_POS);
hardware.arm.setMode(DcMotor.RunMode.RUN_TO_POSITION);
hardware.arm.setPower(0.5);
hardware.wrist.setPosition(0);
sleep(500);
hardware.claw.setPosition(Hardware.CLAW_CLOSE);
sleep(500);
hardware.clawFront.setPosition(Hardware.FRONT_OPEN);
sleep(500);

hardware.arm.setTargetPosition(0);
hardware.arm.setMode(DcMotor.RunMode.RUN_TO_POSITION);
hardware.arm.setPower(0.5);
sleep(500);
hardware.wrist.setPosition(Hardware.WRIST_BACK);
sleep(500);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.firstinspires.ftc.teamcode;

import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.hardware.ColorSensor;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.HardwareMap;
Expand All @@ -9,6 +10,7 @@
import org.firstinspires.ftc.teamcode.hardware.EncoderFor;
import org.firstinspires.ftc.teamcode.hardware.HardwareMapper;
import org.firstinspires.ftc.teamcode.hardware.HardwareName;
import org.firstinspires.ftc.teamcode.hardware.Lift;
import org.firstinspires.ftc.teamcode.hardware.MotorSet;
import org.firstinspires.ftc.teamcode.hardware.Reversed;
import org.firstinspires.ftc.teamcode.hardware.ZeroPower;
Expand All @@ -21,26 +23,36 @@


public class Hardware extends HardwareMapper implements TriOdoProvider {
public static final int ARM_TRANSFER_POS = -40;
public static final double spinTickPerRev = 751.8;
public static final double RIGHT_SLIDE_OUT = 0.72;
public static final double RIGHT_SLIDE_IN = 0.45;
public static final double RIGHT_SLIDE_OUT = 0.69;
@Deprecated public static final double LEFT_SLIDE_OUT = 1.05 - RIGHT_SLIDE_OUT;
public static final double RIGHT_SLIDE_IN = 0.38;
@Deprecated public static final double LEFT_SLIDE_IN = 1.05 - RIGHT_SLIDE_IN;
public static final double CLAW_TWIST_INIT = 0.48;
public static final double SLIDE_INWARD_TIME = 0.75; // seconds
public static final double SLIDE_OUTWARD_TIME = 0.45; // seconds
public static final double SLIDE_OVERSHOOT = 0.05;
public static final double FLIP_DOWN = 0.05;
public static final double SLIDE_OVERSHOOT = 0.28;
public static final double FLIP_DOWN = 0.00;
public static final double FRONT_OPEN = 0.25;
public static final double FRONT_CLOSE = 0.07;
public static final double FLIP_UP = 0.98;
public static final double FLIP_UP = 0.95;
public static final double FLIP_ONE_THIRD = 0.33;
public static final double CLAW_CLOSE = 0.28;
public static final double CLAW_OPEN = 0.5;
public static final double WRIST_UP = 0.42;
public static final double WRIST_UP = 0.36;
public static final double WRIST_BACK = 0.30;
public static final double ARM_POWER = 0.2;
public static final double LAMP_BLUE = 0.611;
public static final double LAMP_RED = 0.28;
public static final double LAMP_ORANGE = 0.333;
public static final double LAMP_YELLOW = 0.36;
public static final double LAMP_PURPLE = 0.700;
public static final int VLIFT_MAX_HEIGHT = 825;
public static final int VLIFT_SCORE_HIGH = 790;
public static final int VLIFT_SCORE_SPECIMEN = 283;
public static final double VLIFT_CLOSENESS = 50.0;
public static final int VLIFT_POWEROFF_HEIGHT = 30;

public static int deg2arm(double degrees) {
return (int) (degrees / 360.0 * spinTickPerRev);
Expand All @@ -67,8 +79,8 @@ public static class Locks {
public static final SharedResource HSlideClaw = new SharedResource("HSlideClaw");
}

public static final double TRACK_WIDTH = 11.3385888;
public static final double FORWARD_OFFSET = 5.05905785;
public static final double TRACK_WIDTH = 11.375;
public static final double FORWARD_OFFSET = 3.062500;
public static final double ENC_WHEEL_RADIUS = 1.25984 / 2.0;
public static final int ENC_TICKS_PER_REV = 2000;

Expand Down Expand Up @@ -96,10 +108,19 @@ public static class Locks {

@HardwareName("verticalSlides")
@ZeroPower(DcMotor.ZeroPowerBehavior.BRAKE)
@Deprecated
public DcMotor verticalSlide;

@HardwareName("verticalSlide2")
@Reversed
@ZeroPower(DcMotor.ZeroPowerBehavior.BRAKE)
private DcMotor verticalSlide2;

public Lift verticalLift;

@HardwareName("verticalSlides")
@AutoClearEncoder
@Deprecated
public DcMotor encoderVerticalSlide;

@HardwareName("arm")
Expand All @@ -109,7 +130,6 @@ public static class Locks {

@EncoderFor("frontLeft")
@AutoClearEncoder
@Reversed
public Encoder encoderLeft;

@EncoderFor("backRight")
Expand All @@ -119,6 +139,7 @@ public static class Locks {

@EncoderFor("frontRight")
@AutoClearEncoder
@Reversed
public Encoder encoderRight;

@HardwareName("gyro")
Expand All @@ -136,6 +157,9 @@ public static class Locks {
@HardwareName("clawFlip")
public Servo clawFlip;

@HardwareName("clawTwist")
public Servo clawTwist;

@HardwareName("horizontalSlide")
public Servo horizontalSlide;

Expand All @@ -151,6 +175,7 @@ public static class Locks {
@HardwareName("clawColor")
public ColorSensor clawColor;


@Override
public Encoder getLeftEncoder() {
return encoderLeft;
Expand Down Expand Up @@ -198,6 +223,7 @@ public Hardware(HardwareMap hwMap) {
backLeft,
backRight
);
verticalLift = new Lift(verticalSlide, verticalSlide2);
}

}
Loading

0 comments on commit 9af2c29

Please sign in to comment.