Speed Control with Motor

I would like to control the speed of a DC motor directly from the Arduino Uno. The DC motor has a relative encoder with Channel A and B to indicate the direction of rotation. Also, would position control be possible? How should I go about coding this?

The way I plan on controlling the motor is two signals: one is a PWM, other is ground. The signals are reversed in the program to change the direction of rotation.

To control the speed, would I need to take the derivative from the encoder data?

I am currently looking at PID and encoder library mentioned on the Arduino site. The PID controller examples I see use an analog input with an analog PWM output. This would not work for forward and reverse direction. Do I need the motor to rotate in both directions for speed control?

Please advise. Thank you.

I think you're basically on the right track - have a search on the forum about hooking up to encoders and also about motor driver options. Once you have input from the encoder and can control the motor then you have to close the feedback loop (which PID control is a general solution for).

If you use the encoder to update an actual position variable (a count of clockwise encoder steps, say), then you can calculate the desired position and use the difference to drive the feedback loop - this gives a continuous-rotation servo motor with repeatable positioning (but not absolute, only relative to the starting position).

Given a motor is usually heavily mechanically damped you may get away with proportional-only control

If you do your loop control using speeds rather than positions you will get speed control only.