root/branches/telle/v2.00-at/mfiles/@NXTmotor/ReadFromNXT.m @ 403

Revision 403, 3.1 KB (checked in by telle, 5 years ago)

* Port to new MATLAB R2008 class syntax
* output at least one set of settings in ReadFromNXT, also if no output arg is given

Line 
1function [ varargout ] = ReadFromNXT( obj )
2%READFROMNXT Read current state of specified motor from NXT brick
3%
4%     DATA = READFROMNXT(OBJ) requests the current state of the motor specified
5%     with OBJ from the NXT brick. NXTmotor object OBJ is not modified.
6%     DATA is a structure with property/value pairs.
7%
8%     [DATA1 DATA2] = READFROMNXT(OBJ) If the NXTmotor object OBJ
9%     controls two motors, DATA1 and DATA2 hold the parameters of
10%     the first and the second motor respectively. If only one
11%     output argument is given, the parameters of the first motor
12%     are returned.
13%
14%     See also NXTmotor.
15
16% Signature
17%   Author: Aulis Telle (see AUTHORS)
18%   Date: 2008/08/15
19%   Copyright: 2007-2008, RWTH Aachen University
20%
21%
22% ***********************************************************************************************
23% *  This file is part of the RWTH - Mindstorms NXT Toolbox.                                    *
24% *                                                                                             *
25% *  The RWTH - Mindstorms NXT Toolbox is free software: you can redistribute it and/or modify  *
26% *  it under the terms of the GNU General Public License as published by the Free Software     *
27% *  Foundation, either version 3 of the License, or (at your option) any later version.        *
28% *                                                                                             *
29% *  The RWTH - Mindstorms NXT Toolbox is distributed in the hope that it will be useful,       *
30% *  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS  *
31% *  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
32% *                                                                                             *
33% *  You should have received a copy of the GNU General Public License along with the           *
34% *  RWTH - Mindstorms NXT Toolbox. If not, see <http://www.gnu.org/licenses/>.                 *
35% ***********************************************************************************************
36
37if ~isa(obj,'NXTmotor')
38    error('MATLAB:RWTHMindstormsNXT:InvalidObject',...
39        'No NXTmotor object.');
40end
41
42
43if nargout > 2
44    error('MATLAB:RWTHMindstormsNXT:WrongNumberOfParameters',...
45          'To many output parameters');
46end
47
48if nargout > numel(obj.Port)
49    error('MATLAB:RWTHMindstormsNXT:WrongNumberOfParameters',...
50          'Number of output parameters does not match number of ports');
51end
52
53if nargout == 0
54    nout = 1;
55else
56    nout = nargout;
57end
58   
59for k = 1:nout
60  settings = NXT_GetOutputState(obj.Port(k));
61  data.Port = settings.Port;
62  data.Power = settings.Power;
63  if strcmp(settings.RunStateName, 'RUNNING') == 1
64    data.IsRunning = 1;
65  else
66    data.IsRunning = 0;
67  end
68  if strcmp(settings.RegModeName, 'SPEED') == 1
69    data.SpeedRegulation = 1;
70  else
71    data.SpeedRegulation = 0;
72  end
73  data.TachoLimit = settings.TachoLimit;
74  data.TachoCount = settings.TachoCount;
75  data.Position   = settings.RotationCount;
76  data.TurnRatio  = settings.TurnRatio;
77 
78  varargout{k} = data;
79end
Note: See TracBrowser for help on using the browser.