I'm trying to practice with encoders using the built in NXT Lego motor encoders.

With this code the NXT Lego motors are doing more than 2 rotations and the program continuously loops.How can I make it just rotate twice and stop afterwards?Does one rotation on NXT Lego motors not equal 1500 on the encoders?

void stopMotors(){ /* This subroutine only stops the 12V motors defined in the Motors and Sensors setup area. * If you add more motors and or servos, please update this routine to stop their movement. */

motor[motorB] = 0; motor[motorA] = 0;

/* If you have servos, a way to stop their movement is with the following code: servoTarget[servo1] = ServoValue[servo1]; */}

task main(){ while (true) { getJoystickSettings(joystick);

// has the FMS stopped the program if (joystick.StopPgm) { nxtDisplayTextLine(2, "Disabled"); stopMotors(); wait1Msec(50); continue; // go back into top of while loop }

The program won't stop because of the Joystick Driver is it's own background task... and ROBOTC won't stop the program until all of the tasks are completed (in the FTC sake, the JoystickInclude will never stop unless told).

On the field, you shouldn't worry, as the Field Management System will forcefully stop your program when the autonomous period is over.

Who is online

Users browsing this forum: No registered users and 2 guests

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