Skip to content
Snippets Groups Projects
Commit baf103f8 authored by Sandra Vogt's avatar Sandra Vogt Committed by Tim Stadtmann
Browse files

Add test-scripts for testing Brick and its devices

parent f6761ead
No related branches found
No related tags found
No related merge requests found
function [] = connectWires() function [] = connectWires()
%Connect motors to ports %Connect motors to ports
disp(sprintf('Please connect front motor to port A, left wheel to port B,\nright wheel to port C. Then press any key to continue.\n\n')); disp(sprintf('Please connect middle motor to port A, large motors to port B and C. Then press any key to continue.\n\n'));
pause(); pause();
%Connect sensors to ports %Connect sensors to ports
disp(sprintf('Please connect touch sensor to port 1, color sensor to port 3,\nultrasonic sensor to port 4. Then press any key to continue.\n\n')); disp(sprintf('Please connect touch sensor to port 1, gyro sensor to port 2, color sensor to port 3,\nultrasonic sensor to port 4. Then press any key to continue.\n\n'));
pause(); pause();
end end
......
...@@ -4,24 +4,20 @@ ret = 0; ...@@ -4,24 +4,20 @@ ret = 0;
disp(sprintf(['--------------------------------------------------------------\nStart motor test ', mode])); disp(sprintf(['--------------------------------------------------------------\nStart motor test ', mode]));
%Test motor A %Test motor A
EV3.motorA.power=20; EV3.motorA.power=20;
try EV3.motorA.start() EV3.motorA.limitValue=1000;
catch all try EV3.motorA.start
end;
pause(1);
try EV3.motorA.stop()
catch all
end;
EV3.motorA.power=-20;
try EV3.motorA.start()
catch all
end;
pause(1);
try EV3.motorA.stop()
catch all catch all
end; end;
answerA = input('Did motor A move? [y/n]', 's'); answerA = input('Did motor A move? [y/n]', 's');
if ~strcmp(answerA,'y') && ~strcmp(answerA,'n')
while true
answerA = input('Incorrect input. Did motor A move? [y/n]', 's');
if strcmp(answerA,'y') || strcmp(answerA,'n')
break;
end
end
end
%Test motor B %Test motor B
EV3.motorB.power=20; EV3.motorB.power=20;
EV3.motorB.limitValue=1000; EV3.motorB.limitValue=1000;
...@@ -30,6 +26,14 @@ catch all ...@@ -30,6 +26,14 @@ catch all
end; end;
answerB = input('Did motor B move? [y/n]', 's'); answerB = input('Did motor B move? [y/n]', 's');
if ~strcmp(answerB,'y') && ~strcmp(answerB,'n')
while true
answerB = input('Incorrect input. Did motor B move? [y/n]', 's');
if strcmp(answerB,'y') || strcmp(answerB,'n')
break;
end
end
end
%Test motor C %Test motor C
EV3.motorC.power=20; EV3.motorC.power=20;
...@@ -39,6 +43,14 @@ catch all ...@@ -39,6 +43,14 @@ catch all
end; end;
answerC = input('Did motor C move? [y/n]', 's'); answerC = input('Did motor C move? [y/n]', 's');
if ~strcmp(answerC,'y') && ~strcmp(answerC,'n')
while true
answerC = input('Incorrect input. Did motor C move? [y/n]', 's');
if strcmp(answerC,'y') || strcmp(answerC,'n')
break;
end
end
end
%Warnings for defect motors %Warnings for defect motors
if (~isempty(strfind(answerA, 'n'))) if (~isempty(strfind(answerA, 'n')))
......
...@@ -11,7 +11,12 @@ if EV3.sensor1.type == DeviceType.Touch ...@@ -11,7 +11,12 @@ if EV3.sensor1.type == DeviceType.Touch
else else
answer1 = 0; answer1 = 0;
end; end;
%Test sensor 2
if EV3.sensor2.type == DeviceType.Gyro
answer2 = 1;
else
answer2 = 0;
end;
%Test sensor 3 %Test sensor 3
if EV3.sensor3.type == DeviceType.Color if EV3.sensor3.type == DeviceType.Color
answer3 = 1; answer3 = 1;
...@@ -28,18 +33,22 @@ end; ...@@ -28,18 +33,22 @@ end;
%Warnings for defect motors %Warnings for defect motors
if answer1 == 0 if answer1 == 0
warning('Test for sensor 1 failed'); warning('Test for sensor 1 failed. Expected touch sensor.');
end;
if answer2 == 0
warning('Test for sensor 2 failed. Expected gyro sensor.');
end; end;
if answer3 == 0 if answer3 == 0
warning('Test for sensor 3 failed'); warning('Test for sensor 3 failed. Expected color sensor.');
end; end;
if answer4 == 0 if answer4 == 0
warning('Test for sensor 4 failed'); warning('Test for sensor 4 failed. Expected ultrasonic sensor');
end; end;
if answer1==1 && answer3==1 && answer4==1 if answer1==1 && answer2==1 && answer3==1 && answer4==1
disp(sprintf('All sensors work correctly.\n')); disp(sprintf('All sensors work correctly.\n'));
ret = 1; ret = 1;
end; end;
......
...@@ -8,10 +8,8 @@ i=0; ...@@ -8,10 +8,8 @@ i=0;
while connected == 0 while connected == 0
disp(sprintf('Please connect the brick via USB and press any key to continue.\n\n')); disp(sprintf('Please connect the brick via USB and press any key to continue.\n\n'));
pause(); pause();
try try b.connect('usb')
b.connect('usb') catch disp('Connection failed, try again...')
catch all
disp('connection failed, try again...')
%discard errors %discard errors
end; end;
connected = b.isConnected(); connected = b.isConnected();
...@@ -24,14 +22,14 @@ end; ...@@ -24,14 +22,14 @@ end;
% Connect motors and sensors to ports % Connect motors and sensors to ports
connectWires(); connectWires();
%Test motors % Test motors (USB)
USBresultMotor = motorTest(b, 'USB'); USBresultMotor = motorTest(b, 'USB');
if USBresultMotor == 0 if USBresultMotor == 0
warning('The USB motor test failed. Please contact us.'); warning('The USB motor test failed. Please contact us.');
end; end;
%Test sensors % Test sensors (USB)
USBresultSensor = sensorTest(b, 'USB'); USBresultSensor = sensorTest(b, 'USB');
if USBresultSensor == 0 if USBresultSensor == 0
...@@ -46,12 +44,13 @@ end; ...@@ -46,12 +44,13 @@ end;
b.disconnect; b.disconnect;
pause(1); pause(1);
%Connect the Brick via BT %Connect the Brick via BT
b=EV3; b=EV3;
connected = 0; connected = 0;
i=0; i=0;
while connected==0 while connected==0
disp(sprintf('Please remove the USB wire, so that the brick can be\nautomatically connected via BT and press any key to continue.\n\n')); disp(sprintf('Please remove the USB wire and use btconnect in the terminal, so that the brick can be\nautomatically connected via BT and press any key to continue.\n\n'));
pause(); pause();
try b.connect('bt', 'serPort', '/dev/rfcomm0') try b.connect('bt', 'serPort', '/dev/rfcomm0')
catch all catch all
...@@ -59,22 +58,22 @@ while connected==0 ...@@ -59,22 +58,22 @@ while connected==0
try b.connect('bt', 'serPort', '/dev/rfcomm1') try b.connect('bt', 'serPort', '/dev/rfcomm1')
catch all catch all
end; end;
connected = b.isConnected();
pause(1); pause(1);
connected = b.isConnected();
i=i+1; i=i+1;
if i==3 if i==3
error('BT connection failed. You can not continue the test. Did you connect the brick with btconnect? If no, start btconnect in the terminal. If yes, restart Matlab and try again. If the error occurs again, please contact us.'); error('BT connection failed. You can not continue the test. Did you connect the brick with btconnect? If no, start btconnect in the terminal. If yes, restart Matlab and try again. If the error occurs again, please contact us.');
end; end;
end; end;
%Test motors %Test motors (BT)
BTresultMotor = motorTest(b, 'BT'); BTresultMotor = motorTest(b, 'BT');
if BTresultMotor == 0 if BTresultMotor == 0
warning('The BT motor test failed. Please contact us.'); warning('The BT motor test failed. Please contact us.');
end; end;
%Test sensors %Test sensors (BT)
BTresultSensor = sensorTest(b, 'BT'); BTresultSensor = sensorTest(b, 'BT');
if BTresultSensor == 0 if BTresultSensor == 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment