Automated electromagnetic generator with self-adaptive structure by coil switching