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
bd4f3929
Commit
bd4f3929
authored
8 years ago
by
Tim Stadtmann
Browse files
Options
Downloads
Patches
Plain Diff
Implement stopAllMotors() in EV3
Also, delete syncMotor-remains
parent
976cd5de
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/EV3.m
+14
-126
14 additions, 126 deletions
source/EV3.m
with
14 additions
and
126 deletions
source/EV3.m
+
14
−
126
View file @
bd4f3929
...
@@ -245,154 +245,42 @@ classdef EV3 < handle
...
@@ -245,154 +245,42 @@ classdef EV3 < handle
%
%
% Example
% Example
% b = EV3();
% b = EV3();
% b.connect(
'ioType',
'bt', 'serPort', '/dev/rfcomm0');
% b.connect('bt', 'serPort', '/dev/rfcomm0');
% % do stuff
% % do stuff
% b.disconnect();
% b.disconnect();
%
%
% if ~ev3.isConnected
% Disconnect motors and sensors
% error('EV3::connect: No brick connected.');
% -> set references to comm handle to 0
% end
% Disconnect motors
% -> set references to brick object to 0
ev3
.
motorA
.
disconnect
();
ev3
.
motorA
.
disconnect
();
ev3
.
motorB
.
disconnect
();
ev3
.
motorB
.
disconnect
();
ev3
.
motorC
.
disconnect
();
ev3
.
motorC
.
disconnect
();
ev3
.
motorD
.
disconnect
();
ev3
.
motorD
.
disconnect
();
% Disconnect sensors
% -> set references to brick object to 0
ev3
.
sensor1
.
disconnect
();
ev3
.
sensor1
.
disconnect
();
ev3
.
sensor2
.
disconnect
();
ev3
.
sensor2
.
disconnect
();
ev3
.
sensor3
.
disconnect
();
ev3
.
sensor3
.
disconnect
();
ev3
.
sensor4
.
disconnect
();
ev3
.
sensor4
.
disconnect
();
% Delete handle to
brick object
% Delete handle to
comm-interface
if
is
BrickValid
(
ev3
.
brick
)
&&
ev3
.
brick
~=
0
if
is
CommInterfaceValid
(
ev3
.
commInterface
)
&&
ev3
.
commInterface
~=
0
ev3
.
brick
.
delete
();
ev3
.
commInterface
.
delete
();
end
end
ev3
.
brick
=
0
;
ev3
.
commInterface
=
0
;
ev3
.
isConnected
=
0
;
ev3
.
isConnected
=
false
;
end
end
function
update
(
ev3
)
%% Device functions
%update Updates all Motors and Sensors to current status of their corresponding ports.
function
stopAllMotors
(
ev3
)
%
%stopAllMotors Sends a stop-command to all motor-ports
% Example
% b = EV3();
% b.connect('ioType', 'bt', 'serPort', '/dev/rfcomm0');
% % Connect some new motors and sensors, disconnect some others (in 'real life')
% b.update();
% % Now, virtual brick knows about all new devices and commands can be sent to
% % them
%
if
~
ev3
.
isConnected
if
~
ev3
.
isConnected
error
(
'EV3::update: No brick connected.'
);
stopAllMotors
([
'EV3::beep: Brick-Object not connected physical brick. '
,
...
end
'You have to call ev3.connect(...) first!'
]);
ev3
.
motorA
.
update
();
ev3
.
motorB
.
update
();
ev3
.
motorC
.
update
();
ev3
.
motorD
.
update
();
ev3
.
sensor1
.
update
();
ev3
.
sensor2
.
update
();
ev3
.
sensor3
.
update
();
ev3
.
sensor4
.
update
();
end
%% System functions
function
syncMotor
=
coupleMotors
(
ev3
,
varargin
)
%coupleMotors Creates and connects a SyncMotor-object using two chosen Motor-objects.
%
% Notes
% * Right now only possible if connection to Brick has been established.
%
% Arguments
% * port ('AB','BA', ...): Motors to 'couple'
% * 'useMotorParams', 0/1/'on'/'off'/'true'/'false': Use first motor's or set own params
% * varargin: other Properties for Motor/SyncMotor (see
% (Sync-)Motor::setProperties(motor, varargin))
%
% Example
% b = EV3(); b.connect('ioType', 'bt', 'serPort', '/dev/rfcomm0');
% sync = b.coupleMotors('AB'); % Couple motors A and B using parameters of
% % Motor-object motorA.
% sync2 = b.coupleMotors('CD', 'useMotorParams', 0, 'power', 50, 'debug', 'on');
% % Couple motors C and D with new object being
% % initialized with default resp. given parameters.
%
if
~
ev3
.
isConnected
error
(
'EV3::update: No brick connected.'
);
end
% Check input arguments
p
=
inputParser
();
p
.
KeepUnmatched
=
1
;
p
.
addRequired
(
'port'
,
@
(
x
)
isPortValid
(
'SyncMotor'
,
x
));
p
.
addOptional
(
'useMotorParams'
,
1
,
@
(
x
)
isBool
(
x
));
p
.
parse
(
varargin
{:});
useMotorParams
=
str2bool
(
p
.
Results
.
useMotorParams
);
if
strcmpi
(
p
.
Results
.
port
,
'AB'
)
motor1
=
ev3
.
motorA
;
motor2
=
ev3
.
motorB
;
elseif
strcmpi
(
p
.
Results
.
port
,
'BA'
)
motor1
=
ev3
.
motorB
;
motor2
=
ev3
.
motorA
;
elseif
strcmpi
(
p
.
Results
.
port
,
'AC'
)
motor1
=
ev3
.
motorA
;
motor2
=
ev3
.
motorC
;
elseif
strcmpi
(
p
.
Results
.
port
,
'CA'
)
motor1
=
ev3
.
motorC
;
motor2
=
ev3
.
motorA
;
elseif
strcmpi
(
p
.
Results
.
port
,
'AD'
)
motor1
=
ev3
.
motorA
;
motor2
=
ev3
.
motorD
;
elseif
strcmpi
(
p
.
Results
.
port
,
'DA'
)
motor1
=
ev3
.
motorD
;
motor2
=
ev3
.
motorA
;
elseif
strcmpi
(
p
.
Results
.
port
,
'BC'
)
motor1
=
ev3
.
motorB
;
motor2
=
ev3
.
motorC
;
elseif
strcmpi
(
p
.
Results
.
port
,
'CB'
)
motor1
=
ev3
.
motorC
;
motor2
=
ev3
.
motorB
;
elseif
strcmpi
(
p
.
Results
.
port
,
'BD'
)
motor1
=
ev3
.
motorB
;
motor2
=
ev3
.
motorD
;
elseif
strcmpi
(
p
.
Results
.
port
,
'DB'
)
motor1
=
ev3
.
motorD
;
motor2
=
ev3
.
motorB
;
elseif
strcmpi
(
p
.
Results
.
port
,
'CD'
)
motor1
=
ev3
.
motorC
;
motor2
=
ev3
.
motorD
;
elseif
strcmpi
(
p
.
Results
.
port
,
'DC'
)
motor1
=
ev3
.
motorD
;
motor2
=
ev3
.
motorC
;
end
% Create SyncMotor-object with parameters of motor1 and given parameters
if
useMotorParams
syncMotor
=
SyncMotor
(
motor1
,
motor2
,
p
.
Results
.
port
,
...
'Power'
,
motor1
.
power
,
...
'SpeedRegulation'
,
motor1
.
speedRegulation
,
...
'BrakeMode'
,
motor1
.
brakeMode
,
...
'LimitMode'
,
motor1
.
limitMode
,
...
'LimitValue'
,
motor1
.
limitValue
,
...
'SmoothStart'
,
motor1
.
smoothStart
,
...
'SmoothStop'
,
motor1
.
smoothStop
,
...
'Debug'
,
motor1
.
debug
);
else
syncMotor
=
SyncMotor
(
motor1
,
motor2
,
p
.
Results
.
port
,
varargin
{
4
:
end
});
end
end
% Connect SyncMotor-object to brick handle.
ev3
.
commInterface
.
outputStopAll
();
syncMotor
.
connect
(
ev3
.
brick
);
end
end
%% Sound functions
%% Sound functions
...
...
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