you're reading...
leJOS Features, Moving around

leJOS Navigation: Navigation model

This is the seventh in a series of posts on leJOS Navigation.

This post is about the Navigation model. The navigation model is a way to integrate all the leJOS navigation features, and communicate with an application on the PC. The PC application typically shows your robot moving around in a mapped area, and lets you control the robot using all the leJOS navigation features. For example, you can use path finders to calculate paths, show them on map, and then follow them. While the robot moves around, any features or obstacles detected can be shown on the map.

leJOS has two standard applications written using the navigation model – EV3MapCommand and EV3MCLCommand.

EV3MapCommand controls a robot in a mapped area. EV3MCLCommand controls a robot that does Monte Carlo Localization. It lets you see the particle set and watch it converge as localization is achieved. You can, however, write your own applications using the navigation model.

The basic navigation model is defined by the abstract class NavigationModel.

There is then an EV3 implementation, EV3NavigationModel, and a PC implementation, PCNavigationModel. These classes extend NavigationModel.

EV3MapCommand runing on the PC, needs an EV3 Navigation model program running on the EV3. By default it uses te EV3MapTest program which does the following:

import java.io.IOException;

import lejos.hardware.Button;
import lejos.hardware.port.SensorPort;
import lejos.hardware.sensor.EV3IRSensor;
import lejos.robotics.RangeFinderAdapter;
import lejos.robotics.RegulatedMotor;
import lejos.robotics.mapping.EV3NavigationModel;
import lejos.robotics.mapping.NavEventListener;
import lejos.robotics.mapping.NavigationModel.NavEvent;
import lejos.robotics.navigation.DifferentialPilot;
import lejos.robotics.navigation.Move.MoveType;
import lejos.robotics.navigation.Navigator;
import lejos.robotics.objectdetection.Feature;
import lejos.robotics.objectdetection.FeatureDetector;
import lejos.robotics.objectdetection.FeatureListener;
import lejos.robotics.objectdetection.RangeFeatureDetector;
import lejos.utility.PilotProps;

 * Used with the MapTest or PathTest PC samples, or other PC mapping applications.
 * Sends moves, updated poses, features detected, waypoints reached and other navigation events
 * to the PC.
 * Receives instructions as events from the PC.
 * @author Lawrie Griffiths
public class MapTest implements NavEventListener {
	public static final float MAX_DISTANCE = 50f;
	public static final int DETECTOR_DELAY = 1000;
	private EV3NavigationModel model;
	public static void main(String[] args) throws Exception {
		(new MapTest()).run();
	public void run() throws Exception {
    	model = new EV3NavigationModel();


	public void whenConnected() {
    	PilotProps pp = new PilotProps();
    	try {
    	} catch (IOException ioe) {
    	float wheelDiameter = Float.parseFloat(pp.getProperty(PilotProps.KEY_WHEELDIAMETER, "4.96"));
    	float trackWidth = Float.parseFloat(pp.getProperty(PilotProps.KEY_TRACKWIDTH, "13.0"));
    	RegulatedMotor leftMotor = PilotProps.getMotor(pp.getProperty(PilotProps.KEY_LEFTMOTOR, "B"));
    	RegulatedMotor rightMotor = PilotProps.getMotor(pp.getProperty(PilotProps.KEY_RIGHTMOTOR, "C"));
    	boolean reverse = Boolean.parseBoolean(pp.getProperty(PilotProps.KEY_REVERSE,"false"));
    	final DifferentialPilot robot = new DifferentialPilot(wheelDiameter,trackWidth,leftMotor,rightMotor,reverse);
    	final Navigator navigator = new Navigator(robot);
    	EV3IRSensor ir = new EV3IRSensor(SensorPort.S1);
    	RangeFeatureDetector detector = new RangeFeatureDetector(new RangeFinderAdapter(ir.getDistanceMode()), MAX_DISTANCE, DETECTOR_DELAY);
    	// Adding the navigator, adds the pilot and pose provider as well
    	// Add the feature detector and start it. 
    	// Give it a pose provider, so that it records the pose when a feature was detected
    	// Stop if an obstacle is detected, unless doing a rotate
    	detector.addListener(new FeatureListener() {
			public void featureDetected(Feature feature, FeatureDetector detector) {
				if (robot.isMoving() && robot.getMovement().getMoveType() != MoveType.ROTATE) {
					if (navigator.isMoving()) navigator.stop();

	public void eventReceived(NavEvent navEvent) {
		// Nothing

You can use your own program to replace this. Some obvious things you can change are the sensor used for obstacle detection, the obstacle detection parameters, and the action taken when an object is detected. You could also change the pilot used from DifferentialPilot to one suitable for driving your specific robot.



2 thoughts on “leJOS Navigation: Navigation model

  1. please i would like to get more details how can i build a map in my PC? i could not understand how it can be happened

    Posted by mizouboss | 2016/02/29, 17:33

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

About leJOS News

leJOS News keeps you up-to-date with leJOS. It features latest news, explains cool features, shows advanced techniques and highlights amazing projects. Be sure to subscribe to leJOS News and never miss an article again. Best of all, subscription is free!
Follow leJOS News on WordPress.com
%d bloggers like this: