RMI Remote Sensor issues

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

RMI Remote Sensor issues

Postby rvanderwerf » Sun Apr 27, 2014 7:03 am

Hi, I've been following along with the remote RMI guide:

http://sourceforge.net/p/lejos/wiki/Rem ... 0an%20EV3/

Motors seems to work OK (already posted about missing) however I am having an issue with the sensors. I've tried a few classes but I can't seem to create the objects, either via instantiate new objects:

EV3UltrasonicSensor uSensor = new EV3UltrasonicSensor(brick.getSensorPort(1));
or:
RMISampleProvider sp =
robot.brick.createSampleProvider("S1", "lejos.hardware.sensor.EV3UltrasonicSensor", "distance");
float sample = sp.fetchSample()

The problem in either case is the thread blocks reading from the UARTSensor class and I can't seem to fetch any data from them. I've also tried both patterns for a couple of other sensors(Infrared, Color) I've connected. It can see the sensors themselves reading data with activity, but I'm not sure how I get past this part. If the call that creates the sample provider or base class block, I'm not sure how I am supposed to read any data from them?

Cheers
rvanderwerf
Novice
 
Posts: 27
Joined: Thu Mar 13, 2014 5:00 am

Re: RMI Remote Sensor issues

Postby gloomyandy » Sun Apr 27, 2014 11:27 am

I'm sure Lawrie will be along shortly as this is his area of expertise, but in the meantime...

I'm a little puzzled about your code, shouldn't that be brick.getPort("S1")?

Also I'm afraid I don't understand your description of what is actually going wrong. Perhaps you can post a stack trace of the blocking call?
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4007
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: RMI Remote Sensor issues

Postby rvanderwerf » Sun Apr 27, 2014 4:40 pm

Hi gloomyandy thanks for the response - that code I have is abstracted a bit but it boils down to the exact samples in the wiki. Once I get the port object, and either construct a sensor class (IR, Ultrasonic, etc) OR construct a createSampleProvider from the EV3Remove object, it immediately blocks - I assume I can hold a reference to either of these open and sample the sensors when I need data. However I can't get to the line after instantiating the sensor object or the RMISampleProvider setup (its just blocking waiting for data coming back) to sample the data. It seems to be contacting my sensor, because I see it lighting up after that like it's reading data, but it seems to not return so I can sample anything - unless I'm not understanding how they work but the RMIRegulatedMotor class seems to work this way.

stacktrace that is stuck on createSampleProvider on the port:
at java.net.SocketInputStream.socketRead0(SocketInputStream.java:-1)
at java.net.SocketInputStream.read(SocketInputStream.java:150)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
at java.io.DataInputStream.readByte(DataInputStream.java:265)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:213)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:160)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at com.sun.proxy.$Proxy27.createSampleProvider(Unknown Source:-1)
at lejos.remote.ev3.RemoteEV3.createSampleProvider(RemoteEV3.java:73)

If I instantiate the sensor directly, it gets stuck here (sensor activity seems the same as above:
It's stuck in this line in the UARTSensor class (Line 57 of v.7):
this(port.open(UARTPort.class));

here is the relevant stack trace:
at java.net.SocketInputStream.socketRead0(SocketInputStream.java:-1)
at java.net.SocketInputStream.read(SocketInputStream.java:150)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
at java.io.DataInputStream.readByte(DataInputStream.java:265)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:213)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:160)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at com.sun.proxy.$Proxy29.setMode(Unknown Source:-1)
at lejos.remote.ev3.RemoteUARTPort.setMode(RemoteUARTPort.java:110)
at lejos.hardware.sensor.UARTSensor.<init>(UARTSensor.java:45)
at lejos.hardware.sensor.UARTSensor.<init>(UARTSensor.java:24)
at lejos.hardware.sensor.UARTSensor.<init>(UARTSensor.java:57)
at lejos.hardware.sensor.EV3UltrasonicSensor.<init>(EV3UltrasonicSensor.java:28)

Cheers

Ryan
rvanderwerf
Novice
 
Posts: 27
Joined: Thu Mar 13, 2014 5:00 am

Re: RMI Remote Sensor issues

Postby lawrie » Sun Apr 27, 2014 8:14 pm

I just tried:

