Doubt using a EV3 IRSeeker

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

Moderators: roger, gloomyandy, skoehler

Doubt using a EV3 IRSeeker

Postby esmetaman » Sun Sep 15, 2013 3:58 pm

I have testing new IRSeeker sensor from EV3 Retail Kit:
http://www.ev-3.net/en/archives/848

Testing the sensor, I have read that it could be used to:

Measure distances
Detect a IR beacon
Receive commands

Measure distances:
Using this mode, I could measure distances without any problem:

Code: Select all
import lejos.nxt.Button;
import lejos.nxt.EV3IRSensor;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.UARTPort;


public class EV3IRSensorTest {

   private final static int SWITCH_DELAY = 250;
   private final static int IR_PROX = 0;
   
   public static void main(String[] args) throws InterruptedException {
      EV3IRSensor ir = new EV3IRSensor((UARTPort) SensorPort.S1);
      ir.switchMode(IR_PROX,SWITCH_DELAY);
      
      LCD.clear();

      while (!Button.ESCAPE.isDown()) {
         LCD.drawString("IR: " + ir.getRange(), 0, 0);
         System.out.println("IR Range: " + ir.getRange());
         
         Thread.sleep(SWITCH_DELAY);
       }
      
      LCD.clear();
      System.out.println("EXIT");      
      System.exit(0);   
   }
}



but when I use the method: getRanges, I have some problems:

Code: Select all
import lejos.nxt.Button;
import lejos.nxt.EV3IRSensor;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.UARTPort;


public class EV3IRSensorTest2 {

   private final static int SWITCH_DELAY = 250;
   private final static int IR_PROX = 0;
   
   public static void main(String[] args) throws InterruptedException {
      EV3IRSensor ir = new EV3IRSensor((UARTPort) SensorPort.S1);
      ir.switchMode(IR_PROX,SWITCH_DELAY);
      float ranges[];
      
      LCD.clear();

      while (!Button.ESCAPE.isDown()) {
         
         ranges = ir.getRanges();
         if(ranges.length > 0){
            System.out.println("IR Ranges: " + ranges.length);
            if(ranges.length == 1){
               System.out.println("IR: " + ranges[0]);
            }else if(ranges.length == 2){
               System.out.println("IR: " + ranges[0]);
               System.out.println("IR: " + ranges[1]);
            }else if(ranges.length == 3){
               System.out.println("IR: " + ranges[0]);
               System.out.println("IR: " + ranges[1]);
               System.out.println("IR: " + ranges[2]);
            }
         }
         Thread.sleep(SWITCH_DELAY);
       }
      
      LCD.clear();
      System.out.println("EXIT");      
      System.exit(0);
      
   }

}


Shell:

Code: Select all
root@EV3:~/lejos/examples/2# jrun EV3IRSensorTest2       
Time is 6
Time is 2179
L1 Time is 2193
L2 Time is 2203
L1 Time is 2213
L2 Time is 2273
Sensor is ready retry cnt 98
L3 Time is 3762
Mode cnt 6
reset cnt 0
Set mode 0
Mode is IR-PROX
status is 8
Exception in thread "main" java.lang.NullPointerException
        at EV3IRSensorTest2.main(EV3IRSensorTest2.java:23)
root@EV3:~/lejos/examples/2#


What is the problem?

In the other side, If I want to detect a IRBeacon, what is the way to use the method getBearings?

Code: Select all
import lejos.nxt.Button;
import lejos.nxt.EV3IRSensor;
import lejos.nxt.LCD;
import lejos.nxt.SensorPort;
import lejos.nxt.UARTPort;


public class EV3IRSensorTest3 {

   private final static int SWITCH_DELAY = 250;
   private final static int IR_SEEK = 1;
   
   public static void main(String[] args) throws InterruptedException {
      EV3IRSensor ir = new EV3IRSensor((UARTPort) SensorPort.S1);
      ir.switchMode(IR_SEEK,SWITCH_DELAY);
      
      byte bearings[] = null;
      int offset = 0;
      int len = 0;
      
      LCD.clear();

      while (!Button.ESCAPE.isDown()) {
         
         ir.getBearings(bearings, offset, len);

         Thread.sleep(50);
       }
      
      LCD.clear();
      System.out.println("EXIT");      
      System.exit(0);
      
   }

}
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 236
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Doubt using a EV3 IRSeeker

