First off, a potentiometer is not an encoder, and an encoder is not a potentiometer. They’re completely different things.
A potentiometer is an analog sensor which can measure angle.
You have 3 pins normally. The left one could be your ground, center will be the signal, and the right one could be your 5V power. This sensor would plug into the analog breakout board.
The reason I say could in the previous paragraph is because you can swap them around. This would change whether the voltage rises or falls in a given direction. To put it plain and simple, a potentiometer is a voltage divider circuit. You will have a voltage from 0 to 5V based on the position of the shaft.
Normal potentiometers have about a 170˚ rotation, but I would say they are only usable for about 140˚, as there is usually a huge dead zone on either end.
Okay, so now you have a general idea on how potentiometers work. Now, how to use them?
In LabVIEW, you will have a few new things to work with…
In your begin VI, you need to open an analog channel.
Here would be how to open the channel and give it a reference… Easy so far, right?
How about we place a while loop in periodic tasks. What we’re going to do is make a PID control loop. This is what is called closed loop control. You have a sensor giving direct feedback to the system in order to control the motor.
I’m going to change your local variable (represented with the home symbol in the first picture you provided) to a global variable. This means, you can set this variable globally (anywhere) in your code. However, this also gives you another responsibility. You cannot set global variables from more than one place in the code at a single time.
An appropriate use of a global variable would be from autonomous and from teleoperated code. However, an inappropriate use would be setting this value multiple times such as from teleop two or three more times. Basically what I’m getting to… this global variable should only show up at most 3 times in all of your code.
- Autonomous Independent.vi
- Teleop.vi
- Periodic Tasks.vi
First, lets create that global variable.
Double click on Robot Global Data.vi in the Project Explorer.
You want to add a numeric control.
It will default to a floating point (double). This is fine for what we want to do. At this point, we need to define what DesiredLevel is… Is it an angle? Is it the voltage being fed back from the potentiometer? For the sake of time and for simplicity of this demo, we’ll make it represent a voltage from 0 to 5 volts.
More to come…