[FTC]: DC MotorEncoder Code

So in the instance of having servos, those servos have set positions you can send them to. What I want to do is tell a motor to go to specific encoder positions in robotC. I haven’t the slightest clue how to begin doing that. My goal is to push a button and have an arm powered by a motor go to a certain position and stop or keep a low level of power to keep it locked in that position until the button isn’t pressed.
Thank You.
John Fogarty

Here’s one way to do it:
Have the motor move back until it hits a touch sensor. Set the input from the encoder as the zero position (store it in a variable) and move the motor forward to the encoder position you want, plus the zero value.
We did this to align a dispenser tread on our old robot. If it doesn’t rotate all the way around, you may not have to do this.

Oh, actually, you could just reset the encoder using the software when it hits the touch sensor. Sorry, I’m a hardware guy. I was unsure about my last post, so I read our team’s own tutorial on using them. :stuck_out_tongue:
http://say-watt.org/wp2/archives/391

nMotorEncoder[motorA] = 0;
wait1Msec(50);
nMotorEncoderTarget[motorA] = x;    <- set this to the number of rotations the Motor Encoder needs to rotate
motor[motorA] = 100;
while ((nMotorRunState[leftMotor] != runStateIdle))
  {
    EndTimeSlice();
  }
  return;

This can only be used if you have a shaft encoder attached to the motor you want to use. Good luck.

another way thats a bit more direct but probably a little bit less reliable in terms of skidding:


motor[FL] = power;
motor[FR] = power;
motor[BL] = power;
motor[BR] = power;
while(nMotorEncoder[FL] < units){}
Stop(); // we wrote this function to set every motor to 0.

please note that this code is for a four wheel drive robot.