|
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
|
| Line | |
|---|
| 1 | function 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 | |
|---|
| 15 | if ~isa(obj,'NXTmotor') |
|---|
| 16 | error('RWTHMINDSTORMS:NXTmotor:InvalidObject',... |
|---|
| 17 | 'No NXTmotor object.'); |
|---|
| 18 | end |
|---|
| 19 | |
|---|
| 20 | if nargin == 1 && nargout == 0 |
|---|
| 21 | display(obj); |
|---|
| 22 | return; |
|---|
| 23 | end |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | if nargin > 1 |
|---|
| 27 | switch prop |
|---|
| 28 | case 'Port' |
|---|
| 29 | val = obj.port; |
|---|
| 30 | case 'Power' |
|---|
| 31 | val = obj.power; |
|---|
| 32 | case 'MotorOn' |
|---|
| 33 | if obj.motorOn == 1 |
|---|
| 34 | val = 'on'; |
|---|
| 35 | else |
|---|
| 36 | val = 'off'; |
|---|
| 37 | end |
|---|
| 38 | case 'Brake' |
|---|
| 39 | if obj.brake == 1 |
|---|
| 40 | val = 'on'; |
|---|
| 41 | else |
|---|
| 42 | val = 'off'; |
|---|
| 43 | end |
|---|
| 44 | case 'RegulationMode' |
|---|
| 45 | switch obj.regulationMode |
|---|
| 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' |
|---|
| 56 | val = obj.turnRatio; |
|---|
| 57 | case 'RunState' |
|---|
| 58 | switch obj.runState |
|---|
| 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' |
|---|
| 69 | val = obj.tachoLimit; |
|---|
| 70 | otherwise |
|---|
| 71 | error('RWTHMINDSTORMS:NXTmotor:unsupportedProperty',... |
|---|
| 72 | sprintf('Unsupported property %s',prop)); |
|---|
| 73 | end |
|---|
| 74 | end |
|---|