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

Add test scripts for motor bug testing

parent 23e350ae
Branches
No related tags found
No related merge requests found
function motorProblemStart(brick)
% Call this multiple times when brick is connected to USB - at some point,
% some of the movements will fail.
%
% brick (EV3): EV3-object connected to physical EV3
motor = brick.motorA;
motor.setProperties('power',30,'limitMode', 'Tacho', 'limitValue', 1000, 'brakeMode', 'Coast')
figure; hold all;
for power=30:20:70
% Set motor power and reset tachocount
motor.power = power;
motor.resetTachoCount();
% Start motor
% BUG: The motor doesn't start sometimes when the data throughput
% is too high.
motor.start;
% Save tachocount values
tic
t = toc;
tVec = []; tachoVec = [];
while t < 6
t = toc;
tVec = [tVec, t]; %#ok<AGROW>
tachoVec = [tachoVec, motor.tachoCount]; %#ok<AGROW>
end
% Wait until motor is not busy anymore
motor.waitFor();
% Plot tachocount values
plot(tVec,tachoVec); drawnow;
end
end
% Works like motorProblemStartScript/motorProblemStart, but only using
% low-level functionality. There is no 'hidden' communication here;
% everytime a method of CommunicationInterface is called, a packet with the
% corresponding command is sent.
%
% Requires:
% * Brick connected via USB
% * Motor at port A
clear all;
b = CommunicationInterface('usb');
b.pauseAfterSend = 0; % Set this to ~0.005 (= 5ms) and the bug should not occur anymore
b.debug = false; % Set this to true to get all packets sent and received printed to the console
for i=1:10
figure; hold all;
for power=30:20:70
% Reset tachocount
b.outputClrCount(0, MotorBitfield.MotorA);
% Start motor
% BUG: The motor doesn't start sometimes when the data throughput
% is too high.
b.outputStepPower(0, MotorBitfield.MotorA, power, 0, 1000, 0, BrakeMode.Coast);
% Save tachocount values
tic
t = toc;
tVec = []; tachoVec = [];
while t < 6
t = toc;
tVec = [tVec, t]; %#ok<AGROW>
tachoVec = [tachoVec, b.outputGetCount(0, MotorPort.MotorA)]; %#ok<AGROW>
end
% Wait until motor is not busy anymore
while(b.outputTest(0, MotorBitfield.MotorA))
end
% Plot tachocount values
plot(tVec,tachoVec); drawnow;
end
end
b.delete();
\ No newline at end of file
% This function requires:
% * Brick connected via USB
% * Motor at port A
b = EV3();
b.connect('usb');
b.pauseAfterSend = 0; % Set this to ~0.005 (= 5ms) and the bug should not occur anymore
b.debug = 0; % Set this to 2 to get all packets sent and received printed to the console
for i=1:10
motorProblemStart(b);
end
b.disconnect();
\ No newline at end of file
function testUSBSpeed(sendOnly, secondsWaitedAfterSend)
% Evaluates the data throughput via USB (in terms of packets/second).
% If sendOnly is true, packets are dispatched without waiting for a reply
% (outputStop-opCode is used).
% If sendOnly is false, packets are dispatched and a reply is received
% (inputReadSI-opCode is used).
%
% Arguments:
% sendOnly (boolean)
%
% This function requires:
% * Brick connected via USB
% * Motor at port A
if ~islogical(sendOnly)
error('sendOnly has to be a boolean (true | false)!');
end
b = CommunicationInterface('usb');
if secondsWaitedAfterSend > 0
b.pauseAfterSend = secondsWaitedAfterSend;
end
t_measure = 10.0;
p = 0;
tic;
while toc < t_measure
if sendOnly
b.outputStop(0, 1, 0);
else
b.inputReadSI(0, 16, 2);
end
p = p+1;
end
fprintf('Packets per second: %.2f\n', p / t_measure);
clear all;
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment