LabVIEW for LEGO MINDSTORMS and LabVIEW for Education

cancel
Showing results for 
Search instead for 
Did you mean: 

NXT coding problem, tic & toc problems?

Hi guys, I'm trying to make a car that parks itself but I'm having a problem with the bit of code that the car uses to find the space, I think there's an issue with my while loop because the car doesn't stop once a big enough gap has been found after three seconds, could you please have a look at my code (we're in matlab by the way) and point out any problems.  Thanks!

 

while motorA == 1

 

 

 

    mB.Stop('brake'); % stop the turning motor so car drives straight

 

 

 

   if distance < 40 %distance needed on ultrasonic sensor to prak in

 

              tic;

             distance = GetUltrasonic(SENSOR_2); % re-set value of distance for next turn through loop

 

   end

 

   if toc > 3

 

      mA.Stop('brake'); % stop the driving motor

              motorA = 0; % break out of loop as gap has been found (while loop no longer satisfied

 

   end

 

 

end

 

0 Kudos
Message 1 of 2
(4,392 Views)

Hi.

 

 

The toc can't be used for comprison like you do with the toc < 3. That I believe would always return 0 and therefore the stop if-loop never runs.

The functionality might be preserved if the toc is loaded into another variable like TimeElapsed = toc.

 

This is stated in the documentation of the tic-toc: http://mathworks.com/help/matlab/ref/tic.html

 

For a more indepth reply you might want to seek out the help from the users/engineers at MATLAB. They are available from http://mathworks.com/matlabcentral/.

 

 

Best Regards,

 

Mette Bertelsen

Application Engineer

National Instruments

 

 

 

 

0 Kudos
Message 2 of 2
(4,366 Views)