diff --git a/tests/IsRunningVsCurrentSpeed.m b/tests/IsRunningVsCurrentSpeed.m new file mode 100644 index 0000000000000000000000000000000000000000..bc882474282244a7351018419beb0d143c9ef56d --- /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 0000000000000000000000000000000000000000..a08aabd7915375d4267d563cf3b23c2b56d28642 --- /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 0000000000000000000000000000000000000000..47b6f2cb1e999dcef377c0bda4fe43274007cd93 --- /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 0000000000000000000000000000000000000000..e8072e30ac4d37f9a8812f485f8e81cdf1d9415f --- /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 0000000000000000000000000000000000000000..e311a6576ffa01b096132478591b1f460dedbe39 --- /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 0000000000000000000000000000000000000000..89c59fd1f68e5d092538e29d36194508d7f9b6e5 --- /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 0000000000000000000000000000000000000000..d27fbc9ef0e6053961b6b1b1902b2f349bca11c6 --- /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 0000000000000000000000000000000000000000..5905e9ad61a1fcba3202e3edb709319fefe846fd --- /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 0000000000000000000000000000000000000000..d15389a18d38e374bab555f4c3379d11f12f6c6d --- /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 0000000000000000000000000000000000000000..026f250596083082c209231b7d213f97bbf57d23 --- /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 0000000000000000000000000000000000000000..658047e6ea451b9be281e32fd2db36c3c398fd83 --- /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 0000000000000000000000000000000000000000..8d543ba820386e3919653c29e616b2384afb647d --- /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 0000000000000000000000000000000000000000..3cec2149d0312a61861904b09a058d61b652d34a --- /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 0000000000000000000000000000000000000000..2ef83d07009242fba63ce2a2642d8b81d21219b1 --- /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 0000000000000000000000000000000000000000..1bbff24993c5e40bada9fc92536322eaa9694c42 --- /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 0000000000000000000000000000000000000000..17f582a013faa9687d0b88fd650605351953db42 --- /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 0000000000000000000000000000000000000000..7d9b7b904d4fa6bf85bcfb13ca2e0f5bf46d1387 --- /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 0000000000000000000000000000000000000000..af933fc196e80b0fb4dd814e85b1210f486f54af --- /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 0000000000000000000000000000000000000000..fc428f8056d36a42af49fd43638c133733c1c318 --- /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 0000000000000000000000000000000000000000..f689f2be905bf20aac68607391d7dee7b8114c61 --- /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 0000000000000000000000000000000000000000..266418cc59cd5fdc0cb66e01d5cd37d17378f281 --- /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 0000000000000000000000000000000000000000..266418cc59cd5fdc0cb66e01d5cd37d17378f281 --- /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 0000000000000000000000000000000000000000..050989b399b040c23acbd2047bac0bc7b965f204 --- /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 0000000000000000000000000000000000000000..6892f0981afbaa94f05c70716d7ec0660b17e089 --- /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 0000000000000000000000000000000000000000..1908fb131eaf2f5bcd80bd2ab5c9e477f9485895 --- /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 0000000000000000000000000000000000000000..ef072ac67f2a625e57074c407c4285032c79a24e --- /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 0000000000000000000000000000000000000000..10560b4539935421d76b4aef9abdf33c0d9cb159 --- /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 0000000000000000000000000000000000000000..d27fbc9ef0e6053961b6b1b1902b2f349bca11c6 --- /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 0000000000000000000000000000000000000000..5905e9ad61a1fcba3202e3edb709319fefe846fd --- /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