A motor controller includes a driver, a current detector, and a command generator. The driver is configured to drive a power converter based on a flux command on which an exploration signal is superimposed. The current detector is configured to detect an output current output from the power converter that has been driven by the driver. The command generator is configured to generate the flux command so as to reduce a current component, among current components included in the output current detected by the current detector, that corresponds to the exploration signal.