Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ev3-toolbox-matlab
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container registry
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mindstorms
ev3-toolbox-matlab
Commits
74426939
Commit
74426939
authored
8 years ago
by
Tim Stadtmann
Browse files
Options
Downloads
Patches
Plain Diff
Update format of device-docs
parent
075d60eb
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
source/Motor.m
+202
-151
202 additions, 151 deletions
source/Motor.m
source/Sensor.m
+67
-20
67 additions, 20 deletions
source/Sensor.m
with
269 additions
and
171 deletions
source/Motor.m
+
202
−
151
View file @
74426939
classdef
Motor
<
MaskedHandle
&
dynamicprops
%
Motor
High-level class to work with motors.
% High-level class to work with motors.
%
% This class is supposed to ease the use of the brick's motors. It is possible to set all
% kinds of parameters, request the current status of the motor ports and of course send
% commands to the brick to be executed on the respective port.
% commands to the brick to be executed on the respective port.
%
% Notes:
% * You don't need to create instances of this class. The EV3-class automatically creates
% instances for each motor port, and you can work with them via the EV3-object.
% * The Motor-class represents motor ports, not individual motors!
%
%
% Signature
% Author: Tim Stadtmann
% Date: 2016/05/19
% Updated: 2016/08/15
% Attributes:
% power (numeric in [-100, 100]): Power level of motor in percent. [WRITABLE]
% speedRegulation (bool): Speed regulation turned on or off. When turned on, motor will
% try to 'hold' its speed at given power level, whatever the load. In this mode, the
% highest possible speed depends on the load and mostly goes up to around 70-80 (at
% this point, the Brick internally input 100% power). When turned off, motor will
% constantly input the same power into the motor. The resulting speed will be
% somewhat lower, depending on the load. [WRITABLE]
% smoothStart (numeric s. t. smoothStart+smoothStop < limitValue): Degrees/Time
% indicating how far/long the motor should smoothly start. Depending on limitMode,
% the input is interpreted either in degrees or milliseconds. The first
% {smoothStart}-milliseconds/degrees of limitValue the motor will slowly accelerate
% until reaching its defined speed. [WRITABLE]
% smoothStop (numeric s. t. smoothStart+smoothStop < limitValue): Degrees/Time
% indicating how far/long the motor should smoothly stop. Depending on limitMode, the
% input is interpreted either in degrees or milliseconds. The last
% [smoothStop]-milliseconds/degrees of limitValue the motor will slowly slow down
% until it has stopped. [WRITABLE]
% limitValue (numeric>=0): Degrees/Time indicating how far/long the motor should run.
% Depending on limitMode, the input is interpreted either in degrees or
% milliseconds. [WRITABLE]
% limitMode ('Tacho'|'Time'): Mode for motor limit. [WRITABLE]
% brakeMode ('Brake'|'Coast'): Mode for braking. If 'Coast', the motor will (at
% tacholimit, if ~=0) coast to a stop. If 'Brake', the motor will stop immediately
% (at tacholimit, if ~=0) and hold the brake. [WRITABLE]
% debug (bool): Debug turned on or off. In debug mode, everytime a command is passed to
% the sublayer ('communication layer'), there is feedback in the console about what
% command has been called. [WRITABLE]
% isRunning (bool): True if motor is running. [READ-ONLY]
% tachoCount (numeric): Current tacho count. [READ-ONLY]
% currentSpeed (numeric): Current speed of motor. If speedRegulation=on this should equal power,
% otherwise it will probably be lower than that. [READ-ONLY]
% type (DeviceType): Type of connected device if any. [READ-ONLY]
properties
% Standard properties to be set by user
%power
- [Writable]
Power level of motor in percent
(numeric in [-100, 100])
%
power
(numeric in [-100, 100]):
Power level of motor in percent
. [WRITABLE]
power
;
%speedRegulation
- [Writable]
Speed regulation turned on or off
(0/1/off/on/'false'/'true')
%
When turned on, motor will
try to 'hold' its speed at given power level, whatever the
%
load. In this mode, the
highest possible speed depends on the load and mostly goes up
%
to around 70-80 (at
this point, the Brick internally input 100% power).
%
When turned off, motor will
constantly input the same power into the motor. The
%
resulting speed will be
somewhat lower, depending on the load.
%
speedRegulation
(bool):
Speed regulation turned on or off
. When turned on, motor will
%
try to 'hold' its speed at given power level, whatever the
load. In this mode, the
%
highest possible speed depends on the load and mostly goes up
to around 70-80 (at
%
this point, the Brick internally input 100% power).
When turned off, motor will
%
constantly input the same power into the motor. The
resulting speed will be
%
somewhat lower, depending on the load.
[WRITABLE]
speedRegulation
;
%smoothStart
- [Writable] Degrees/Time indicating how far/long the motor should smoothly start
(numeric s
uch that
smoothStart+smoothStop < limitValue)
%
Depending on limitMode, the input is interpreted either in degrees or milliseconds.
%
The first [smoothStart]-milliseconds/degrees of limitValue the motor will slowly
%
accelerate until reaching it's defined speed.
%
See also MOTOR.LIMITMODE
%
smoothStart (numeric s
. t.
smoothStart+smoothStop < limitValue)
: Degrees/Time
%
indicating how far/long the motor should smoothly start. Depending on limitMode,
%
the input is interpreted either in degrees or milliseconds. The first
%
{smoothStart}-milliseconds/degrees of limitValue the motor will slowly accelerate
%
until reaching its defined speed. [WRITABLE]
smoothStart
;
%smoothStop
- [Writable] Degrees/Time indicating how far/long the motor should smoothly stop
(numeric s
uch that
smoothStart+smoothStop < limitValue)
%
Depending on limitMode, the input is interpreted either in degrees or milliseconds.
%
The last [smoothStop]-milliseconds/degrees of limitValue the motor will slowly
%
slow down until it has stopped.
%
See also MOTOR.LIMITMODE
%
smoothStop (numeric s
. t.
smoothStart+smoothStop < limitValue)
: Degrees/Time
%
indicating how far/long the motor should smoothly stop. Depending on limitMode, the
%
input is interpreted either in degrees or milliseconds. The last
%
[smoothStop]-milliseconds/degrees of limitValue the motor will slowly slow down
%
until it has stopped. [WRITABLE]
smoothStop
;
%limitValue - [Writable] Degrees/Time indicating how far/long the motor should run (numeric>=0)
% Depending on limitMode, the input is interpreted either in degrees or milliseconds.
% See also MOTOR.LIMITMODE
% limitValue (numeric>=0): Degrees/Time indicating how far/long the motor should run.
% Depending on limitMode, the input is interpreted either in degrees or
% milliseconds. [WRITABLE]
% See also MOTOR.LIMITMODE
limitValue
;
%limitMode
- [Writable]
Mode for motor limit
('Tacho'/'Time')
%
limitMode
('Tacho'|'Time'):
Mode for motor limit
. [WRITABLE]
% See also MOTOR.SMOOTHSTART, MOTOR.SMOOTHSTOP, MOTOR.LIMITMODE
limitMode
;
%brakeMode
- [Writable] Mode for braking ('Brake'/'Coast')
%
If 'Coast', the motor will (at
tacholimit, if ~=0) coast to a stop. If
%
'Brake', the motor will stop immediately
(at tacholimit, if ~=0) and hold the brake.
%
brakeMode
('Brake'|'Coast'): Mode for braking. If 'Coast', the motor will (at
%
tacholimit, if ~=0) coast to a stop. If
'Brake', the motor will stop immediately
%
(at tacholimit, if ~=0) and hold the brake.
[WRITABLE]
brakeMode
;
%debug
- [Writable]
Debug turned on or off
(0/1/off/on/'false'/'true')
%
In debug mode, everytime a command is passed to the sublayer ('communication layer'),
%
there is feedback in the console about what
command has been called
%
debug
(bool):
Debug turned on or off
. In debug mode, everytime a command is passed to
%
the sublayer ('communication layer'), there is feedback in the console about what
%
command has been called
. [WRITABLE]
debug
;
end
properties
(
Dependent
)
% Read-only parameters to be read directly from physical brick
%isRunning
- [Read-only]
True if motor is running
(i.e. speed > 0)
%
isRunning
(bool):
True if motor is running
. [READ-ONLY]
isRunning
;
%tachoCount
- [Read-only]
Current tacho count
%
tachoCount
(numeric):
Current tacho count
. [READ-ONLY]
tachoCount
;
%currentSpeed - [Read-only] Current speed of motor
% If speedRegulation=on this should equal power, otherwise it will probably be lower
% than that.
% currentSpeed (numeric): Current speed of motor. If speedRegulation=on this should
% equal power, otherwise it will probably be lower than that. [READ-ONLY]
% See also MOTOR.SPEEDREGULATION
currentSpeed
;
%type - [Read-only] Type of connected device if any
% See also DEVICETYPE
% type (DeviceType): Type of connected device if any. [READ-ONLY]
type
;
end
properties
(
Hidden
,
Access
=
'private'
)
% Hidden properties for internal use only
commInterface
;
% Communication interface
properties
(
Hidden
,
Access
=
private
)
% Hidden properties for internal use only
% commInterface (CommunicationInterface): Commands are created and sent via the
% communication interface class.
commInterface
;
%% Hidden brick parameters
%port - [Read-only] Motor port
% This is only the string representation of the motor port to work with.
% Internally, either MotorPort-, MotorBitfield- or MotorInput-member will be used.
% port (string): Motor port. This is only the string representation of the motor port
% to work with. Internally, either MotorPort-, MotorBitfield- or MotorInput-member
% will be used.
port
;
% brakeMode is an actual parameter on the brick. To avoid inconsistencies with other
% modi and to prettify the output, a string representing it is saved. In order to avoid
% using string comparisons each time it is used, the corresponding value, that is going
% to be sent, is saved (hidden from the user).
% brakeMode_ (BrakeMode): Byte value, corresponding to brakeMode, that will be sent to the brick
% brakeMode is an actual parameter on the brick. To avoid inconsistencies with other
% modi and to prettify the output, a string representing it is saved. In order to avoid
% using string comparisons each time it is used, the corresponding value, that is going
% to be sent, is saved (hidden from the user).
% See also BRAKEMODE
brakeMode_
;
%% Flags
init
=
true
;
% Indicates 'init-phase' (True as long as constructor is running)
connectedToBrick
=
false
;
% Connection to physical Brick?
state
=
MotorState
();
% State consisting of several special Motor-flags
% init (bool): Indicates init-phase (i.e. constructor is running).
init
=
true
;
% connectedToBrick (bool): True if virtual brick is connected to physical brick.
connectedToBrick
=
false
;
% state (MotorState): State-struct consisting of several special Motor-flags
% See also MOTORSTATE
state
=
MotorState
();
end
properties
(
Hidden
,
Dependent
,
Access
=
'private'
)
% Hidden, dependent properties for internal use only
portNo
;
% Port number
portInput
;
% Port number for input functions
properties
(
Hidden
,
Dependent
,
Access
=
private
)
% Hidden, dependent properties for internal use only
% portNo (PortNo): Internal number of motor port.
% * Port 'A': 0
% * Port 'B': 1
% * Port 'C': 2
% * Port 'D': 3
% See also PORTNO
portNo
;
isSynced
;
% Is motor running in synced mode?
physicalMotorConnected
;
% Physical motor connected to this port?
%portInput (PortInput): Internal number of motor port if accessed via input-opCodes
% * Port 'A': 16
% * Port 'B': 17
% * Port 'C': 18
% * Port 'D': 19
% See also PORTINPUT
portInput
;
internalTachoCount
;
% Internal tachocount used for positioning the motor with tacholimit
%isSynced (bool): True if motor is running in synced mode
isSynced
;
%physicalMotorConnected (bool): True if physical motor is connected to this port
physicalMotorConnected
;
%internalTachoCount (numeric): internal tacho counter used for positioning the motor with a limit
internalTachoCount
;
end
methods
% Standard methods
%% Constructor
function
motor
=
Motor
(
varargin
)
%Motor Sets properties of Motor-object and indicates end of init-phase when it's done
.
%Motor Sets properties of Motor-object and indicates end of init-phase when it's done
%
% Arguments
% * varargin: see
EV3::
setProperties(
ev3
, varargin)
% Arguments
:
% * varargin: see setProperties(
motor
, varargin)
%
motor
.
setProperties
(
varargin
{:});
...
...
@@ -125,9 +179,9 @@ classdef Motor < MaskedHandle & dynamicprops
%% Brick functions
function
start
(
motor
)
%
start
Starts the motor
% Starts the motor
%
% Notes
% Notes
:
% * Right now, alternatingly calling this function with and without tacho limit
% may lead to unexpected behaviour. For example, if you run the motor without
% a tacholimit for some time using Coast, then stop using Coast, and then try
...
...
@@ -271,7 +325,7 @@ classdef Motor < MaskedHandle & dynamicprops
end
function
stop
(
motor
)
%
stop
Stops the motor
% Stops the motor
if
~
motor
.
connectedToBrick
error
(
'Motor::stop: Motor-Object not connected to comm handle.'
);
...
...
@@ -293,7 +347,7 @@ classdef Motor < MaskedHandle & dynamicprops
end
function
syncedStart
(
motor
,
syncMotor
,
varargin
)
%
syncedStart
Starts this motor synchronized with another
% Starts this motor synchronized with another
% This motor acts as a 'master', meaning that the synchronized control is done via
% this one. When syncedStart is called, the master sets some of the slave's
% (syncMotor) properties to keep it consistent with the physical brick. So, for
...
...
@@ -302,32 +356,33 @@ classdef Motor < MaskedHandle & dynamicprops
% The following parameters will be affected on the slave: power, brakeMode,
% limitValue, speedRegulation
%
% Arguments
% * syncMotor (the other motor object to sync with)
% * 'turnRatio', numeric in [-200,200]
% Arguments:
% syncMotor (Motor): the motor-object to sync with
% turnRatio (numeric in [-200,200]): Description of turn_ratio (Excerpt of Firmware-comments, in c_output.c):
% "Turn ratio is how tight you turn and to what direction you turn. [OPTIONAL]
% * 0 value is moving straight forward
% * Negative values turn to the left
% * Positive values turn to the right
% * Value -100 stops the left motor
% * Value +100 stops the right motor
% * Values less than -100 makes the left motor run the opposite
% direction of the right motor (Spin)
% * Values greater than +100 makes the right motor run the opposite
% direction of the left motor (Spin)"
%
% Notes
% * Description of turn_ratio (Excerpt of Firmware-comments, in c_output.c):
% "Turn ratio is how tight you turn and to what direction you turn.
% -> 0 value is moving straight forward
% -> Negative values turn to the left
% -> Positive values turn to the right
% -> Value -100 stops the left motor
% -> Value +100 stops the right motor
% -> Values less than -100 makes the left motor run the opposite
% direction of the right motor (Spin)
% -> Values greater than +100 makes the right motor run the opposite
% direction of the left motor (Spin)"
% * This is right now a pretty 'heavy' function, as it tests if both motors are
% connected AND aren't running, wasting four packets, so keep that in mind
% Notes:
% * This is right now a pretty 'heavy' function, as it tests if both motors are
% connected AND aren't running, wasting four packets, keep that in mind
% * It is necessary to call syncedStop() and not stop() for stopping the motors
% (otherwise the sync-state cannot be exited correctly)
%
% Example
% b = EV3(); b.connect('usb');
% m = b.motorA;
% m.power = 50;
% m.syncedStart(b.motorB);
% % Do stuff
% m.syncedStop();
% Example
:
%
b = EV3(); b.connect('usb');
%
m = b.motorA;
%
m.power = 50;
%
m.syncedStart(b.motorB);
%
% Do stuff
%
m.syncedStop();
%
turnRatio
=
0
;
...
...
@@ -420,7 +475,7 @@ classdef Motor < MaskedHandle & dynamicprops
end
function
syncedStop
(
motor
)
%
syncedStop
Stops both motors previously started with syncedStart
% Stops both motors previously started with syncedStart
.
% Obviously, if motors have not been started synchronized, this throws an error.
%
% See also MOTOR.SYNCEDSTART
...
...
@@ -471,7 +526,7 @@ classdef Motor < MaskedHandle & dynamicprops
end
function
waitFor
(
motor
)
%
waitFor
Stops execution of program as long as motor is running
% Stops execution of program as long as motor is running
%
% Notes:
% * (OLD)This one's a bit tricky. The opCode OutputReady makes the brick stop sending
...
...
@@ -529,7 +584,7 @@ classdef Motor < MaskedHandle & dynamicprops
end
function
internalReset
(
motor
)
%
internalReset
Resets internal tacho count
% Resets internal tacho count
% Use this if motor behaves weird (i.e. not starting at all, or not correctly
% running to limitValue)
%
...
...
@@ -559,6 +614,8 @@ classdef Motor < MaskedHandle & dynamicprops
end
function
resetTachoCount
(
motor
)
% Resets tachocount
if
~
motor
.
connectedToBrick
error
(
'Motor::resetTachoCount: Motor-Object not connected to comm handle.'
);
elseif
~
motor
.
physicalMotorConnected
...
...
@@ -575,10 +632,10 @@ classdef Motor < MaskedHandle & dynamicprops
end
function
setBrake
(
motor
,
brake
)
%
setBrake
Apply or release brake of motor
% Apply or release brake of motor
%
% Arguments
%
*
brake (
0/1/off/on/'false'/'true')
% Arguments
:
%
brake (
bool): If true, brake will be pulled
if
~
isBool
(
brake
)
error
(
'Motor::setBrake: Given parameter is not a valid bool.'
);
...
...
@@ -736,28 +793,29 @@ classdef Motor < MaskedHandle & dynamicprops
end
function
setProperties
(
motor
,
varargin
)
%
setProperties
Sets multiple Motor properties at once using MATLAB's inputParser.
% Sets multiple Motor properties at once using MATLAB's inputParser.
%
% Arguments
%
* '
debug
',
bool
%
* '
smoothStart
',
numeric in [0, limitValue]
%
* '
smoothStop
',
numeric in [0, limitValue]
%
* '
speedRegulation
',
bool
%
* '
brakeMode
',
'Coast'
/
'Brake'
%
* '
limitMode
',
'Time'
/
'Tacho'
%
* '
limitValue
',
numeric > 0
%
* '
power
',
numeric in
[-100,100]
%
* '
batteryMode
',
'Voltage'
/
'Percentage'
% Arguments
:
%
debug
(
bool
)
%
smoothStart
(
numeric in [0, limitValue]
)
%
smoothStop
(
numeric in [0, limitValue]
)
%
speedRegulation
(
bool
)
%
brakeMode
(
'Coast'
|
'Brake'
)
%
limitMode
(
'Time'
|
'Tacho'
)
%
limitValue
(
numeric > 0
)
%
power
(
numeric in [-100,100]
)
%
batteryMode
(
'Voltage'
|
'Percentage'
)
%
% Example
% b = EV3();
% b.connect('bt', 'serPort', '/dev/rfcomm0');
% b.motorA.setProperties('debug', 'on', 'power', 50, 'limitValue', 720, 'speedRegulation', 'on');
% % Instead of: b.motorA.debug = 'on';
% % b.motorA.power = 50;
% % b.motorA.limitValue = 720;
% % b.motorA.speedRegulation = 'on';
% Example
:
%
b = EV3();
%
b.connect('bt', 'serPort', '/dev/rfcomm0');
%
b.motorA.setProperties('debug', 'on', 'power', 50, 'limitValue', 720, 'speedRegulation', 'on');
%
% Instead of: b.motorA.debug = 'on';
%
% b.motorA.power = 50;
%
% b.motorA.limitValue = 720;
%
% b.motorA.speedRegulation = 'on';
%
p
=
inputParser
();
p
.
KeepUnmatched
=
1
;
...
...
@@ -894,17 +952,20 @@ classdef Motor < MaskedHandle & dynamicprops
end
end
methods
(
Access
=
'
private
'
)
% Private functions that directly interact with commLayer
methods
(
Access
=
private
)
% Private functions that directly interact with commLayer
function
success
=
setPower
(
motor
,
power
)
%setPower Sets given power value on the physical Brick.
%
% Notes:
% * If motor is running with a limit, calling outputSpeed/outputPower, to
% manually set the power on the physical brick, would stop the motor and adopt
% the new power value on next start. To avoid this, the motor could be 'restarted'
% with the new value instantly. However, this sometimes leads to unexpected behaviour.
% Therefore, if motor is running with a limit, setPower aborts with a warning.
%
% * If motor is running with a limit, calling outputSpeed/outputPower, to
% manually set the power on the physical brick, would stop the motor and adopt
% the new power value on next start. To avoid this, the motor could be 'restarted'
% with the new value instantly. However, this sometimes leads to unexpected behaviour.
% Therefore, if motor is running with a limit, setPower aborts with a warning.
%
% Returns:
% success (bool): if true, power has successfully been set
if
~
motor
.
connectedToBrick
||
~
motor
.
physicalMotorConnected
% error('Motor::getTachoCount: Motor-Object not connected to comm handle.');
success
=
false
;
...
...
@@ -1012,9 +1073,9 @@ classdef Motor < MaskedHandle & dynamicprops
%getMotorStatus Returns whether motor is busy or not.
%
% Notes:
% * This *mostly* works. Sometimes this falsely returns 0 if isRunning() gets
% called immediately after starting the motor.
% * Busy is set to true if motor is running with tacholimit or synced
%
* This *mostly* works. Sometimes this falsely returns 0 if isRunning() gets
%
called immediately after starting the motor.
%
* Busy is set to true if motor is running with tacholimit or synced
%
if
~
motor
.
connectedToBrick
...
...
@@ -1077,7 +1138,7 @@ classdef Motor < MaskedHandle & dynamicprops
end
end
methods
(
Access
=
'
private
'
,
Hidden
=
true
)
methods
(
Access
=
private
,
Hidden
=
true
)
function
saveState
(
motor
)
%saveState Saves current motor state in dynamic property
...
...
@@ -1118,22 +1179,18 @@ classdef Motor < MaskedHandle & dynamicprops
end
end
methods
(
Access
=
{
?
EV3
}
)
methods
(
Access
=
?
EV3
)
function
connect
(
motor
,
commInterface
)
%connect Connects Motor-object to physical brick.
%
% Notes:
% * This method actually only saves a handle to a Brick-object which has been
% created beforehand (probably by an EV3-object).
%
% Arguments
% * commInterface: instance of Brick-class
% * This method is automatically called by EV3.connect()
% * This method actually only saves a handle to a Brick-object which has been
% created beforehand (probably by an EV3-object).
%
% Examples (for use without EV3-class)
% m = Motor();
% brickInterface = Brick('usb');
% m.connect(brickInterface);
% % do stuff
% Arguments:
% commInterface (CommunicationInterface): Handle to a communication interface
% device
%
if
motor
.
connectedToBrick
...
...
@@ -1162,23 +1219,17 @@ classdef Motor < MaskedHandle & dynamicprops
%disconnect Disconnects Motor-object from physical brick.
%
% Notes:
% * As with Motor::connect, this method actually only sets the property, in which
% the handle to the Brick-class was stored, to 0.
% * This method is automatically called by EV3.disconnect()
% * This method actually only sets the property, in which
% the handle to the CommInterface-class was stored, to 0.
%
% Examples (for use without EV3-class)
% m = Motor();
% brickInterface = Brick('usb');
% m.connect(brickInterface);
% % do stuff
% m.disconnect();
% brickInterface.delete(); % Actual disconnecting!!!
%
motor
.
commInterface
=
0
;
% Note: actual deleting is done in EV3::disconnect.
motor
.
commInterface
=
0
;
motor
.
connectedToBrick
=
false
;
end
function
resetPhysicalMotor
(
motor
)
%
if
~
motor
.
connectedToBrick
||
~
motor
.
physicalMotorConnected
return
;
end
...
...
This diff is collapsed.
Click to expand it.
source/Sensor.m
+
67
−
20
View file @
74426939
classdef
Sensor
<
MaskedHandle
% Sensor High-level class to work with sensors.
% High-level class to work with sensors.
%
% The Sensor-class facilitates the communication with sensors. This mainly consists of
% reading the sensor's type and current value in a specified mode.
%
% Signature
% Author: Tim Stadtmann
% Date: 2016/05/20
% Updated: 2016/08/15
% Notes:
% * You don't need to create instances of this class. The EV3-class automatically creates
% instances for each sensor port, and you can work with them via the EV3-object.
% * The Sensor-class represents sensor ports, not individual sensors!
%
% Attributes:
% mode (DeviceMode.{Type}): Sensor mode in which the value will be read. By default,
% mode is set to DeviceMode.Default.Undefined. Once a physical sensor is connected
% to the port *and* the physical Brick is connected to the EV3-object, the allowed
% mode and the default mode for a Sensor-object are the following (depending on the
% sensor type): [WRITABLE]
%
% * Touch-Sensor:
% * DeviceMode.Touch.Pushed [Default]
% * DeviceMode.Touch.Bumps
% * Ultrasonic-Sensor:
% * DeviceMode.UltraSonic.DistCM [Default]
% * DeviceMode.UltraSonic.DistIn
% * DeviceMode.UltraSonic.Listen
% * Color-Sensor:
% * DeviceMode.Color.Reflect [Default]
% * DeviceMode.Color.Ambient
% * DeviceMode.Color.Col
% * Gyro-Sensor:
% * DeviceMode.Gyro.Angular [Default]
% * DeviceMode.Gyro.Rate
% debug (bool): Debug turned on or off. In debug mode, everytime a command is passed to
% the sublayer ('communication layer'), there is feedback in the console about what
% command has been called. [WRITABLE]
% value (numeric): Value read from hysical sensor. What the value represents depends on
% sensor.mode.
% type (DeviceType): Type of physical sensor connected to the port. Possible types are: [READ-ONLY]
% * DeviceType.NXTTouch
% * DeviceType.NXTLight
% * DeviceType.NXTSound
% * DeviceType.NXTColor
% * DeviceType.NXTUltraSonic
% * DeviceType.NXTTemperature
% * DeviceType.LargeMotor
% * DeviceType.MediumMotor
% * DeviceType.Touch
% * DeviceType.Color
% * DeviceType.UltraSonic
% * DeviceType.Gyro
% * DeviceType.InfraRed
% * DeviceType.Unknown
% * DeviceType.None
% * DeviceType.Error
properties
% Standard properties to be set by user
%mode - [Writable] Sensor mode in which the value will be read (DeviceMode.[...])
...
...
@@ -42,7 +89,7 @@ classdef Sensor < MaskedHandle
type
;
end
properties
(
Hidden
,
Access
=
'
private
'
)
% Hidden properties for internal use only
properties
(
Hidden
,
Access
=
private
)
% Hidden properties for internal use only
commInterface
=
0
;
% Communication interface
%port - [Read-only] Sensor port ('1'/'2'/'3'/'4')
...
...
@@ -56,7 +103,7 @@ classdef Sensor < MaskedHandle
init
=
true
;
% Indicates 'init-phase' (True as long as constructor is running)
end
properties
(
Hidden
,
Dependent
,
Access
=
'
private
'
)
properties
(
Hidden
,
Dependent
,
Access
=
private
)
physicalSensorConnected
;
% Physical sensor connected to this port?
end
...
...
@@ -70,6 +117,7 @@ classdef Sensor < MaskedHandle
%% Brick functions
function
reset
(
sensor
)
%reset Resets value on sensor
%
% Note: This clears ALL the sensors right now, no other Op-Code available... :(
if
~
sensor
.
connectedToBrick
error
(
'Sensor::reset: Sensor-Object not connected to comm handle.'
);
...
...
@@ -139,16 +187,16 @@ classdef Sensor < MaskedHandle
function
setProperties
(
sensor
,
varargin
)
%setProperties Sets multiple Sensor properties at once using MATLAB's inputParser.
%
% Arguments
%
* 'debug', 0/1/'on'/'off'/'true'/'false'
% * 'mode', DeviceMode.[...]
% Arguments
:
%
* 'debug', 0/1/'on'/'off'/'true'/'false'
%
* 'mode', DeviceMode.[...]
%
% Example
% b = EV3();
% b.connect('bt', 'serPort', '/dev/rfcomm0');
% b.sensor1.setProperties('debug', 'on', 'mode', DeviceMode.Color.Ambient);
% % Instead of: b.sensor1.debug = 'on';
% % b.sensor1.mode = DeviceMode.Color.Ambient;
% Example
:
%
b = EV3();
%
b.connect('bt', 'serPort', '/dev/rfcomm0');
%
b.sensor1.setProperties('debug', 'on', 'mode', DeviceMode.Color.Ambient);
%
% Instead of: b.sensor1.debug = 'on';
%
% b.sensor1.mode = DeviceMode.Color.Ambient;
%
p
=
inputParser
();
...
...
@@ -221,7 +269,7 @@ classdef Sensor < MaskedHandle
end
end
methods
(
Access
=
'
private
'
)
% Private brick functions that are wrapped by dependent params
methods
(
Access
=
private
)
% Private brick functions that are wrapped by dependent params
function
setMode
(
sensor
,
mode
)
if
~
sensor
.
connectedToBrick
error
(
'Sensor::getTachoCount: Sensor-Object not connected to comm handle.'
);
...
...
@@ -242,7 +290,7 @@ classdef Sensor < MaskedHandle
function
val
=
getValue
(
sensor
,
varargin
)
%getValue Reads value from sensor
%
% Notes
% Notes
:
% * After changing the mode, sensors initially always send an invalid value. In
% this case, the inputReadSI-opCode is sent again to get the correct value.
%
...
...
@@ -324,7 +372,7 @@ classdef Sensor < MaskedHandle
end
methods
(
Access
=
{
?
EV3
}
)
methods
(
Access
=
?
EV3
)
function
connect
(
sensor
,
commInterface
)
%connect Connects Sensor-object to physical brick
...
...
@@ -368,4 +416,3 @@ classdef Sensor < MaskedHandle
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment