[LeJOS] Let's remotely control the EV3 motor with Java

Introduction

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]

Overview

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.

Sample program

Remote control of the motor

IMG_8638.JPG

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

}

Commentary

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

reference

http://www.lejos.org/ev3/docs/lejos/remote/ev3/RMIEV3.html

https://yoshio3.com/tag/lejos/

Summary

I found that EV3 can be easily remotely controlled. It seems that you can develop GUI tools by combining with JavaFX etc.

Recommended Posts

[LeJOS] Let's remotely control the EV3 motor with Java
[LeJOS] Let's control the EV3 motor with Java
[LeJOS] Get EV3 sensor value remotely with Java
[ev3 x Java] Single motor control
Let's scrape with Java! !!
Let's experiment with Java inlining
Let's operate Excel with Java! !!
Version control Java with SDKMAN
Java version control with jenv
Make an Ev3 radio control with JavaFx and leJOS [Part 2]
Make an Ev3 radio control with JavaFx and leJOS [Part 1]
Returning to the beginning, getting started with Java ② Control statements, loop statements
[ev3 × Java] Display, sound, LED control
Follow the link with Selenium (Java)
Image processing: Let's play with the image
Let's try WebSocket with Java and javascript!
Try using the Wii remote with Java
[Java] Get the date with the LocalDateTime class
Let's make a calculator application with Java ~ Create a display area in the window
Let's write Java file input / output with NIO
[Java] Set the time from the browser with jsoup
Understanding the MVC framework with server-side Java 1/4 View
Understanding the MVC framework with server-side Java 3/4 Controller
Java starting with JShell-A peek into the Java world
Understanding the MVC framework with server-side Java 2/4 Model
Let leJOS ev3 communicate with Bluetooth without blocking
You also need to specify the host when debugging remotely with Java 9 or later