A method for controlling the energy supply of a mining vehicle, which mining vehicle comprises at least one mining work device at least one AC electric motor for powering the at least one mining work device, an auxiliary energy source, a power electronics device for charging the auxiliary energy source, and a connecting device connectable to a supply cable for supplying electric current to the mining vehicle from a supply grid, characterised in that the method further comprises: determining a maximum value for the current of the supply cable, which current of the supply cable may comprise an effective current of the at least one electric motor, a reactive current of the at least one electric motor and an effective charging current of the power electronics device used for charging the auxiliary energy source, using the power electronics device for supplying reactive current and for charging or discharging the auxiliary energy source, determining a maximum value for the current of the power electronics device, which current of the power electronics device may comprise the reactive current supplied by the power electronics device and the effective charging current for charging or discharging the auxiliary energy source, whereby the maximum value for the current of the power electronics device is smaller than the sum of the maximum value of the effective charging current for charging or discharging the auxiliary energy source and the maximum value of the reactive current the power electronics device is able to supply and controlling the amount of the effective current from the supply grid, the amount of reactive current supplied by the power electronics device and the amount of the effective charging current for charging or discharging the auxiliary energy source such that the maximum value for the current of the supply cable and the maximum value for the current of the power electronics device are not exceeded, determining a need for charging and, if there is a need for charging, determining whether the needed charging current would cause an overshoot of the maximum value for the current of the power electronics device, and if it would, determining if it is possible to reduce the reactive current compensation, and, if it is possible, reducing the reactive current compensation and thereafter charging. determining a maximum value for the current of the supply cable, which current of the supply cable may comprise an effective current of the at least one electric motor, a reactive current of the at least one electric motor and an effective charging current of the power electronics device used for charging the auxiliary energy source, using the power electronics device for supplying reactive current and for charging or discharging the auxiliary energy source, determining a maximum value for the current of the power electronics device, which current of the power electronics device may comprise the reactive current supplied by the power electronics device and the effective charging current for charging or discharging the auxiliary energy source, whereby the maximum value for the current of the power electronics device is smaller than the sum of the maximum value of the effective charging current for charging or discharging the auxiliary energy source and the maximum value of the reactive current the power electronics device is able to supply and controlling the amount of the effective current from the supply grid, the amount of reactive current supplied by the power electronics device and the amount of the effective charging current for charging or discharging the auxiliary energy source such that the maximum value for the current of the supply cable and the maximum value for the current of the power electronics device are not exceeded, determining a need for charging and, if there is a need for charging, determining whether the needed charging current would cause an overshoot of the maximum value for the current of the power electronics device, and if it would, determining if it is possible to reduce the reactive current compensation, and, if it is possible, reducing the reactive current compensation and thereafter charging.