There are several good resources for this on ni.com/frc.
There is example code performing PID using an encoder available here:
https://decibel.ni.com/content/docs/DOC-26316 and a PID tutorial available here:
https://decibel.ni.com/content/docs/DOC-26317