I'm in a robotics class here at Lawrence Tech. University. The class is based around laptop robots running java. I thaught it would be great if I could drive my robot like a remote control car via my playstation controller (with usb adapter). The goal is to eventually control the robot across campus (LTU is a wireless campus) from my desk.
While trying to understand Jinput, I found the tutorial at
https://freefodder.dev.java.net/tutorial/jinputTutorialOne.htmlIt's a great tutorial, but the examples seem to be broken. Running in Eclipse 3.1.1 and on the command line with ant result in the same error for the ControllerDetails example.
"
Exception in thread "main" java.lang.NoSuchMethodError: net.java.games.input.Controller.getAxes()[Lnet/java/games/input/Axis;
at net.java.games.input.tutorialone.ControllerDetails.printControllerDetails(ControllerDetails.java:74)
at net.java.games.input.tutorialone.ControllerDetails.main(ControllerDetails.java:46)
"
I understand that the tutorial is out of date and may have been broken with new versions of Jinput. What I need is a solution for the example.
-Swift-
Here is the code for the example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| package net.java.games.input.tutorialone;
import net.java.games.input.Axis; import net.java.games.input.Controller; import net.java.games.input.ControllerEnvironment;
public class ControllerDetails {
public static void main(String[] args) { if (args.length < 1) { printUsage(); } else { try { int index = 2; ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
Controller[] controllers = ce.getControllers();
if (index < 0 || index >= controllers.length) { System.out.println( "The provided index is out of range.\nUse a value between 0 and " + (controllers.length - 1)); return; }
printControllerDetails(controllers[index]); } catch (NumberFormatException nfe) { printUsage(); } } }
private static void printUsage() { System.out.println("Start application with an index as an argument"); System.out.println( "denoting the controller you want detailed information"); System.out.println("from."); }
private static void printControllerDetails(Controller c) { System.out.println("name: " + c.getName()); System.out.println("type: " + c.getType()); System.out.println("port: " + c.getPortType());
printAxesDetails(c.getAxes()); Controller[] subControllers = c.getControllers(); if (subControllers.length > 0) { for (int i = 0; i < subControllers.length; i++) { System.out.println("subcontroller: " + i); printControllerDetails(subControllers[i]); } } }
private static void printAxesDetails(Axis[] axes) { if (axes.length > 0) { System.out.println("axes:");
for (int i = 0; i < axes.length; i++) { System.out.println( i + " - " + axes[i].getName() + " - " + axes[i].getIdentifier() + " - " + (axes[i].isRelative() ? "relative" : "absolute") + " - " + (axes[i].isNormalized() ? "normalized" : "arbitrary") + " - " + (axes[i].isAnalog() ? "analog" : "digital") + " - " + axes[i].getDeadZone()); } }
}
} |