1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
%Init
clear all
close all
%Ouverture NXT
h = COM_OpenNXT();
COM_SetDefaultNXT(h);
%Ouverture de la matrice
%
%Ouverture de l'image de la matrice (simulation)
a = imread('PLAN_SIMU.bmp','bmp');
%Convertit matrice en type "double" indispensable pour les calculs
M = double(a);
%Affiche l'image
image(M);
x = 1;
y = 1;
while true
%Avance en ligne droite
forward = NXTMotor([MOTOR_B;MOTOR_C]);
forward.Power = 15;
forward.SendToNXT();
%Si colonne impaire
if y == 1 || 3 || 5 || 7 || 9 || 11 || 13 || 15 || 17 || 19
while x <= 20 %Tant que l'indice des lignes < 20
if M(x,y) == 255 %Si la valeur d'une cellule est à 255
DirectMotorCommand(MOTOR_A, -90, 90, 'off', 'off', 0, 'off'); %On remonte le stylo
StopMotor(MOTOR_A,'off');
pause(0.5);
x = x + 1; %On incrémente l'indice de la ligne
else
DirectMotorCommand(MOTOR_A, 90, 90, 'off', 'off', 0, 'off'); %On abaisse le stylo
StopMotor(MOTOR_A,'off');
pause(0.5);
x = x + 1; %On incrémente l'indice de la ligne
end
end
end
pause(1);
StopMotor('all','off');
%NXT_ResetMotorPosition(MOTOR_B,'false');
%NXT_ResetMotorPosition(MOTOR_C,'false');
%Relève le stylo au cas où il serait baissé
DirectMotorCommand(MOTOR_A, -90, 90, 'off', 'off', 0, 'off');
pause(0.3);
StopMotor(MOTOR_A,'off');
%NXT_ResetMotorPosition(MOTOR_A,'false');
%Avance un peu pour combler l'imprécision du virage (fonction)
marche_avant_distance(5);
%Demi tour 180° gauche
demi_tour_robot_g_2(241);
%On incrémente la colonne et on corrige l'exédant de la variable "x"
y = y + 1;
x = x - 1;
%Ligne Droite
forward = NXTMotor([MOTOR_B;MOTOR_C]);
forward.Power = 15;
forward.SendToNXT();
%Si colonne paire
if y == 2 || 4 || 6 || 8 || 10 || 12 || 14 || 16 || 18 || 20
while x >= 1 %Tant que l'indice des lignes >= 1
if M(x,y) == 255 %Si une valeur d'une cellule est égale à 255
DirectMotorCommand(MOTOR_A, -90, 90, 'off', 'off', 0, 'off'); %On remonte le stylo
StopMotor(MOTOR_A,'off');
pause(0.5);
x = x - 1; %On décrémente l'indice de la ligne
else
DirectMotorCommand(MOTOR_A, 90, 90, 'off', 'off', 0, 'off'); %On abaisse le stylo
StopMotor(MOTOR_A,'off');
pause(0.5);
x = x - 1; %On décrémente l'indice de la ligne
end
end
end
StopMotor('all','off');
%NXT_ResetMotorPosition(MOTOR_B,'false');
%NXT_ResetMotorPosition(MOTOR_C,'false');
%Relève le stylo au cas où il serait baissé
DirectMotorCommand(MOTOR_A, -90, 90, 'off', 'off', 0, 'off');
pause(0.3);
StopMotor(MOTOR_A,'off');
%NXT_ResetMotorPosition(MOTOR_A,'false');
%Avance un peu pour combler l'imprécision du virage (fonction)
marche_avant_distance(5);
%Demi tour 180° vers la droite
demi_tour_robot_d_2(241);
y = y + 1;
x = x + 1;
%Si la matrice a été faite entièrement
if y == 21
StopMotor('all','off');
NXT_ResetMotorPosition('all','false');
break %On sort de la boucle et stop programme
end
end
COM_CloseNXT(h); %Fermeture NXT |
Partager