Go to Post FIRST has taught me to mind my semicolons. - ComradeNikolai [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 06-02-2017, 06:49
YairZiv's Avatar
YairZiv YairZiv is offline
Registered User
FRC #5951 (Makers Assemble)
Team Role: Programmer
 
Join Date: Oct 2016
Rookie Year: 2016
Location: Tel Aviv, Israel
Posts: 41
YairZiv is an unknown quantity at this point
What is a trigger?

We've moved to command based from iterative robot a little while ago, and I saw this... thing called Trigger (that I can in eclipse go new -> Trigger). What is it, what're it's uses and how do I use it?
Reply With Quote
  #2   Spotlight this post!  
Unread 06-02-2017, 09:48
Waz Waz is offline
Strategy and programming mentor
AKA: Steve
FRC #2357 (System Meltdown)
Team Role: Mentor
 
Join Date: Feb 2013
Rookie Year: 2009
Location: Raymore, MO
Posts: 20
Waz is an unknown quantity at this point
Re: What is a trigger?

Quote:
Originally Posted by YairZiv View Post
We've moved to command based from iterative robot a little while ago, and I saw this... thing called Trigger (that I can in eclipse go new -> Trigger). What is it, what're it's uses and how do I use it?
Answering this from memory, but here goes...

The are several ways in wlilib to schedule commands to run. The most common is something like this:
Code:
myButton.whenPressed(new MyCommand());
If you look at the wpilib source code, you will notice that Button is a subclass of Trigger (and JoystickButton is a subclass of Button). All the whenPressed code does is turn around and do this:
Code:
this.whenActive(command);
where whenActive is the Trigger method that really makes the scheduling happen.

So, whenever you use a Button, you are just using a thin, more button like veneer over a Trigger. So, you already know how to use Triggers but just did not realize it yet.

The thing you came across in Eclipse is that you can create you own custom Trigger subclasses (siblings of Button) and use them the exact same way. Teams I have mentored have occasionally done this. Usually it is because we want to check multiple conditions before letting the command get scheduled. One example is that we once used a custom trigger to require 2 buttons to both be down at the same time to reset our gyro during a match. It was something we rarely if ever did, wanted to have it available just in case but also wanted to avoid having it happen accidentally. I have also seen custom triggers that check a button and a limit switch.

If I recall correctly, you override the Trigger's get() method to specify your condition. Something like:
Code:
public boolean get() {
    button1.get() && button2.get();
}
Where more than likely, you passed the two buttons into your CustomTrigger class' constructor.

I hope this helps,
Steve
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:43.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi