Feature.getRangeReadings().getAngle(i) always returning 0,0

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

Moderators: roger, imaqine, 99jonathan

jngl
New User
Posts: 6
Joined: Fri Mar 21, 2014 10:30 am

Feature.getRangeReadings().getAngle(i) always returning 0,0

Postby jngl » Fri Apr 11, 2014 8:20 am

Hi,

We're having an issue uring a UltrasonicSensor through a RangeFeatureDetector.

We'd like to use the getRangeReadings().getAngle(int) function from the Feature instance (argument of the featureDetected(...) function) but it always returns 0,0 no matter what.

getRangeReadings().getDistance(int) works fine tho.

Thanks for your time.

jngl
New User
Posts: 6
Joined: Fri Mar 21, 2014 10:30 am

Re: Feature.getRangeReadings().getAngle(i) always returning

Postby jngl » Fri Apr 11, 2014 8:29 am

Quick code snippet :

Code: Select all

package robot;

import lejos.nxt.SensorPort;
import lejos.nxt.UltrasonicSensor;
import lejos.robotics.objectdetection.Feature;
import lejos.robotics.objectdetection.FeatureDetector;
import lejos.robotics.objectdetection.FeatureListener;
import lejos.robotics.objectdetection.RangeFeatureDetector;

public class Sonar implements FeatureListener {
    private final float MAX_RANGE = 200.0f;
    private final int TIMER_DETECTION = 5;
    private UltrasonicSensor us;
    private RangeFeatureDetector rfd;

    Sonar() {
    }

    void initSonar(SensorPort sonar) {
        us = new UltrasonicSensor(sonar);
        rfd = new RangeFeatureDetector(us, MAX_RANGE, TIMER_DETECTION);
        rfd.addListener(this);
    }

    public void featureDetected(Feature feature, FeatureDetector detector) {
        feature.getRangeReadings().getAngle(0); // always returns 0
        feature.getRangeReadings().getDistance(0); // works fine
    }
}

User avatar
gloomyandy
leJOS Team Member
Posts: 4315
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Feature.getRangeReadings().getAngle(i) always returning

Postby gloomyandy » Fri Apr 11, 2014 8:41 am

Hi, what you are seeing is correct. The sensor you are using (Lego Ultrasonic) does not have any capability to determine the angle to the object, it basically always returns what is directly in front of it (hence the angle is 0).

jngl
New User
Posts: 6
Joined: Fri Mar 21, 2014 10:30 am

Re: Feature.getRangeReadings().getAngle(i) always returning

Postby jngl » Fri Apr 11, 2014 9:45 am

Hey,

Thanks for your quick reply !

The UltrasonicSensor does have a "field of view" of approximately 60°, isn't it possible to get the angle of a detected objet relative to the robot ?

Image

In this example ~ 20° for the ball and ~ -5° for the box.

Thanks for your time !

User avatar
gloomyandy
leJOS Team Member
Posts: 4315
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Feature.getRangeReadings().getAngle(i) always returning

Postby gloomyandy » Fri Apr 11, 2014 2:38 pm

No, at least not easily. You may be able to do it by rotating the sensor and looking for when objects appear and leave the field of view, but the basic sensor has no capability to provide any angle information.

Aswin
leJOS Team Member
Posts: 210
Joined: Tue Apr 26, 2011 9:18 pm
Location: Netherlands
Contact:

Re: Feature.getRangeReadings().getAngle(i) always returning

Postby Aswin » Fri Apr 11, 2014 5:49 pm

Hi,

If you've got two US sensors you can use triangulation to get the direction of the object.
See this article with code and a video.

Aswin
My NXT blog: http://nxttime.wordpress.com/


Return to “NXJ Software”

Who is online

Users browsing this forum: No registered users and 1 guest