Log in

View Full Version : [FTC]: DC MotorEncoder Code


JohnFogarty
02-02-2011, 11:34
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

normalmutant
02-02-2011, 19:15
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.

normalmutant
02-02-2011, 21:43
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. :p
http://say-watt.org/wp2/archives/391

Tim Delles
04-02-2011, 02:42
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.

clwillingham
04-02-2011, 14:54
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.