Controlling EV3 by WiFi using Eclipse application

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

Moderators: roger, gloomyandy, skoehler

Controlling EV3 by WiFi using Eclipse application

Postby Empuza » Mon Jan 13, 2014 9:08 pm

Hi guys!

I'm just a begginer and I want to know how create (step by step) an application (with interface) on Eclipse, which after clicking button on that interface, EV3 will do an operation, for example it will do a simple rotation.
It is very important to me! I will appreciate any kind of help.

HELP ME PLEASE! :(
Empuza
New User
 
Posts: 5
Joined: Sun Nov 17, 2013 5:06 pm

Re: Controlling EV3 by WiFi using Eclipse application

Postby lawrie » Tue Jan 14, 2014 12:15 am

I am not sure why remote access is so popular rather than running programs on the EV3, but if you want to do it, you can create a new Java project, add the ev3classes project to the Java build path, and add a class called Control to the src directory and overwrite it as:

Code: Select all
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.rmi.RemoteException;

import javax.swing.JButton;
import javax.swing.JFrame;

import lejos.hardware.BrickFinder;
import lejos.remote.ev3.RMIRegulatedMotor;
import lejos.remote.ev3.RemoteEV3;

public class Control extends JFrame {
   public Control() {
      super("My Controller");
      RemoteEV3 ev3 = (RemoteEV3) BrickFinder.getDefault();
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      JButton rotate = new JButton("Rotate");
      this.getContentPane().add(rotate);
      final RMIRegulatedMotor left = ev3.createRegulatedMotor("A");
      final RMIRegulatedMotor right = ev3.createRegulatedMotor("B");
      
      rotate.addActionListener(new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent arg0) {
            try {
               left.rotate(500,true);
               right.rotate(-500);
            } catch (RemoteException e) {
               e.printStackTrace();
            }
         }         
      });
      
       addWindowListener(new WindowAdapter() {
           @Override
           public void windowClosing(WindowEvent e) {
              try {
               left.close();
               right.close();
            } catch (RemoteException e1) {
               e1.printStackTrace();
            }
           }
       });
   }
   
   public static void main(String[] args) {
      Control control = new Control();
        control.pack();
        control.setVisible(true);
   }
}


Then run it as a Java application,and press the Rotate button in the little window.
lawrie
leJOS Team Member
 
Posts: 842
Joined: Mon Feb 05, 2007 1:27 pm

Re: Controlling EV3 by WiFi using Eclipse application

Postby Empuza » Tue Jan 14, 2014 4:59 pm

Thank you very much for your reply lawrie :)

In my project I added ev3classes project to the build path, and create class Control and put there code. I found two errors in those lines:
final RMIRegulatedMotor left = ev3.createRegulatedMotor("A");
final RMIRegulatedMotor right = ev3.createRegulatedMotor("B");

After "ev3." I can only add createRegulatedProvider instead of createRegulatedMotor. Is it that what you meant?
I checked it in the way like one line above and I got this message:

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class com.sun.jna.Native
at lejos.internal.io.NativeHCI$LibBlue.<clinit>(NativeHCI.java:55)
at lejos.internal.io.NativeHCI.<clinit>(NativeHCI.java:62)
at lejos.hardware.LocalBTDevice.<init>(LocalBTDevice.java:19)
at lejos.hardware.Bluetooth.getLocalDevice(Bluetooth.java:12)
at lejos.hardware.BrickFinder.discoverNXT(BrickFinder.java:89)
at lejos.hardware.BrickFinder.getDefault(BrickFinder.java:42)
at test.Control.<init>(Control.java:19)
at test.Control.main(Control.java:52)

How to fix this?
Empuza
New User
 
Posts: 5
Joined: Sun Nov 17, 2013 5:06 pm

Re: Controlling EV3 by WiFi using Eclipse application

Postby lawrie » Tue Jan 14, 2014 9:35 pm

I think I changed createRegulatedProvider to createRegulatedMotor after the 0.5.0-alpha release.

