What is a commutator? How does it bring direct current?

A commutator is used in a DC generator and helps to produce direct current.
If a commutator is used, one brush is at all times in contact with the wire moving up in the field, while the other is in contact with the wire moving down, as split rings change their position after every half rotation. Thus, a unidirectional current is produced.