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

leJOS Navigation: Object Detection

This is the third of a series of posts on leJOS navigation. It covers object detection.

We first looked at pilots that move your robot around.

We then found that you could easily add localization to your navigation application and keep track of the robot’s position and heading.

Another thing that you are likely to want to do is to avoid bumping into anything as your robot moves around. Some navigation applications continually scan for obstacles as they move around unknown. The object detection classes can help with this by automating scanning and obstacle or feature detection. If you consider whatever you detect as an obstacle, you might want to find a path that avoids it. If you consider it to be a feature, you might want to add it to a map.

Another type of application may be moving a robot around a known or a mapped environment and not expect to bump into anything. However, if the estimate of the robot’s position becomes inaccurate, or if there are unexpected obstacles in the environment, then you might want to take action, for example by stopping the robot before it hits an obstacle.

It is this latter type of application that we will look at.

To detect obstacles or features you will need one or more sensors. Typically a distance sensor such the EV3 IR sensor or the EV3 Ultrasonic sensor is used, but you can use other sensors such as EV3 Touch sensor. You might have just one such range sensor pointing forwards, or you could have a set of such sensors at different angles, or you might use a scanning range finder. We will concentrate on the case of a single distance (or range) sensor, facing forwards.

The thing that object detection detects is known as a feature and is defined by the Feature interface.

There is currently just one implementation of this interface: RangeFeature.

The classes that detect features are known as feature detectors and must implement the FeatureDetector interface. leJOS currently has two implementations of this: RangeDetector for use with range sensors and TouchDetector for use with touch sensors. These two classes are subclasses of FeatureDetectorAdapter, which makes writing new feature detectors easier.

When a feature detector detects a feature, it calls a FeatureListener. You can switch feature detection on and off, by calling the enableDetection method.

Here is a simple example of object detection, that implements a simple bumper car. The robot moves forward until it detects an obstacle, and the does a simple obstacle avoidance action, and ten goes forward again.

import lejos.hardware.Button;
import lejos.hardware.motor.Motor;
import lejos.hardware.port.SensorPort;
import lejos.hardware.sensor.EV3IRSensor;
import lejos.robotics.RangeFinderAdapter;
import lejos.robotics.navigation.DifferentialPilot;
import lejos.robotics.objectdetection.Feature;
import lejos.robotics.objectdetection.FeatureDetector;
import lejos.robotics.objectdetection.FeatureListener;
import lejos.robotics.objectdetection.RangeFeatureDetector;

public class FeatureAvoider {
	static final float MAX_DISTANCE = 50f;
	static final int DETECTOR_DELAY = 1000;

	public static void main(String[] args) {   	
    	final DifferentialPilot robot = new DifferentialPilot(4.0,18.0,Motor.A, Motor.C);
    	EV3IRSensor ir = new EV3IRSensor(SensorPort.S4);
    	RangeFeatureDetector detector = new RangeFeatureDetector(new RangeFinderAdapter(ir.getDistanceMode()), MAX_DISTANCE, DETECTOR_DELAY);

    	detector.addListener(new FeatureListener() {
			public void featureDetected(Feature feature, FeatureDetector detector) {
    	while(Button.ESCAPE.isUp()) Thread.yield();

In the case where you have multiple feature detectors the FusionDetector class can be useful to treat the as a group, and, for example, enable or disable them together.



No comments yet.

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: