JWST communicates with ground stations on the Earth, and the delay in sending signals back and forth can be used to measure the distance to the telescope. Small shifts in the frequency of a signal can be used to measure its velocity (thanks to the Doppler effect).
Operators here on Earth use that info, called telemetry, to calculate the telescope’s trajectory and can send commands to make the telescope move as needed.
Latest Answers