Combine Accelerometer and Encoders on redbot

I am trying to figure out a way to drive the redbot in a predetermined map using Accel and encoders and PID. Has anyone run across the code to do this? Eventually i want to be able to use IR sensors to triangulate the robots position but i wanted to figure this out first.

Thanks!