[FTC]: Encoders

Does anybody have any sample code for encoders that i can take a look at. Thanks if you do.

Which language?

If you are using RobotC, this will work

nMotorEncoder[YOUR_MOTOR1_HERE] = 0;
nMotorEncoder[YOUR_MOTOR2_HERE] = 0;
nMotorEncoderTarget[YOUR_MOTOR1_HERE] = X_Distance;
nMotorEncoderTarget[YOUR_MOTOR2_HERE] = X_Distance;
motor[YOUR_MOTOR1_HERE] = 100;
motor[YOUR_MOTOR2_HERE] = 100;

Just substitute “YOUR_MOTOR1_HERE” and “YOUR_MOTOR2_HERE” for the names of the motors you are using, and then substitute “X_Distance” for the number of rotations you want to travel.

I don’t think you need to do the motor[motorname] = 100;, I think the encoders already go to the target encoder positions.

Is that right?

You still need to motor[motorname] = 100;. nMotorEncoderTarget] does not move the motor. It only set the target.

Oh…really…what happens when the encoders reach the target position?

The motors should just stop.

I want to know how to use encoders on an arm in and out of autonomous. I have gotten it to go up but its not reconizing a second button in robotc what should i do

Can you post what code you have so far?