Skip to content

Commit

Permalink
Merge pull request #69 from ftc16072/RoadRunnerTuning
Browse files Browse the repository at this point in the history
Road runner tuning
  • Loading branch information
ImaginaryCeiling authored Feb 19, 2024
2 parents 75e28e3 + 452a4d5 commit 5d1b5e1
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 137 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions;

import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories.SetLeftSpikeTrajectory;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories.SetMiddleSpikeTrajectory;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories.SetRightSpikeTrajectory;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Node;
import org.firstinspires.ftc.teamcode.ftc16072.Mechanisms.PixelServo;
import org.firstinspires.ftc.teamcode.ftc16072.OpModes.QQOpMode;

public class ReleaseAutoPixel extends Node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,30 @@

public class FollowTrajectory extends Node{
boolean started;
TrajectorySequence trajectorySequence;
String trajectorySequenceString;

@Override
public State tick(QQOpMode opmode) {
if(!started){
TrajectorySequence trajectorySequence = opmode.board.get(TrajectorySequence.class, "TrajectorySequence");
trajectorySequence = opmode.board.get(TrajectorySequence.class, "TrajectorySequence");
trajectorySequenceString = opmode.board.get(String.class, "TrajectorySequenceString");
if(trajectorySequence == null){
return State.FAILURE;
}
opmode.robot.nav.startNewTrajectorySequence(trajectorySequence);
started = true;
}
else{

opmode.robot.nav.update();
if (!opmode.robot.nav.isBusy()){
return State.SUCCESS;
}
}
opmode.telemetry.addData("Current trajectory:", trajectorySequence);


return State.RUNNING;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories;
package org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories.LeftSpikeTrajectory;

import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Node;
import org.firstinspires.ftc.teamcode.ftc16072.OpModes.QQOpMode;
Expand All @@ -7,21 +7,19 @@
import org.firstinspires.ftc.teamcode.rr_trajectorysequence.TrajectorySequenceBuilder;

public class SetLeftSpikeTrajectory extends Node {
public static final int FORWARD_DISTANCE_INCHES = 20;
public static final int LEFT_DISTANCE_INCHES = 5;
public static final int FORWARD_DISTANCE_INCHES = 23;


@Override
public State tick(QQOpMode opMode) {
TrajectorySequenceBuilder builder = opMode.robot.nav.trajectorySequenceBuilder(opMode.robot.nav.getPoseEstimate());
TrajectorySequence sequence = builder.back(FORWARD_DISTANCE_INCHES).
//strafeLeft(LEFT_DISTANCE_INCHES).
//strafeRight(LEFT_DISTANCE_INCHES).
forward(FORWARD_DISTANCE_INCHES).
build();
if (sequence == null){
return State.FAILURE;
}
opMode.board.add("TrajectorySequence", sequence);
opMode.board.add("TrajectorySequenceString", "Left Spike Trajectory 1");
opMode.board.add("SpikePosition", SpikePosition.LEFT);
return State.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories.LeftSpikeTrajectory;

import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Node;
import org.firstinspires.ftc.teamcode.ftc16072.OpModes.QQOpMode;
import org.firstinspires.ftc.teamcode.ftc16072.Util.SpikePosition;
import org.firstinspires.ftc.teamcode.rr_trajectorysequence.TrajectorySequence;
import org.firstinspires.ftc.teamcode.rr_trajectorysequence.TrajectorySequenceBuilder;

public class SetLeftSpikeTrajectoryPart2 extends Node {

public static final int LEFT_DISTANCE_INCHES = 8;

@Override
public State tick(QQOpMode opMode) {
TrajectorySequenceBuilder builder = opMode.robot.nav.trajectorySequenceBuilder(opMode.robot.nav.getPoseEstimate());
TrajectorySequence sequence = builder
//right because robot is facing backward
.strafeRight(LEFT_DISTANCE_INCHES)
.build();
if (sequence == null){
return State.FAILURE;
}
opMode.board.add("TrajectorySequence", sequence);
opMode.board.add("TrajectorySequenceString", "Left Spike Trajectory 2");

opMode.board.add("SpikePosition", SpikePosition.LEFT);
return State.SUCCESS;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories;
package org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories.RightSpikeTrajectory;

import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Node;
import org.firstinspires.ftc.teamcode.ftc16072.OpModes.QQOpMode;
Expand All @@ -8,15 +8,12 @@

public class SetRightSpikeTrajectory extends Node {
public static final int FORWARD_DISTANCE_INCHES = 20;
public static final int RIGHT_DISTANCE_INCHES = 5;


@Override
public State tick(QQOpMode opMode) {
TrajectorySequenceBuilder builder = opMode.robot.nav.trajectorySequenceBuilder(opMode.robot.nav.getPoseEstimate());
TrajectorySequence sequence = builder.forward(FORWARD_DISTANCE_INCHES).
strafeRight(RIGHT_DISTANCE_INCHES).
strafeLeft(RIGHT_DISTANCE_INCHES).
back(FORWARD_DISTANCE_INCHES).
TrajectorySequence sequence = builder.back(FORWARD_DISTANCE_INCHES).
build();
if (sequence == null){
return State.FAILURE;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories.RightSpikeTrajectory;

import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Node;
import org.firstinspires.ftc.teamcode.ftc16072.OpModes.QQOpMode;
import org.firstinspires.ftc.teamcode.ftc16072.Util.SpikePosition;
import org.firstinspires.ftc.teamcode.rr_trajectorysequence.TrajectorySequence;
import org.firstinspires.ftc.teamcode.rr_trajectorysequence.TrajectorySequenceBuilder;

public class SetRightSpikeTrajectoryPart2 extends Node {

public static final int RIGHT_DISTANCE_INCHES = 20;

@Override
public State tick(QQOpMode opMode) {
TrajectorySequenceBuilder builder = opMode.robot.nav.trajectorySequenceBuilder(opMode.robot.nav.getPoseEstimate());
TrajectorySequence sequence = builder.strafeLeft(RIGHT_DISTANCE_INCHES)
.build();
if (sequence == null){
return State.FAILURE;
}
opMode.board.add("TrajectorySequence", sequence);
opMode.board.add("SpikePosition", SpikePosition.RIGHT);
return State.SUCCESS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
import org.firstinspires.ftc.teamcode.rr_trajectorysequence.TrajectorySequenceBuilder;

public class SetMiddleSpikeTrajectory extends Node {
public static final int FORWARD_DISTANCE_INCHES = 20;
public static final int FORWARD_DISTANCE_INCHES = 24;
public static final int BACKWARD_DISTANCE_INCHES = 20;

@Override
public State tick(QQOpMode opMode) {
TrajectorySequenceBuilder builder = opMode.robot.nav.trajectorySequenceBuilder(opMode.robot.nav.getPoseEstimate());
TrajectorySequence sequence = builder
.back(FORWARD_DISTANCE_INCHES)
.back(FORWARD_DISTANCE_INCHES).
build();
if (sequence == null){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Trees;

import org.checkerframework.checker.units.qual.A;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.SpikeLocationTelemetry;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.PlacePurplePixel;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.ReleaseAutoPixel;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.SetBackboardFromSpikeTrajectory;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.SpikeLocationTelemetry;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories.FollowTrajectory;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories.SetLeftSpikeTrajectory;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories.LeftSpikeTrajectory.SetLeftSpikeTrajectory;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories.LeftSpikeTrajectory.SetLeftSpikeTrajectoryPart2;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories.RightSpikeTrajectory.SetRightSpikeTrajectoryPart2;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories.SetMiddleSpikeTrajectory;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories.SetRightSpikeTrajectory;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Trajectories.RightSpikeTrajectory.SetRightSpikeTrajectory;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Conditions.IsLeftSpike;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Conditions.IsRightSpike;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Failover;
Expand All @@ -31,22 +30,36 @@ public class SpikeAutoTree {
*/
public static Node root(){
return new Sequence(
//shows spike location
new SpikeLocationTelemetry(),
//checks and sets trajectory for each spike position
new Failover(
new Sequence(
new IsLeftSpike(),
new SetLeftSpikeTrajectory()
new SetLeftSpikeTrajectory(),
new FollowTrajectory(),
new SetLeftSpikeTrajectoryPart2(),
new FollowTrajectory()

),
new Sequence(
new IsRightSpike(),
new SetRightSpikeTrajectory()
new SetRightSpikeTrajectory(),
new FollowTrajectory(),
new SetRightSpikeTrajectoryPart2(),
new FollowTrajectory()
),
new SetMiddleSpikeTrajectory()
new Sequence(
new SetMiddleSpikeTrajectory(),
new FollowTrajectory()
)
),

new FollowTrajectory(),
//Move servo to release purple pixel
new ReleaseAutoPixel(),
//set trajectory to backboard from tape location
new SetBackboardFromSpikeTrajectory(),
//follow backboard trajectory
new FollowTrajectory()

);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
@Config

public class PixelServo implements Mechanism{
public static final double RELEASE_POSITION= .7; //Tuned
public static final double RELEASE_POSITION= .4; //Tuned

Servo pixelServo;
@Override
public void init(HardwareMap hwMap) {
Expand All @@ -26,7 +27,7 @@ public void releasePixel(){

@Override
public List<QQtest> getTests() {
return Collections.singletonList(new TestServo("Pixel Servo", .8, 0.6
return Collections.singletonList(new TestServo("Pixel Servo", RELEASE_POSITION, 0.67
, pixelServo));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ abstract public class SpikeAutoBase extends VisionBase{
@Override
public void init(){
super.init();
board.add("proploocation", robot.cameraBack.getTeamPropPosition());
robot.makeDriveOnly();

telemetry.addData("prop Location", robot.cameraBack.getTeamPropPosition());
}
@Override
public void init_loop(){
telemetry.addData("PropLocation: ", robot.cameraBack.getTeamPropPosition());
}
@Override
public void start(){
board.add("proplocation", robot.cameraBack.getTeamPropPosition());
}
@Override
public void loop() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
package org.firstinspires.ftc.teamcode.ftc16072.OpModes;
package org.firstinspires.ftc.teamcode.ftc16072.OpModes.SpikeTrajectories;

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

import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Node;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Trees.SpikeAutoTree;
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Trees.TeleopTree;
import org.firstinspires.ftc.teamcode.ftc16072.OpModes.SpikeAutoBase;
import org.firstinspires.ftc.teamcode.ftc16072.Util.Alliance;
import org.firstinspires.ftc.teamcode.ftc16072.Util.StartPosition;
@Autonomous
public class BlueClose_SpikeAuto extends SpikeAutoBase {



@Override
public void init(){
super.init();
board.add("Alliance", Alliance.BLUE);
board.add("StartPosition", StartPosition.CLOSE);


}

@Override
public void init_loop() {
super.init_loop();
telemetry.addData("Prop Location: ", robot.cameraBack.getTeamPropPosition());
}
}
Loading

0 comments on commit 5d1b5e1

Please sign in to comment.