root/branches/telle/RWTHMindstormsNXT/@NXTmotor/get.m @ 246

Revision 246, 1.9 KB (checked in by telle, 5 years ago)

Create version without the use of function closures. This is necessary to make
copying motor objects more intuitive. With function closures a motor object was
like a handle, so that 'set' worked like it works with, e.g., matlab figure
handles. As a result, copying a motor object makes no independent copy. If a
property was set on the copy it was also set on the original. I think this is not
very intuitive as it does not act like a struct.

In this version also synchronization of the properties of synced motors is forced

RevLine 
[218]1function val = get(obj, prop)
2% GET Get NXTmotor object properties.
3%
4%     GET(OBJ) displays all property names and their current values for
5%     NXTmotor object OBJ.
6%
7%     V = GET(OBJ, 'PropertyName') returns the value, V, of the specified
8%     property, PropertyName, for NXTmotor object OBJ.
9%
10%     See also NXTmotor/set, NXTmotor/display.
11%
12
13% Author: Aulis Telle, IND, RWTH Aachen
14
15if ~isa(obj,'NXTmotor')
16    error('RWTHMINDSTORMS:NXTmotor:InvalidObject',...
17        'No NXTmotor object.');
18end
19
20if nargin == 1 && nargout == 0
21    display(obj);
22    return;
23end
24
[246]25
[218]26if nargin > 1
27    switch prop
28        case 'Port'
[246]29            val = obj.port;
[218]30        case 'Power'
[246]31            val = obj.power;
[218]32        case 'MotorOn'
[246]33            if obj.motorOn == 1
[218]34                val = 'on';
35            else
36                val = 'off';
37            end
38        case 'Brake'
[246]39            if obj.brake == 1
[218]40                val = 'on';
41            else
42                val = 'off';
43            end
44        case 'RegulationMode'
[246]45            switch obj.regulationMode
[218]46                case 'IDLE'
47                    val = 'idle';
48                case 'SPEED'
49                    val = 'speed';
50                case 'SYNC'
51                    val = 'sync';
52                case 'SPEEDSYNC'
53                    val = 'speedsync';
54            end
55        case 'TurnRatio'
[246]56            val = obj.turnRatio;
[218]57        case 'RunState'
[246]58            switch obj.runState
[218]59                case 'IDLE';
60                    val = 'idle';
61                case 'RUMPUP';
62                    val = 'rampup';
63                case 'RUNNING';
64                    val = 'running';
65                case'RAMPDOWN';
66                    val = 'rampdown';
67            end
68        case 'TachoLimit'
[246]69            val = obj.tachoLimit;
[218]70        otherwise
71            error('RWTHMINDSTORMS:NXTmotor:unsupportedProperty',...
72                sprintf('Unsupported property %s',prop));
73    end
74end
Note: See TracBrowser for help on using the browser.