function Impact(H)

globalVar;

sendServo(H,1,21,0,0,0,0,0,0);

[command,return1,return2,return3] = readServo(H);
isVal = return1;

if (isVal == 1)
    return1 = 0;        % apenas para limpar o registo
    i=0;
    while (return1 ~= 1 || return2 ~= 2 || return3 ~= 3)
        i = i+1;
        [command,return1,return2,return3] = readServo(H);
        XYZ_z(i) = return1*256 + return2;
        [command,return1,return2,return3] = readServo(H);
        t(1,i) = return1*256+return2;

        [command,return1,return2,return3] = readServo(H);
        valSensor(1,i) = return1*256 + return2;
        temp_ret = return3;
        [command,return1,return2,return3] = readServo(H);
        valSensor(2,i) = temp_ret*256 + return1;
        valSensor(3,i) = return2*256 + return3;
        [command,return1,return2,return3] = readServo(H);
        valSensor(4,i) = return1*256+return2;
    end
    N1 = i-1;
    XYZ_z = XYZ_z(1,1:N1)/10-200;
end

return1 = 0;        % apenas para limpar o registo
if (isVal == 1)
    i = i-2;
else
    i=0;
end
while (return1 ~= 1 || return2 ~= 2 || return3 ~= 3)
    i = i+1;
    [command,return1,return2,return3] = readServo(H);
    t(1,i) = return1*256+return2;
    
    [command,return1,return2,return3] = readServo(H);
    valSensor(1,i) = return1*256 + return2;
    temp_ret = return3;
    [command,return1,return2,return3] = readServo(H);
    valSensor(2,i) = temp_ret*256 + return1;
    valSensor(3,i) = return2*256 + return3;
    [command,return1,return2,return3] = readServo(H);
    valSensor(4,i) = return1*256+return2;
end
N2 = i-1;
t = t(1,1:N2);
valSensor = valSensor(:,1:N2);

[command,return1,return2,return3] = readServo(H);
j = return1;
N2 = i-1;
disp(['Movement with ', num2str(N2), ' values.']);
disp(['Movement with ', num2str(j), ' invalid InvKin.']);

solo(1:N2)=-10.3;

figure
if (isVal == 1)
    subplot(2,1,1)
    hold on
    plot(t(1,1:N1)',XYZ_z','.')
    plot(t',solo','-k','LineWidth',2)
    title('Localização do Pé em altura (eixo zz)','FontWeight','bold','FontSize',12)
    xlabel('Tempo (ms)','FontWeight','bold','FontSize',12)
    ylabel('Pos em Z (mm)','FontWeight','bold','FontSize',12)
    axis([t(1) max(t) -15 15])
    grid on
    hold off
    
    subplot(2,1,2)
end
hold on
plot(t',valSensor(1,:)','r-')
plot(t',valSensor(2,:)','c-')
plot(t',valSensor(3,:)','m-')
plot(t',valSensor(4,:)','g-')
title('Valor dos Sensores','FontWeight','bold','FontSize',12)
xlabel('Tempo (ms)','FontWeight','bold','FontSize',12)
ylabel('Valor (0...1023)','FontWeight','bold','FontSize',12)
legend('Sensor 1','Sensor 2','Sensor 3','Sensor 4','FontWeight','bold','FontSize',11);
axis([t(1) max(t) -10 390])
grid on
hold off

end