to close
Over the years, several of the mentors and students involved in writing the content of this website have found themselves designing a manipulator and trying to decide between an encoder and a potentiometer for the feedback in the system.
Several reasons that have been considered for the encoder are:
Several reasons that have been considered for the potentiometer are:
The purpose of this tutorial is to show how to have the software on the robot allow for a potentiometer to account for this.
Because potentiometers “know” where they are at startup, it doesn’t matter where the actuator is, the set points (min, max, and others) are still correct.
First, we must setup a potentiometer.
We attached a knob to our potentiometer for testing purposes, but it would likely be attached to a motor or gear shaft in mechanics of the manipulator to be controlled.
We also need to open the potentiometer in Begin.vi
We start by putting the logic in Teleop.vi to decide what the target setpoint of a PID is and reading the potentiometer for the process variable.
We can improve this by moving the potentiometer code into a sub-vi.
We will use a while loop to remember whether or not the values have been initialized
Add a case structure to the loop and a shift register
Wire from the inside of the selector terminal to the right shift register (in the True case)
Create a True constant in the False case and connect it to the tunnel. This will cause the input of the shift register to default to False, but to remember the True after that. We can use this to decide when to initialize the values.
We now want to move the GetDevRef VI into the false case.
We now need to wire the DevRef to the while loop.
And create a shift register for it.
Move the Potentiometer Get VI after the case structure the True case and connect it’s DevRef terminals to the shift registers and the output to the indicator.
Create a constant on the while loop’s control terminal and set it to True (to make it run only once).
On the output wire, insert a subtract node.
And create a constant. This can be used as the expected offset - so that when the manipulator is in a known state (i.e. against a hard stop) the VI can read 0 (if the known state is with the arm at the top of the potentiometer range, make it an add so that the sensor reads 1 at that point).
To move the offset value to being stored in a file (this will enable use to later update it programmatically, but have it remembered across reboots),
PuTTY will prompt you for a username and password. This is the same as you use on the web interface (default to admin, blank).
Nothing will be displayed (echoed) as you enter the password. To enter a blank password (the default), just press enter.
If login is successful, a prompt will be displayed (most likely admin@{the host name you used}:~#).
The first two values tell us what machine we are logged into
(logged in as admin on roboRIO-3937-FRC in this case).
After the colon, the current file path is displayed
(~ means home, similar to the user’s directory on Windows). Finally, a pound sine indicates the end of the prompt.
(because the prompt is configurable in Linux,
this can be changed).
We can find the absolute path by entering the command pwd
.
Create a folder to hold any and all settings files.
To see the permissions (who can read or write to files in this directory), enter the command ls -l
(ListSubdirectory -Longformat)
The total 0
in the output means that there are no files in the current directory.
The second lines gives us information about the settings directory.
We gather from this that the directory (by default) can be [R]ead from, [W]ritten to, and e[X]ecuted
(or rather, the programs in side it can be) by the owner (who is admin).
Only read and executed by other members of the group, and the world.
So that we don’t have to care what user our LabVIEW program is executing as,
we will change the permissions so that anyone can read or write to the this directory
by running the command chmod 777 settings
(this will also make it executable,
to remove that access for the group and world, use 766).
If you run ls -l
now,
you will see that the dashes have been replaced with w’s - signifying that the write permission is now granted.
You can use a text editor like vi to create the file, but we will show how to have LabVIEW create it with a default value (this allows for less setup when moving between controllers).
First, move the offset constant into the False case of the Case Structure and reconnect it to the subtraction node. Then, also connect it to the while loop and create a shift register.
Connect the left shift register to the tunnel in the True case to make this value remembered after the initialization.
In the False case, you can press the Control key while clicking and moving the mouse to create some more space.
Get an Open/Create/… VI from the File I/O palette.
Right click on the “file path” terminal
and create a constant.
Also create a constant for the operation terminal and set it to open.
Finally, set the access terminal to read only
If we highlight the VI and it’s constants, we can use the diagram cleanup button to cleanup just the selection.
We’ll need to create some more space to handle if the file does not exist yet.
We then add a Case Structure and connect the File Open’s error out terminal to it.
In the No Error case, we add a Read Text File VI (we set it to read 1 character, but later changed our minds on that.)
From the String Palette -> Number/String Conversion, we get the Frac/Exp String to Number VI (this allows for decimal values).
We place this after the case structure and wire the output from the read to it.
And use the number it returns as the default value.
In the Error case (this will be triggered if the file does not exist yet), we use another File Open VI, but set this one to Create Mode and Write-Only access.
We add a Write Text File VI and connect it to the Open VI. We then create a constant for the text to write that we will set to the desired default value.
Now close the file.
We then re-open the file with read access.
At this point, we realized we wanted to read the file in either case, so we move it to being after the Case Structure and rewire the error and refnum values through the No Error case.
We then wire the refnum from re-opening the file in the error case to the read VI via the tunnel.
We also connect the error wire to the read, and the output of the read to the convert VI and cleanup the diagram.
To allow us to programmatically update the file (and zero point) we insert a Compound Arithmetic into the wire control the main case structure.
First, we invert the input that is not used
Then, we change the mode to And
Finally, we create a control on the inverted input. And name it Set.
We now add a case structure inside the false case, around the logic to read the file.
Move the convert inside the new structure and reconnect it.
Connect the Set control to the new case structures control terminal.
Swap the case structure’s False case.
Move the path constant outside the case structures and reconnect it.
In the outer False Case, inner True case, add an Open File VI set to replace or create and write only
Add a Write Text File VI.
From the String Palette, get a Number to Fractional String VI
Connect it to the write and create a control for the zero point.
Wire the path constant to the Open VI
Wire the zero point to the tunnel so that it can start being used.
At this point, we we add some comments, and do a diagram cleanup.
This method allows a potentiometer’s read to be quickly adjusted * removing the disadvantage of having to get the shaft just right when making adjustments, but keeping the advantage of a known position at startup (without always starting in the same spot).
Always make sure the manipulator is not going to move based on an old config! If this is in Periodic tasks, the code will run and can have the set point update without enabling the robot; however, if this is implemented in Teleop, pull the breakers to the actuator **before** enabling to call the set
Google Form to request details