ParallelCommandGroup .onlyWhile() Command

We (our programming TEAM), have being trying to create a command for autonomous paths, that will rev our shooter up to speed, and angle our shooter to the correct °, however, we are having issues with the last command, which feeds a note into the shooter.

We need to have the Pivot° command, as well as our revShooter command run in parallel, and until the command ends, so we have to use a parallel command group.

However, we can’t seem to be able to delay our command which feeds a note into the shooter.

We currently have this, but can’t find a way to get a booleanSupplier for the .onlyWhile command:
image

Any ideas on how we can either delay the FeedNoteAuto command, or find a booleanSupplier for .onlyWhile()? (Assuming the supplier would be something similar to isShooterAtSpeed)

Thanks in advance; code

You could do a waitcommand with .until() before it.

Edit: just realized youre in a parallel race group… this idea might still work, but its a little more complicated than originally thought.

1 Like

Couldn’t you just do a SequentialCommandGroup with the shooter stuff in the race group and the FeedNoteAuto comes after? Like this:

new SequentialCommandGroup (
    new ParallelRaceGroup(
        new AnglePivot(pivot).withTimeout(4),
        new RevShooter(shooter)
    ),
    new FeedNoteAuto(storage)
)
1 Like

The revShooter and anglePivot commands would end before the note gets shot, or at least thats what happened when i tried this

Maybe you could use .beforeStarting(new WaitCommand(x)) instead of .onlyWhile? You’d have to get the timing right, but I think that could work. x would be however many seconds you want to wait

1 Like

If I’m understanding correct, could you do something like

new ParallelRaceGroup(
  new AnglePivout(pivot),
  new RevShooter(Shooter),
  new SequentialCommandGroup(
    new WaitCommand(4),
    new FeedNoteAuto(storage)
  )
)

if you just wanted to make a delay. Or if you wanted to wait for the anglePivot maybe you could make a function in Pivot.java that checks if the angle is close to the calculated one. Something like

return Math.isNear(pivotPID.calculate(pivotRelativeEncoder.getPosition(), calculateAngle()), povitRelativeEncoder.getPosition(), 0.1)  // the order here might be different, 0.1 is tolerance

and then do .until() or onlyWhile(pivot::atAngle) or however.

I’m writing this on my phone right now so I cant check the syntax or anything right now, but I can later today when I get home.

2 Likes

Id have to check, but im almost certain .beforeStarting is only for a sequential command group, idk if that will work with a parallel command group

Edit: .beforeStarting is only for sequential command groups, 95% sure those don’t work with parallel command groups

1 Like

Ill check this once I get back to my laptop, seems like it may work

1 Like

So, it seems like it should work in theory, but I can’t seem to find an import for Math.isClose


(I did this with our shooter because it takes longer to rev to speed than our pivot.

image

Oops its MathUtil.isNear I misremembered.

but in your shooter subsystem you already have the static variable isatspeed, so for your boolean supplier you can just make a lambda function. .onlyWhile(()->{return Shooter.isatspeed;}

1 Like

Awesome, thanks.
I’ll test this when I get a chance

1 Like

So you probably don’t want a race group in this case. Check out this link with a pretty picture of the various groups.

It sounds like what you want is in parallel

  1. Angle the shooter pivot to a specific point.
  2. Spin the wheels to the appropriate speed

and then
3. Index the note into the shooter.

Lots of ways to compose that, but one example could be:

    new AnglePivot(pivot).until(pivot.atAngle())
    .alongwith(new Revshooter(shooter).until(shooter::atSpeed)
    .withTimeout(4)
    .andthen(new FeedNoteAuto(storage)
    .andThen(new StopShooter(shooter)  // assuming you want to the motors to stop

If my Java understanding is correct, that will create a ParallelRaceGroup wherein the ParallelCommand Group(AnglePivot, Shooter Spin Up) and a timeout of 4 seconds are all racing.

That ParallelRaceGroup will then be the first command of the SequentialCommandGroup, which will then index the note, and stop the shooters.

This would stop the pivot and shooter, then shoot, instead of stopping the shooter after a note is shot
(I think)

1 Like

With this comit, it works as intended (will send video later)

Edit: Video

It pivots up after shooting because we hit the AT, don’t worry about that…

1 Like

These decorators compose commands within each other, and all work with each other. In this case, beforeStarting would create a SequentialCommandGroup containing a ParallelCommandGroup.

3 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.