My US sensor returns strange value. How can I treat it?
-
- Posts: 2
- Joined: 15 Mar 2012, 13:42
My US sensor returns strange value. How can I treat it?
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?
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?
-
- Posts: 175
- Joined: 28 Dec 2011, 13:07
- Location: Gelderland, Netherlands
- Contact:
Re: My US sensor returns strange value. How can I treat it?
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.
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
http://studl.es Mindstorms Building Instructions
Re: My US sensor returns strange value. How can I treat it?
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!
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/
-
- Posts: 2
- Joined: 15 Mar 2012, 13:42
Re: My US sensor returns strange value. How can I treat it?
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?
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?
-
- Posts: 220
- Joined: 23 Jan 2012, 17:07
- Location: Round Rock, TX
Re: My US sensor returns strange value. How can I treat it?
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.
Mindsensors has some IR range finders that appear to work better. I do not have one, so cannot say for sure.
McSummation aka James
http://www.mcsummation.com/Mindstorms/
http://www.mcsummation.com/Mindstorms/
-
- Posts: 346
- Joined: 27 Sep 2010, 03:05
- Contact:
Re: My US sensor returns strange value. How can I treat it?
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.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?
Steve
---> Link to lots of MINDSTORMS stuff under my picture --->
Re: My US sensor returns strange value. How can I treat it?
Try this ROBOTC program, make sure the sensor is hooked up to S1.
- Xander
- 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)
| 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)
Re: My US sensor returns strange value. How can I treat it?
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);
}
Who is online
Users browsing this forum: No registered users and 0 guests