A non-transitory machine readable medium containing program code which upon execution causes an image pickup apparatus to which a lens unit provided with an image taking optical system including a focus lens is detachably mountable and which is provided with an image sensor operable to perform charge accumulation and generate an image signal, to perform:
- a focus signal generating step of generating a focus signal indicating a focus state of the image taking optical system by using the image signal;
- a drive instruction generating step of generating a drive instruction for the focus lens on a basis of the focus signal;
- and
- a controlling step of controlling, when a reciprocating operation of the focus lens is performed, communication with the lens unit comprising sending information relating to a predetermined timing and the drive instruction to the lens unit and receiving, from the lens unit, a first signal indicating whether the focus lens is able to be moved by a movement amount based on the drive instruction to satisfy the predetermined timing,
- wherein in the drive instruction generating step,
- (a) if the first signal indicates that the focus lens is able to be moved by the movement amount based on the drive instruction to satisfy the predetermined timing, the method generates the new drive instruction by using a focus signal generated based on charge accumulated in a first time period, and
- (b) if the first signal indicates that the focus lens is not able to be moved by the movement amount based on the drive instruction, the method generates the new drive instruction by using a focus signal generated based on charge accumulated in a second time period after the first time period,
- wherein the reciprocating operation of the focus lens is performed for determining an in-focus direction before a peak-climbing operation, to drive the focus lens in a direction in which the focus signal is increased, or determining an in-focus state after the peak-climbing operation, and
- wherein the predetermined timing is timing relating to starting of the charge accumulation for generating the focus signal.