From 9cf3b5b3c8180c5d42efda9eb264b3bb84a0aa7f Mon Sep 17 00:00:00 2001 From: Tim Stadtmann <tim.stadtmann@rwth-aachen.de> Date: Tue, 4 Jul 2017 16:47:32 +0200 Subject: [PATCH] Add a bunch of old test scripts --- tests/IsRunningVsCurrentSpeed.m | 53 +++++++++++++++ tests/LimitValueVsTachoCount.m | 39 +++++++++++ tests/MotorBraking.m | 21 ++++++ tests/TachoCountVsLimitValue.m | 53 +++++++++++++++ tests/TachoCountVsSpeedRegulation.m | 53 +++++++++++++++ tests/checkMatlabPauseCommand.m | 23 +++++++ tests/executeMotorCmd.m | 31 +++++++++ tests/generateRandomMotorParams.m | 38 +++++++++++ tests/linusM1.m | 8 +++ tests/linusM2.m | 8 +++ tests/motorProblemStart.m | 32 +++++++++ tests/motorProblemStartScript.m | 3 + tests/motorProblemWaitfor.m | 22 ++++++ tests/packetsPerSecond.m | 17 +++++ tests/plotBusyFlag.m | 77 +++++++++++++++++++++ tests/plotHTGyro.m | 24 +++++++ tests/randomMotorTestPlot.m | 81 +++++++++++++++++++++++ tests/readAllSensors.m | 23 +++++++ tests/test4.m | 8 +++ tests/test5.m | 10 +++ tests/testAccSensor | 8 +++ tests/testAccSensor.m | 8 +++ tests/testIssue25.m | 29 ++++++++ tests/testMotor.m | 40 +++++++++++ tests/testToolbox.m | 44 ++++++++++++ tests/testUSBSpeed.m | 16 +++++ tests/valuesPerSecond.m | 16 +++++ tools/private/executeMotorCmd.m | 31 +++++++++ tools/private/generateRandomMotorParams.m | 38 +++++++++++ 29 files changed, 854 insertions(+) create mode 100644 tests/IsRunningVsCurrentSpeed.m create mode 100644 tests/LimitValueVsTachoCount.m create mode 100644 tests/MotorBraking.m create mode 100644 tests/TachoCountVsLimitValue.m create mode 100644 tests/TachoCountVsSpeedRegulation.m create mode 100644 tests/checkMatlabPauseCommand.m create mode 100644 tests/executeMotorCmd.m create mode 100644 tests/generateRandomMotorParams.m create mode 100644 tests/linusM1.m create mode 100644 tests/linusM2.m create mode 100644 tests/motorProblemStart.m create mode 100644 tests/motorProblemStartScript.m create mode 100644 tests/motorProblemWaitfor.m create mode 100644 tests/packetsPerSecond.m create mode 100644 tests/plotBusyFlag.m create mode 100644 tests/plotHTGyro.m create mode 100644 tests/randomMotorTestPlot.m create mode 100644 tests/readAllSensors.m create mode 100644 tests/test4.m create mode 100644 tests/test5.m create mode 100644 tests/testAccSensor create mode 100644 tests/testAccSensor.m create mode 100644 tests/testIssue25.m create mode 100644 tests/testMotor.m create mode 100644 tests/testToolbox.m create mode 100644 tests/testUSBSpeed.m create mode 100644 tests/valuesPerSecond.m create mode 100644 tools/private/executeMotorCmd.m create mode 100644 tools/private/generateRandomMotorParams.m diff --git a/tests/IsRunningVsCurrentSpeed.m b/tests/IsRunningVsCurrentSpeed.m new file mode 100644 index 0000000..bc88247 --- /dev/null +++ b/tests/IsRunningVsCurrentSpeed.m @@ -0,0 +1,53 @@ +%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; diff --git a/tests/LimitValueVsTachoCount.m b/tests/LimitValueVsTachoCount.m new file mode 100644 index 0000000..a08aabd --- /dev/null +++ b/tests/LimitValueVsTachoCount.m @@ -0,0 +1,39 @@ +%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 diff --git a/tests/MotorBraking.m b/tests/MotorBraking.m new file mode 100644 index 0000000..47b6f2c --- /dev/null +++ b/tests/MotorBraking.m @@ -0,0 +1,21 @@ +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 diff --git a/tests/TachoCountVsLimitValue.m b/tests/TachoCountVsLimitValue.m new file mode 100644 index 0000000..e8072e3 --- /dev/null +++ b/tests/TachoCountVsLimitValue.m @@ -0,0 +1,53 @@ +%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 diff --git a/tests/TachoCountVsSpeedRegulation.m b/tests/TachoCountVsSpeedRegulation.m new file mode 100644 index 0000000..e311a65 --- /dev/null +++ b/tests/TachoCountVsSpeedRegulation.m @@ -0,0 +1,53 @@ +%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 diff --git a/tests/checkMatlabPauseCommand.m b/tests/checkMatlabPauseCommand.m new file mode 100644 index 0000000..89c59fd --- /dev/null +++ b/tests/checkMatlabPauseCommand.m @@ -0,0 +1,23 @@ +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 diff --git a/tests/executeMotorCmd.m b/tests/executeMotorCmd.m new file mode 100644 index 0000000..d27fbc9 --- /dev/null +++ b/tests/executeMotorCmd.m @@ -0,0 +1,31 @@ +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 diff --git a/tests/generateRandomMotorParams.m b/tests/generateRandomMotorParams.m new file mode 100644 index 0000000..5905e9a --- /dev/null +++ b/tests/generateRandomMotorParams.m @@ -0,0 +1,38 @@ +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 diff --git a/tests/linusM1.m b/tests/linusM1.m new file mode 100644 index 0000000..d15389a --- /dev/null +++ b/tests/linusM1.m @@ -0,0 +1,8 @@ +function linusM1(m) + m.brakeMode = 'Brake'; + m.limitValue = 5000; + m.power = 60; + m.limitMode = 'Tacho'; + m.start(); + + \ No newline at end of file diff --git a/tests/linusM2.m b/tests/linusM2.m new file mode 100644 index 0000000..026f250 --- /dev/null +++ b/tests/linusM2.m @@ -0,0 +1,8 @@ +function linusM2(m) + m.brakeMode = 'Coast'; + m.limitValue = 0; + m.power = 30; + m.limitMode = 'Tacho'; + m.start(); + + \ No newline at end of file diff --git a/tests/motorProblemStart.m b/tests/motorProblemStart.m new file mode 100644 index 0000000..658047e --- /dev/null +++ b/tests/motorProblemStart.m @@ -0,0 +1,32 @@ +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 + diff --git a/tests/motorProblemStartScript.m b/tests/motorProblemStartScript.m new file mode 100644 index 0000000..8d543ba --- /dev/null +++ b/tests/motorProblemStartScript.m @@ -0,0 +1,3 @@ +for i=1:10 + motorProblemStart(); +end \ No newline at end of file diff --git a/tests/motorProblemWaitfor.m b/tests/motorProblemWaitfor.m new file mode 100644 index 0000000..3cec214 --- /dev/null +++ b/tests/motorProblemWaitfor.m @@ -0,0 +1,22 @@ +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 + diff --git a/tests/packetsPerSecond.m b/tests/packetsPerSecond.m new file mode 100644 index 0000000..2ef83d0 --- /dev/null +++ b/tests/packetsPerSecond.m @@ -0,0 +1,17 @@ +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 + diff --git a/tests/plotBusyFlag.m b/tests/plotBusyFlag.m new file mode 100644 index 0000000..1bbff24 --- /dev/null +++ b/tests/plotBusyFlag.m @@ -0,0 +1,77 @@ +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 diff --git a/tests/plotHTGyro.m b/tests/plotHTGyro.m new file mode 100644 index 0000000..17f582a --- /dev/null +++ b/tests/plotHTGyro.m @@ -0,0 +1,24 @@ +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 diff --git a/tests/randomMotorTestPlot.m b/tests/randomMotorTestPlot.m new file mode 100644 index 0000000..7d9b7b9 --- /dev/null +++ b/tests/randomMotorTestPlot.m @@ -0,0 +1,81 @@ +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 diff --git a/tests/readAllSensors.m b/tests/readAllSensors.m new file mode 100644 index 0000000..af933fc --- /dev/null +++ b/tests/readAllSensors.m @@ -0,0 +1,23 @@ +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 + diff --git a/tests/test4.m b/tests/test4.m new file mode 100644 index 0000000..fc428f8 --- /dev/null +++ b/tests/test4.m @@ -0,0 +1,8 @@ +function test4(power, limit, motor) + motor.limitValue = limit; + motor.power = power; + motor.start(); + motor.waitFor; +end + + diff --git a/tests/test5.m b/tests/test5.m new file mode 100644 index 0000000..f689f2b --- /dev/null +++ b/tests/test5.m @@ -0,0 +1,10 @@ +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); + diff --git a/tests/testAccSensor b/tests/testAccSensor new file mode 100644 index 0000000..266418c --- /dev/null +++ b/tests/testAccSensor @@ -0,0 +1,8 @@ +b = CommunicationInterface('usb'); +b.debug = 1; + +v = 0; +for i=1:100 + v = [v, b.inputReadSI(0, SensorPort.Sensor1, DeviceMode.HTAccelerometer.AccelerationAllAxes)]; +end + diff --git a/tests/testAccSensor.m b/tests/testAccSensor.m new file mode 100644 index 0000000..266418c --- /dev/null +++ b/tests/testAccSensor.m @@ -0,0 +1,8 @@ +b = CommunicationInterface('usb'); +b.debug = 1; + +v = 0; +for i=1:100 + v = [v, b.inputReadSI(0, SensorPort.Sensor1, DeviceMode.HTAccelerometer.AccelerationAllAxes)]; +end + diff --git a/tests/testIssue25.m b/tests/testIssue25.m new file mode 100644 index 0000000..050989b --- /dev/null +++ b/tests/testIssue25.m @@ -0,0 +1,29 @@ +b = EV3(); +b.connect('bt', 'serPort', '/dev/rfcomm0'); + +motorR = b.motorA; +motorL = b.motorC; + +motorR.setProperties('power', 100, 'limitValue', 850, 'speedRegulation', true); +motorL.setProperties('power', -100, 'limitValue', 850, 'speedRegulation', true); + +motorL.start(); +motorR.start(); + +pause(1); +motorL.waitFor(); + +motorR.speedRegulation = 'Off'; + +% move out of box +motorL.speedRegulation = 'Off'; % notwendig, sonst auch Fehlermeldung +while motorL.currentSpeed ~= 0 + pause(0.1); +end + +motorL.power = -motorL.power; +motorR.power = -motorL.power; + +motorL.limitValue = 360; +motorL.brakeMode = 'brake'; +motorL.syncedStart(motorR); \ No newline at end of file diff --git a/tests/testMotor.m b/tests/testMotor.m new file mode 100644 index 0000000..6892f09 --- /dev/null +++ b/tests/testMotor.m @@ -0,0 +1,40 @@ +clear all + +brickObject = EV3(); +brickObject.connect('bt', 'serPort', '/dev/rfcomm0'); + +frate = 2.25; +dist = []; +ang = []; +ma = brickObject.motorA; +mb = brickObject.motorB; +ma.limitValue = 0; %Dummywert +mb.limitValue = 0; %Dummywert +ma.power = 30; +mb.power = -30; + +ma.limitValue = 1000; %Dummywert +mb.limitValue = 1000; %Dummywert +ma.smoothStart = 30; +ma.smoothStop = 30; +mb.smoothStart = 30; +mb.smoothStop = 30; +ma.resetTachoCount; +mb.resetTachoCount; +ma.brakeMode = 'Brake'; +mb.brakeMode = 'Brake'; + +ma.limitValue = 360*frate; +mb.limitValue = 360*frate; +ma.start(); +mb.start(); +pause(0.5); +while mb.isRunning + ma.tachoCount + a = ma.tachoCount / frate; + d = brickObject.sensor4.value; + ang = [ang a]; + dist = [dist d]; +end +dist = min(150,dist); +polar(single(ang)/180.*pi,dist); \ No newline at end of file diff --git a/tests/testToolbox.m b/tests/testToolbox.m new file mode 100644 index 0000000..1908fb1 --- /dev/null +++ b/tests/testToolbox.m @@ -0,0 +1,44 @@ +clear all + +b = EV3(); +b.connect('serPort', '/dev/rfcomm0'); +b.sensor3.mode = DeviceMode.Color.Col; +b.sensor4.mode = DeviceMode.UltraSonic.DistCM; +tic; +t = 0; + +b.motorA.setProperties('power', 50, 'speedRegulation', 'on', 'smoothStart', 10, 'limitMode', ... + 'Time', 'limitValue', 3000); +b.motorA.start(); + +pause(0.5); +while b.motorA.isRunning() + b.sensor3.value + b.sensor4.value + b.motorA.tachoCount +end + +b.motorB.power = 50; +b.motorB.limitValue = 4*360; +b.motorB.start(); +b.motorB.waitFor(); +b.beep(); + +b.motorA.speedRegulation = false; +pause(1); +b.motorA.syncedStart(b.motorB, 'turnRatio', 200); +b.motorA.waitFor(); + +for i=1:10 + b.sensor3.value + b.motorA.tachoCount + b.sensor3.reset + b.motorA.tachoCount +end + +b.beep +b.beep + + +b.disconnect +b.delete \ No newline at end of file diff --git a/tests/testUSBSpeed.m b/tests/testUSBSpeed.m new file mode 100644 index 0000000..ef072ac --- /dev/null +++ b/tests/testUSBSpeed.m @@ -0,0 +1,16 @@ +clear all; + +b = EV3(); +b.connect('bt', 'serPort', '/dev/rfcomm1'); +%b = CommunicationInterface('bt', 'serPort', '/dev/rfcomm1'); + +p = 0; +tic; +while toc < 10 + temp = b.sensor1.value; + p = p+1; +end + +fprintf('Packets per second: %.2f\n', p / 10.0); + +clear all; \ No newline at end of file diff --git a/tests/valuesPerSecond.m b/tests/valuesPerSecond.m new file mode 100644 index 0000000..10560b4 --- /dev/null +++ b/tests/valuesPerSecond.m @@ -0,0 +1,16 @@ +function valuesPerSecond(brick) + MAX_ITERATIONS = 100; + + dt = []; + tic; + for i=1:MAX_ITERATIONS + temp = brick.motorA.tachoCount; + dt = [dt, toc]; + end + + transmission = diff(dt); + meanTransmission = mean(transmission); + + fprintf('Mean transmission: %.4fs (+- %.4fs)\n', meanTransmission, std(transmission)); + fprintf('-> ~ %d values per second\n', int32(1/meanTransmission)); +end \ No newline at end of file diff --git a/tools/private/executeMotorCmd.m b/tools/private/executeMotorCmd.m new file mode 100644 index 0000000..d27fbc9 --- /dev/null +++ b/tools/private/executeMotorCmd.m @@ -0,0 +1,31 @@ +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 diff --git a/tools/private/generateRandomMotorParams.m b/tools/private/generateRandomMotorParams.m new file mode 100644 index 0000000..5905e9a --- /dev/null +++ b/tools/private/generateRandomMotorParams.m @@ -0,0 +1,38 @@ +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 -- GitLab