root/trunk/demos/Example_3_DriveAroundTable_MotorClass.m @ 994

Revision 994, 2.6 KB (checked in by staas, 19 months ago)

* formatted some strings for better display in Matlab Help

Line 
1%% Example 3: Drive Around Table (Motor Class)
2% Let a robot (e.g. Tribot or CATTbot) drive a square on the floor
3%
4% Signature
5%
6% *  Author: Linus Atorf, Alexander Behrens
7% *  Date: 2009/07/17
8% *  License: BSD
9% *  RWTH - Mindstorms NXT Toolbox: http://www.mindstorms.rwth-aachen.de
10
11
12%% Check toolbox installation
13% verify that the RWTH - Mindstorms NXT toolbox is installed.
14if verLessThan('RWTHMindstormsNXT', '3.00');
15    error(strcat('This program requires the RWTH - Mindstorms NXT Toolbox ' ...
16        ,'version 3.00 or greater. Go to http://www.mindstorms.rwth-aachen.de ' ...
17        ,'and follow the installation instructions!'));
18end%if
19
20
21%% Clear and close
22COM_CloseNXT all
23clear all
24close all
25
26
27%% Constants and so on
28TableLength      = 1000;     % in degrees of motor rotations :-)
29QuarterTurnTicks = 219;      % in motor degrees, how much is a 90° turn of the bot?
30Ports = [MOTOR_B; MOTOR_C];  % motorports for left and right wheel
31DrivingSpeed     = 60;
32TurningSpeed     = 40;
33
34
35%% Open Bluetooth connetion
36h = COM_OpenNXT('bluetooth.ini');
37COM_SetDefaultNXT(h);
38
39
40%% Initialize motor-objects:
41
42mStraight                   = NXTMotor(Ports);
43% next command since we are driving in SYNC-mode. This should not be
44% necessary with correct default values, but at the moment, I have to set
45% it manually,
46mStraight.SpeedRegulation   = false;  % not for sync mode
47mStraight.Power             = DrivingSpeed;
48mStraight.TachoLimit        = TableLength;
49mStraight.ActionAtTachoLimit = 'Brake';
50
51
52mTurn1                      = NXTMotor(Ports(2)); % ports swapped because it's nicer
53mTurn1.SpeedRegulation      = false;  % we could use it if we wanted
54mTurn1.Power                = TurningSpeed;
55mTurn1.TachoLimit           = QuarterTurnTicks;
56mStraight.ActionAtTachoLimit = 'Brake';
57
58
59mTurn2          = mTurn1;
60mTurn2.Port     = Ports(1);   % ports swapped again...
61mTurn2.Power    = - mTurn1.Power;
62
63
64
65%% Initialize Motors...
66% we send this in case they should still be spinning or something...
67mStraight.Stop('off');
68
69
70%% Start the engines, main loop begins (repeated 4 times)
71
72% 4 times because we got 4 equal sides of the table :-)
73for j = 1 : 4
74
75%% Drive
76
77    mStraight.SendToNXT();
78   
79%% Wait for the end end of table
80    mStraight.WaitFor();
81   
82%% Now please turn
83
84    mTurn1.SendToNXT();
85    mTurn1.WaitFor();
86   
87    mTurn2.SendToNXT();
88    mTurn2.WaitFor();
89   
90%% Thats it. Repeat 4 times....
91end%for
92
93%% Done.
94% Hey! End of a hard day's work
95% Just to show good style, we close down our motors again:
96mStraight.Stop('off');
97
98
99%% Close Bluetooth connection
100COM_CloseNXT(h);
Note: See TracBrowser for help on using the browser.