| 1 | |
|---|
| 2 | <!DOCTYPE html |
|---|
| 3 | PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
|---|
| 4 | <html><head> |
|---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
|---|
| 6 | <!-- |
|---|
| 7 | This HTML is auto-generated from an M-file. |
|---|
| 8 | To make changes, update the M-file and republish this document. |
|---|
| 9 | --><title>GetUltrasonic</title><meta name="generator" content="MATLAB 7.9"><meta name="date" content="2009-11-27"><meta name="m-file" content="script_GetUltrasonic"> |
|---|
| 10 | <link type="text/css" rel="stylesheet" href="../../style.css"> |
|---|
| 11 | </head><body><div class="content"><h1>GetUltrasonic</h1><!--introduction--><p>Reads the current value of the NXT ultrasonic sensor</p><!--/introduction--><h2>Contents</h2><div><ul><li><a href="#2">Syntax</a></li><li><a href="#5">Description</a></li><li><a href="#14">Limitations</a></li><li><a href="#18">Example</a></li><li><a href="#20">See also</a></li><li><a href="#22">Signature</a></li></ul></div><h2>Syntax<a name="2"></a></h2><p><tt>distance = GetUltrasonic(port)</tt></p><p><tt>distance = GetUltrasonic(port, handle)</tt></p><h2>Description<a name="5"></a></h2><p><tt>distance = GetUltraSonic(port)</tt> returns the current measurement value <tt>distance</tt> of the NXT ultrasonic sensor. <tt>distance</tt> represents the measured distance in cm. If no echo can be detected (which could indicate that either there is no obstacle in the way, or the ultrasound does not get reflected, e.g. by fur-like surfaces), the reading will be 255. If no measurement can be made (defect sensor, cable disconnected, etc.), a value of -1 will be returned.</p><p>The given <tt>port</tt> number specifies the connection port. The value <tt>port</tt> can be addressed by the symbolic constants <tt>SENSOR_1</tt> , <tt>SENSOR_2</tt>, <tt>SENSOR_3</tt> and <tt>SENSOR_4</tt> analog to the labeling on the NXT Brick.</p><p>The last optional argument can be a valid NXT handle. If none is specified, the default handle will be used (call <tt>COM_SetDefaultNXT</tt> to set one).</p><p><b>Note:</b></p><p>This function only works when the sensor was correctly opened with <tt>OpenUltrasonic(port)</tt>. If the sensor is being used in snapshot mode, <tt>GetUltrasonic</tt> will not work correctly!</p><p>For different uses, see also <tt>OpenUltrasonic(port, 'snapshot')</tt> and the functions <tt>USMakeSnapshot</tt> and <tt>USGetSnapshotResults</tt>.</p><h2>Limitations<a name="14"></a></h2><p>Since the Ultrasonic sensors all operate at the same frequency, multiple US sensors will interfere with each other! If multiple US sensors can "see each other" (or their echos and reflections), results will be unpredictable (and probably also unusable). You can avoid this problem by turning off US sensors, or operating them in snapshot mode (see also <tt>USMakeSnapshot</tt> and <tt>USGetSnapshotResults</tt>).</p><p>Due to the speed of sound in air, the ultrasonic sensor needs a certain amount of time to complete a successful measurement. This is why the maximum polling rate has been limited to 50 Hz (i.e. a call will take 20ms if called too often). This is only relevant for fast USB connections.</p><h2>Example<a name="18"></a></h2><pre class="codeinput"> OpenUltrasonic(SENSOR_4); |
|---|
| 12 | distance = GetUltrasonic(SENSOR_4); |
|---|
| 13 | CloseSensor(SENSOR_4); |
|---|
| 14 | </pre><h2>See also<a name="20"></a></h2><p><a href="OpenUltrasonic.html">OpenUltrasonic</a>, <a href="USMakeSnapshot.html">USMakeSnapshot</a>, <a href="USGetSnapshotResults.html">USGetSnapshotResults</a>, <a href="CloseSensor.html">CloseSensor</a>, <a href="NXT_LSRead.html">NXT_LSRead</a>, <a href="NXT_LSWrite.html">NXT_LSWrite</a>, </p><h2>Signature<a name="22"></a></h2><div><ul><li><b>Author:</b> Linus Atorf, Alexander Behrens (see AUTHORS)</li><li><b>Date:</b> 2008/01/15</li><li><b>Copyright:</b> 2007-2009, RWTH Aachen University</li></ul></div><p class="footer"><br> |
|---|
| 15 | Published with wg_publish; V1.0<br></p></div><!-- |
|---|
| 16 | ##### SOURCE BEGIN ##### |
|---|
| 17 | %% GetUltrasonic |
|---|
| 18 | % Reads the current value of the NXT ultrasonic sensor |
|---|
| 19 | %% |
|---|
| 20 | %% Syntax |
|---|
| 21 | % |distance = GetUltrasonic(port)| |
|---|
| 22 | %% |
|---|
| 23 | % |distance = GetUltrasonic(port, handle)| |
|---|
| 24 | %% |
|---|
| 25 | %% Description |
|---|
| 26 | % |distance = GetUltraSonic(port)| returns the current measurement value |distance| of the NXT |
|---|
| 27 | % ultrasonic sensor. |distance| represents the measured distance in cm. |
|---|
| 28 | % If no echo can be detected (which could indicate that either there is |
|---|
| 29 | % no obstacle in the way, or the ultrasound does not get reflected, e.g. |
|---|
| 30 | % by fur-like surfaces), the reading will be 255. If no measurement can |
|---|
| 31 | % be made (defect sensor, cable disconnected, etc.), a value of -1 will |
|---|
| 32 | % be returned. |
|---|
| 33 | %% |
|---|
| 34 | % The given |port| number specifies the connection port. The value |port| can be |
|---|
| 35 | % addressed by the symbolic constants |SENSOR_1| , |SENSOR_2|, |SENSOR_3| and |SENSOR_4| analog to |
|---|
| 36 | % the labeling on the NXT Brick. |
|---|
| 37 | %% |
|---|
| 38 | % The last optional argument can be a valid NXT handle. If none is |
|---|
| 39 | % specified, the default handle will be used (call |COM_SetDefaultNXT| to |
|---|
| 40 | % set one). |
|---|
| 41 | %% |
|---|
| 42 | %% |
|---|
| 43 | % *Note:* |
|---|
| 44 | %% |
|---|
| 45 | %% |
|---|
| 46 | % This function only works when the sensor was correctly opened with |
|---|
| 47 | % |OpenUltrasonic(port)|. If the sensor is being used in snapshot mode, |
|---|
| 48 | % |GetUltrasonic| will not work correctly! |
|---|
| 49 | %% |
|---|
| 50 | % For different uses, see also |OpenUltrasonic(port, 'snapshot')| and the |
|---|
| 51 | % functions |USMakeSnapshot| and |USGetSnapshotResults|. |
|---|
| 52 | %% |
|---|
| 53 | %% Limitations |
|---|
| 54 | % Since the Ultrasonic sensors all operate at the same frequency, |
|---|
| 55 | % multiple US sensors will interfere with each other! If multiple US |
|---|
| 56 | % sensors can "see each other" (or their echos and reflections), |
|---|
| 57 | % results will be unpredictable (and probably also unusable). You can |
|---|
| 58 | % avoid this problem by turning off US sensors, or operating them in |
|---|
| 59 | % snapshot mode (see also |USMakeSnapshot| and |USGetSnapshotResults|). |
|---|
| 60 | %% |
|---|
| 61 | %% |
|---|
| 62 | % Due to the speed of sound in air, the ultrasonic sensor needs a certain |
|---|
| 63 | % amount of time to complete a successful measurement. This is why the |
|---|
| 64 | % maximum polling rate has been limited to 50 Hz (i.e. a call will take |
|---|
| 65 | % 20ms if called too often). This is only relevant for fast USB |
|---|
| 66 | % connections. |
|---|
| 67 | %% |
|---|
| 68 | %% Example |
|---|
| 69 | OpenUltrasonic(SENSOR_4); |
|---|
| 70 | distance = GetUltrasonic(SENSOR_4); |
|---|
| 71 | CloseSensor(SENSOR_4); |
|---|
| 72 | %% |
|---|
| 73 | %% See also |
|---|
| 74 | % OpenUltrasonic, USMakeSnapshot, USGetSnapshotResults, CloseSensor, NXT_LSRead, NXT_LSWrite |
|---|
| 75 | %% |
|---|
| 76 | %% Signature |
|---|
| 77 | %% |
|---|
| 78 | % * *Author:* Linus Atorf, Alexander Behrens (see AUTHORS) |
|---|
| 79 | % * *Date:* 2008/01/15 |
|---|
| 80 | % * *Copyright:* 2007-2009, RWTH Aachen University |
|---|
| 81 | % |
|---|
| 82 | |
|---|
| 83 | ##### SOURCE END ##### |
|---|
| 84 | --></body></html> |
|---|