A controller includes a first data acquiring portion for acquiring a time
constant of a position control circuit based on a position command value
to a drive source and an actual position value, during operation of a
controlled object; a second data acquiring portion for acquiring a
rigidity value for the controlled object and a workpiece based on a force
data obtained when the controlled object is brought into contact with the
workpiece; and an automatic gain calculating portion for calculating a
force control gain of a force control circuit from the time constant of
the position control circuit acquired by the first data acquiring portion
and the rigidity value acquired by the second data acquiring portion,
under conditions where a time constant of the force control circuit is
larger than the time constant of the position control circuit.