|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have recently begun learning Java as my team is in need of a programmer next year and have hit a road block. I am trying to make the trigger on the standard joystick run a specific command when pressed. The tutorials I have been following so far are these. My initial thoughts were it would be very similar to making a button run a specific command however I can't seem to get it to work. I have searched the web high and low but can't find anything useful.
|
|
#2
|
||||||
|
||||||
|
Re: commands activated by trigger, how?
You are correct. It would be helpful if you posted the code that you tried and what didn't work so that people can provide more helpful suggestions.
|
|
#3
|
||||
|
||||
|
Re: commands activated by trigger, how?
Is is a boolean trigger or a variable one? If it's variable, like the triggers on an xBox controller, it's called as a separate joystick axis. Which joystick are you using?
|
|
#4
|
|||
|
|||
|
Re: commands activated by trigger, how?
Some of the code that I have tried thus far is:
Code:
//code trial 1
Trigger DT1 = new Joystick.getTrigger(DriveStick);
//code trial 2
package edu.wpi.first.Command_Learner;
import edu.wpi.first.wpilibj.Joystick;
public class OI {
Joystick DriveStick = new Joystick(1);
Joystick SecondaryStick = new Joystick(2);
public OI(){
if(DriveStick.getTrigger()){
LauncherSpinWheels();
}
else{
LauncherStopWheels();
}
}
}
//code trial 3
package edu.wpi.first.Command_Learner;
import edu.wpi.first.Command_Learner.commands.LauncherSpinWheels;
import edu.wpi.first.wpilibj.Joystick;
public class OI {
Joystick DriveStick = new Joystick(1);
Joystick SecondaryStick = new Joystick(2);
public boolean ST1;
public OI(){
ST1 = DriveStick.getTrigger();
if(ST1=true){
new LauncherSpinWheels();}
As for the Joystick, I am trying to get the trigger off of an attack 3 Logitech joystick(so it's a Boolean trigger). Last edited by cad321 : 08-06-2013 at 23:50. |
|
#5
|
||||
|
||||
|
Re: commands activated by trigger, how?
If you take a look at the javadoc for the Joystick class, then look at the getTrigger() method, you'll see that it doesn't return a boolean value. The triggers on the logitech [edit] F310 [/edit](and xbox if I remember correctly) are on axis 3. Axes in the Joystick class return doubles, in this case, a numerical value from 1.0 to -1.0. So when one trigger is pulled all the way, axis 3 reads 1.0. When the other is pulled all the way, axis 3 reads -1.0. When they are both pulled simultaneously, the values are essentially added. So if you were to pull them both down all the way you would read 0.0 on axis three. This is important to understand. It is the reason why you wouldn't put two commands that needed to be used at the same time onto the same axis. Both triggers pressed looks the same as neither trigger pressed. To get back to your question though... if you want to kick off commands from an analog axis on a joystick, then you need to turn that axis into a button. You need to turn a value of 1.0 to -1.0 (double) into true or false (boolean). I developed a class for my team last year which does just this. I've tried to clean up the code and document how it should be used. It is available here. There is an example of its use in the comment at the top of the code. Please let me know if you have any questions. Last edited by otherguy : 09-06-2013 at 12:39. |
|
#6
|
|||
|
|||
|
Re: commands activated by trigger, how?
Quote:
To use the trigger treat it exactly like a button. |
|
#7
|
||||
|
||||
|
Re: commands activated by trigger, how?
Quote:
Well what I posted earlier is applicable to using using axes as buttons if anyone needs that lol. |
|
#8
|
|||
|
|||
|
Re: commands activated by trigger, how?
Quote:
From what I can tell the attack 3 should be returning a Boolean as there is only one per joystick and there is only 2 states(pressed and not pressed). Please correct me if I am wrong as I know very little so far and could easily be mistaken. |
|
#9
|
|||
|
|||
|
Re: commands activated by trigger, how?
Thank you very much! I couldn't find anything saying it was actually just button 1 and didn't realize that in all the documentation that button one was never listed(just trigger).
|
|
#10
|
|||
|
|||
|
Re: commands activated by trigger, how?
Quote:
|
|
#11
|
|||
|
|||
|
Re: commands activated by trigger, how?
There is online documentation for CommandBased programming, in particular this link shows how to attach commands to a joystick.
Code:
Joystick DriveStick = new Joystick(1);
Button button = new JoystickButton(joystick, BUTTON_NUMBER);
public OI() {
button.whenPressed(new LauncherSpinWheels());
// ...
}
In addition to the online documentation, you might find these videos helpful if you're having trouble understanding CommandBasedProgram.: CommandBased Programming with RobotBuilder: http://www.youtube.com/watch?v=k7PaY...lgn vhGObeKzp CommandBased Programming without RobotBuilder: http://www.youtube.com/watch?v=v0vt9yKLxUQ |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|