Go to Post If you don't like physical play build a stronger robot. - Koko Ed [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 02-17-2012, 05:15 PM
nubie nubie is offline
Registered User
FRC #2734
 
Join Date: Feb 2012
Location: Illinois
Posts: 4
nubie is an unknown quantity at this point
Can't read joystick values in Java

Our team is trying to implement a simple mecanum drive in Java, but whenever we try to set a motor speed based on a joystick value, the motor simply does nothing. No error is thrown, but it does not spin.

We are extending the SimpleRobot class. We are initializing the joysticks with:

Code:
private Joystick leftStick;

public RobotTemplate() {
leftStick = new Joystick(1);
and then later on...

Code:
drivetrain.tankDrive(leftStick, rightStick);

//or

leftMotor.set(leftStick.getX());
We just switched from C++ to Java and we were able to use the joysticks fine in our C++ program, so we don't think it's a control system issue.

Any help would be greatly appreciated! Thanks.
Reply With Quote
  #2   Spotlight this post!  
Unread 02-17-2012, 05:23 PM
compboy07's Avatar
compboy07 compboy07 is offline
Registered User
AKA: Jake M.
FRC #2449 (Out of Orbit)
Team Role: Electrical
 
Join Date: Feb 2012
Rookie Year: 2011
Location: Tempe, AZ
Posts: 19
compboy07 is on a distinguished road
Re: Can't read joystick values in Java

The getX() method is for the kinectStick. Use getRawAxis(int axis) or getAxis(Joystick.AxisType.kX);
Reply With Quote
  #3   Spotlight this post!  
Unread 02-17-2012, 05:51 PM
nubie nubie is offline
Registered User
FRC #2734
 
Join Date: Feb 2012
Location: Illinois
Posts: 4
nubie is an unknown quantity at this point
Re: Can't read joystick values in Java

Thank you for your fast reply. I tried switching to using the getRawAxis method, but it still does the same thing. I try:

Code:
// I also try 1-6 instead of 0
leftMotor.set(leftDriveStick.getRawAxis(0));
When I put in 3, the motor drives at full speed, but for everything else it does not drive at all. In either case, I can't control them with the joysticks. Am I missing something else?
Reply With Quote
  #4   Spotlight this post!  
Unread 02-17-2012, 07:10 PM
compboy07's Avatar
compboy07 compboy07 is offline
Registered User
AKA: Jake M.
FRC #2449 (Out of Orbit)
Team Role: Electrical
 
Join Date: Feb 2012
Rookie Year: 2011
Location: Tempe, AZ
Posts: 19
compboy07 is on a distinguished road
Re: Can't read joystick values in Java

Try two things: firstly, output your values using the LCD display class; it helps a ton. Also, try the getAxis, as it has an enum instead of the index. Instead of some arbitrary number as an argument, it uses Joystick.AxisType.kX
Reply With Quote
  #5   Spotlight this post!  
Unread 02-18-2012, 01:11 PM
nubie nubie is offline
Registered User
FRC #2734
 
Join Date: Feb 2012
Location: Illinois
Posts: 4
nubie is an unknown quantity at this point
Re: Can't read joystick values in Java

I managed to find the default code project that was missing from the libraries on a different thread, and when I ran that, it worked. I still do not know what the root issue is but maybe I will be able to determine it in the future.

Thank you for your help.
Reply With Quote
  #6   Spotlight this post!  
Unread 02-18-2012, 06:14 PM
jesusrambo jesusrambo is offline
Self-Proclaimed Programmer Messiah
AKA: JD Russo
FRC #2035 (Robo Rockin' Bots)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2010
Location: Carmel, CA
Posts: 114
jesusrambo is an unknown quantity at this point
Re: Can't read joystick values in Java

Quote:
Originally Posted by compboy07 View Post
The getX() method is for the kinectStick.
No, getX() is inherited in both Joystick and kinectStick from GenericHID.

Look in the libraries at Joystick.java and you'll find

Code:
/**
     * Get the X value of the joystick.
     * This depends on the mapping of the joystick connected to the current port.
     *
     * @param hand Unused
     * @return The X value of the joystick.
     */
    public double getX(Hand hand) {
        return getRawAxis(m_axes[AxisType.kX.value]);
    }

    /**
     * Get the Y value of the joystick.
     * This depends on the mapping of the joystick connected to the current port.
     *
     * @param hand Unused
     * @return The Y value of the joystick.
     */
    public double getY(Hand hand) {
        return getRawAxis(m_axes[AxisType.kY.value]);
    }
TL;DR getX() works for joysticks, not just kinectSticks.
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 08:57 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