This paper proposes an online compensation method of gravity and friction by least squares method (LSM) for robots implementing haptics. In order to expand the range of tasks using the robot such as telepresence robot, implementing haptics technology is essential. However, with higher gear ratio motors, the friction lowers the quality of the haptic transmission. In order to comfortably control the robot with haptics, compensation of gravity and friction torques are essential. In the case of bilateral control, incremental position encoders are often used because they are easy to use at low cost. However, with the conventional method, the control start position must always be returned to the same initial value in order achieve the gravity torque compensation, as the value of the angle can not be stored with incremental encoders. In order to estimate and compensate the gravity and friction torque from any starting position of the robot, this paper proposes a new online compensation method using LSM while achieving the bilateral control. Using the proposed method, the absolute encoder is not necessary, and no matter where the starting position of the control is, the gravity torque and friction torque can be compensated, allowing a comfortable control for the operator. The validity of the proposed method was confirmed by the experiment.