A controller is configured to control an operation of a self-propelled mechanism provided in an elongated insertion section of an endoscope. The controller includes a circuit configured to: acquire a speed value corresponding to a rotation speed of a motor of the self-propelled mechanism; acquire a torque value corresponding to a torque generated by the motor; control rotation of the motor by switching between at least two of speed control that controls rotation of the motor based on the speed value and torque control that controls rotation of the motor based on the torque value; and stop the rotation of the motor if the torque value has exceeded a predetermined threshold value, perform the torque control when the rotation of the motor is resumed.