moving dc motor with help of optical encoder data

I have written the code for getting the encoder data and have used it to give me the number of counts (ticks) of encoder and an algorithm to give me both angle and velocity of the motor shaft.

So, this might seem to be a silly question, but how do i actually use this data to move the motor at a specific angle and velocity? I mean when i rotate the motor shaft with my hand, i am getting the number of counts , angle and velocity of motor shaft on the serial monitor. so please help me with the code for how to move the motor at specific angle and at specific velocity

I am still a noob so please help me with the code. I am using an arduino mega. I have attached the code below.

I am using the following dc motor and driver :

Encoder dc motor : https://robokits.co.in/motors/encoder-dc-servo/planetary-encoder-geared-motor-24v-1000rpm-100w?zenid=5prh047gko82nboffq5ptpo870

motor driver : Hercules 6V-24V, 16Amp Motor Driver with built in current se - Nex Robotics

encoder_1.ino (1.03 KB)

read_encoders.ino (1.78 KB)

how do i actually use this data to move the motor at a specific angle

If you mean "position the motor shaft to a particular angle", then you would use PID calculations.

Since the encoder is relative, you must have some way of specifying the "home" or zero angle position. People often use a slotted disk attached to the shaft and an optointerrupter to define zero upon program startup. Your program then has to keep track of the current position.

That's a heavy motor. Unless you have some good brakes, it will continue rotating after you have reached your angle. If that's not an issue, just provide power to the motor, follow the encoder counter. When it reaches the count corresponding the desired angle, stop providing power.

For setting a speed, do the PID thing. If the PID thing is too difficult, try something simple. Measure speeds at different powers and loads and create a table. Set some start speed according to your table. Measure the real speed. Calculate how much off it is from the desired speed. Say +12%. Take 12% off the power and measure again. Now you have two measured speeds for two amounts of power. Interpolate or extrapolate to get a new estimation for right power for desired speed. Repeat the procedure with the two last measurements. In the best of worlds, this will lead to narrowing down towards the right power for the desired speed.