Pedro Pathing
The pedro module connects Pedro Pathing to NextFTC.
PedroMechanism stores your Pedro Follower and updates it every loop,
NextMecanum drives the follower with NextMotors,
and Pedro’s geometry types can be logged with Telemetry.
The commands for following paths come from Ivy’s pedro module.
To add the module to your project, see Installation.
PedroMechanism
Section titled “PedroMechanism”Add a PedroMechanism to your robot’s mechanisms and pass it a function that builds your Follower from a HardwareMap,
such as the createFollower method in your Pedro Constants class.
class MyRobot : NextRobot { val pedro = PedroMechanism(Constants::createFollower)
override val mechanisms = setOf(pedro)}public class MyRobot implements NextRobot { PedroMechanism pedro = new PedroMechanism(Constants::createFollower);
@Override public Set<Mechanism> getMechanisms() { return Set.of(pedro); }}The follower is built the first time you access it, so constructing a PedroMechanism in your robot’s constructor is safe.
Its periodic() calls follower.update() every loop, so don’t call update() yourself.
Setting the starting pose
Section titled “Setting the starting pose”Like other NextFTC hardware, the follower lives as long as the robot instance does, and every OpMode gets the same robot. Set the starting pose at the beginning of each OpMode, in its constructor:
@NextAutonomous(name = "Close Auto")class CloseAuto(robot: MyRobot) : NextOpMode(robot) { init { robot.pedro.follower.setPose(Pose(0.0, 0.0, 0.0)) }}@NextAutonomous(name = "Close Auto")public class CloseAuto extends NextOpMode { public CloseAuto(MyRobot robot) { super(robot); robot.pedro.follower().setPose(new Pose(0, 0, 0)); }}Following paths
Section titled “Following paths”Ivy’s pedro module provides PedroCommands, which builds commands around a Follower:
| Method | What the command does |
|---|---|
follow(follower, path) |
Starts following path, and finishes when the follower reaches the end of it. |
hold(follower, pose) |
Tells the follower to hold pose, and finishes on the same loop. |
hold(follower) |
Holds the follower’s pose at the time you create the command, not when it starts. |
They don’t require any mechanism, so add requiring(pedro) to let the scheduler know they own the drivetrain.
With Ivy’s default settings, starting one then interrupts any other command that requires pedro.
@NextAutonomous(name = "Close Auto")class CloseAuto(private val robot: MyRobot) : NextOpMode(robot) { override fun start() { PedroCommands.follow(robot.pedro.follower, scorePath) .requiring(robot.pedro) .schedule() }}@NextAutonomous(name = "Close Auto")public class CloseAuto extends NextOpMode { private final MyRobot robot;
public CloseAuto(MyRobot robot) { super(robot); this.robot = robot; }
@Override public void start() { PedroCommands.follow(robot.pedro.follower(), scorePath) .requiring(robot.pedro) .schedule(); }}scorePath is a Path you’ve built with Pedro.
Logging Pedro types
Section titled “Logging Pedro types”Creating a PedroMechanism registers struct schemas for Pedro’s geometry types,
so you can pass them straight to Telemetry.log:
Telemetry.log("Pose", robot.pedro.follower.pose())Telemetry.log("Pose", robot.pedro.follower().pose());Pedro works in inches, so distances and speeds are converted to meters to match the WPILib layouts that AdvantageScope reads. Positions stay in Pedro’s coordinate frame.
| Pedro type | Logged as | Fields |
|---|---|---|
Pose |
Pose2d |
translation in meters, rotation in radians |
Vector2D |
Translation2d |
x, y in meters |
Twist (robot frame) |
ChassisVelocities |
vx, vy in m/s, omega in rad/s |
Velocity (field frame) |
ChassisVelocities |
vx, vy in m/s, omega in rad/s |
Showing poses on an AdvantageScope field
Section titled “Showing poses on an AdvantageScope field”AdvantageScope’s FTC fields use the traditional FTC field coordinates: the origin is the center of the field, and the axes are rotated 90° from Pedro’s. Pedro’s origin is the bottom-left corner of the 144-inch field. A Pedro pose logged as is shows up shifted and rotated, so convert it before logging it for a field view:
val pose = robot.pedro.follower.pose()Telemetry.log("FieldPose", Pose(72 - pose.y(), pose.x() - 72, pose.heading() + Math.PI / 2))Pose pose = robot.pedro.follower().pose();Telemetry.log("FieldPose", new Pose(72 - pose.y(), pose.x() - 72, pose.heading() + Math.PI / 2));This moves the origin to the field center and undoes Pedro’s rotation, the reverse of Pedro’s FTC coordinate conversion.
Convert Vector2D points the same way, without the heading.
Field-frame velocities need the rotation but not the shift.