This article assumes that you have a leJOS development environment in place. Please refer to this article for details.
[LeJOS] Let's program mindstorm-EV3 in Java [Environment construction first part]
[LeJOS] Let's program mindstorm-EV3 in Java [Environment construction part 2]
In leJOS, the development method of deploying the program created on the PC side to the EV3 main unit and executing it is common, but in fact it is possible to remotely control the program without deploying it via WiFi. By the way, I explained before how to remotely control ev3dev from Python.
[Ev3dev] Let's make a remote control program by Python with RPyC protocol
This time we'll do this in Java using leJOS.
Connect the L motor to the A port of the EV3 main unit and execute the following program on the PC side. No need to deploy. Please match the IP address to each environment. It is a program that makes a beep and rotates the L motor 180 degrees.
RemoteEv3.java
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import lejos.hardware.Sound;
import lejos.remote.ev3.RMIRegulatedMotor;
import lejos.remote.ev3.RemoteEV3;
public class RemoteEv3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
RemoteEV3 ev3 = null;
RMIRegulatedMotor m = null;
try {
//Connect to EV3, EV3 IP address as an argument
ev3 = new RemoteEV3("192.168.2.91");
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NotBoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Initialization
ev3.setDefault();
//Instantiation of motor(Connect a large motor to port A)
m = ev3.createRegulatedMotor("A",'L');
//Beep
Sound.beep();
//Rotate the motor 180 degrees
try {
m.rotate(180);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Create a RemoteEV3 class for remote control. Create an instance by passing the EV3 IP address as an argument.
ev3 = new RemoteEV3("192.168.2.91");
Use the createRegulatedMotor method to access the motor. Specify the connection port with the String type in the first argument and the motor type ('L' or'M') with the char type in the second argument.
m = ev3.createRegulatedMotor("A",'L');
L motor M motor
http://www.lejos.org/ev3/docs/lejos/remote/ev3/RMIEV3.html
https://yoshio3.com/tag/lejos/
I found that EV3 can be easily remotely controlled. It seems that you can develop GUI tools by combining with JavaFX etc.
Recommended Posts