Patent ID: 8805643

Claim:
A displacement sensor for repeatedly performing a detection process including projecting light onto an object and receiving light reflected from the object and a measurement process that measures an amount of displacement of the object based on the reception of the reflected light, and determines a moving average calculation of data of the measured amount, for outputting detection data based on an average value obtained by the moving average calculation, comprising: a register that registers a number of pieces of data of the moving average calculation; an input that inputs a parameter representing conditions related to a response time of the displacement sensor and a parameter representing conditions related to accuracy of the detection data; and a teaching mode processor that executes a teaching mode in which the number of pieces of data of the moving average calculation is registered with the register, wherein the teaching mode processor includes: a setting processor that executes the detection process and the measurement process, each for a plurality of times, and executes a process for setting a processing time of the detection process and a process of calculating a variation of measurement data obtained by the measurement process, a data number deriving processor that derives, on a condition that at least one of the parameter representing conditions related to response time and the parameter representing conditions related to accuracy of the detection data is input to the input and the processes are executed by the setting processor, the number of pieces of data of moving average calculation suitable for the value of the input parameter, by an operation using results of processing by the setting processor, and a registration processor that determines the number of pieces of data of the moving average calculation based on the result of processing by the data number deriving processor and registers the number with the register.