View Single Post
  #5   Spotlight this post!  
Unread 29-01-2017, 11:16
GKannel GKannel is offline
Registered User
FRC #4207 (PyroBotics)
Team Role: Mentor
 
Join Date: Jan 2017
Rookie Year: 2012
Location: Minnesota
Posts: 1
GKannel is an unknown quantity at this point
Re: Help with Programming a trigger!

Be aware that "trigger" may not always be a trigger in code. On a regular joystick you are probably going to use something like the following with shooter being some sort of motor controller such as CANTalon shooter = new CANTalon(10);

Code:
    if(stick.getTrigger()) {
          shooter.set(1.0);     // turn it on when pressed
    } else {                     
          shooter.set(0.0);   // turn it off when released
    }
We would have this inside the while loop of the operatorControl function (SampleRobot based project) but that will presumably vary with types of robot projects.

!!!However, if you are using something like a Playstation type controller (such as Logitech F310 with switch on back in X position), the two triggers may actually show as a pair of axis (each with values on a 0-1.0 scale) instead of as a trigger. On ours the left trigger is axis 2 and the right is axis 3 but you can use the USB section of the driver station to determine yours. This then looks more like the following.
Code:
if(stick.getRawAxis(3) > .5) {    
    motor.set(1.0);
} else {
   motor.set(0.0);
}
You could also have variable power from 0 to 1 if you just did
Code:
   motor.set(stick.getRawAxis(3));
It should be 0 when not pressed and range up to 1.0 when fully pressed.
Reply With Quote