Keeping track of Encoder Shaft Location using WPI Counter VI

My team is using a Light Sensor with tape on shaft as Encoder to keep track of the extension arm position. We are using Lab View. To keep track of Count (every revolution reflective tape passes light sensor) I am using the WPI Counter VI. After testing, it is not as accurate as I would hope… may have to live with it since this is what I was given and they can not change it now. I believe it is the mechanical binding that is the problem, not sensor bandwidth.
The counter will only increment in either direction. When one button pressed extension arm extends, other button, reverse motor and retracts. I am not sure why, but I can not keep proper count in reverse direction. I am using a shift register, add count in forward (check if forward button pressed), subtract count in reverse (check if reverse button pressed). I set while loop stop to True, so executes once, having shift register return previous count and compare new count. I am not sure why it is not working, timing issue with counter & while loop/shift register? If no button pressed, I pass shift register previous straight thru. I tried other ways than shift register, appears to be similar problem. This seems like a simple thing to do, but is not working. I would appreciate any support or new ideals. I can only attach retract (subtract counter) portion of code do to file size. Thanx… Appreciate help, in theory code should be simple, something else must be wrong





I can’t see the forward direction, but the FALSE doesn’t work when I plug in some numbers. The first call works, but the second call would subtract far too much.

As an example, assume the shift register is 1000 and the Get Counter value is up by 1010. The returned value is correct at 990, but the value stored in the shift register is also 990. If on the next call, the Get Counter has the same, the code will return 970. If the Get Counter goes up by ten to 1020, then the return value is 960. It seems to me like the right-most subtract is taking the delta from the wrong value. If it takes it from the shift register, then subsequent calls take off more and more. If the delta is subtracted from the Get Counter value, then that seems like it would work.

Greg McKaskle

Hi Greg

I believe this is what is happening and I think the forward is correct, although forward has not been checked after the counter has properly subtracted. I could not attach forward because files were not allowed do to size

Can you please give me an example of the correction, I am not sure how to connect back to get and have shift register work correctly. Also, my straight through may be wrong (no buttons pressed) if this is the case? I am attaching forward code
thanx again!





If you are only passing through a single value a Feedback Node may be more intuitive than a loop and shift register.

If you connect the output of the Get to a Feedback node and then subtract the current output of the Get from the fed back value, you will get the proper delta value.

If you want to keep the loop you want the output of the Get connected to the right side shift register in addition to its current connections. This will make the initial subtraction produce the correct delta value.

I actually think my early morning quick-fix didn’t fix. Taking a step back, it feels to me like you want three pieces of state data.

  1. Last counter value – used to compute delta, and updated to new counter value each call.

  2. Number of forward counts

  3. Number of backward counts

The button is used to determine whether the new delta is added to the Fwd or Bkwd state data.

The return value is the Fwd - Bkwd counts.

Perhaps you can do it with less, state, but to me, this seems the most natural way to think of it.

Hope that helps.
Greg McKaskle

My previous post was incorrect. I believe you need at least two pieces of state data to accomplish what you want.

  1. The value of the WPIlib counter
  2. The value of your counter

Each cycle the delta is calculated as the Current WPIlib value - the previous WPIlib value.

This delta is then added or subtracted from the previous value of your counter based on direction.

So you need either at least 2 shift registers or 2 feedback nodes. You can also use 3 pieces of state data as Greg described above.

I am not not sure why, may be my inexperience with LAB View…

I fully understand the states I need… even if I create a state machine, my problem is I can not properly keep track of Previous Count…

I played with a 3 state machine, end up with same problem, not keeping previous count properly… Suggestion of wiring two shift registers may work, but I played with this, still can not get it to work properly on reverse… when needing to subtract from previous count

Can you please give example code, I can not move forward programing/calibrating the extension arm until I can properly keep track of previous count and subtract when reverse/retract button pressed…

Will appreciate help, a lot of time and still can not subtract properly when needed…

Thanx… Mark

I prefer feedback nodes to shift registers, and Select to a case structure for simple conditionals both are just a personal preference.

I believe this code snippet should do what you want.

Counter.jpg


Counter.jpg

Thank You Vikesrock, I will have to try tonight