Grade crossings

How are RR crossings activated? is it via switch in cab or a magnetic sensor??

Track circuits mainly. In the UK some are operated by a treadle (a switch operated by the train wheels)

By track circuits. The most sophisticated can sense the train’s speed by the rate of change of resistance and adjust the timing of the warning accordingly.