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

Discussion specific to the intelligent brick, sensors, motors, and more.
Post Reply
victor5432
Posts: 2
Joined: 15 Mar 2012, 13:42

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

Post 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:
pepijndevos
Posts: 175
Joined: 28 Dec 2011, 13:07
Location: Gelderland, Netherlands
Contact:

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

Post 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.
-- Pepijn
http://studl.es Mindstorms Building Instructions
pbenco
Posts: 71
Joined: 29 Sep 2010, 09:43
Contact:

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

Post 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!
pbenco.wordpress.com/
victor5432
Posts: 2
Joined: 15 Mar 2012, 13:42

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

Post 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:
mcsummation
Posts: 220
Joined: 23 Jan 2012, 17:07
Location: Round Rock, TX

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

Post 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.
hassenplug
Posts: 346
Joined: 27 Sep 2010, 03:05
Contact:

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

Post 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
---> Link to lots of MINDSTORMS stuff under my picture --->
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

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

Post 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);
  }
}
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

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

Post 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);
}
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 18 guests