root/trunk/publishing/MATLABCentral/Example_4_DriveAroundTable_MotorClass.m @ 701

Revision 701, 2.4 KB (checked in by behrens, 4 years ago)
  • update MATLAB Central documents
Line 
1%% Example 7: Drive Around Table (Motor Class)
2% This example equals demo 3, but uses the motor class and an advanced motor control.
3%
4% Note: For using the advanced motor control the MotorControl program has to be downloaded onto your
5% NXT. The MotorControl program is located at /tools/MotorControl.
6%
7% Signature
8%   Author: Linus Atorf, Alexander Behrens
9%   Date: 2009/07/17
10%   RWTH - Mindstorms NXT Toolbox: http://www.mindstorms.rwth-aachen.de
11
12%% Clear and close
13COM_CloseNXT all
14clear all
15close all
16
17
18%% Constants and so on
19TableLength      = 1000;     % in degrees of motor rotations :-)
20QuarterTurnTicks = 217;      % in motor degrees, how much is a 90° turn of the bot?
21Ports = [MOTOR_B; MOTOR_C];  % motorports for left and right wheel
22DrivingSpeed     = 50;
23TurningSpeed     = 30;
24
25
26%% Open Bluetooth connetion
27h = COM_OpenNXT('bluetooth.ini');
28COM_SetDefaultNXT(h);
29
30
31%% Initialize motor-objects:
32
33mStraight                   = NXTMotor(Ports);
34% next command since we are driving in SYNC-mode. This should not be
35% necessary with correct default values, but at the moment, I have to set
36% it manually,
37mStraight.SpeedRegulation   = false;  % not for sync mode
38mStraight.Power             = DrivingSpeed;
39mStraight.TachoLimit        = TableLength;
40mStraight.BrakeAtTachoLimit = true;
41
42
43mTurn1                      = NXTMotor(Ports(2)); % ports swapped because it's nicer
44mTurn1.SpeedRegulation      = true; 
45mTurn1.Power                = TurningSpeed;
46mTurn1.TachoLimit           = QuarterTurnTicks;
47mTurn1.BrakeAtTachoLimit    = true;
48
49
50mTurn2          = mTurn1;
51mTurn2.Port     = Ports(1);   % ports swapped again...
52mTurn2.Power    = - mTurn1.Power;
53
54
55
56%% Initialize Motors...
57% we send this in case they should still be spinning or something...
58mStraight.Stop('off');
59
60
61%% Start the engines, main loop begins (repeated 4 times)
62
63% 4 times because we got 4 equal sides of the table :-)
64for j = 1 : 4
65
66%% Drive
67
68    mStraight.SendToNXT();
69   
70   
71%% Check for the end end of table
72        mStraight.WaitFor();
73   
74%% Now please turn
75
76    mTurn1.SendToNXT();
77    mTurn1.WaitFor();
78   
79    mTurn2.SendToNXT();
80    mTurn2.WaitFor();
81   
82   
83%% Thats it. Repeat 4 times....
84end%for
85
86
87
88% Hey! End of a hard day's work
89% Just to show good style, we close down our motors again:
90mStraight.Stop('off');
91
92
93%% Close Bluetooth connection
94COM_CloseNXT(h);
Note: See TracBrowser for help on using the browser.