| 1 | |
|---|
| 2 | <!DOCTYPE html |
|---|
| 3 | PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
|---|
| 4 | <html> |
|---|
| 5 | <head> |
|---|
| 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
|---|
| 7 | |
|---|
| 8 | <!-- |
|---|
| 9 | This HTML is auto-generated from an M-file. |
|---|
| 10 | To make changes, update the M-file and republish this document. |
|---|
| 11 | --> |
|---|
| 12 | <title>WaitFor</title> |
|---|
| 13 | <meta name="generator" content="MATLAB 7.7"> |
|---|
| 14 | <meta name="date" content="2008-11-05"> |
|---|
| 15 | <meta name="m-file" content="script_WaitFor"> |
|---|
| 16 | <link type="text/css" rel="stylesheet" href="../../style.css"> |
|---|
| 17 | </head> |
|---|
| 18 | <body> |
|---|
| 19 | <p class="header">RWTH - Mindstorms NXT Toolbox</p> |
|---|
| 20 | <div class="content"> |
|---|
| 21 | <h1>WaitFor</h1> |
|---|
| 22 | <!--introduction--> |
|---|
| 23 | <p>Wait for motor to stop (busy waiting)</p> |
|---|
| 24 | <!--/introduction--> |
|---|
| 25 | <h2>Contents</h2> |
|---|
| 26 | <div> |
|---|
| 27 | <ul> |
|---|
| 28 | <li><a href="#1">Syntax</a></li> |
|---|
| 29 | <li><a href="#2">Description</a></li> |
|---|
| 30 | <li><a href="#7">Example</a></li> |
|---|
| 31 | <li><a href="#9">See also</a></li> |
|---|
| 32 | <li><a href="#12">Signature</a></li> |
|---|
| 33 | </ul> |
|---|
| 34 | </div> |
|---|
| 35 | <h2>Syntax<a name="1"></a></h2><pre>[ timedOut ] = WaitFor( obj, timeout, handle)</pre><h2>Description<a name="2"></a></h2> |
|---|
| 36 | <p><tt>WaitFor(OBJ)</tt> or <tt>OBJ.WaitFor</tt> Wait for motor specified by <tt>OBJ</tt> to stop. We do this by reading the motor settings from the NXT brick repeatedly until the RunState goes to 'idle'. If the |
|---|
| 37 | motor is set to run infinitely, return immediately and display a warning. |
|---|
| 38 | </p> |
|---|
| 39 | <p><tt>TIMEDOUT = WaitFor(OBJ, TIMEOUT)</tt> or <tt>OBJ.WaitFor(TIMEOUT)</tt> Does the same as described above but has an additional timeout <tt>TIMEOUT</tt> (given in seconds). After this time the function stops waiting and returns 1. Otherwise it returns 0. |
|---|
| 40 | </p> |
|---|
| 41 | <p><tt>TIMEDOUT = WaitFor(OBJ, TIMEOUT, HANDLE)</tt> or <tt>OBJ.WaitFor(TIMEOUT, HANDLE)</tt> Use <tt>HANDLE</tt> to identify the connection to use for this command. |
|---|
| 42 | </p> |
|---|
| 43 | <h2>Example<a name="7"></a></h2><pre class="codeinput"> <span class="comment">% Instantiate Motor and run it</span> |
|---|
| 44 | m = NXTmotor(<span class="string">'A'</span>, <span class="string">'Power'</span>, 50, <span class="string">'MotorOn'</span>, 1, <span class="keyword">...</span> |
|---|
| 45 | <span class="string">'RunState'</span>, <span class="string">'running'</span>, <span class="string">'TachoLimit'</span>, 1000); |
|---|
| 46 | SendToNXT(m); |
|---|
| 47 | <span class="comment">% Wait for the motor</span> |
|---|
| 48 | t = WaitFor(m, 0.5); |
|---|
| 49 | <span class="keyword">if</span> t ~= 0 |
|---|
| 50 | disp(<span class="string">'Timed out'</span>); |
|---|
| 51 | <span class="keyword">end</span> |
|---|
| 52 | </pre><h2>See also<a name="9"></a></h2> |
|---|
| 53 | <p><a href="NXTmotor.html">NXTmotor</a>, <a href="ReadFromNXT.html">ReadFromNXT</a>, <a href="SendToNXT.html">SendToNXT</a>, <a href="Stop.html">Stop</a></p> |
|---|
| 54 | <h2>Signature<a name="12"></a></h2> |
|---|
| 55 | <div> |
|---|
| 56 | <ul> |
|---|
| 57 | <li><b>Author:</b> Aulis Telle (see AUTHORS) |
|---|
| 58 | </li> |
|---|
| 59 | <li><b>Date:</b> 2008/08/15 |
|---|
| 60 | </li> |
|---|
| 61 | <li><b>Copyright:</b> 2007-2008, RWTH Aachen University |
|---|
| 62 | </li> |
|---|
| 63 | </ul> |
|---|
| 64 | </div> |
|---|
| 65 | <p class="footer"><br> |
|---|
| 66 | Published with wg_publish; V1.0<br></p> |
|---|
| 67 | </div> |
|---|
| 68 | <!-- |
|---|
| 69 | ##### SOURCE BEGIN ##### |
|---|
| 70 | %% WaitFor |
|---|
| 71 | % Wait for motor to stop (busy waiting) |
|---|
| 72 | %% Syntax |
|---|
| 73 | % [ timedOut ] = WaitFor( obj, timeout, handle) |
|---|
| 74 | %% Description |
|---|
| 75 | %% |
|---|
| 76 | % |WaitFor(OBJ)| or |OBJ.WaitFor| Wait for motor specified by |OBJ| to stop. |
|---|
| 77 | % We do this by reading the motor settings from the NXT |
|---|
| 78 | % brick repeatedly until the RunState goes to 'idle'. If the motor |
|---|
| 79 | % is set to run infinitely, return immediately and display a |
|---|
| 80 | % warning. |
|---|
| 81 | %% |
|---|
| 82 | % |TIMEDOUT = WaitFor(OBJ, TIMEOUT)| or |OBJ.WaitFor(TIMEOUT)| Does the |
|---|
| 83 | % same as described above but has an additional timeout |TIMEOUT| (given |
|---|
| 84 | % in seconds). After this time the function stops waiting and |
|---|
| 85 | % returns 1. Otherwise it returns 0. |
|---|
| 86 | %% |
|---|
| 87 | % |TIMEDOUT = WaitFor(OBJ, TIMEOUT, HANDLE)| or |OBJ.WaitFor(TIMEOUT, HANDLE)| |
|---|
| 88 | % Use |HANDLE| to identify the connection to use for this command. |
|---|
| 89 | %% |
|---|
| 90 | %% Example |
|---|
| 91 | % Instantiate Motor and run it |
|---|
| 92 | m = NXTmotor('A', 'Power', 50, 'MotorOn', 1, ... |
|---|
| 93 | 'RunState', 'running', 'TachoLimit', 1000); |
|---|
| 94 | SendToNXT(m); |
|---|
| 95 | % Wait for the motor |
|---|
| 96 | t = WaitFor(m, 0.5); |
|---|
| 97 | if t ~= 0 |
|---|
| 98 | disp('Timed out'); |
|---|
| 99 | end |
|---|
| 100 | %% |
|---|
| 101 | %% See also |
|---|
| 102 | % NXTmotor, ReadFromNXT, SendToNXT, Stop |
|---|
| 103 | %% |
|---|
| 104 | %% |
|---|
| 105 | %% Signature |
|---|
| 106 | %% |
|---|
| 107 | % * *Author:* Aulis Telle (see AUTHORS) |
|---|
| 108 | % * *Date:* 2008/08/15 |
|---|
| 109 | % * *Copyright:* 2007-2008, RWTH Aachen University |
|---|
| 110 | % |
|---|
| 111 | |
|---|
| 112 | ##### SOURCE END ##### |
|---|
| 113 | --> |
|---|
| 114 | </body> |
|---|
| 115 | </html> |
|---|