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

Revision 392, 3.0 KB (checked in by telle, 5 years ago)

Edit comments

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   
53for k = 1:nargout
54  settings = NXT_GetOutputState(obj.Port(k));
55  data.Port = settings.Port;
56  data.Power = settings.Power;
57  if strcmp(settings.RunStateName, 'RUNNING') == 1
58    data.IsRunning = 1;
59  else
60    data.IsRunning = 0;
61  end
62  if strcmp(settings.RegModeName, 'SPEED') == 1
63    data.SpeedRegulation = 1;
64  else
65    data.SpeedRegulation = 0;
66  end
67  data.TachoLimit = settings.TachoLimit;
68  data.TachoCount = settings.TachoCount;
69  data.Position   = settings.RotationCount;
70  data.TurnRatio  = settings.TurnRatio;
71 
72  varargout{k} = data;
73end
Note: See TracBrowser for help on using the browser.