Draft: port pdcontrol from Vanilla
This is just to get this code off my client machine in case we'd want to merge it.
I'd much rather implement pdcontrol as an abstraction, which may be found here:
If for some reason that doesn't work, we can merge the C code here.