Page 1 of 1

My US sensor returns strange value. How can I treat it?

Posted: 15 Mar 2012, 13:51
by victor5432
Hi there! I'm a newbie who just started learning programming with NXT.
I connected US Sensor and tried to get the value from US Sensor.
It works well if something is in the range of sensor.
But if there's nothing in the range of sensor, after then, it sucks to return the value even though something is in the range of the sensor.
I got the values which makes no sense : 315, 375, 789, and so on...

Here's my code(in NXC),

task measure_dist() {
int sv;
SetSensorUltrasonic(S4);
ClearSensor(S4);
while(true) {
TextOut(20,LCD_LINE7,"Reading:");
sv=SensorUS(S4);
NumOut(70,LCD_LINE7,sv);
wait(250);
}
}

I really need your help... How can i fix it? :cry:

Re: My US sensor returns strange value. How can I treat it?

Posted: 15 Mar 2012, 15:39
by pepijndevos
Clear the screen.

What you are likely seeing is a 3-digit value partially overwritten with a 2-diget value.

So reading 123 and then 23 would display 233.

Re: My US sensor returns strange value. How can I treat it?

Posted: 16 Mar 2012, 09:30
by pbenco
Hello victor5432

You can find the Drawing option here : http://bricxcc.sourceforge.net/nbc/nxcd ... tants.html, for use with TextOut(), NumOut(), PointOut(), LineOut(), CircleOut(), RectOut(), PolyOut(), EllipseOut(), FontTextOut(), FontNumOut(), GraphicOut(), GraphicArrayOut()

Best regards
Ben
P.S. the doc provided with NXC compiler, and Bricxcc are your friends!

Re: My US sensor returns strange value. How can I treat it?

Posted: 17 Mar 2012, 12:24
by victor5432
When I tested sensor with robot c sensor test application, it returned abnormal value.
Tested with 3 us sensors, I think there would be another problem.
Thank you who answered my question!
Anyway, is there any possible problem with my devices? :cry:

Re: My US sensor returns strange value. How can I treat it?

Posted: 17 Mar 2012, 16:00
by mcsummation
An easy way to test the US is to use the built-in NXT function. On the main NXT menu, select "View", then pick "Ultrasonic inch" or "Ultrasonic cm", then select the port you have it plugged into. It will give continuous readings coming from the US. You can see there how poor the US is for measuring distance. I found that between 10 and 50 cm it gives fairly accurate readings. Outside that range, the results are almost random. Even inside that range, you will get occasional spurious readings.

Mindsensors has some IR range finders that appear to work better. I do not have one, so cannot say for sure.

Re: My US sensor returns strange value. How can I treat it?

Posted: 18 Mar 2012, 03:33
by hassenplug
victor5432 wrote:When I tested sensor with robot c sensor test application, it returned abnormal value.
Tested with 3 us sensors, I think there would be another problem.
Thank you who answered my question!
Anyway, is there any possible problem with my devices? :cry:
It sounds like there's a problem with your testing procedure. The sensors can't really return a value greater than 255. I assume you did what pepijndevos suggested. I would suggest exactly the same thing.

Steve

Re: My US sensor returns strange value. How can I treat it?

Posted: 19 Mar 2012, 18:05
by mightor
Try this ROBOTC program, make sure the sensor is hooked up to S1.

- Xander

Code: Select all

#pragma config(Sensor, S1,     SONAR,          sensorSONAR)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main () 
{
  while (true)
  {
    eraseDisplay();
    nxtDisplayCenteredBigTextLine(2, "%d", SensorValue[S1]);
    wait1Msec(50);
  }
}

Re: My US sensor returns strange value. How can I treat it?

Posted: 19 Mar 2012, 20:16
by HaWe
what happens with this:

Code: Select all

// code: NXC, enhanced firmware required!

task measure_dist() {
  int sv;
  SetSensorUltrasonic(S4);
  ClearSensor(S4);
  while(true) {
    TextOut(18,LCD_LINE7,"Reading:      ");
    sv=SensorUS(S4);
    NumOut(72,LCD_LINE7,sv);
    Wait(100);
  }
}

task main() {
  start  measure_dist;
  while(true);
}