tyre_deflection is coefficient for compensation of tyre flexibility. If we assume wheels as non-deformable rigid bodies, we could calculate traveled distance with use of standard inverse-kinematics. In real world we need to take into account that tyres are deflecting a little, thus traveled distance is changed.
diameter_mod is coefficient for compensation of wheels placement. In our model we calculate average rotation of front and rear wheel and assume it as virtual side wheel between both of them. When robot rotates, its angular position is calculated as quotient of distance traveled by wheels and rotation diameter (
robot_width in code). The rotation diameter could be a distance between geometrical centers of bot wheels if they are non-deformable rigid bodies with infinitesimal width. In our case, we need to take into account, that wheels are quite wide and each of them is moved to the front or rear relative to robot geometrical center.
For security stop, the
turnOff() will be correct way, the motors will stop immediately.
turnOn() should be called when cause of stopping the robot is safely solved. It will depend on your use case.