what are the function of commutator
The direction of the current in the coil reverses periodically as the coil flips, or turns upside down after every half turn.
The commutator is used to provide a current in the same direction as it will maintain the polarity (positive and negative ends) of the circuit.