Skip to content
Snippets Groups Projects
Commit b090ca85 authored by Tim Stadtmann's avatar Tim Stadtmann
Browse files

Slave-motor now saves its master in sync mode

parent 147c4269
No related branches found
No related tags found
No related merge requests found
......@@ -155,11 +155,35 @@ classdef Motor < MaskedHandle & dynamicprops
end
% If motor has been started synced with another, and it stopped 'itself' (when
% using a tacholimit), the sync cache has to be deleted (in general, syncedStop
% using a tacholimit), the sync cache has to be deleted (otherwise, syncedStop
% would do so)
if motor.isSynced
delete(motor.findprop('slave'));
motor.internalReset(); % Better safe than sorry
% Retrieve and delete former slave
if length(findprop(motor, 'slave'))==1
syncMotor = motor.slave;
delete(motor.findprop('slave'));
delete(syncMotor.findprop('master'));
else
syncMotor = motor.master;
delete(motor.findprop('master'));
delete(syncMotor.findprop('slave'));
end
% Reset state
motor.applyState();
syncMotor.applyState();
% Send power on next set
if motor.state.sendPowerOnSet
motor.state.sendOnStart = bitset(motor.state.sendOnStart, SendOnStart.Power, 1);
end
if syncMotor.state.sendPowerOnSet
syncMotor.state.sendOnStart = bitset(syncMotor.state.sendOnStart, SendOnStart.Power, 1);
end
% Better safe than sorry
motor.internalReset();
syncMotor.internalReset();
end
% If the motor coasts into its stops, the internal tachocount has to be reset
......@@ -357,18 +381,11 @@ classdef Motor < MaskedHandle & dynamicprops
end
end
% Cache old values to make it possible to reset them on stopSynced
% 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()
meta = motor.findprop('slave');
if isempty(meta)
meta = motor.addprop('slave');
meta.Hidden = true;
meta.Access = 'private';
end
meta.Hidden = true;
meta.Access = 'private';
motor.slave = syncMotor;
motor.addProperty(syncMotor, 'slave', true);
syncMotor.addProperty(motor, 'master', true);
motor.saveState();
syncMotor.saveState();
......@@ -411,13 +428,20 @@ classdef Motor < MaskedHandle & dynamicprops
if ~motor.isSynced
error('Motor::syncedStop: Motor has not been started synchronized with another.');
else
% Retrieve synced motor from cache
if length(findprop(motor, 'slave'))==1
syncMotor = motor.slave;
delete(motor.findprop('slave'));
delete(syncMotor.findprop('master'));
else
syncMotor = motor.master;
delete(motor.findprop('master'));
delete(syncMotor.findprop('slave'));
end
end
% Retrieve synced motor from cache
syncMotor = motor.slave;
delete(motor.findprop('slave'));
if ~motor.state.connectedToBrick || ~syncMotor.state.connectedToBrick
if ~motor.connectedToBrick || ~syncMotor.connectedToBrick
error('Motor::syncedStop: Motor-Object not connected to comm handle.');
elseif ~motor.physicalMotorConnected || ~syncMotor.physicalMotorConnected
error('Motor::syncedStop: No physical motor connected to either Port %s or %s.',...
......@@ -847,11 +871,12 @@ classdef Motor < MaskedHandle & dynamicprops
end
function synced = get.isSynced(motor)
synced = (length(findprop(motor, 'slave'))==1);
synced = (length(findprop(motor, 'slave'))==1 || ...
length(findprop(motor, 'master'))==1);
end
function motorType = get.type(motor)
if motor.state.connectedToBrick
if motor.connectedToBrick
[motorType, ~] = motor.getTypeMode();
else
motorType = DeviceType.Unknown;
......@@ -1075,6 +1100,22 @@ classdef Motor < MaskedHandle & dynamicprops
motor.state = motor.savedState;
delete(motor.findprop('savedState'))
end
function addProperty(motor, propValue, propName, override)
override = str2bool(override);
meta = motor.findprop(propName);
if isempty(meta)
meta = motor.addprop(propName);
meta.Hidden = true;
meta.Access = 'private';
elseif ~override
error('Motor::addProperty: Motor already has this property.');
end
motor.(propName) = propValue;
end
end
methods (Access = {?EV3})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment