In 1 - sorry for my English level)
2 - please take a Look at the picture - pid with auto-tuning. The problem is the opener, speed want to control using pid. The speed depends on the loop. The idea - the loop above the sensor - the greater the speed of the decoiler.
According to the program stored in SD6301 current high (analog input to which you've ultrasonic sensor), D1500 specified value. In D204 - output pid. I have the exit D204 either 0 or 9999. Help me?