From 3980140af2a1f447ae8bb475cf23808ef614e7b1 Mon Sep 17 00:00:00 2001
From: Tim Stadtmann <tim.stadtmann@rwth-aachen.de>
Date: Mon, 12 Dec 2016 17:21:10 +0100
Subject: [PATCH] Fix issues #27 and #28

---
 source/Motor.m | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/source/Motor.m b/source/Motor.m
index 386fab4..1756ed1 100755
--- a/source/Motor.m
+++ b/source/Motor.m
@@ -452,31 +452,38 @@ classdef Motor < MaskedHandle & dynamicprops
                 end
             end
             
+            % Keep 'slave'-motor synchronized
+            syncMotor.speedRegulation = false;
+        	syncMotor.limitValue= motor.limitValue;
+            syncMotor.brakeMode = motor.brakeMode;
+            syncMotor.power = motor.power;
+            
+            % Save old states
+            motor.saveState();
+            syncMotor.saveState();
+            
             % Cache old values to make it possible to reset them on syncedStop
             % Note: the existence of 'slave' is also used to determine whether motor is 
             %       running synchronized or not, see get.isSynced()
             motor.addProperty(syncMotor, 'slave', true);
             syncMotor.addProperty(motor, 'master', true);
             
-            motor.saveState();
-            syncMotor.saveState();
             
             % Disable immediate sending of new power values
             motor.state.sendPowerOnSet = false;
             syncMotor.state.sendPowerOnSet = false;
             
-            % Keep 'slave'-motor synchronized
-            syncMotor.speedRegulation = false;
-        	syncMotor.limitValue= motor.limitValue;
-            syncMotor.brakeMode = motor.brakeMode;
-            syncMotor.power = motor.power;
+            % Synchronous running is a 'busy'-operation
+            motor.state.startedNotBusy = false;
+            syncMotor.state.startedNotBusy = false;
+           
             
             if strcmpi(motor.limitMode, 'Tacho')
                motor.commInterface.outputStepSync(0, motor.port+syncMotor.port, ...
                                               motor.power, turnRatio, ...
                                               motor.limitValue, motor.brakeMode_);
                if motor.debug
-                   fprintf(['(DEBUG) SyncMotor::syncedStart: Called outputStepSync on ' ,...
+                   fprintf(['(DEBUG) Motor::syncedStart: Called outputStepSync on ' ,...
                            'Ports %s and %s.\n'], port2str('Motor', motor.port), port2str('Motor', syncMotor.port));
                end
             elseif strcmpi(motor.limitMode, 'Time')
@@ -484,7 +491,7 @@ classdef Motor < MaskedHandle & dynamicprops
                                               motor.power, turnRatio, ...
                                               motor.limitValue, motor.brakeMode_); 
                if motor.debug
-                   fprintf('(DEBUG) SyncMotor::start: Called outputStepSync on Ports %s and %s.\n',...
+                   fprintf('(DEBUG) Motor::start: Called outputStepSync on Ports %s and %s.\n',...
                          port2str('Motor', motor.port), port2str('Motor', syncMotor.port));
                end
             end
-- 
GitLab