diff --git a/source/Motor.m b/source/Motor.m index fc0de1b582036feaef07b9513063ec0556347dc9..27633f4d400364f9defde9cc389fc83d037f7013 100755 --- a/source/Motor.m +++ b/source/Motor.m @@ -1148,7 +1148,7 @@ classdef Motor < MaskedHandle & dynamicprops error('Motor::releaseBrake: No physical motor connected to Port %s',... port2str('Motor', motor.port)); elseif motor.currentSpeed~=0 - error('Motor::releaseBrake: Can''t releaseBrake brake because Motor is moving'); + error('Motor::releaseBrake: Can''t release brake because Motor is moving'); end if motor.speedRegulation @@ -1257,15 +1257,34 @@ classdef Motor < MaskedHandle & dynamicprops end function resetPhysicalMotor(motor) - % + % Do nothing if their is either no connection or no motor connected to port if ~motor.connectedToBrick || ~motor.physicalMotorConnected return; end + % If motor is *busily* running, stop it. That avoids suicidal stuff like: + % b = EV3(); b.connect('usb'); + % b.motorA.start(); + % b.disconnect(); -> Motor still running and cannot directly be stopped anymore + if motor.isRunning + motor.stop(); + end + + % Reset tacho values motor.resetTachoCount(); motor.internalReset(); - motor.setBrake(0); - %motor.stop(); + + % setBrake (correctly) throws an error if currentSpeed ~= 0. In this case, it + % has already been checked if motor is busily running. At this point, the only + % things that provoke a currentSpeed~=0 are coasting into a stop or a user manually + % spinning the motor. In both cases, there is no active brake set which means that + % setBrake(0) unnecessary either way. Therefore, if setBrake throws an error, it + % can be safely ignored. + try + motor.setBrake(0); + catch ME + % Safely ignore this... + end end end end diff --git a/source/Sensor.m b/source/Sensor.m index 53949fddb39f0050dc12bab1f32fad93790f2fba..d7758695076f47d871d6a240f3348dc2d01f3e60 100755 --- a/source/Sensor.m +++ b/source/Sensor.m @@ -527,8 +527,12 @@ classdef Sensor < MaskedHandle return end - sensor.mode = DeviceMode(sensor.type, uint8(0)); - sensor.reset; + try + sensor.mode = DeviceMode(sensor.type, uint8(0)); + sensor.reset; + catch ME + % For now: ignore... + end end end end