PDA

View Full Version : [FTC]: Encoders


astephen68
02-17-2009, 11:03 PM
Does anybody have any sample code for encoders that i can take a look at. Thanks if you do.

gdo
02-18-2009, 08:43 AM
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.

ttldomination
02-18-2009, 12:32 PM
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?

ShawnH
02-18-2009, 12:36 PM
You still need to motor[motorname] = 100;. nMotorEncoderTarget[] does not move the motor. It only set the target.

ttldomination
02-18-2009, 03:19 PM
Oh..really...what happens when the encoders reach the target position?

ShawnH
02-18-2009, 04:32 PM
The motors should just stop.

astephen68
02-18-2009, 10:43 PM
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

gdo
02-19-2009, 09:53 AM
Can you post what code you have so far?