%% moving forward for a fixed time

close all; clear all; % close all figure windows and clear workspace

% set up connection to brick
COM_CloseNXT('all');  
hNXT=COM_OpenNXT(); 
COM_SetDefaultNXT(hNXT);

% Define motor command for forward movement
forward=NXTMotor('BC'); 
forward.Power=50; 
forward.TachoLimit=0; 


%% linear controler

%mark the starting position and run forward for 1 sec
% measure distance between start and end position
% assign distance in cm to d

forward.SendToNXT();
tic;

while toc<1
end
forward.Stop('brake')

return
d=29

forward.SendToNXT();
tic;

while toc<60/d
end
forward.Stop('brake')

%% 
%define sensor on port 1
OpenUltrasonic(SENSOR_1); 



%%cleaning up
forward.Stop('off');
CloseSensor(SENSOR_1);
COM_CloseNXT(hNXT);

