Charging and discharging of lithium batteries and nickel batteries