Next, let's go to periodic tasks. Create a new while loop, place a timer inside of it, and set your execution to never stop.
This code will start running as soon as your code begins running, and it will never stop. Having loops in periodic tasks is fine because they execute outside the scope of teleop. Basically what you're doing is multitasking. Your robot can run simultaneous loops at the same time.
Now let's just get your hardware setup... for this we have the potentiometer and the lift motor. Let's also get in that global variable. To do this, just drag and drop the Robot Global Data into the Periodic Tasks VI. Right click on the global variable, and select "Change to Read" You also need to select the DesiredLevel variable. You can do this also by right clicking, and going to "Select Item".
Now we have everything we need to do a closed loop controller. By far, my favorite is PID.
To implement a PID controller, right click in the Block Diagram, go to PID, and select PID.vi.
Hook it up as you would expect. Your setpoint is the desired level, your process variable is the voltage from the potentiometer, and the output goes directly to the motor.
You'll want to be extremely careful the first time you run it. You have to tune the PID controller for your system.
You need to specify the output range (-1 to 1 for our motors), and the PID gains, which are what controls the response of the system.
Here's the block diagram for the finished control loop.
Here's what will be on your front panel.
Once the system is tuned, you'll want to save those values. To do this, right click on the cluster, go to Data Operations, and select Make Current Values Default.
