Changes between Version 20 and Version 21 of Preview
- Timestamp:
- 12/30/11 17:22:51 (17 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Preview
v20 v21 110 110 {{{ 111 111 #!html 112 <h2>Clear and close<a name="2"></a></h2><pre class="codeinput">COM_CloseNXT <span style="color: #A020F0">all</span> 112 <h2>Clear and close<a name="2"></a></h2> 113 <pre style="background: #EEEEEE; padding: 10px;">COM_CloseNXT <span style="color: #A020F0">all</span> 113 114 clear <span style="color: #A020F0">all</span> 114 115 close <span style="color: #A020F0">all</span> 115 </pre><h2>Constants and so on<a name="3"></a></h2><pre class="codeinput">TableLength = 1000; <span style="color: #228B22">% in degrees of motor rotations :-)</span> 116 117 <h3>Constants and so on</h3> 118 TableLength = 1000; <span style="color: #228B22">% in degrees of motor rotations :-)</span> 116 119 QuarterTurnTicks = 219; <span style="color: #228B22">% in motor degrees, how much is a 90° turn of the bot?</span> 117 120 Ports = [MOTOR_B; MOTOR_C]; <span style="color: #228B22">% motorports for left and right wheel</span> 118 121 DrivingSpeed = 60; 119 122 TurningSpeed = 40; 120 </pre><h2>Open Bluetooth connetion<a name="4"></a></h2><pre class="codeinput">h = COM_OpenNXT(<span style="color: #A020F0">'bluetooth.ini'</span>); 123 124 <h3>Open Bluetooth connetion</h3> 125 h = COM_OpenNXT(<span style="color: #A020F0">'bluetooth.ini'</span>); 121 126 COM_SetDefaultNXT(h); 122 </pre><h2>Initialize motor-objects:<a name="5"></a></h2><pre class="codeinput">mStraight = NXTMotor(Ports); 127 128 <h3>Initialize motor-objects:</h3> 129 mStraight = NXTMotor(Ports); 123 130 <span style="color: #228B22">% next command since we are driving in SYNC-mode. This should not be</span> 124 131 <span style="color: #228B22">% necessary with correct default values, but at the moment, I have to set</span> … … 140 147 mTurn2.Port = Ports(1); <span style="color: #228B22">% ports swapped again...</span> 141 148 mTurn2.Power = - mTurn1.Power; 142 </pre><h2>Initialize Motors...<a name="6"></a></h2><p>we send this in case they should still be spinning or something...</p><pre class="codeinput">mStraight.Stop(<span style="color: #A020F0">'off'</span>); 143 </pre><h2>Start the engines, main loop begins (repeated 4 times)<a name="7"></a></h2><pre class="codeinput"><span style="color: #228B22">% 4 times because we got 4 equal sides of the table :-)</span> 149 150 <h3>Initialize Motors...</h3><span style="color: #228B22">% we send this in case they should still be spinning or something...</span> 151 mStraight.Stop(<span style="color: #A020F0">'off'</span>); 152 <h3>Start the engines, main loop begins (repeated 4 times)</h3> 153 <span style="color: #228B22">% 4 times because we got 4 equal sides of the table :-)</span> 144 154 <span class="keyword">for</span> j = 1 : 4 145 </pre><h2>Drive<a name="9"></a></h2><pre class="codeinput"> mStraight.SendToNXT(); 146 </pre><h2>Wait for the end end of table<a name="10"></a></h2><pre class="codeinput"> mStraight.WaitFor(); 147 </pre><h2>Now please turn<a name="11"></a></h2><pre class="codeinput"> mTurn1.SendToNXT(); 155 156 <h3>Drive</h3> mStraight.SendToNXT(); 157 <h3>Wait for the end end of table</h3> mStraight.WaitFor(); 158 <h3>Now please turn</h3> mTurn1.SendToNXT(); 148 159 mTurn1.WaitFor(); 149 160 150 161 mTurn2.SendToNXT(); 151 162 mTurn2.WaitFor(); 152 </pre><h2>Thats it. Repeat 4 times....<a name="12"></a></h2><pre class="codeinput"><span class="keyword">end</span><span style="color: #228B22">%for</span> 153 </pre><h2>Done.<a name="14"></a></h2><p>Hey! End of a hard day's work Just to show good style, we close down our motors again:</p><pre class="codeinput">mStraight.Stop(<span style="color: #A020F0">'off'</span>); 154 </pre><h2>Close Bluetooth connection<a name="15"></a></h2><pre class="codeinput">COM_CloseNXT(h); 163 <h3>Thats it. Repeat 4 times....</h3><span class="keyword">end</span><span style="color: #228B22">%for</span> 164 <h3>Done.</h3><span style="color: #228B22">% Hey! End of a hard day's work Just to show good style, we close down our motors again:</span> 165 mStraight.Stop(<span style="color: #A020F0">'off'</span>); 166 <h3>Close Bluetooth connection</h3>COM_CloseNXT(h); 155 167 </pre><p style="text-align: right; 156 168 font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;"><br>
