Go to Post I have learned so much from this program and am forever changed by FIRST and its community. You have made me a better person in so many ways. Thank you. - Jessica Boucher [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-08-2013, 06:55 PM
cad321 cad321 is offline
Jack of all trades, Master of none
AKA: Brian Wagg
FRC #2386 (Trojans)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Burlington, Ontario
Posts: 319
cad321 is just really nicecad321 is just really nicecad321 is just really nicecad321 is just really nice
Question commands activated by trigger, how?

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.
Reply With Quote
  #2   Spotlight this post!  
Unread 06-08-2013, 08:14 PM
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,547
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: commands activated by trigger, how?

Quote:
Originally Posted by cad321 View Post
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.
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 06-08-2013, 10:35 PM
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
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?
Reply With Quote
  #4   Spotlight this post!  
Unread 06-08-2013, 11:48 PM
cad321 cad321 is offline
Jack of all trades, Master of none
AKA: Brian Wagg
FRC #2386 (Trojans)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Burlington, Ontario
Posts: 319
cad321 is just really nicecad321 is just really nicecad321 is just really nicecad321 is just really nice
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();}
I have been working on this more tonight and think I have gotten close in my 3rd trial of code(seen above). The only issue I am having is that the line with the command "LauncherSpinWheels." In netbeans it underlines in yellow indicating an error and says "New Instance ignored." If you need more in terms of my code please just let me know.

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 : 06-08-2013 at 11:50 PM.
Reply With Quote
  #5   Spotlight this post!  
Unread 06-09-2013, 11:06 AM
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: commands activated by trigger, how?

I don't think the getTrigger() method does what you are hoping it does.
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.
__________________
http://team2168.org

Last edited by otherguy : 06-09-2013 at 12:39 PM.
Reply With Quote
  #6   Spotlight this post!  
Unread 06-09-2013, 11:11 AM
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 985
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: commands activated by trigger, how?

Quote:
Originally Posted by otherguy View Post
I don't think the getTrigger() method does what you are hoping it does.
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 (and xbox if I remember correctly) are on axis 3.
The getTrigger method does return a boolean. The trigger on the Logitech Attack 3 Joystick is button 1.

To use the trigger treat it exactly like a button.
Reply With Quote
  #7   Spotlight this post!  
Unread 06-09-2013, 11:19 AM
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 429
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: commands activated by trigger, how?

Quote:
Originally Posted by RufflesRidge View Post
The getTrigger method does return a boolean. The trigger on the Logitech Attack 3 Joystick is button 1.

To use the trigger treat it exactly like a button.
You're right, I was thinking about the the Logitech F310... and I apparently can't read the javdoc I linked lol.

Well what I posted earlier is applicable to using using axes as buttons if anyone needs that lol.
__________________
http://team2168.org
Reply With Quote
  #8   Spotlight this post!  
Unread 06-09-2013, 11:26 AM
cad321 cad321 is offline
Jack of all trades, Master of none
AKA: Brian Wagg
FRC #2386 (Trojans)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Burlington, Ontario
Posts: 319
cad321 is just really nicecad321 is just really nicecad321 is just really nicecad321 is just really nice
Re: commands activated by trigger, how?

Quote:
Originally Posted by otherguy View Post
I don't think the getTrigger() method does what you are hoping it does.
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 (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.
Thank you for the help, this is will be very useful for later on(as I think my team will be switching to Gamepads in the near future) however I think there has been a misunderstanding as to what I would like to control the robot with. I am trying to use the standard Attack 3 Joystick, not a gamepad like this one.

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.
Reply With Quote
  #9   Spotlight this post!  
Unread 06-09-2013, 11:29 AM
cad321 cad321 is offline
Jack of all trades, Master of none
AKA: Brian Wagg
FRC #2386 (Trojans)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Burlington, Ontario
Posts: 319
cad321 is just really nicecad321 is just really nicecad321 is just really nicecad321 is just really nice
Re: commands activated by trigger, how?

Quote:
Originally Posted by RufflesRidge View Post
The getTrigger method does return a boolean. The trigger on the Logitech Attack 3 Joystick is button 1.

To use the trigger treat it exactly like a button.
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).
Reply With Quote
  #10   Spotlight this post!  
Unread 06-09-2013, 01:14 PM
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 985
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: commands activated by trigger, how?

Quote:
Originally Posted by cad321 View Post
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).
The first step I would recommend when using any USB input device for FRC is to document the button and axis mapping and ranges. The easiest way to do this is to (on Windows 7, XP may or may not vary slightly):
  1. Click the Start Menu
  2. In the run box type "joy.cpl" and press Enter
  3. Select the desired device from the list and click Properties
  4. Select the Test tab if it is not selected already
The X axis (horizontal) and Y axis (vertical) are represented by the crosshair in the box. Axes 3-6 are represented in order, top to bottom, by bars to the right of the box. The buttons are represented below and light up when pressed. The first 6 axes (including X/Y) and 12 buttons will be transmitted, if your device has more they will be ignored.
Reply With Quote
  #11   Spotlight this post!  
Unread 08-10-2013, 05:52 PM
alexhenning alexhenning is offline
WPILib Developer
FRC #0348
 
Join Date: Apr 2010
Rookie Year: 2003
Location: MA
Posts: 49
alexhenning will become famous soon enough
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());
    // ...
}
Replace BUTTON_NUMBER with the button you want to run the command.

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
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 07:46 AM.

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