I’m attempting to use an Xbox One wired controller on my MacBook Pro laptop, Im using Java with Eclipse that has lejos and LWJGL installed on it in order to control an NXT via my controller, like how we control our robots. I have a gamepad driver installed, it’s called “XOne Controller” (link)https://github.com/FranticRain/Xone-OSX Also i have a little program to test the data from the joysticks and buttons of the controller
my problem is i don’t know how to make the main program listen to live input data and send it to the robot wirelessly, Also note that I’m not at basic but not advanced in the realms of coding. JSYK (just so you know).
I’m not sure what each line of this is doing, but assuming those are the correct methods, all you have to do is assign their values to variables instead of printing them (see below). From there, you need to figure out how you are getting the commands from the computer to the NXT. For this you would want to also include a bluetooth library on the computer side. I would imagine that Lejos has methods for bluetooth on the NXT side.
axisZero = control.getAxisValue(0);
Hope that helps.
EDIT: what do the last 2 lines of the while loop do? it seems like that might not be something you want to do for every iteration of the loop, but I could be wrong.
EDIT (again): I see that the constructor called in the lines I referenced above is the constructor for the parent class. Is the start class the class that you are using to run the program in the JVM, or is it a class that you intend to use to create start objects? I assumed the former since you omitted a constructor but included a main() method, but it occurred to me that you might have intended the latter.
The easiest way to set up communication between the computer and the robot is to use the communication classes included in the leJOS PC library.
The computer side project (the one that reads from the controller) should be set up according to these instructions. Then you can use DataOutputStream (on the computer) and DataInputStream (on the robot) to send numbers over bluetooth. I would recommend using USB for testing as it is more reliable and faster to connect and the APIs are nearly identical. These instructions might help with setting up communications.
I also have some more complicated communication code that you can look at if you want. This provides a way for bidirectional communication that is sort of similar to I2C. There are a few intermittent threading bugs, but it might give you some idea of how to connect the computer and the robot. Computer Code Robot Code
Feel free to ask any other questions you have about the specifics of getting your leJOS working.
Hopefully the last time i need help. everything runs fine but when it connects this is the error i get
Loading: net.java.games.input.OSXEnvironmentPlugin
Using joystick: Xbox One Controller
Found NXT: Tim fork 0016530A7EAE
Connected to NXT: Tim fork@0016530A7EAE
Connection to NXT timed out.
Are you running the code on the robot that responds to the requests from the computer? This error means that the program on your computer sent a request to the robot and the robot did not respond.
You have to start the program on the robot before starting the program on the computer. I might add the ability to cleanly connect, disconnect and reconnect (like the FRC system), but it doesn’t have that capability at the moment.
Loading: net.java.games.input.OSXEnvironmentPlugin
Using joystick: Xbox One Controller
dyld: lazy symbol binding failed: Symbol not found: _IOBluetoothLocalDeviceReadSupportedFeatures
Referenced from: /private/var/folders/_2/xj9xgcd50xd820c_rjmpltwc0000gn/T/bluecove_BradenShepard_0/libbluecove.jnilib
Expected in: /System/Library/Frameworks/IOBluetooth.framework/Versions/A/IOBluetooth
dyld: Symbol not found: _IOBluetoothLocalDeviceReadSupportedFeatures
Referenced from: /private/var/folders/_2/xj9xgcd50xd820c_rjmpltwc0000gn/T/bluecove_BradenShepard_0/libbluecove.jnilib
Expected in: /System/Library/Frameworks/IOBluetooth.framework/Versions/A/IOBluetooth
That’s an OSX problem, not my code, but I’ll try to help anyway.
It looks like this is a bug in BlueCove (the bluetooth library) caused by some changes in Mac OS 10.8 and newer. What are your OS and BlueCove versions?
I don’t much experience with Mac OS, so Googling might help more than I can.
I’ll take you up on that offer, i got everything to work, but i am now stuck on how to integrate the xbox controller’s inputs into the code. as far as i can tell, it is only passing on the key and then the keystroke reaches the robot, it goes forward, i want it to coast up to speed but i don’t know if you can called in joystick function on the robot (server) side,
ex.
int i = 0
if(control.getAxisValue(1) > 0.35){
i = i +5;
Motor.BC.setSpeed(i) }
else
i=0;