Command-based Match Time Event

Thank you in advance for any help. I’m trying to determine the best route to go for scheduling a command based on the match time (in java). I’d prefer to use a local timer in the FPGA rather than the getMatchTime() method from the DriverStation class. I’m not sure if it’s a lot more stable now, but we’ve had issues with getMatchTime() in the past.

I could schedule a command in the Robot class (that extends TimedRobot), but I’m wondering if there’s a better method. I’ve searched CD for answers, but they still elude me.

  • Bryce

Use an ordinary Trigger binding. You can base a Trigger on any boolean condition you want.

2 Likes

So if I wanted a trigger that executed some time after teleopInit(), would I need to create the timer and trigger in Robot.java? This lambda stuff is throwing me for a loop. I’ve really mostly programmed in C++. Could you provide a basic structure for where to place the pieces if I wanted to trigger an event after 10 seconds into teleop?

I’m not really a legit programmer, I just play one on TV. I appreciate your patience.

  • Bryce

You need to create your Triggers on init() functions. RobotContainer would be the best place for your case, which runs in robotInit()

An example Trigger using getMatchTime() would be:

new Trigger(() -> Timer.getMatchTime() == 125)

Consider the following in RobotContainer, in the same place as your ordinary button bindings:

new Trigger(DriverStation::isTeleopEnabled)
    .onTrue(Commands.wait(10).andThen(FooCommand));

Where FooCommand is whatever command you want to run 10 seconds into the teleoperated period.

I realize the above might not look much like code you’re familiar with, but it should be pretty clear why this’ll do what you want.

2 Likes

Used this accidentally …

Thank you for the help, y’all. :slight_smile: I really appreciate your time on this.

I’ve got the idea now. Nice and simple. I was definitely overthinking it.

  • Bryce

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