Thermobarometry uses equilibrium constants to calculate information about the environmental conditions present during the rocks' formation. While each rock is forming, it reacts with the surrounding elements until it cools down enough to become inert. Each mineral within the rock will cool and crystalize at different points; a petrogenetic grid is a useful way to visualize each mineral crystalizing in sequence.
Individual reactions of specific minerals can be used to calculate either the temperature or pressure. Therefore, two different reactions are needed to calculate both the temperature and pressure of the magma for a single rock. Some reactions are better for pressure and others are better for temperature, based on thermodynamics and Le Chatelier's Principle.
This technique requires each reaction to be calibrated, which is done through experimentation and data analysis. Experimentation involves simulating the temperatures and pressures at which these rocks form and observing how the reaction proceeds at those conditions, while data analysis relies on amassing a large database of rock samples with pressure and temperature information. Experimental data tends to have significant variation, so using data from natural formations is more accurate, if it's available.