-
Notifications
You must be signed in to change notification settings - Fork 1
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 #36 from ftc16072/increase-score-power
Added behavior trees to auto and coded a new preload place auto
- Loading branch information
Showing
16 changed files
with
333 additions
and
24 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...in/java/org/firstinspires/ftc/teamcode/ftc16072/BehaviorTrees/Actions/DriveToChamber.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,36 @@ | ||
package org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions; | ||
|
||
import com.ftcteams.behaviortrees.DebugTree; | ||
|
||
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.QQTimeoutNode; | ||
import org.firstinspires.ftc.teamcode.ftc16072.OpModes.QQOpMode; | ||
|
||
public class DriveToChamber extends QQTimeoutNode { | ||
public static final double FORWARD_SPEED = 0.3; | ||
State lastStatus = State.RUNNING; | ||
|
||
public DriveToChamber(double seconds) { | ||
super(seconds); | ||
} | ||
|
||
@Override | ||
public State tick(DebugTree debug, QQOpMode opMode) { | ||
if (lastStatus != State.RUNNING){ | ||
return lastStatus; | ||
}else{ | ||
if(hasTimedOut()){ | ||
opMode.robot.mecanumDrive.stop(); | ||
lastStatus = State.FAILURE; | ||
return State.FAILURE; | ||
} | ||
opMode.robot.mecanumDrive.move(FORWARD_SPEED,0,0); | ||
if (opMode.robot.scoreArm.isChamberContacted()){ | ||
opMode.robot.mecanumDrive.stop(); | ||
lastStatus = State.SUCCESS; | ||
return State.SUCCESS; | ||
|
||
} | ||
return State.RUNNING; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ode/src/main/java/org/firstinspires/ftc/teamcode/ftc16072/BehaviorTrees/Actions/Park.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,25 @@ | ||
package org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions; | ||
|
||
import com.ftcteams.behaviortrees.DebugTree; | ||
|
||
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.QQTimeoutNode; | ||
import org.firstinspires.ftc.teamcode.ftc16072.OpModes.QQOpMode; | ||
|
||
public class Park extends QQTimeoutNode { | ||
public Park(double seconds) { | ||
super(seconds); | ||
} | ||
|
||
@Override | ||
public State tick(DebugTree debug, QQOpMode opMode) { | ||
boolean isDoneDriving = opMode.nav.driveToPositionIN(14,-109.5,0); | ||
opMode.telemetry.addData("location",opMode.robot.otos.getOtosPosition()); | ||
if (isDoneDriving) { | ||
return State.SUCCESS; | ||
} | ||
if (hasTimedOut()) { | ||
return State.FAILURE; | ||
} | ||
return State.RUNNING; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...n/java/org/firstinspires/ftc/teamcode/ftc16072/BehaviorTrees/Actions/WaitForClawOpen.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,23 @@ | ||
package org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions; | ||
|
||
import com.ftcteams.behaviortrees.DebugTree; | ||
|
||
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.QQTimeoutNode; | ||
import org.firstinspires.ftc.teamcode.ftc16072.OpModes.QQOpMode; | ||
|
||
public class WaitForClawOpen extends QQTimeoutNode { | ||
public WaitForClawOpen(double seconds) { | ||
super(seconds); | ||
} | ||
|
||
@Override | ||
public State tick(DebugTree debug, QQOpMode opMode) { | ||
if (hasTimedOut()){ | ||
opMode.robot.scoreArm.setNotScoring(); | ||
return State.FAILURE; | ||
}else if (opMode.robot.scoringClaw.isClawOpen()){ | ||
return State.SUCCESS; | ||
} | ||
return State.RUNNING; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...main/java/org/firstinspires/ftc/teamcode/ftc16072/BehaviorTrees/Actions/WaitForScore.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,24 @@ | ||
package org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions; | ||
|
||
import com.ftcteams.behaviortrees.DebugTree; | ||
|
||
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.QQTimeoutNode; | ||
import org.firstinspires.ftc.teamcode.ftc16072.OpModes.QQOpMode; | ||
|
||
public class WaitForScore extends QQTimeoutNode { | ||
public WaitForScore(double seconds) { | ||
super(seconds); | ||
} | ||
|
||
@Override | ||
public State tick(DebugTree debug, QQOpMode opMode) { | ||
if (hasTimedOut()){ | ||
opMode.robot.scoreArm.setNotScoring(); | ||
opMode.robot.scoringClaw.open(); | ||
return State.FAILURE; | ||
}else if (opMode.robot.scoringClaw.isScoreSwitchPressed()){ | ||
return State.SUCCESS; | ||
} | ||
return State.RUNNING; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
TeamCode/src/main/java/org/firstinspires/ftc/teamcode/ftc16072/BehaviorTrees/QQNode.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,14 @@ | ||
package org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees; | ||
|
||
import com.ftcteams.behaviortrees.DebugTree; | ||
import com.ftcteams.behaviortrees.Node; | ||
|
||
import org.firstinspires.ftc.teamcode.ftc16072.OpModes.QQOpMode; | ||
|
||
abstract public class QQNode extends Node { | ||
@Override | ||
public State tick(DebugTree debug, Object obj) { | ||
return tick(debug, (QQOpMode)obj); | ||
} | ||
abstract public State tick(DebugTree debug, QQOpMode opMode); | ||
} |
24 changes: 24 additions & 0 deletions
24
...de/src/main/java/org/firstinspires/ftc/teamcode/ftc16072/BehaviorTrees/QQTimeoutNode.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,24 @@ | ||
package org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees; | ||
|
||
import com.qualcomm.robotcore.util.ElapsedTime; | ||
|
||
abstract public class QQTimeoutNode extends QQNode { | ||
ElapsedTime timer = new ElapsedTime(); | ||
public double seconds; | ||
boolean isTimerStarted; | ||
|
||
public QQTimeoutNode(double seconds){ | ||
super(); | ||
this.seconds = seconds; | ||
} | ||
public boolean hasTimedOut(){ | ||
if (!isTimerStarted){ | ||
timer.reset(); | ||
isTimerStarted = true; | ||
} | ||
if (timer.seconds() >= seconds){ | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...rc/main/java/org/firstinspires/ftc/teamcode/ftc16072/BehaviorTrees/Trees/PreloadAuto.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,35 @@ | ||
package org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Trees; | ||
|
||
/* Tree PreloadAuto for 16072 generated by http://behaviortrees.ftcteams.com */ | ||
|
||
import com.ftcteams.behaviortrees.Node; | ||
import com.ftcteams.behaviortrees.Failover; | ||
import com.ftcteams.behaviortrees.Sequence; | ||
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.DriveToChamber; | ||
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.WaitForClawOpen; | ||
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.WaitForScore; | ||
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Actions.Park; | ||
|
||
|
||
public class PreloadAuto { | ||
|
||
public static final int TIMEOUT_SECONDS = 10; | ||
|
||
public static Node root(){ | ||
return new Failover( | ||
new Sequence( | ||
new DriveToChamber(TIMEOUT_SECONDS), | ||
new WaitForClawOpen(TIMEOUT_SECONDS), | ||
new Park(TIMEOUT_SECONDS)), | ||
new Park(TIMEOUT_SECONDS)); | ||
} | ||
} | ||
|
||
/* TREE | ||
? | ||
| -> | ||
| | [DriveToChamber] | ||
| | [Score] | ||
| | [Park] | ||
| [Park] | ||
*/ |
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
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
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
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
45 changes: 45 additions & 0 deletions
45
...ode/src/main/java/org/firstinspires/ftc/teamcode/ftc16072/OpModes/NavigationPIDTuner.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,45 @@ | ||
package org.firstinspires.ftc.teamcode.ftc16072.OpModes; | ||
|
||
import com.qualcomm.robotcore.eventloop.opmode.Autonomous; | ||
import com.qualcomm.robotcore.eventloop.opmode.TeleOp; | ||
import com.qualcomm.robotcore.util.ElapsedTime; | ||
|
||
@TeleOp | ||
public class NavigationPIDTuner extends QQOpMode{ | ||
private final int autodelay = 0; | ||
|
||
ElapsedTime elapsedTime = new ElapsedTime(); | ||
private double step = 0; | ||
boolean isPlacing; | ||
boolean chamberContactWasPressed; | ||
int contactLostPos; | ||
boolean clawWasClosed; | ||
public void init(){ | ||
super.init(); | ||
robot.otos.setOtosPosition(7,-61.5,0); | ||
robot.scoringClaw.close(); | ||
} | ||
public void start(){ | ||
elapsedTime.reset(); | ||
} | ||
public void loop(){ | ||
super.loop(); | ||
|
||
if(step == 0){ | ||
boolean isDoneDriving = nav.driveToPositionIN(7.5, -37.5,0); | ||
if (isDoneDriving){ | ||
step = 1; | ||
} | ||
}else if(step == 1){ | ||
boolean isDoneDriving = nav.driveToPositionIN(7.5,-85.5,0); | ||
if (isDoneDriving){ | ||
step = 0; | ||
} | ||
} | ||
chamberContactWasPressed = robot.scoreArm.isChamberContacted(); | ||
clawWasClosed = robot.scoringClaw.isClawClosed(); | ||
} | ||
} | ||
|
||
|
||
|
62 changes: 62 additions & 0 deletions
62
...rc/main/java/org/firstinspires/ftc/teamcode/ftc16072/OpModes/PreloadAutoBehaviorTree.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,62 @@ | ||
package org.firstinspires.ftc.teamcode.ftc16072.OpModes; | ||
|
||
import com.ftcteams.behaviortrees.DebugTree; | ||
import com.ftcteams.behaviortrees.Node; | ||
import com.qualcomm.robotcore.eventloop.opmode.Autonomous; | ||
import com.qualcomm.robotcore.util.ElapsedTime; | ||
|
||
import org.firstinspires.ftc.teamcode.ftc16072.BehaviorTrees.Trees.PreloadAuto; | ||
|
||
@Autonomous | ||
public class PreloadAutoBehaviorTree extends QQOpMode{ | ||
boolean clawWasClosed; | ||
boolean done; | ||
Node root = PreloadAuto.root(); | ||
DebugTree debugTree = new DebugTree(); | ||
ElapsedTime moveTimer = new ElapsedTime(); | ||
double INIT_MOVE_TIME_SECONDS = 1; | ||
double INIT_MOVE_SPEED = -0.2; | ||
@Override | ||
public void init(){ | ||
super.init(); | ||
moveTimer.reset(); | ||
robot.scoreArm.goToScoring(); | ||
robot.scoringClaw.close(); | ||
} | ||
|
||
@Override | ||
public void init_loop() { | ||
if (moveTimer.seconds() < INIT_MOVE_TIME_SECONDS){ | ||
robot.mecanumDrive.move(INIT_MOVE_SPEED,0,0); | ||
}else { | ||
robot.mecanumDrive.stop(); | ||
robot.controlHub.resetGyro(); | ||
} | ||
robot.scoreArm.update(telemetry); | ||
|
||
} | ||
public void start(){ | ||
robot.otos.setOtosPosition(7,-61.5,0); | ||
} | ||
|
||
public void loop() { | ||
super.loop(); | ||
if (robot.scoringClaw.isClawClosed() && !clawWasClosed) { | ||
robot.intakeClaw.open(); | ||
robot.scoreArm.goToPlace(); | ||
|
||
} | ||
if (robot.scoringClaw.isScoreSwitchPressed()){ | ||
robot.scoreArm.setNotScoring(); | ||
} | ||
if(!done){ | ||
Node.State state = root.tick(debugTree, this); | ||
telemetry.addData("BT",debugTree); | ||
if(state == Node.State.SUCCESS){ | ||
done = true; | ||
} | ||
} | ||
clawWasClosed = robot.scoringClaw.isClawClosed(); | ||
} | ||
} | ||
|
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
Oops, something went wrong.