|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
Problems with laserinterfaceHi all,
I don't know how to use the laserInterface, so I run the following code for a try: lsri = robot.requestInterfaceLaser (0, PlayerConstants.PLAYER_OPEN_MODE); while(lsri.isDataReady()); lnum=lsri.getData().getRanges_count(); lsri.getData().getRanges(); ldata=lsri.getData().getRanges(); I get the error of "NullPointerException". Could you advise me on how to use the laserInterface? And I am confused with the method "public void readData(PlayerMsgHdr header)" , how can I get a PlayerMsgHdr variable? Thanks a lot, kevin. |
|
|
Re: Problems with laserinterfaceWhat is your version of JavaClient?
I don't work a lot on JavaClient, but I know that you have to call (directly or not) a function whose name is Read() (PlayerClient in the c++ native library), in order to retrieve data from Player/Stage, to fill up fields of your structure, and then you can reach data by functions like getRanges(). So your first call of getRanges, "lsri.getData().getRanges();", can't fill these fields. It's useless. Maybe you have to call readAll() (of the class PlayerClient in javaClient) if you're not in threaded mode, or call runThreaded(0,0) if you implemented the Runnable interface. Those functions will call an equivalent of Read. I guess that "isDataReady" doesn't ask a reading from Player/Stage, but only check if, in the most recent data retrieved, there is data about laser. But you still have to retrieve it. If it doesn't work, check your "robot" creation. Maybe it's your nullpointer error' source. Do you know the name of the function which cause the error?
|
|
|
Re: Problems with laserinterfaceIf you get a "NullPointerException" you should also know which line it is thrown from. I guess it's thrown from the "while(lsri.isDataReady());" as lsri may be null if "robot.requestInterfaceLaser (0, PlayerConstants.PLAYER_OPEN_MODE);" is unable to locate the laser interface. Anyway try to get more info on the NullPointerException and post the whole stacktrace if you need more help.
Bests Leo 2009/4/10 Skuld <tan312yenai@...>
-- ************************************** Leonardo Nomdedeu Calvente leo.nomdedeu@... ------------------------------------------------------------------------------ This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com _______________________________________________ Java-player-users mailing list Java-player-users@... https://lists.sourceforge.net/lists/listinfo/java-player-users |
|
|
Re: Problems with laserinterfaceHi Skuld,
Thank you for your advice, I call runThreaded(-1,-1) before my code and I can get the data now. And I'm sorry to reply your message so late. And I am confused why the fuction of runThreaded(-1,-1) will call an equivalent of Read. Could you tell me why? Thanks a lot, kevin
|
|
|
Re: Problems with laserinterface^^
Sure I can. As I told you in my first reply, you have to call the Read method to fill up your structure's fields, from a communication pipe with Player. That is the code of the JavaClient (2.0.1 version, but all versions should work the same.) public void runThreaded (long millis, int nanos) { if (isThreaded) { System.err.println ("[PlayerClient]: A second call for runThreaded, ignoring!"); return; } this.millis = millis; this.nanos = nanos; isThreaded = true; this.start (); } As you can see, when you call RunThreaded, you just set some special fields before launching the start method. I guess you know how works Threads in java, so I'll just show you the run method (which is called by the start method): public void run () { try { while (isThreaded) { if (this.datamode == PLAYER_DATAMODE_PULL) { this.requestData (); while (read () != PLAYER_MSGTYPE_SYNCH && isThreaded); } else // while (is.available () != 0) // while (read () != PLAYER_MSGTYPE_SYNCH && isThreaded); read (); if (millis < 0) Thread.yield (); else if (nanos <= 0) Thread.sleep (millis); else Thread.sleep (millis, nanos); } } catch (InterruptedException e) { throw new PlayerException (e); } // } catch (IOException e) { throw new PlayerException (e); } } Do you understand? This function have a while's loop. This loop first wait for data from Player, and dispatch it in the structures's fields with a read() 's loop. There is the call of the Read function. (an equivalent to be meticulous, because Read function is available in C library, but in Java, read is a private function. You just can call it by readAll(), which does the same things that the C one does, and the simple read does too -but with verifications.) So, in fact when you call RunThreaded, one Thread is specially created to catch information from Player and dispatch it into structures, for the other Thread (because threads share memory.), so for your code, so you doesn't have to call Read() anymore. And you still have informations from Player. Here it is ! I hope I was clear enough ^^ If I wasn't, tell me so. Have a nice day! Skuld
|
|
|
Re: Problems with laserinterfaceHi Skuld,
Thanks very much.^_^ I get it. So the thread will keep calling the read() until yield() or sleep(). Yours sincerely, kevin.
|
| Free embeddable forum powered by Nabble | Forum Help |