One answer: Closed loop systems and/or sensor fusions
You can't just send the right commands to the motor and expect that the robot will act exactly as expected. Think about a very very small difference in the torque produced by your two motors that received two identical PWM signal (due to motor manufacturing tolerances). One will go slightly faster than the other and the robot will run along a circle (very big, but still a circle) instead of a straight line.
The answer to this problem is closed loop control. Your motors, or your wheels will have encoders. And your control system will receive the signals from the encoders and will react in a way that ensure that your wheels are doing exactly what you expect them to do.
But in the case of an autonomous robot, this in not enough. Think about having a wheel that is slightly bigger than the other, because of wearing, or just due to manufacturing tolerances. Or think about a wheel that slips a little bit on the floor. In this case you don't know anymore for sure where you are. This method is called odometry or dead reckoning. In order to solve this, you have to use sensors that adds knowledge about your environment to your system. (Vision, proximity sensor, bumpers, magnetometer, gyroscopes, etc). Then, advanced algorithms are used to use the best of every sensor at each time step.