Position control with dc motor with encoder

Hi I want to do position control of dc motor with encoder. Is there any link I can Start from. I am using SN755410 driver IC and pololu motor with arduino Mega.

///////////////////////////////////////
The Motor specs are :

19:1 Metal Gearmotor 37Dx52L mm with 64 CPR Encoder
1200 counts per revolution of the gearbox’s output shaft
Key specs at 12 V: 500 RPM and 300 mA free-run, 84 oz-in (5 kg-cm) and 5 A stall.
Red motor power (connects to one motor terminal)
Black motor power (connects to the other motor terminal)
Green encoder GND
Blue encoder Vcc (3.5 – 20 V)
Yellow encoder A output
White encoder B output

/////////////////////////////////////////

How Can I do this, I have seen some codes online but I am not able to program.

Regards
Vasu

I have seen some codes online but I am not able to program.

Then you need to learn. You need to learn to make the motor move. You need to learn to read the encoder output. You need to learn to stop the motor when the count gets to where you want. You may need to learn to slow the motor so you don't overshoot. More likely, though, you may need to buy the right kind of motor, instead.

Do some reading up on PIDs, then download the Arduino PID library. That is exactly what PIDs were designed for.

Regards,
Ray L.

Okay I have this motor Pololu - 19:1 Metal Gearmotor 37Dx52L mm 12V with 64 CPR Encoder (No End Cap)

Hi Vasu_mn I found this code on arduino forum, It does move back and forth, only thing I dont understand is that tick number

moveMotor(FORWARD, 50, 1200*2);                        // direction, PWM, ticks number
#define InA1            10                      // INA motor pin
#define InB1            11                      // INB motor pin
#define PWM1            6                       // PWM motor pin
#define encodPinA1      2                       // encoder A pin
#define encodPinB1      3                       // encoder B pin

#define LOOPTIME        100                     // PID loop time
#define FORWARD         1                       // direction of rotation
#define BACKWARD        2                       // direction of rotation

unsigned long lastMilli = 0;                    // loop timing
unsigned long lastMilliPrint = 0;               // loop timing
long count = 0;                                 // rotation counter
long countInit;
long tickNumber = 0;
boolean run = false;                                     // motor moves

void setup() {
 pinMode(InA1, OUTPUT);
 pinMode(InB1, OUTPUT);
 pinMode(PWM1, OUTPUT);
 pinMode(encodPinA1, INPUT);
 pinMode(encodPinB1, INPUT);
 digitalWrite(encodPinA1, HIGH);                      // turn on pullup resistor
 digitalWrite(encodPinB1, HIGH);
 attachInterrupt(1, rencoder, FALLING);
}

void loop() {
 moveMotor(FORWARD, 50, 1200*2);                        // direction, PWM, ticks number
 delay(5000);
 //moveMotor(BACKWARD, 100, 2400*2);                           // 464=360°
 //delay(3000);
}

void moveMotor(int direction, int PWM_val, long tick)  {
 countInit = count;    // abs(count)
 tickNumber = tick;
 if(direction==FORWARD)          motorForward(PWM_val);
 else if(direction==BACKWARD)    motorBackward(PWM_val);
}

void rencoder()  {                                    // pulse and direction, direct port reading to save cycles
 if (PINB & 0b00000001)    count++;                  // if(digitalRead(encodPinB1)==HIGH)   count_r ++;
 else                      count--;                  // if (digitalRead(encodPinB1)==LOW)   count_r --;
 if(run)  
   if((abs(abs(count)-abs(countInit))) >= tickNumber)      motorBrake();
}

void motorForward(int PWM_val)  {
 analogWrite(PWM1, PWM_val);
 digitalWrite(InA1, LOW);
 digitalWrite(InB1, HIGH);
 run = true;
}

void motorBackward(int PWM_val)  {
 analogWrite(PWM1, PWM_val);
 digitalWrite(InA1, HIGH);
 digitalWrite(InB1, LOW);
 run = true;
}

void motorBrake()  {
 analogWrite(PWM1, 0);
 digitalWrite(InA1, HIGH);
 digitalWrite(InB1, HIGH);
 run = false;
}