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

Add a bunch of old test scripts

parent 277c31cd
No related branches found
No related tags found
No related merge requests found
Showing
with 624 additions and 0 deletions
%Variablen bitte anpassen
clear all;
brick=EV3;
brick.connect('bt');
motorToTest = brick.motorC;
N = 50;
tic;
time = [];
plotIsRunning = [];
plotCurrentSpeed = [];
%plotPower = [];
figure('NumberTitle', 'off', 'Name', 'IsRunning vs CurrentSpeed');
%Schleifendurchlauf
for j = 1 : N
[limitValue, limitMode, brakeMode, speedRegulation, power, syncedMode] = generateRandomMotorParams;
executeMotorCmd(limitValue, limitMode, brakeMode, speedRegulation, power, syncedMode, brick, motorToTest);
motorToTest
disp(syncedMode)
while (motorToTest.isRunning())
time(end+1) = toc;
%IsRunning/CurrentSpeed
plotIsRunning(end+1) = motorToTest.isRunning()*25;
plotCurrentSpeed(end+1) = motorToTest.currentSpeed();
plot(time, plotIsRunning, time, plotCurrentSpeed);
legend('isRunning', 'currentSpeed');
drawnow;
end%while
xxx = toc;
delta = 0;
while (delta <= 3)
time(end+1) = toc;
plotIsRunning(end+1) = motorToTest.isRunning()*25;
plotCurrentSpeed(end+1) = motorToTest.currentSpeed();
plot(time, plotIsRunning, time, plotCurrentSpeed);
legend('isRunning', 'currentSpeed');
drawnow;
delta = toc - xxx;
end%while
end%for
brick.disconnect;
clear all;
%Variablen bitte anpassen
clear all;
brick=EV3;
brick.connect('bt', 'serPort', '/dev/rfcomm1');
motorToTest = brick.motorC;
N = 10;
tic;
time = [];
vPower = [];
vBrakeMode = [];
vTachoCount = [];
vLimitValue = [];
%Schleifendurchlauf
for j = 1 : N
[limitValue, limitMode, brakeMode, speedRegulation, power, syncedMode] = generateRandomMotorParams;
executeMotorCmd(limitValue, 'Tacho', brakeMode, speedRegulation, abs(power), syncedMode, brick, motorToTest);
motorToTest
disp(syncedMode)
while(motorToTest.isRunning())
end%while
pause(3);
vPower(end+1) = motorToTest.power();
if (strcmp(motorToTest.brakeMode(), 'Brake'))
vBrakeMode(end+1) = 1;
else
vBrakeMode(end+1) = 0;
end%if
vTachoCount(end+1) = motorToTest.tachoCount();
vLimitValue(end+1) = motorToTest.limitValue();
motorToTest.resetTachoCount();
end%for
%fprint(vPower, vBrakeMode, vTachoCount, vLimitValue);
brick.disconnect;
clear all;
\ No newline at end of file
b = EV3('debug', 2);
b.connect('bt', 'serPort', '/dev/rfcomm0');
m = b.motorA;
sl = b.motorB;
m.tachoLimit = 1000;
m.brakeMode = 'Coast';
counts = [];
power = [60, 65, 70, 75, 80, 85, 90, 95, 100];
for i=1:length(power)
m.resetTachoCount;
m.reset;
m.power = power(i);
m.syncedStart(sl);
m.waitFor();
counts = [counts, m.tachoCount];
b.beep;
b.debug = false;
end
\ No newline at end of file
%Variablen bitte anpassen
clear all;
brick=EV3;
brick.connect('bt');
motorToTest = brick.motorC;
N = 50;
tic;
time = [];
plotIsRunning = [];
plotTachoCount = [];
plotLimitValue = [];
%plotPower = [];
figure('NumberTitle', 'off', 'Name', 'TachoCount vs LimitValue');
%Schleifendurchlauf
for j = 1 : N
[limitValue, limitMode, brakeMode, speedRegulation, power, syncedMode] = generateRandomMotorParams;
executeMotorCmd(limitValue, 'Tacho', brakeMode, speedRegulation, power, syncedMode, brick, motorToTest);
motorToTest
disp(syncedMode)
while (motorToTest.isRunning())
time(end+1) = toc;
%LimitValue/TachoCount
plotTachoCount(end+1) = motorToTest.tachoCount();
plotLimitValue(end+1) = motorToTest.limitValue();
plot(time, plotTachoCount, time, plotLimitValue);
drawnow;
end%while
xxx = toc;
delta = 0;
while (delta <= 3)
time(end+1) = toc;
plotTachoCount(end+1) = 0;
plotLimitValue(end+1) = motorToTest.limitValue();
plot(time, plotTachoCount, time, plotLimitValue);
drawnow;
delta = toc - xxx;
end%while
motorToTest.resetTachoCount();
end%for
brick.disconnect;
clear all;
\ No newline at end of file
%Variablen bitte anpassen
clear all;
brick=EV3;
brick.connect('bt', 'serPort', '/dev/rfcomm1');
motorToTest = brick.motorC;
N = 50;
tic;
time = [];
plotTachoCount = [];
plotSpeedRegulation = [];
figure('NumberTitle', 'off', 'Name', 'TachoCount vs SpeedRegulation');
%Schleifendurchlauf
for j = 1 : N
[limitValue, limitMode, brakeMode, speedRegulation, power, syncedMode] = generateRandomMotorParams;
executeMotorCmd(limitValue, limitMode, brakeMode, speedRegulation, power, syncedMode, brick, motorToTest);
motorToTest
disp(syncedMode)
while (motorToTest.isRunning())
time(end+1) = toc;
%Power/TachoCount/SpeedReg
plotTachoCount(end+1) = motorToTest.tachoCount/10;
plotSpeedRegulation(end+1) = motorToTest.speedRegulation*30;
plot(time, plotTachoCount, time, plotSpeedRegulation);
legend('TachoCount', 'SpeedRegulation')
drawnow;
end%while
xxx = toc;
delta = 0;
while (delta <= 3)
time(end+1) = toc;
plotTachoCount(end+1) = motorToTest.tachoCount()/10;
plotSpeedRegulation(end+1) = motorToTest.speedRegulation()*30;
plot(time, plotTachoCount, time, plotSpeedRegulation);
legend('TachoCount','SpeedRegulation')
drawnow;
delta = toc - xxx;
end%while
motorToTest.resetTachoCount();
pause(1);
end%for
brick.disconnect;
clear all;
\ No newline at end of file
close all
clear all
N = 5000;
t = zeros(N, 1);
tic
t = 0;
j = 0;
while(toc < 5)
j = j + 1;
t(j) = toc;
pause(0.010);
end
figure;
plot(t, '.-')
grid on
hold all
figure;
hist(diff(t));
\ No newline at end of file
function [] = executeMotorCmd(limitValue, limitMode, brakeMode, speedRegulation, power, syncedMode, ev3, motorToTest)
%executeMotorCmd Assigns the parameters as values for an EV3 object and
%tests a given motor
% The parameters will be assigned as values for a specific motor object.
% The motor will be started, in normal mode or synced with another motor
% of the EV3 object.
motorToTest.limitValue = limitValue;
motorToTest.limitMode = limitMode;
motorToTest.brakeMode = brakeMode;
motorToTest.speedRegulation = speedRegulation;
motorToTest.power = power;
if ((~syncedMode) || (strcmp(motorToTest.type, 'MediumMotor')))
motorToTest.start();
else
if strcmp(char(ev3.motorA.type), 'LargeMotor') && (ev3.motorA.limitValue ~= motorToTest.limitValue)
motorToTest.syncedStart(ev3.motorA)
end%if
if strcmp(char(ev3.motorB.type), 'LargeMotor') && (ev3.motorB.limitValue ~= motorToTest.limitValue)
motorToTest.syncedStart(ev3.motorB)
end%if
if strcmp(char(ev3.motorC.type), 'LargeMotor') && (ev3.motorC.limitValue ~= motorToTest.limitValue)
motorToTest.syncedStart(ev3.motorC)
end%if
if strcmp(char(ev3.motorD.type), 'LargeMotor') && (ev3.motorD.limitValue ~= motorToTestlimitValue)
motorToTest.syncedStart(ev3.motorD)
end%if
end%if
end%function
\ No newline at end of file
function [limitValue, limitMode, brakeMode, speedRegulation, power, syncedMode] = generateRandomMotorParams
%generateRandomMotorParams Generates random values for a motor
% Generates and returns random values for tachoLimit, limitMode, brakeMode,
% speedRegulation, power and syncedMode.
limitValue = int64(200 + 1000*rand());
limitModeNum = round(rand());
if limitModeNum == 0
limitMode = 'Tacho';
else
limitMode = 'Time';
end;
brakeModeNum = round(rand());
if brakeModeNum == 0
brakeMode = 'Brake';
else
brakeMode = 'Coast';
end;
speedRegulation = round(rand());
while true
power = int64(rand()*200-100);
if power <= -10 || power >= 10
break;
end%if
end%while
if speedRegulation == 0
syncedMode = round(rand());
else
syncedMode = 0;
end%if
end%function
\ No newline at end of file
function linusM1(m)
m.brakeMode = 'Brake';
m.limitValue = 5000;
m.power = 60;
m.limitMode = 'Tacho';
m.start();
\ No newline at end of file
function linusM2(m)
m.brakeMode = 'Coast';
m.limitValue = 0;
m.power = 30;
m.limitMode = 'Tacho';
m.start();
\ No newline at end of file
function motorProblemStart()
% Call this multiple times, then one of the three movements will fail.
brick = EV3();
brick.connect('usb');
%brick.debug = 2;
motor = brick.motorA;
motor.setProperties('power',30,'limitMode', 'Tacho', 'limitValue', 1000, 'brakeMode', 'Coast')
figure; hold all;
for power=30:20:70
motor.power = power;
motor.resetTachoCount();
% Problem: sometimes, the start command is ignored
motor.start;
tic
t = toc;
tVec = []; tachoVec = [];
while t < 6
t = toc;
tVec = [tVec, t]; %#ok<AGROW>
tachoVec = [tachoVec, motor.tachoCount]; %#ok<AGROW>
end
motor.waitFor();
plot(tVec,tachoVec); drawnow;
end
brick.disconnect();
end
for i=1:10
motorProblemStart();
end
\ No newline at end of file
function motorProblemWaitfor( )
% This function will provoke an error in the destructor (at line 14).
brick = EV3();
%brick.connect('usb');
brick.connect('bt', 'serPort', '/dev/rfcomm0');
motor = brick.motorA;
motor.setProperties('power',30,'limitMode', 'Tacho', 'limitValue', 1000, 'brakeMode', 'Coast')
motor.resetTachoCount();
motor.start;
% Problem
motor.waitFor(); %this does not account for coasting
% % Solution to the problem
% while motor.currentSpeed > 0
% end
brick.beep;
brick.disconnect();
end
function packetsPerSecond(brick)
MAX_ITERATIONS = 100;
dt = [];
tic;
for i=1:MAX_ITERATIONS
temp = brick.inputReadSI(0, 16, 0);
dt = [dt, toc];
end
transmission = diff(dt);
meanTransmission = mean(transmission);
fprintf('Mean transmission: %.4fs (+- %.4fs)\n', meanTransmission, std(transmission));
fprintf('-> ~ %d packets per second\n', int32(1/meanTransmission));
end
function plotBusyFlag(brick, varargin)
p = inputParser();
powerValid = @(x) (x>=-100 && x <= 100);
limitValid = @(x) (x>=0);
p.addOptional('power', 50);
p.addOptional('limitValue', 3*360);
p.addOptional('speedRegulation', false);
p.addOptional('smoothStart', 0);
p.addOptional('smoothStop', 0);
p.addOptional('brakeMode', 'coast');
p.addOptional('limitMode', 'Tacho');
p.addOptional('synced', false);
p.parse(varargin{:});
synced = p.Results.synced;
% if ~isDeviceValid('EV3', brick) || ~brick.isConnected
% error('Given object is not a connected EV3-object.');
% end
ma = brick.motorA;
mb = brick.motorB;
ma.resetTachoCount;
if synced
mb.resetTachoCount;
end
ma.setProperties('power', p.Results.power, 'brakeMode', p.Results.brakeMode, ...
'limitMode', p.Results.limitMode, 'limitValue', p.Results.limitValue, ...
'smoothStart', p.Results.smoothStart, ...
'smoothStop', p.Results.smoothStop, ...
'speedRegulation', p.Results.speedRegulation);
t = [];
flag = [];
tacho = [];
stopSent = false;
stopTime = 0;
if ~synced
tic;
ma.start();
while(toc < 10)
flag = [flag, ma.isRunning];
tacho = [tacho, ma.tachoCount];
t = [t, toc];
end
if ma.limitValue == 0
ma.stop();
end
tacho = [tacho, ma.tachoCount];
flag = [flag, ma.isRunning];
t = [t, toc];
else
tic;
ma.syncedStart(mb);
while(toc < 10)
flag = [flag, ma.isRunning];
tacho = [tacho, ma.tachoCount];
t = [t, toc];
if ma.limitValue == 0
if (~stopSent && toc > 8)
stopTime = toc;
ma.syncedStop();
stopSent = true;
end
end
end
end
hold all
plot(t,tacho,t,max(tacho)*int32(flag),'-.or')
%plot([stopTime stopTime],[0 1000], '.-m')
grid on
end
\ No newline at end of file
b = EV3();
b.connect('bt', 'serPort', '/dev/rfcomm0');
t = [];
val = [];
stopSent = false;
stopTime = 0;
s = b.sensor1;
tic;
while(toc < 10)
val = [val, s.value];
t = [t, toc];
end
val = [val, s.value];
t = [t, toc];
hold all
plot(t,val,'-.or')
%plot([stopTime stopTime],[0 1000], '.-m')
grid on
\ No newline at end of file
function [] = randomMotorTestPlot
%testMotor Random test for motors
% Starts N times the motor motorToTest of the object ev3
%Variablen bitte anpassen
clear all;
brick=EV3;
brick.connect('bt', 'serPort', '/dev/rfcomm0');
motorToTest = brick.motorC;
TIMEOUT_SEC = 20.0;
N = 10;
% %Initialisiere Plot
% tic;
% plotIsRunning = [];
% plotPower = [];
% plotTachoCount = [];
% plotCurrentSpeed = [];
% time = [];
% figure;
% grid on;
% %legend('isRunning', 'power', 'tachoCount', 'currentSpeed');
%Schleifendurchlauf
for j = 1 : N
[limitValue, limitMode, brakeMode, speedRegulation, power, syncedMode] = generateRandomMotorParams;
executeMotorCmd(limitValue, limitMode, brakeMode, speedRegulation, power, syncedMode, brick, motorToTest);
motorToTest
disp(syncedMode)
while motorToTest.isRunning
end%while
% hTimeout = tic();
% timeoutHappened = false;
% while (motorToTest.isRunning())
%
% if (toc(hTimeout) > TIMEOUT_SEC)
% timeoutHappened = true;
% break;
% end%if
%
% %update plot
% time = [time, toc];
% plotIsRunning = 1;
% plotPower = [plotPower, motorToTest.power];
% %plotTachoCount = [plotTachoCount, motorToTest.tachoCount/100];
% %plotCurrentSpeed = [plotCurrentSpeed, motorToTest.currentSpeed*10];
% plot(time, plotIsRunning, time, plotPower);
% %legend('isRunning', 'power', 'tachoCount', 'currentSpeed');
% drawnow;
%
% end%while
%
% % optional: update plot
% % time = [time, toc];
% % plotIsRunning = 0;
% % plotPower = [plotPower, motorToTest.power];
% % plotTachoCount = [plotTachoCount, motorToTest.tachoCount/100];
% % plotCurrentSpeed = [plotCurrentSpeed, motorToTest.currentSpeed*10];
% % plot(time, plotIsRunning, time, plotCurrentSpeed, time, plotPower, time, plotTachoCount);
% % drawnow;
%
% if timeoutHappened
% warning('Timeout happened');
% end%if
%
% pause(1.0);
end%for
brick.disconnect;
clear all;
end%function
function [port1, port2, port3, port4] = readAllSensors(varargin)
b = CommunicationInterface(varargin{:});
mode = 0;
cmd = Command();
cmd.addHeaderDirectReply(42,4*4,0);
cmd.opINPUT_READSI(0,SensorPort.Sensor1,0,0,0);
cmd.opINPUT_READSI(0,SensorPort.Sensor2,0,0,4);
cmd.opINPUT_READSI(0,SensorPort.Sensor3,0,0,8);
cmd.opINPUT_READSI(0,SensorPort.Sensor4,0,0,12);
cmd.addLength();
b.send(cmd);
msg = b.receive()';
port1 = typecast(uint8(msg(6:9)),'single');
port2 = typecast(uint8(msg(10:13)),'single');
port3 = typecast(uint8(msg(14:17)),'single');
port4 = typecast(uint8(msg(18:21)),'single');
end
function test4(power, limit, motor)
motor.limitValue = limit;
motor.power = power;
motor.start();
motor.waitFor;
end
b = EV3();
b.connect('bt', 'serPort', '/dev/rfcomm0');
ma = b.motorA;
mb = b.motorB;
s4 = b.sensor4;
ma.setProperties('power', 20);
mb.setProperties('power', 20);
ma.syncedStart(mb);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment