NeXT-Gen is correct, the command you are looking for is 'nMotorEncoder'. This will let you read and write values for the specified motor. For instance, to clear the motor's encoder to a value of zero:
There are multiple ways to keep a motor running until an encoder value is reached; one of the more common ways is to use a while loop:
This will run motor A at a value of 50 power until it reaches 1000 encoder ticks; once 1000 encoder ticks are reached, the motors will turn off. Always make sure to either clear the encoders beforehand (or tweak your while loop condition accordingly) and to turn the motor off after the loop is over (if you want the motor to stop at that point).
You may notice that the motors drift past the desired encoder value by a bit; to avoid this, you will want to use the 'nMotorEncoderTarget' command:
To learn more about the encoder commands in ROBOTC, check out our NXT Motor Functions wiki page
. You may also be interested in our [urlhttp://www.education.rec.ri.cmu.edu/previews/robot_c_products/teaching_rc_tetrix_preview/index.html]online curriculum video trainer[/url] which covers all of the basic ROBOTC commands and functions (including encoders and while loops).
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