Need help with lego NXT lejos xbox controlling

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

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Controller;
import org.lwjgl.input.Controllers;
public class Start extends Virtual_JoyStick 
{
	public static Controller control;
	public static boolean Start;
	
	
	public static void main(String] args)
	{
		try
		{
			Controllers.create();			
		}
		catch(LWJGLException e)
		{
			e.printStackTrace();
		}
		Controllers.poll();
		
		for(int i=0;i<Controllers.getControllerCount();i++)
		{
			control=Controllers.getController(i);
			System.out.print(control.getName());
		}
		
		control=Controllers.getController(0);
		
		for(int i=0; i < control.getAxisCount(); i++)
		{
			System.out.print(i+ ": "+ control.getAxisName(i));
			//System.out.print("c");
			control.setDeadZone(i, (float) 0.30);
			
		}
		
		for(int i=0; i < control.getButtonCount(); i++)
		{
			System.out.print(i+ ": "+ control.getButtonName(i));
		}	

		while(true)
		{
			control.poll();
		    //Start=control.isButtonPressed(7);
			/**System.out.print(control.getAxisValue(0));
			System.out.print("   ");
			System.out.print(control.getAxisValue(1));
			System.out.print("   ");
			System.out.print(control.getAxisValue(2));
			System.out.print("   ");
			System.out.print(control.getAxisValue(3));
			System.out.print("   ");
			System.out.print(control.getAxisValue(4));
			System.out.print("   ");
			System.out.print(control.getAxisValue(5));
			System.out.println(); */
			Virtual_JoyStick joy = new Virtual_JoyStick();
			joy.repaint();
	  }	    
   }
}

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.

This might help. I have a little bit of experience using LeJos with an NXT with Bluetooth and Joystick control so I may be of some assistance.

Ikr, i’ve search the web for like 3 weeks al the links are clicked on and i still couldnt find anything

I need some help i keep getting this error and i can’t figure out why

Native Library bluecove not available Failed to open connection to the NXT

Solution!: it is solved by adding -d32 in the arguments tab of the run config file !

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.

Any clue as to what is going on ?

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.

I did as you suggested and now i get this

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


last time i hopefully

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.

OSX: 10.10.2 Yosemite

and im using lejos version: leJOS_NXJ_0.9.1beta-3 2 i can’t find the versoin of bluecove.

Solved it, the usb that is i needed to switch this little line of code

 public Robot() {
        // RConsole.open();
        // pilot.steer(90, false);
        // pilot.steer(140, false);
        // pilot.steer(180, false);
        // pilot.steer(0, false);
        final NXTConnection connection = Bluetooth.waitForConnection();
        communication = new CommunicationSlave(connection.openInputStream(), connection.openOutputStream(), new CommunicationHandler() {

to

  public Robot() {
        // RConsole.open();
        // pilot.steer(90, false);
        // pilot.steer(140, false);
        // pilot.steer(180, false);
        // pilot.steer(0, false);
        final NXTConnection connection = USB.waitForConnection();
        communication = new CommunicationSlave(connection.openInputStream(), connection.openOutputStream(), new CommunicationHandler() {

in the robot class, $@#$@#$@# well at the tri controller class

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;

how would i add this to the code?