ElectroDromos

Autonomous Usage

How to use Pedro Pathing and ElectroDromos in autonomous

We now have everything needed to build an autonomous: a follower, Poses, paths, and a way to follow them.

If you need to revisit a step, see Setting Up Your Autonomous, Creating a Pose, Creating a Path, or Following a Path.

We'll look at how to build an autonomous both without Ivy and with Ivy.

With Ivy

Ivy lets us organize the same autonomous as commands instead of manually keeping track of states.

Add the Ivy imports:

ExampleAuto.java
import com.pedropathing.ivy.Command;
import com.pedropathing.ivy.Scheduler;

import static com.pedropathing.ivy.Scheduler.schedule;
import static com.pedropathing.ivy.groups.Groups.sequential;
import static com.pedropathing.ivy.pedro.PedroCommands.follow;

For a larger autonomous, create the Poses the robot needs to visit:

ExampleAuto.java
private final PoseFactory poseFactory = PoseFactory.degrees();

private final Pose startPose = poseFactory.of(24, 24, 0);
private final Pose scorePose = poseFactory.of(48, 48, 90);
private final Pose parkPose = poseFactory.of(72, 48, 90);

Creating the Paths

Create the paths inside of their own methods, calling each method should return a Path object:

ExampleAuto.java
private Path startToScore() {
    return line(startPose, scorePose).linear(startPose, scorePose);
}

private Path park(){
    return line(scorePose, parkPose).linear(scorePose, parkPose);
}

Creating the Routine

sequential() runs each command one after another:

ExampleAuto.java
private Command autoRoutine() {
    return sequential(
            follow(follower, startToScore()),
            // Add mechanism commands here.
            follow(follower, park())
    );
}

The second path begins after the first follow() command finishes.

Other Ivy commands can be placed between the paths or run alongside them using different command groups.

Running the Routine

Reset Ivy and create the follower inside init():

ExampleAuto.java
@Override
public void init() {
    Scheduler.reset();

    follower = Constants.create(hardwareMap);
    follower.setPose(startPose);
    follower.update();
}

Schedule the routine inside start():

ExampleAuto.java
@Override
public void start() {
    schedule(autoRoutine());
}

Then update both systems inside loop():

ExampleAuto.java
@Override
public void loop() {
    follower.update();
    Scheduler.execute();
    // add your other methods needed in the loop here
}

Tip

See the Ivy documentation to learn about commands, sequential groups, parallel groups, and other ways to organize an autonomous.

Complete example

And that is how you make an Autonomous with Ivy! Here is a completed version for reference, with ElectroDromos's loop timer and a mechanism motor added.

ExampleAuto.java
import com.pedropathing.api.PoseFactory;
import com.pedropathing.follower.Follower;
import com.pedropathing.ivy.Command;
import com.pedropathing.ivy.Scheduler;
import com.pedropathing.math.Pose;
import com.pedropathing.paths.Path;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import me.munchem.electrodromos.LoopTimer;
import me.munchem.electrodromos.Dromos;
import me.munchem.electrodromos.hardware.DromosMotor;
import org.firstinspires.ftc.teamcode.pedro.Constants;

import static com.pedropathing.api.Paths.line;
import static com.pedropathing.ivy.Scheduler.schedule;
import static com.pedropathing.ivy.groups.Groups.sequential;
import static com.pedropathing.ivy.pedro.PedroCommands.follow;

@Autonomous
public class ExampleAuto extends OpMode {
    private Follower follower;   // Pedro Pathing, built with ElectroDromos in Constants.create
    private LoopTimer loop;      // ElectroDromos
    private DromosMotor lift;     // ElectroDromos: a write-caching mechanism motor
    private final PoseFactory poseFactory = PoseFactory.degrees();

    // Poses
    private final Pose startPose = poseFactory.of(24, 24, 0);
    private final Pose scorePose = poseFactory.of(48, 48, 90);
    private final Pose parkPose = poseFactory.of(72, 48, 90);

    // Path methods
    private Path startToScore() {
        return line(startPose, scorePose).linear(startPose, scorePose);
    }

    private Path park(){
        return line(scorePose, parkPose).linear(scorePose, parkPose);
    }

    private Command autoRoutine() {
        return sequential(
                follow(follower, startToScore()),
                // Add mechanism commands here.
                follow(follower, park())
        );
    }

    @Override
    public void init() {
        Scheduler.reset();

        follower = Constants.create(hardwareMap);
        follower.setPose(startPose);
        follower.update();

        loop = Dromos.loopTimer(follower);
        lift = new DromosMotor(hardwareMap, "lift");
    }

    @Override
    public void start() {
        loop.reset();   // don't count the wait on init
        schedule(autoRoutine());
    }

    @Override
    public void loop() {
        follower.update();   // once per loop: moves the robot and ticks the loop timer
        Scheduler.execute();
        // add your other methods needed in the loop here

        telemetry.addData("X", follower.pose().x());
        telemetry.addData("Y", follower.pose().y());
        telemetry.addData("Heading", Math.toDegrees(follower.pose().heading()));
        telemetry.addData("Follower Mode", follower.mode());
        telemetry.addData("Loop Hz", loop.hz());
        telemetry.update();
    }
}

Using other command libraries

We strongly recommend Ivy because it has builtin integration with PedroPathing. In addition, it is very simple and neat to create your own commands for your subystems with. If you want to use other command libraries, refer to Following a path on how to make your own follow command.

Last updated on