diff --git a/source/Motor.m b/source/Motor.m index c16c29821d1dc8eb29aa8cd50f2c34c01cbe29d2..5220f46afee9111edbb6ac48f0365ed05f7f0fbf 100755 --- a/source/Motor.m +++ b/source/Motor.m @@ -142,6 +142,10 @@ classdef Motor < MaskedHandle & dynamicprops % state (MotorState): State-struct consisting of several special Motor-flags . % See also MOTORSTATE state = MotorState(); + + % currentSpeedRegulation (bool): speedRegulation-value with which the motor has been started + % See also SPEEDREGULATION + currentSpeedRegulation; end properties (Hidden, Dependent, Access = private) % Hidden, dependent properties for internal use only @@ -204,6 +208,11 @@ classdef Motor < MaskedHandle & dynamicprops error('Motor::start: Motor is already running!'); end + if motor.speedRegulation ~= motor.currentSpeedRegulation + motor.currentSpeedRegulation = motor.speedRegulation; + motor.state.sendOnStart = bitset(motor.state.sendOnStart, SendOnStart.Power, 1); + end + % If motor has been started synced with another, and it stopped 'itself' (when % using a tacholimit), the sync cache has to be deleted (otherwise, syncedStop % would do so) @@ -668,15 +677,37 @@ classdef Motor < MaskedHandle & dynamicprops speedRegulation = str2bool(speedRegulation); - if ~isempty(motor.speedRegulation) && (speedRegulation ~= motor.speedRegulation) - if motor.state.sendPowerOnSet - motor.state.sendOnStart = bitset(motor.state.sendOnStart, SendOnStart.Power, 1); + if speedRegulation ~= motor.speedRegulation + if ~isempty(motor.speedRegulation) + if motor.state.sendPowerOnSet + motor.state.sendOnStart = bitset(motor.state.sendOnStart, SendOnStart.Power, 1); + end + end + + if ~motor.isRunning + motor.currentSpeedRegulation = speedRegulation; end end motor.speedRegulation = speedRegulation; end + function set.currentSpeedRegulation(motor, currentSpeedRegulation) + if ~isBool(currentSpeedRegulation) + error('Motor::set.currentSpeedRegulation: Given parameter is not a bool.'); + end + + currentSpeedRegulation = str2bool(currentSpeedRegulation); + +% if ~isempty(motor.speedRegulation) && (speedRegulation ~= motor.speedRegulation) +% if motor.state.sendPowerOnSet +% motor.state.sendOnStart = bitset(motor.state.sendOnStart, SendOnStart.Power, 1); +% end +% end + + motor.currentSpeedRegulation = currentSpeedRegulation; + end + function set.smoothStart(motor, steps) if ~isnumeric(steps) error('Motor::set.smoothStart: Given parameter is not a numeric.'); @@ -746,7 +777,7 @@ classdef Motor < MaskedHandle & dynamicprops motor.state.sendPowerOnSet = false; end - motor.limitValue= limitValue; + motor.limitValue = limitValue; end function set.port(motor, port) @@ -847,6 +878,7 @@ classdef Motor < MaskedHandle & dynamicprops motor.brakeMode = p.Results.brakeMode; motor.debug = p.Results.debug; motor.speedRegulation = p.Results.speedRegulation; + motor.currentSpeedRegulation = p.Results.speedRegulation; motor.smoothStart = p.Results.smoothStart; motor.smoothStop = p.Results.smoothStop; end @@ -955,7 +987,7 @@ classdef Motor < MaskedHandle & dynamicprops return; end; - if motor.speedRegulation + if motor.currentSpeedRegulation motor.commInterface.outputSpeed(0, motor.port, power); if motor.debug