That would calculate velocity. There is also an in depth analysis of different ways to calculate velocity in this thread.
You need to decide what your units are, all the code I post uses revs/minute, ie. angular velocity. If you use these then the “target” for the PID calculations needs to be in the same units. It looks like your existing code is trying to use something else.