tuning PID and programming main loop