Skip to content

Commit 4896575

Browse files
committed
Change autonomous to implement AutonomousBase
This change allows AutonomousBase to be implemented thus creating a much easier to use API. This change will make it much easier to deal with all the potential changes for the 2018-2019 season becase user code will not have to change
1 parent 13299b1 commit 4896575

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

Autonomous/AutonomousBase.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.firstinspires.ftc.teamcode.FTC_API.Autonomous;
22

3+
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
34
import com.qualcomm.robotcore.hardware.HardwareMap;
4-
import org.firstinspires.ftc.robotcore.external.Telemetry;
55
import org.firstinspires.ftc.teamcode.FTC_API.Autonomous.Modules.Module;
66
import org.firstinspires.ftc.teamcode.FTC_API.Robot.RobotBase;
77

@@ -11,9 +11,8 @@
1111
* Base autonomous class that manages modules and running them on time
1212
*/
1313

14-
public class AutonomousBase {
14+
abstract public class AutonomousBase extends OpMode{
1515
public RobotBase robot;
16-
private Telemetry telemetry = null;
1716
private Module[][] steps;
1817
private int currentStep = 0;//zero indexed
1918
private int currentPosition = 0;
@@ -22,7 +21,7 @@ public class AutonomousBase {
2221

2322
private boolean isFirstLoop = true;
2423

25-
public void init(HardwareMap map, RobotBase robot, Module[][] steps) {
24+
protected void init(HardwareMap map, RobotBase robot, Module[][] steps) {
2625
robot.init(map);//starts and initializes the robot
2726
robot.start();
2827
this.steps = steps;
@@ -31,7 +30,10 @@ public void init(HardwareMap map, RobotBase robot, Module[][] steps) {
3130
this.robot = robot;
3231
}
3332

33+
abstract public void init();
34+
3435
public void loop() {
36+
tick();//run user code
3537
robot.tick();//ticks the robot automatically
3638

3739
if (!isDone) {
@@ -67,13 +69,12 @@ public void loop() {
6769
}
6870
}
6971

70-
public RobotBase getRobot() {
71-
return robot;
72-
}
72+
//can be overridden by the user to do stuff every loop
73+
public void tick(){
7374

74-
public AutonomousBase setTelemetry(Telemetry telemetry) {
75-
this.telemetry = telemetry;
76-
return this;
7775
}
7876

77+
public RobotBase getRobot() {
78+
return robot;
79+
}
7980
}

Examples/SimpleAutonomous.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
44
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
5-
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
6-
75
import org.firstinspires.ftc.teamcode.FTC_API.Autonomous.AutonomousBase;
86
import org.firstinspires.ftc.teamcode.FTC_API.Autonomous.Modules.CallFunction;
97
import org.firstinspires.ftc.teamcode.FTC_API.Autonomous.Modules.Module;
@@ -14,8 +12,7 @@
1412
*/
1513
@Disabled
1614
@Autonomous(name = "Simple Autonomous")
17-
public class SimpleAutonomous extends OpMode {
18-
private AutonomousBase auto = new AutonomousBase();
15+
public class SimpleAutonomous extends AutonomousBase {
1916
private SimpleRobot bot = new SimpleRobot();
2017
private final Module[][] steps = new Module[][]{
2118
{new DriveTime().setSpeeds(1, 1).setTime(2000)},
@@ -30,13 +27,11 @@ public class SimpleAutonomous extends OpMode {
3027

3128
@Override
3229
public void init() {
33-
auto.init(hardwareMap, bot, steps);
30+
init(hardwareMap, bot, steps);
3431
}
3532

3633
@Override
37-
public void loop() {
38-
auto.loop();
39-
40-
telemetry.addData("Test", bot.drive.leftMotor.getPower());//Add telemetry
34+
public void tick(){
35+
telemetry.addLine("Wow this works!");
4136
}
4237
}

0 commit comments

Comments
 (0)