How can I write a linear state space model for a 4 wheel mobile robot with Ackerman steering in terms of error. I want the robot to follow a line. The robot is rear wheel drive
Read and understand this. Refer to other sections of that site, if needed.
I know this is not exactly what you wanted, but you should look into the Pure Pursuit algorithm for line following.