Motor Encoder code. LabVIEW

So this year for FRC we are using an arm system with motors that are geared down so much they are non-back drivable meaning when there is no power applied to them the won’t move. What I want to accomplish in LabVIEW is to be able to push a button and have a motor go to a certain position. and in reality a button would be able to move several motors simultaneously to certain predefined positions. I’ve been told that the encoders we use are relative encoders and so that changes how this can be accomplished a bit. Any help would be appreciated.

John Fogarty

  1. Potentiometers are better than encoders because the are absolute, so you don’t loose your position when you reboot (and if you happen to die during a match, you won’t have to return to home before using your robot)

  2. You would probably want to use P or PID control. Wikipedia has a great article about it -

  3. Start with P. If it has issues (which generally only happens if it moves very fast, which yours dosen’t seem like it does), then you can add D. I might be necessary, but probably not.

  4. You would probably have a controller for each joint, and feed the setpoints from an array.

Here’s how I would write the code:

  1. Create an enumerated type to define the state. In LabVIEW, create an enum and edit the items in the list.
  2. Create a cluster (in C++, it’s a structure), defining the setpoints for all controllers. For example, you would have a Dbl for each joint, then hit the “align horizontal” button for LabVIEW to make them all nice and neat
  3. Create an array of the clusters. Each line in the array will represent one item in the state.
  4. Since an enumerated type can be used as a uint8, find the numeric representation of each and label each item in the list. Then, use the Index Array block (just index in C, with an array[item]) and get the item in the array that goes with the state.
  5. Drive the arm with the newly aquired cluster of positions
  6. Set the state whenever a button is pressed.
    Make sense?

Here’s a generic example of using PID to drive a motor to a desired position.

Generic PID.jpg

Generic PID.jpg

Couldn’t you just use the absolute encoder to get around this?


…It’s included in the KOP, what other expenses are there?

We’re using 3 potentiometers on our robot this year and they work great. We’ll also have encoders, but so far they don’t work as easily. Plus, it’s really easy to convert a potentiometer’s voltage to an angle or distance (even changing where your base position is).

Soo It sounds like Pots are alot more common and easier to use, and the only encoders we found in the KOP are a optical disk type of encoder that are relative encoders. There are small boards for rotary and linear encoders but the encoders themselves aren’t included. We plan on going to radioshack and getting some pots to use.

“The encoders themselves” are embedded in the larger black integrated circuit devices on those boards. The two magnetic rotary encoders came with the small round magnets that are used with them. The magnetic linear encoder came with the thin flexible magnetic strip that is used with it.

Look at the Kit of Parts web page to find the Parts Data Sheets for the AS5030 - Rotary Magnetic Encoder and AS5304 - Linear Magnetic Encoder devices.

Hey guys I had a quick question, where do we hook up the Potentiometers? I’m begining to branch out and learn some electronics to help some freshmen but the example vi on lv didn’t help much.

They are analog inputs, so use the Analog Breakout.

Thanks Mark!