Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zigathustra committed Jan 17, 2024
1 parent 38f3159 commit c9f6175
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,15 @@ public void runOpMode() {

// Place pixel on correct spike mark and return to escape position
// Use propDirection determined using webcam during init
placePropPixel(propDirection, riggingDirection);
placePropPixel(propDirection, riggingDirection);

roughTravelToBoard(boardDirection, riggingDirection);
roughTravelToBoard(boardDirection, riggingDirection);

visionSensor.goToAprilTagDetectionMode();

targetAprilTagNumber = getTargetAprilTagNumber(alliance, propDirection);

roughAlignToAprilTag(boardDirection, targetAprilTagNumber, startPosition);

roughAlignToAprilTag(boardDirection, targetAprilTagNumber, startPosition);
// if (runTimer.time() <= orientMaxTime()) {
// Correct strafe to directly face the target April Tag
autoOrientToAprilTag(visionSensor, targetAprilTagNumber, boardDirection);
Expand All @@ -91,13 +90,19 @@ public void runOpMode() {
// }

// if (runTimer.time() <= parkMaxTime()) {
if (opModeIsActive()) {

park(boardDirection, targetAprilTagNumber, parkDirection);
}
// }
// telemetry.addData("finish park Time: ",runTimer.time());
// telemetry.update();
// sleep(1000);
// Lower lift, lower wrist, open grabber
setToTeleopStartingPosition();

if (opModeIsActive()) {
setToTeleopStartingPosition();
}
}

protected int determineRiggingDirection() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class Constants {
public static final DcMotor.Direction drivetrainRightRearDirection = DcMotor.Direction.FORWARD;
public static final double maxNormalSpeed = 0.8;
public static final double maxCreepSpeed = 0.15;
public static final double maxAutoSpeed = 0.7;
public static final double maxAutoSpeed = 0.75;
public static final double autoTurnGain = 0.02; // Larger is more responsive, but also less stable
public static final double autoDriveGain = 0.03;
public static final double maxAutoStrafeSpeed = 0.7;
public static final double maxAutoStrafeSpeed = 0.75;
public static final double maxAutoCorrectionDriveSpeed = 0.5; // Max driving speed for better distance accuracy
public static final double maxAutoCorrectionTurnSpeed = 0.5; // Max Turn speed to limit turn rate
public static final double autoHeadingThreshold = 0.5; // How close the heading must be to the target
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package org.firstinspires.ftc.teamcode.opmode;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.util.ElapsedTime;

import org.firstinspires.ftc.teamcode.common.Alliance;
import org.firstinspires.ftc.teamcode.common.Bot;
import org.firstinspires.ftc.teamcode.common.Constants;
import org.firstinspires.ftc.teamcode.common.ParkPosition;
import org.firstinspires.ftc.teamcode.common.PropDirection;
import org.firstinspires.ftc.teamcode.common.PropPipeline;
import org.firstinspires.ftc.teamcode.common.StartPosition;

import org.firstinspires.ftc.teamcode.common.VisionSensor;
import org.firstinspires.ftc.teamcode.auto.AutoMaster;
import org.firstinspires.ftc.vision.apriltag.AprilTagProcessor;


@Autonomous(name = "BoardPlacementTest", group = "Test")
public class BoardPlacementTest extends AutoMaster {
public BoardPlacementTest() {
super(Alliance.RED, StartPosition.NEAR, ParkPosition.CORNER);
}
public void runOpMode() {
int riggingDirection;
int boardDirection;
int parkDirection;
int targetAprilTagNumber;
PropPipeline propProcessor = null;
AprilTagProcessor aprilTagProcessor;
PropDirection propDirection = null;
ElapsedTime runTimer = new ElapsedTime();

bot = new Bot(this, Constants.maxAutoSpeed);

visionSensor = new VisionSensor(this, alliance);

riggingDirection = determineRiggingDirection();

boardDirection = determineBoardDirection(riggingDirection);

parkDirection = determineParkDirection(parkPosition, boardDirection);

visionSensor.goToPropDetectionMode();

bot.wristDown();
bot.grabberClose();
sleep(500);

while (!isStarted() && !isStopRequested()) {
propDirection = visionSensor.getPropDirection();

telemetry.addData("Prop Position: ", propDirection);
telemetry.update();

// Don't burn CPU cycles busy-looping in this sample
sleep(50);
}
runTimer.reset();
visionSensor.goToNoSensingMode();
setToLowCruisingPosition();

// Move forward to escape position
// bot.moveStraightForDistance(Constants.pdDistanceToEscapePosition);

// Place pixel on correct spike mark and return to escape position
// Use propDirection determined using webcam during init
// placePropPixel(propDirection, riggingDirection);

// roughTravelToBoard(boardDirection, riggingDirection);

visionSensor.goToAprilTagDetectionMode();

// targetAprilTagNumber = getTargetAprilTagNumber(alliance, propDirection);

// roughAlignToAprilTag(boardDirection, targetAprilTagNumber, startPosition);

// if (runTimer.time() <= orientMaxTime()) {
// // Correct strafe to directly face the target April Tag
// autoOrientToAprilTag(visionSensor, targetAprilTagNumber, boardDirection);
// }

if (runTimer.time() <= placeMaxTime()) { // Correct strafe to directly face the target April Tag
placePixelOnBoard();
}

// if (runTimer.time() <= parkMaxTime()) {
// park(boardDirection, targetAprilTagNumber, parkDirection);
// }
// telemetry.addData("finish park Time: ",runTimer.time());
// telemetry.update();
// sleep(1000);
// Lower lift, lower wrist, open grabber
setToTeleopStartingPosition();
}

protected void placePixelOnBoard() {
bot.moveStraightForDistance(Constants.boardApproachDistance);
bot.strafeForDistance(-Constants.sensorToDrivetrainMiddle);
bot.liftStopAtPosition(Constants.liftAutoBoardProbePosition);
bot.wristDown();
// sleep(500);
bot.creepUntilContact();
bot.creepStraightForDistance(-Constants.boardOffsetDistance);
bot.wristUp();
bot.liftStopAtPosition(Constants.liftAutoBoardPlacementPosition);
sleep(250);
bot.creepStraightForDistance(Constants.boardOffsetDistance + 4.5);
// bot.liftStopAtPosition(Constants.liftAutoBoardPosition - 150);
bot.grabberOpen();
sleep(250);
// bot.liftStopAtPosition(Constants.liftAutoBoardPosition + 150);
// sleep(250);
bot.moveStraightForDistance(-Constants.boardEscapeDistance);
}

}

0 comments on commit c9f6175

Please sign in to comment.