diff --git a/source/EV3.m b/source/EV3.m index 07e0e39a9c712a5949d22f4ce04305fe30a88d2a..29aeda84acbb2c7d4f03abd06626ad0690fd095f 100755 --- a/source/EV3.m +++ b/source/EV3.m @@ -310,7 +310,7 @@ classdef EV3 < MaskedHandle % Example: % b = EV3(); |br| % b.connect('bt', 'serPort', '/dev/rfcomm0'); |br| - % b.playTone(50, 5000, 1000); % Plays tone with 50% volume and 5000Hz for 1 + % b.playTone(40, 5000, 1000); % Plays tone with 40% volume and 5000Hz for 1 % second. |br| % diff --git a/source/Motor.m b/source/Motor.m index 1756ed19285657ccc81cebb96b20c43518a512d8..3d8039f8cd175ce09d1b756c6193169fc13cd42a 100755 --- a/source/Motor.m +++ b/source/Motor.m @@ -9,6 +9,8 @@ classdef Motor < MaskedHandle & dynamicprops % * 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! + % * If you start a motor with power=0, the internal state will still be set to + % 'isRunning' % % Attributes: % power (numeric in [-100, 100]): Power level of motor in percent. *[WRITABLE]* @@ -32,7 +34,7 @@ classdef Motor < MaskedHandle & dynamicprops % 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 + % brakeMode ('Brake'|'Coast'): Action done when stopping. 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 @@ -49,31 +51,31 @@ classdef Motor < MaskedHandle & dynamicprops % power (numeric in [-100, 100]): Power level of motor in percent. [WRITABLE] power; - % 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 (bool): Speed regulation turned on or off. [WRITABLE] + % 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; - % 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 (numeric s. t. smoothStart+smoothStop < limitValue): Degrees/Time indicating how far/long the motor should smoothly start. [WRITABLE] + % 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. + % See also MOTOR.LIMITVALUE, MOTOR.LIMITMODE smoothStart; - % 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 (numeric s. t. smoothStart+smoothStop < limitValue): Degrees/Time indicating how far/long the motor should smoothly stop. [WRITABLE] + % 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.LIMITVALUE, MOTOR.LIMITMODE smoothStop; - % limitValue (numeric>=0): Degrees/Time indicating how far/long the motor should run. + % limitValue (numeric>=0): Degrees/Time indicating how far/long the motor should run. [WRITABLE] % Depending on limitMode, the input is interpreted either in degrees or - % milliseconds. [WRITABLE] + % milliseconds. % See also MOTOR.LIMITMODE limitValue; @@ -81,14 +83,14 @@ classdef Motor < MaskedHandle & dynamicprops % See also MOTOR.SMOOTHSTART, MOTOR.SMOOTHSTOP, MOTOR.LIMITMODE limitMode; - % 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 ('Brake'|'Coast'): Action done when stopping. [WRITABLE] + % 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; - % 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 (bool): Debug turned on or off. [WRITABLE] + % 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; end @@ -99,8 +101,9 @@ classdef Motor < MaskedHandle & dynamicprops % tachoCount (numeric): Current tacho count. [READ-ONLY] tachoCount; - % currentSpeed (numeric): Current speed of motor. If speedRegulation=on this should - % equal power, otherwise it will probably be lower than that. [READ-ONLY] + % currentSpeed (numeric): Current speed of motor. [READ-ONLY] + % If speedRegulation=on this should equal power, otherwise it will probably be + % lower than that. % See also MOTOR.SPEEDREGULATION currentSpeed; @@ -146,7 +149,7 @@ classdef Motor < MaskedHandle & dynamicprops % See also PORTNO portNo; - %portInput (PortInput): Internal number of motor port if accessed via input-opCodes + % portInput (PortInput): Internal number of motor port if accessed via input-opCodes % - Port 'A': 16 % - Port 'B': 17 % - Port 'C': 18 @@ -154,7 +157,7 @@ classdef Motor < MaskedHandle & dynamicprops % See also PORTINPUT portInput; - %isSynced (bool): True if motor is running in synced mode + % isSynced (bool): True if motor is running in synced mode isSynced; % isMaster (bool): True if motor is running in synced mode and has a slave @@ -166,7 +169,7 @@ classdef Motor < MaskedHandle & dynamicprops % 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 (numeric): internal tacho counter used for positioning the motor with a limit internalTachoCount; end @@ -196,7 +199,7 @@ classdef Motor < MaskedHandle & dynamicprops % a tacholimit for some time using Coast, then stop using Coast, and then try % to run the with a tacholimit, it will stop sooner or later than expected, % or may not even start at all. - % * After calling one of the functions to control the motor with some kind of + % * (OLD)After calling one of the functions to control the motor with some kind of % limit (which is done if limit~=0), the physical brick's power/speed value for % starting without a limit (i.e. if limit==0) is reset to zero. So if you want % to control the motor without a limit after doing so with a limit, you would @@ -342,11 +345,7 @@ classdef Motor < MaskedHandle & dynamicprops error('Motor::stop: No physical motor connected to Port %s',... port2str('Motor', motor.port)); elseif motor.isSynced && motor.isRunning - if motor.isMaster - motor.syncedStop(); - elseif motor.isSlave - motor.('master').syncedStop(); - end + motor.syncedStop(); return; % error(['Motor::stop: Motor is running synchronized with another motor. ' ,... % 'Use ''syncedStop'' on the ''master''-motor.']); @@ -400,7 +399,6 @@ classdef Motor < MaskedHandle & dynamicprops % % Do stuff % m.syncedStop(); |br| % - turnRatio = 0; % Check parameters @@ -506,7 +504,7 @@ classdef Motor < MaskedHandle & dynamicprops error('Motor::syncedStop: Motor has not been started synchronized with another.'); else % Retrieve synced motor from cache - if length(findprop(motor, 'slave'))==1 + if motor.isMaster syncMotor = motor.slave; delete(motor.findprop('slave')); delete(syncMotor.findprop('master')); @@ -615,6 +613,9 @@ classdef Motor < MaskedHandle & dynamicprops % % Notes: % * A better name would probably be resetPosition... + % * Gets called automatically when starting the motor and the internal tacho + % count is > 0 + % % % See also MOTOR.RESETTACHOCOUNT @@ -945,7 +946,7 @@ classdef Motor < MaskedHandle & dynamicprops busyFlag = 0; end - assert(~(motor.state.startedNotBusy && busyFlag)); + % assert(~(motor.state.startedNotBusy && busyFlag)); running = motor.state.startedNotBusy || busyFlag; end diff --git a/source/Sensor.m b/source/Sensor.m index bf01571bbafa73e5a0259a623e987890a54333dc..53949fddb39f0050dc12bab1f32fad93790f2fba 100755 --- a/source/Sensor.m +++ b/source/Sensor.m @@ -17,20 +17,60 @@ classdef Sensor < MaskedHandle % 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 + % * 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 + % * Infrared-Sensor: + % * DeviceMode.InfraRed.Prox *[Default]* + % * DeviceMode.InfraRed.Seek + % * DeviceMode.InfraRed.Remote + % * NXTColor-Sensor: + % * DeviceMode.NXTColor.Reflect *[Default]* + % * DeviceMode.NXTColor.Ambient + % * DeviceMode.NXTColor.Color + % * DeviceMode.NXTColor.Green + % * DeviceMode.NXTColor.Blue + % * DeviceMode.NXTColor.Raw + % * NXTLight-Sensor: + % * DeviceMode.NXTLight.Reflect *[Default]* + % * DeviceMode.NXTLight.Ambient + % * NXTSound-Sensor: + % * DeviceMode.NXTSound.DB *[Default]* + % * DeviceMode.NXTSound.DBA + % * NXTTemperature-Sensor + % * DeviceMode.NXTTemperature.C *[Default]* + % * DeviceMode.NXTTemperature.F + % * NXTTouch-Sensor: + % * DeviceMode.NXTTouch.Pushed *[Default]* + % * DeviceMode.NXTTouch.Bumps + % * NXTUltraSonic-Sensor: + % * DeviceMode.NXTUltraSonic.CM *[Default]* + % * DeviceMode.NXTUltraSonic.IN + % * HTAccelerometer-Sensor: + % * DeviceMode.HTAccelerometer.Acceleration *[Default]* + % * DeviceMode.HTAccelerometer.AccelerationAllAxes + % * HTCompass-Sensor: + % * DeviceMode.HTCompass.Degrees *[Default]* + % * HTColor-Sensor: + % * DeviceMode.HTColor.Col *[Default]* + % * DeviceMode.HTColor.Red + % * DeviceMode.HTColor.Green + % * DeviceMode.HTColor.Blue + % * DeviceMode.HTColor.White + % * DeviceMode.HTColor.Raw + % * DeviceMode.HTColor.Nr, + % * DeviceMode.HTColor.All % 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]* @@ -38,22 +78,25 @@ classdef Sensor < MaskedHandle % sensor.mode. *[READ-ONLY]* % 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 + % * 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.HTColor + % * DeviceType.HTCompass + % * DeviceType.HTAccelerometer + % * DeviceType.Unknown + % * DeviceType.None + % * DeviceType.Error properties % Standard properties to be set by user % mode (DeviceMode.{Type}): Sensor mode in which the value will be read. By default, @@ -76,7 +119,46 @@ classdef Sensor < MaskedHandle % * Gyro-Sensor: % * DeviceMode.Gyro.Angular [Default] % * DeviceMode.Gyro.Rate - % + % * Infrared-Sensor: + % * DeviceMode.InfraRed.Prox [Default] + % * DeviceMode.InfraRed.Seek + % * DeviceMode.InfraRed.Remote + % * NXTColor-Sensor: + % * DeviceMode.NXTColor.Reflect [Default] + % * DeviceMode.NXTColor.Ambient + % * DeviceMode.NXTColor.Color + % * DeviceMode.NXTColor.Green + % * DeviceMode.NXTColor.Blue + % * DeviceMode.NXTColor.Raw + % * NXTLight-Sensor: + % * DeviceMode.NXTLight.Reflect [Default] + % * DeviceMode.NXTLigth.Ambient + % * NXTSound-Sensor: + % * DeviceMode.NXTSound.DB [Default] + % * DeviceMode.NXTSound.DBA + % * NXTTemperature-Sensor + % * DeviceMode.NXTTemperature.C [Default] + % * DeviceMode.NXTTemperature.F + % * NXTTouch-Sensor: + % * DeviceMode.NXTTouch.Pushed [Default] + % * DeviceMode.NXTTouch.Bumps + % * NXTUltraSonic-Sensor: + % * DeviceMode.NXTUltraSonic.CM [Default] + % * DeviceMode.NXTUltraSonic.IN + % * HTAccelerometer-Sensor: + % * DeviceMode.HTAccelerometer.Acceleration [Default] + % * DeviceMode.HTAccelerometer.AccelerationAllAxes + % * HTCompass-Sensor: + % * DeviceMode.HTCompass.Degrees [Default] + % * HTColor-Sensor: + % * DeviceMode.HTColor.Col [Default] + % * DeviceMode.HTColor.Red + % * DeviceMode.HTColor.Green + % * DeviceMode.HTColor.Blue + % * DeviceMode.HTColor.White + % * DeviceMode.HTColor.Raw + % * DeviceMode.HTColor.Nr, + % * DeviceMode.HTColor.All % See also SENSOR.VALUE, SENSOR.TYPE mode; @@ -87,13 +169,13 @@ classdef Sensor < MaskedHandle end properties (Dependent) % Parameters to be read directly from physical brick - % value (numeric): Value read from hysical sensor. What the value represents depends on - % sensor.mode. *[READ-ONLY]* + % value (numeric): Value read from physical sensor. [READ-ONLY] + % What the value represents depends on sensor.mode. % See also SENSOR.MODE value; - % type (DeviceType): Type of physical sensor connected to the port. Possible types are - % *[READ-ONLY]*: + % type (DeviceType): Type of physical sensor connected to the port. [READ-ONLY] + % Possible types are: % * DeviceType.NXTTouch % * DeviceType.NXTLight % * DeviceType.NXTSound @@ -107,6 +189,9 @@ classdef Sensor < MaskedHandle % * DeviceType.UltraSonic % * DeviceType.Gyro % * DeviceType.InfraRed + % * DeviceType.HTColor + % * DeviceType.HTCompass + % * DeviceType.HTAccelerometer % * DeviceType.Unknown % * DeviceType.None % * DeviceType.Error