Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Need help with lego NXT lejos xbox controlling (http://www.chiefdelphi.com/forums/showthread.php?t=137333)

TheModMaster8 25-05-2015 16:24

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
Code:

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).

PAR_WIG1350 25-05-2015 17:41

Re: Need help with lego NXT lejos xbox controlling
 
Quote:

Originally Posted by TheModMaster8 (Post 1484060)
Code:

                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();
                }


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.

Code:

                    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.

Ben Wolsieffer 25-05-2015 18:01

Re: Need help with lego NXT lejos xbox controlling
 
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.

Jalerre 25-05-2015 18:10

Re: Need help with lego NXT lejos xbox controlling
 
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.

TheModMaster8 25-05-2015 19:26

Re: Need help with lego NXT lejos xbox controlling
 
Quote:

Originally Posted by dongeng (Post 1484087)
Thanks for help, Its same with me problem since 3 week ago

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

TheModMaster8 27-05-2015 23:38

Re: Need help with lego NXT lejos xbox controlling
 
I need some help i keep getting this error and i can't figure out why

Code:

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 !

TheModMaster8 28-05-2015 13:06

Re: Need help with lego NXT lejos xbox controlling
 
Hopefully the last time i need help. everything runs fine but when it connects this is the error i get

Code:

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 ?

Ben Wolsieffer 28-05-2015 13:14

Re: Need help with lego NXT lejos xbox controlling
 
Quote:

Originally Posted by TheModMaster8 (Post 1484606)
Hopefully the last time i need help. everything runs fine but when it connects this is the error i get

Code:

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.

TheModMaster8 28-05-2015 21:25

Re: Need help with lego NXT lejos xbox controlling
 
Quote:

Originally Posted by lopsided98 (Post 1484613)
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
Code:

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

Ben Wolsieffer 29-05-2015 10:14

Re: Need help with lego NXT lejos xbox controlling
 
Quote:

Originally Posted by TheModMaster8 (Post 1484761)
I did as you suggested and now i get this
Code:

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.

TheModMaster8 29-05-2015 11:39

Re: Need help with lego NXT lejos xbox controlling
 
Quote:

Originally Posted by lopsided98 (Post 1484834)
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
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
Code:

  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

TheModMaster8 29-05-2015 21:46

Re: Need help with lego NXT lejos xbox controlling
 
Quote:

Originally Posted by Jalerre (Post 1484079)
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.

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?


All times are GMT -5. The time now is 01:48.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi