When a rocket is knocked its intended flight course by wind, how is the gimbal angle calculated to return the rocket to its courses? Like, if the rocket intended course is 90 degrees straight off, and it knocked off to 110 degrees how is the gimbal angle calculated?
The gimbal angle is some function of the error angle; this is a typical application of control theory.
One common approach is the PID controller. This algorithm starts with a gimbal angle proportional to the steering error (the P part). It then adds additional correction based on the integral of the error (effectively, a measure of how long the rocket has been off course for) -- that's the I part. Finally, there's a correction based on the derivative of the error (the D part), that is, how fast the error is changing -- which helps avoid overshooting.
The proportional constant for each term (usually called the gain in control theory) has to be tuned for a particular rocket design to make sure that it doesn't correct too slowly or too quickly, or overcorrect.
Real rocket guidance may not use the classic PID controller, but it's usually something not too distantly related.
At a very high level, it works like this:
1) The onboard computer is constantly calculating the attitude (roll, pitch, yaw) the vehicle should be in at the current time (target attitude).
2) The onboard computer is also constantly calculating the actual attitude the vehicle is in at the current time (actual attitude) using data from the vehicle's sensors (gimbals, accelerometers, etc).
3) If there is a difference between the target and actual attitude, the computer will move the engines so that they rotate the vehicle in the correct direction to reduce the difference towards zero.
How fast this happens, the details of how it happens, are going to vary significantly depending on the vehicle you are are talking about. There are many constraints that have to be factored in like how fast the actuators can move the engines, rate limits that the vehicle is allowed to change its attitude in, etc. etc.
Here is a very general drawing showing the sensors on the left, computers in the middle, and actuators including thrust vector control on the right.
This is from the 1982 Shuttle Press Manual, page 443.