Take the 2-minute tour ×
LEGO® Answers is a question and answer site for LEGO® and building block enthusiasts. It's 100% free, no registration required.

Can I use an ultrasound sensor while the Robot is moving, or will it give bad data?

share|improve this question

3 Answers 3

up vote 7 down vote accepted

Short answer: The ultrasonic sensor is perfectly accurate while moving!

A regular NXT robot will move at a maximum speed of several meters per second (usually about 1 or 2 m/s max.). Ultrasound, on the other hand, travels with about 330 meters per second through air. So during the "snapshot" the ultrasound sensor does (basically it sends a ping, listens for the pong-echo, and takes the time difference), your robot appears to be frozen for this brief moment.

So this is why, whenever your ultrasonic sensor makes a measurement, you get a freze-frame snapshot of the current distance to the nearest object it detects. In reality, the sensor sends out pings all the time during default operation, and you just get the very latest measurment -- but essntially, this feels the same.

Since the ultrasonic sensor is digital and offers its data via the I²C protocol, this is where the main latency comes from. On the other hand, you shouldn't poll (i.e. read out) your sensor too frequently, if that is what you're worried about. In several tests we've concluded with hundred NXT kits, that a polling rate of 50 Hz (50 times per second, delay of 20ms between each poll) does work perfectly with no problems at all. When you're using NXT-G, you shouldn't worry at all: You won't get values faster anyway. When you're working with other languages, and you feel your ultrasonic sensor doesn't work so well in a tight loop with constant polling, try to insert this little 20ms break!

Far more important are the objects you try to detect. This is due to the wavelength of ultrasound. You can't detect objects with dimensions of just a couple of centimeters.

  • The US works best when facing walls, perpendicular to the sensor
  • It has big problems detecting furr, carpet- or cloth-like surfaces (the ultrasound doesn't get reflected)
  • It has big problems detecting smooth surfaces, facing the sensor at skew angles (not 90°) -- the ultrasound gets reflected away
  • It has problems detecting round objects (e.g. a water bottle or a football) accurately. The ultrasound gets reflected too widely, so you'll see the bottle or ball "bigger and wider" than it is in reality.
  • It will miss tiny objects

The first rule is, as always: Experiment on your own! For more resources, try the LEGO NXT Hardware SDK or at least the pictures in this german paper, pages 24, 27ff.

share|improve this answer
    
Fantastic answer Linus, many thanks :) –  Zhaph - Ben Duguid Apr 26 '12 at 16:43

The shooterbot, one of the robots that can be built from the instructions in the nxt 2.0 set, uses this sensor while rotating in place, which proves this works pretty well.

please note that your results might be different, depending on the angle, speed of movement and distance of the objects you're measuring. Basically, there's no problem - but the best way to find out is to start building ;)

share|improve this answer

The ultrasound sensor will only be affected by the rate in which it captures and processes data, which could be a matter of milliseconds.

Supposing the ultrasound sensor captured data at one second intervals whilst moving towards an object at a rate of ten inches a second. If the rate at which it was moving was consistent the sensor would report measurements of say 60, 50, 40, 30 inches. This is not 'bad data', it can be considered insufficient depending on objective.

LEGO haven't specified the rate at which the ultrasound sensor processes data, if it hasn't been documented, you might want to try a couple of controlled experiments to see how it is affected by motion.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.