View unanswered posts | View active topics It is currently Fri Aug 29, 2014 7:15 pm






Reply to topic  [ 2 posts ] 
question about stop() 
Author Message
Rookie

Joined: Thu May 16, 2013 1:08 pm
Posts: 3
Post question about stop()
Hi! I am just starting to use Natural Language with NXT, and setup and writing simple programs has gone well. However, I notice that most of the sample code snippets are of the following form:

forward();
wait();
stop();

Can you tell me why the stop() is needed? My original thought was to put on the brakes instead of letting to robot coast to a stop, but when I tried it both ways, the robot seemed to stop in the same place with or without the stop(). Admittedly, I was just marking the
distances with electrical tape, so it was not a super precise experiment. At any rate, if you could satisfy my curiosity about this, I would really appreciate it.


Thu May 16, 2013 1:11 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 566
Post Re: question about stop()
The stop(); command by default applies a 'brake' command to the motors and stops them in place. This is useful for stopping the NXT motors from coasting past the intended travel point if the program then does other things.

In ROBOTC, the closing brace of task main() (the } at the end of the program) also sends a 'brake' command to all of the motors on the NXT as a safety feature; so in this particular program, removing the stop() command will result in similar behavior then the program with the stop() command. However, it is always good practice to explicitly stop the motors whenever you want them to stop to ensure that the robot does not coast past the desired point of travel.

This code:
Code:
//Psuedocode below

task main()
{

forward();
wait();
stop();
//Other code; the motors are stopped, so no problems

}


Is not the same at this code:
Code:
//Psuedocode

task main()
{

forward();
wait();
//Other code; the motors are not stopped, so they keep on turning until the last } brace. This should be avoided (unless desired)!

}

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Thu May 16, 2013 2:58 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.