Problem with ultrasonic sensors

This is where you talk about the NXJ hardware related topics such as the brick, sensors, LEGO pieces, etc.

Moderators: roger, imaqine, 99jonathan

aldos
New User
Posts: 1
Joined: Tue Oct 19, 2010 8:17 am
Location: Germany

Problem with ultrasonic sensors

Postby aldos » Thu Nov 04, 2010 9:02 am

Hi, I have some Problems with the nxt ultrasonic sensors and I´m quit new to NXJ and the LEGO robots. I was doing some test measurements with low distances and noticed a variance in the measurement.

To measure the distances i used a big cartboard, foot rule and the stadard NXT ultrasonic Sensor. For each new measurment i replaced the cartboard in a new distance to the sensor. Also i wrote a simple peace of code:

Code: Select all

public static void main(String[] args)
   {
      UltrasonicSensor Sens1 = new UltrasonicSensor(SensorPort.S2);
      
      LCD.drawString("US Measuring", 0, 0);
      LCD.drawString("press Button", 0, 1);
      Button.waitForPress();
      
      RConsole.openUSB(2500);
      RConsole.print("srart of measure loop");
      
      float temp;
      int a;
               
      while (true)
      {
         LCD.clear();
         temp = Sens1.getRange();
         Delay.msDelay(50);
         LCD.drawInt(Math.round(temp), 0, 0);
         RConsole.println("float: " + Float.toString(temp));
         a = Sens1.getDistance();
         Delay.msDelay(50);
         LCD.drawInt(a, 0, 1);
         RConsole.println("int: " + Integer.toString(a));
         Delay.msDelay(2000);
      }

   }


Here are my measurements: (2 from 10 measurmends)
real distance: 24 23 22 21 20 ... 10 ... 5 4 3 2
meas. dist 1: 24 24 23 23 22 ... 12 ... 7 6 5 255
meas. dist 2: 24 24 23 23 22 ... 12 ... 7 6 8 67

You will see that i get a constant variance of 2. This is true for all distances betewwn 21 and 3.

Another Problem is the distance of 3 here i only get every 5th measurmend correct and this only if you calculate the variation of 2 into the measured distance.

Is this a known problem? What causes this beheavior? Can i fix this somehow to get more accurate measurements with low distances?

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

Postby gloomyandy » Thu Nov 04, 2010 2:31 pm

Hi,
are those units inches or cm? The Ultrasonic sensor was not really designed to handle objects closer than about 5cm or so. So I'm surprised you are having problems. If you want to measure such close distances there are better sensors available...
http://www.mindsensors.com/index.php?mo ... PAGE_id=69

Andy


Return to “NXJ Hardware”

Who is online

Users browsing this forum: No registered users and 1 guest