The error you are getting only happens if an EV3 cannot be found. Make sure your EV3 is running and you have not stopped the menu. Try it again if it fails that way. You will probably have to update EV3Menu to the head version if you are using the 0.5.0-alpha version, as there was a bug in the 0.5.0-alpha release with remote access. You have to run the EV3Menu ant build file to copy the new menu to the EV3, and then reboot the EV3.

Unfortunately, you cannot now update ev3classes to the latest version, as Andy had added new motor regulation code in a kernel module and the latest ev3lasses.jar only works if you have the update kernel module.

As you cannot update ev3classes, remote access might not work for you until the 0.6.0 release. Give it another try though, as I am not sure if it works with the 0.5.0-alpha version of ev3classes.

The program works for me, though!
lawrie
leJOS Team Member
 
Posts: 842
Joined: Mon Feb 05, 2007 1:27 pm

Re: Controlling EV3 by WiFi using Eclipse application

Postby Empuza » Tue Jan 14, 2014 9:57 pm

I updated EV3Menu and now I have message:

"Exception in thread "main" lejos.hardware.port.PortException: java.rmi.ConnectException: Connection refused to host: 192.168.0.9; nested exception is:
java.net.ConnectException: Connection timed out: connect
at lejos.remote.ev3.RemoteEV3.createRegulatedProvider(RemoteEV3.java:77)
at Control.<init>(Control.java:21)
at Control.main(Control.java:50)
Caused by: java.rmi.ConnectException: Connection refused to host: 192.168.0.9; nested exception is:
java.net.ConnectException: Connection timed out: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:129)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at com.sun.proxy.$Proxy0.createRegulatedMotor(Unknown Source)
at lejos.remote.ev3.RemoteEV3.createRegulatedProvider(RemoteEV3.java:75)
... 2 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:208)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:147)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 9 more
"
My EV3 IP is 192.168.1.4 and I don't know why it found 192.168.0.9. Can I set it my IP by hand, and not use BrickFinder?
I changed IP to correct one in ev3classes and DBusJava, and for them Ant build worked previously.
Empuza
New User
 
Posts: 5
Joined: Sun Nov 17, 2013 5:06 pm

Re: Controlling EV3 by WiFi using Eclipse application

Postby Empuza » Tue Jan 14, 2014 11:17 pm

You were right about this problem with EV3Menu. I updated it and program started and the window with button showed up. But unfortunately after click and some time I've got this message and brick is frozen:

java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:
java.net.SocketTimeoutException: Read timed out
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:228)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
at com.sun.proxy.$Proxy1.rotate(Unknown Source)
at Control$1.actionPerformed(Control.java:28)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
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:214)
... 41 more

It is possible to fix this? :(
Empuza
New User
 
Posts: 5
Joined: Sun Nov 17, 2013 5:06 pm

Re: Controlling EV3 by WiFi using Eclipse application

Postby lawrie » Wed Jan 15, 2014 9:00 am

Hi Empuza,

I don't think you can have updated EV3Menu to the latest as that changes "192.168.0.9" to lastIp. You can make this change by hand. That is the only change that is necessary. I would try making that change and running the EV3Menu ant build file to put the new menu on the EV3, and then rebooting the EV3. However, what you have done may be the equivalent of this.

I have not seen the time out problem with remote access before. I would try it again to see if it is consistent. Otherwise it could be a problem with incompatible version of things and you may have to wait for a 0.6.0 release to fix that.
lawrie
leJOS Team Member
 
Posts: 842
Joined: Mon Feb 05, 2007 1:27 pm

Re: Controlling EV3 by WiFi using Eclipse application

Postby RaRoboto » Sun Jan 19, 2014 10:24 am

Maybe is something with the BrickFinder. I had similar problems that are now solved using ev3 = new RemoteEV3("10.0.1.1"); Change the ip if yours is different.
RaRoboto
New User
 
Posts: 1
Joined: Sat Jan 18, 2014 6:25 pm


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff