Re: NXC: motor rotating to a encoder target
Posted: 17 Aug 2011, 21:57
I think you want APR (Absolute Position Regulation). It is a feature that was developed (released) last fall, and implemented officially by John in March 2011.
Here is an example using the (now) native NXC API(s).
Note, that before you start the APR (using PosRegEnable), the motor can be used normally (with things like OnFwd, Off...). This is nice to have to center the motor (home the encoder).
Here is an example using the (now) native NXC API(s).
Code: Select all
task main(){
PosRegEnable (OUT_A); //Start the APR control
PosRegSetMax (OUT_A, 0, 0); //Set the max parameters (0 is unlimited)
while(true){
PosRegSetAngle (OUT_A, (Random(1000)-500)); //Set the position you want, as often as you want.
Wait(2500);
}
}