I will try to answer your general question with application to NASA's New Horizons spacecraft.
The AOCS/GNC (Attitude and Orbital Control System / Guidance Navigation and Control) subsystem takes care that a spacecraft points to a specific point in space, determines the s/c attitude, and does trajectory corrections.
So in simple terms, an AOCS system is built up by:
- sensors (star-trackers, Earth sensor, magnetometer IMU, etc.)
- actuators (the different thrusters, reaction wheels, magnetorquers)
- control algorithm (for example C code).
Now, to put this into perspective, you need a basic diagram to understand the very basics of control engineering:
A typical, single-input, single-output feedback loop with descriptions for its various parts. Image: Wikimedia Commons
I won't get into too much detail. In essence: you are trying to minimize the error based on sensory feedback via controlling the s/c actuators.
According to Johns Hopkins Applied Physics Laboratory's (APL's) mission description, Spacecraft Systems and Components page, New Horizons has the following GNC system:
Attitude determination – knowing which direction New Horizons is
facing – is performed using star-tracking cameras, Inertial
Measurement Units (containing sophisticated gyroscopes and
accelerometers that measure rotation and horizontal/vertical motion),
and digital Sun sensors. Attitude control for the spacecraft – whether
in a steady, three-axis pointing mode or in a spin-stabilized mode –
is accomplished using thrusters.
The IMUs and star trackers provide constant positional information to
the spacecraft’s Guidance and Control processor, which like the
Command and Data Handling processor is a 12-MHz Mongoose V. New
Horizons carries two copies of each of these units for redundancy. The
star-tracking cameras store a map of about 3,000 stars; 10 times per
second one of the cameras snaps a wide-angle picture of space,
compares the locations of the stars to its onboard map, and calculates
the spacecraft’s orientation. The IMU feeds motion information 100
times a second. If data shows New Horizons is outside a predetermined
position, small hydrazine thrusters will fire to re-orient the
spacecraft. The Sun sensors back up the star trackers; they would find
and point New Horizons toward the Sun (with Earth nearby) if the other
sensors couldn’t find home in an emergency.
Operators use thrusters to maneuver the spacecraft, which has no
internal reaction wheels. Its smaller thrusters are used for fine
pointing; thrusters that are approximately five times more powerful
are used during the trajectory course maneuvers that guide New
Horizons toward its targets. New Horizons spins – typically at 5
revolutions per minute (RPM) – during trajectory-correction maneuvers
and long radio contacts with Earth, and while it “hibernated” during
long cruise periods. Operators steady and point the spacecraft during
science observations and instrument-system checkouts.