Postby skoehler » Sun Sep 15, 2013 4:18 pm

Dude! That NPE is in your own main method. Obviously, the ranges array becomes zero at some point. So what does the documentation of the getRanges method say?
skoehler
leJOS Team Member
 
Posts: 1350
Joined: Thu Oct 30, 2008 4:54 pm

Re: Doubt using a EV3 IRSeeker

Postby gloomyandy » Sun Sep 15, 2013 4:40 pm

You could always try looking at the source code. As you will see getRanges for the IRSensor always returns null. This is because it can only return a single range (unlike the NXT Ultrasonic sensor). Arguably I should have returned a single element array, but I didn't.

Also there is no need to call switch_mode. Simply use the appropriate method and it will take care of the switch for you. In the next release I will make it so that you can not access that method directly.

Finally is there something unclear about the following comment?
Code: Select all
    /**
     * return the bearing and distance to one or more IR beacons. Up to four
     * beacons (on different channels 0-3) can be detected. Each beacon has an
     * associated two byte value (so the beacon on channel 0 will have values
     * in locations 0 and 1 in the array. The first location contains the relative
     * bearing to the beacon, the second the distance.<br>
     * The bearing values range from -12 to +12 (with values increasing clockwise
     * when looking from behind the sensor. A bearing of 0 indicates the beacon is
     * directly in front of the sensor. Distance values (0-100) are in cm and if no
     * beacon is detected a bearing of 0 and a distance of -128(255) is returned.
     * @param bearings
     * @param offset
     * @param len
     */
    public void getBearings(byte[] bearings, int offset, int len)


Do you have the source code checked out as part of your development environment? If not please do so. There is a lot of information in there that will explain things to you...

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

Re: Doubt using a EV3 IRSeeker

Postby skoehler » Sun Sep 15, 2013 4:43 pm

gloomyandy wrote:Do you have the source code checked out as part of your development environment? If not please do so. There is a lot of information in there that will explain things to you...


Also, remove the JAR file from your build path, and add a project dependency on the ev3classes project instead. That will allow Eclipse to show you the Javadoc as you program. Also make sure to have the JavaDoc View enabled in Eclipse. (I assume, Andy didn't add the sources to the JAR, meaning that if only the JAR is part of your build path, then Eclipse can't find the JavaDoc).
skoehler
leJOS Team Member
 
Posts: 1350
Joined: Thu Oct 30, 2008 4:54 pm

Re: Doubt using a EV3 IRSeeker

Postby gloomyandy » Sun Sep 15, 2013 4:45 pm

Correct no source as part of the jar, at this stage we do not really have an end user package I'm expecting people to have all of the source directly available. This is how things have been documented on the wiki.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3632
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Doubt using a EV3 IRSeeker

Postby esmetaman » Mon Sep 16, 2013 5:46 pm

Hi Andy,

many thanks for the advice, I will do it.

In relation to the method:

Code: Select all
ir.getBearings(bearings, offset, len);


How to use it?

Cheers
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 236
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Doubt using a EV3 IRSeeker

Postby gloomyandy » Mon Sep 16, 2013 8:08 pm

Did you read my post above? There is a large comment that describes what getBearings does. You may also want to look at some of the videos I've posted one of which shows the IR sensor being used to track the IR remote control in beacon mode...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3632
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Doubt using a EV3 IRSeeker

Postby ruperty » Thu Jan 09, 2014 5:05 pm

gloomyandy wrote:Did you read my post above? There is a large comment that describes what getBearings does. You may also want to look at some of the videos I've posted one of which shows the IR sensor being used to track the IR remote control in beacon mode...


Hi, Where are these videos? I can't find them.
Regards,
Rupert
ruperty
Novice
 
Posts: 71
Joined: Sun Oct 14, 2007 11:21 am

Re: Doubt using a EV3 IRSeeker

Postby gloomyandy » Thu Jan 09, 2014 6:26 pm

You could try reading the sticky posts at the top of this section of the forum...
viewtopic.php?f=18&t=4480

The first post has a link to the video, using the IR Seeker is about 5 minutes in.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3632
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff