acmerobotics / road-runner-quickstart

FTC quickstart for https://github.com/acmerobotics/road-runner
BSD 3-Clause Clear License
168 stars 855 forks source link

Bring back drive.isBusy()? #354

Closed Vector5233 closed 5 months ago

Vector5233 commented 5 months ago

RR FTC Version

1.0.6

Observed Behavior

in 1.x, the MecanumDrive.isBusy() method no longer exists. Thus a drive can no longer report whether a trajectory is complete. This (appears to) make it impossible to run parallel actions where one action is intended to run for as long as a trajectory action is executing. For example:

new ParallelAction( drive.actionBuilder.strafeTo(FINAL_LOCATION), myPoseUpdateFromAprilTagAction);

where myPoseUpdateFromAprilTagAction updates the drive pose from AprilTags. The hope was that this action could check in with the drive to see whether it is finished, and then simply return drive.isBusy(). However, that method no longer exists in 1.x.

Is there a way to see whether a MecanumDrive is done moving, or is there a way to create a ParallelAction that leaves when one particular Action is complete? We have considered potentially computing distance-to-target as a stopping condition, or potentially modifying the FollowTrajectoryAction.run() method in MecanumDrive to notify when done.

Tuning Files

No response

Robot Logs

No response

rbrott commented 5 months ago

or is there a way to create a ParallelAction that leaves when one particular Action is complete?

This is what you should do. You can write a RaceParallelAction that exits when one action is completed instead of waiting until each one has completed.

Alternatively, you can create a new action that wraps the TAB action and provides apriltag pose updates.

Vector5233 commented 5 months ago

Hm. I don't see a RaceParallelAction in the docs nor does it import from com.acmerobotics.roadrunner.

It sounds ideal though!

j5155 commented 5 months ago

Hm. I don't see a RaceParallelAction in the docs nor does it import from com.acmerobotics.roadrunner.

It sounds ideal though!

It is something you can create yourself. This is my implementation:

// Run actions in parallel until any one of them ends. As soon as one ends all will stop.
// Useful for running trajectories with controller update actions
// I suggest making your controller update actions always return true
public static class RaceParallelCommand implements Action {
        private final Action[] actions;

        public RaceParallelCommand(Action... actions) {
            this.actions = actions;
        }

        @Override
        public boolean run(@NonNull TelemetryPacket t) {
            boolean finished = true;
            for (Action action : actions) finished = finished && action.run(t);
            return finished;
        }

        @Override
        public void preview(@NonNull Canvas canvas) {
            for (Action action : actions) action.preview(canvas);
        }

    }
Vector5233 commented 5 months ago

Ah, here it is. Yes, my only suggestion is to change "finished" to "stillRunning" or something similar.