Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ev3-toolbox-matlab
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container registry
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mindstorms
ev3-toolbox-matlab
Commits
b090ca85
Commit
b090ca85
authored
8 years ago
by
Tim Stadtmann
Browse files
Options
Downloads
Patches
Plain Diff
Slave-motor now saves its master in sync mode
parent
147c4269
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/Motor.m
+61
-20
61 additions, 20 deletions
source/Motor.m
with
61 additions
and
20 deletions
source/Motor.m
+
61
−
20
View file @
b090ca85
...
...
@@ -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 s
topS
ynced
% Cache old values to make it possible to reset them on synced
Stop
% 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
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment