An infusion device for a medicinal fluid, the device including: a user interface; a motor operable to deliver the fluid in response to commands; a sensor configured to sense a physiological condition influenced by the medicinal fluid; a pump control module coupled to the user interface, the motor, and the sensor, and including: a command generator comprising; a first algorithm which when executed causes the command generator to issue commands to the motor to deliver the fluid according to a predetermined schedule; and a second algorithm which when executed causes the command generator to issue commands to the motor to deliver fluid to implement a closed-loop control to bring the measured physiological condition to a target value; the command generator further being switchable to execute either the first or the second algorithm; a diagnostic unit connected to the command generator; and configured to receive an expected time for a future switching of the command generator from the first algorithm to the second algorithm and starting a buffer time period before the expected time checking the viability of operation of the command generator after the future switching time; the diagnostic unit also being configured to report said viability to the user interface characterized in that the second algorithm has gain coefficients and in that it is checked that said second algorithm gain coefficients can be calculated before the future switching time; wherein the command generator is configured to provide proportional-integral derivative control when executing the second algorithm and the gain coefficients are the gain coefficients for the proportional, the integral and derivative paths, respectively; wherein the gain coefficients are user- specific or patient-specific and dynamically calculated prior to entering the closed-loop operating mode based on historical insulin delivery information, historical sensor measurement values, historical reference blood glucose measurement values, user-reported or user-input events data; and wherein patient-specific control parameters are utilized to adjust the PID gain coefficients. a user interface; a motor operable to deliver the fluid in response to commands; a sensor configured to sense a physiological condition influenced by the medicinal fluid; a pump control module coupled to the user interface, the motor, and the sensor, and including: a command generator comprising; a first algorithm which when executed causes the command generator to issue commands to the motor to deliver the fluid according to a predetermined schedule; and a second algorithm which when executed causes the command generator to issue commands to the motor to deliver fluid to implement a closed-loop control to bring the measured physiological condition to a target value; the command generator further being switchable to execute either the first or the second algorithm; a diagnostic unit connected to the command generator; and configured to receive an expected time for a future switching of the command generator from the first algorithm to the second algorithm and starting a buffer time period before the expected time checking the viability of operation of the command generator after the future switching time; the diagnostic unit also being configured to report said viability to the user interface a command generator comprising; a first algorithm which when executed causes the command generator to issue commands to the motor to deliver the fluid according to a predetermined schedule; and a second algorithm which when executed causes the command generator to issue commands to the motor to deliver fluid to implement a closed-loop control to bring the measured physiological condition to a target value; a first algorithm which when executed causes the command generator to issue commands to the motor to deliver the fluid according to a predetermined schedule; and a second algorithm which when executed causes the command generator to issue commands to the motor to deliver fluid to implement a closed-loop control to bring the measured physiological condition to a target value; the command generator further being switchable to execute either the first or the second algorithm; a diagnostic unit connected to the command generator; and configured to receive an expected time for a future switching of the command generator from the first algorithm to the second algorithm and starting a buffer time period before the expected time checking the viability of operation of the command generator after the future switching time; the diagnostic unit also being configured to report said viability to the user interface characterized in that the second algorithm has gain coefficients and in that it is checked that said second algorithm gain coefficients can be calculated before the future switching time; wherein the command generator is configured to provide proportional-integral derivative control when executing the second algorithm and the gain coefficients are the gain coefficients for the proportional, the integral and derivative paths, respectively; wherein the gain coefficients are user- specific or patient-specific and dynamically calculated prior to entering the closed-loop operating mode based on historical insulin delivery information, historical sensor measurement values, historical reference blood glucose measurement values, user-reported or user-input events data; and wherein patient-specific control parameters are utilized to adjust the PID gain coefficients.