Code: Select all
      RemoteEV3 ev3 = new RemoteEV3("192.168.0.9");
      
      RMISampleProvider sp = ev3.createSampleProvider("S1", "lejos.hardware.sensor.EV3UltrasonicSensor", "Distance");
      
      float[] sample = sp.fetchSample();
      
      System.out.println("Sample");
      for(float data: sample) {
         System.out.println("  " + data);
      }
      
      sp.close();


and it worked OK with the latest version of ev3classes from Git. There was a problem reported in another thread and I noticed that the mode parameter was not implemented. The example in the Wiki worked for me for the IR sensor because the mode ("distance") was ignored but the sensor driver implemented distance mode as its default. This wasn't true of EV3UltrasonicSensor which needed the mode parameter. Also mode is case sensitive and should have an upper case D (I will correct the Wiki).

So I think it should work with the latest ev3classes but not the 0.8.1 version. I don't understand the hangup problem you are getting. If you post exact code I will cut and paste it and try it. The hangup looks more like a problem with Java RMI. Are you using Wifi?
lawrie
leJOS Team Member
 
Posts: 921
Joined: Mon Feb 05, 2007 1:27 pm

Re: RMI Remote Sensor issues

Postby rvanderwerf » Tue Apr 29, 2014 5:15 am

thanks for the the respone lawrie. I will try the latest master version on git. Yep I'm using wifi. I don't think my RMI is/was broken, because the RMIRegulatedMotor classes work fine. I'm rebuilding a current sd card from scratch to see if I can get it to boot (I built ev3classes, EV3Menu, dbusjava and manually copied those over to my sd card from 0.7 but the RMI server didn't seem to start, and the menu looked all garbled).
rvanderwerf
Novice
 
Posts: 27
Joined: Thu Mar 13, 2014 5:00 am

Re: RMI Remote Sensor issues

Postby rvanderwerf » Sun May 04, 2014 11:42 pm

Thanks Lawrie! I have all of my stuff merged in with the master, and have everything working. Sometimes I am getting NPE's from isMoving() but if I just catch them and assume that is false, it works fine.

One issue I do have one issue, when I connect remotely, and stop my app the RMI menu on the ev3 unit won't accept a connection any more. Is there a proper way I need to disconnect so I don't have to reboot the EV3 everytime I restart my app? I didn't see that mentioned on the wiki - I call close() on the motors themselves, but I see no obvious way to close EV3Remote or the sensor gracefully?

Cheers
rvanderwerf
Novice
 
Posts: 27
Joined: Thu Mar 13, 2014 5:00 am

Re: RMI Remote Sensor issues

Postby lawrie » Mon May 05, 2014 10:04 am

You should only have to close motors and sensors. There is no close on the EV3 object as it does not claim any resources. I have not seen a problem connecting multiple times. EV3Control uses the same mechanism and connects multiple times without a problem. I will probably add a reset option to the menu to close anything left open.
lawrie
leJOS Team Member
 
Posts: 921
Joined: Mon Feb 05, 2007 1:27 pm

Re: RMI Remote Sensor issues

Postby rvanderwerf » Thu May 08, 2014 5:19 am

Well I was wrong, I realized I had the sensor code commented out. I do have my motors working with my RMIDifferentialPilot, but the following method of getting the Ultrasonic sensor gives me this exception (This is over wifi):

comm = new RemoteEV3("192.168.1.14");
RMISampleProvider sp =
comm.createSampleProvider("S1", "lejos.hardware.sensor.EV3UltrasonicSensor", "distance");

lejos.hardware.port.PortException: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException: Failed to create sample provider RemoteEV3.java:75)


However this seems to work:

EV3UltrasonicSensor uSensor = new EV3UltrasonicSensor(brick.getSensorPort(1));
SampleProvider sp = uSensor.getDistanceMode();
float[] sample = new float[1];
sp.fetchSample(sample,0);

which gives me a value. Does one way to instantiate them just work on some sensors one way and not on others?
rvanderwerf
Novice
 
Posts: 27
Joined: Thu Mar 13, 2014 5:00 am

Re: RMI Remote Sensor issues

Postby lawrie » Thu May 08, 2014 11:28 am

As I mentioned before, you need "Distance" not "distance" as the mode parameter.

The first way creates the sensor driver on the remote machine and returns the samples to the PC. The second way runs the sensor driver on the PC and sends the port requests to to the EV3.

The first method should be more efficient.
lawrie
leJOS Team Member
 
Posts: 921
Joined: Mon Feb 05, 2007 1:27 pm


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 3 guests

more stuff