Quadrature Encoder to calculate Angular Velocity


sce6th

Recommended Posts

Dear All,

I am using a quadrature encoder and a labjack u6 and my aim is to be able to calculate the angular velocity of the shaft the encoder will be attached to in real time. I am a beginner with regards to using this hardware and I am not particularly advance with the scripting side of things.

To date I have managed to successfully connect the encoder to the labjack and using dagFactorry i have managed to output pulses, and therefore number of revolutions against time (since for this particular encoder there are 4000 pulses per rev) on a graph. However the number of revolutions continually increases and I have no means to reset the value as well as calculating the rpm.

I have tried to scan some of the literature but I cannot seem to find much with regards to this problem

Any comments, help or a point in the right direction would be much appreciated

Tom

Link to comment
Share on other sites

The encoder is going to give you an absolute value for position. That's why you get an ever increasing graph, you are moving in one direction. To calculate the # of pulses per second, simply do a dx/dt calculation between successive reads. For example, assuming your channel is called "count":

(count[0] - count[1])/(count.time[0] - count.time[1])

You can smooth the signal a bit by spreading the delta over several reads:

(count[0] - count[4])/(count.time[0] - count.time[4])

These just generate a scalar. If you want to graph it, you'll need an array, so just add ,99999 after the numbers:

(count[0,99999] - count[1,99999])/(count.time[0,99999] - count.time[1,99999])

The units of all these are counts/second because time is in seconds. To convert to rpm, just divide by 4000 counts/rpm and multiply by 60 seconds/minute.

You can do these calcs right in the graph if you want, but its probably more useful to have the data in a channel so you can log it, among other things. To do that, create a second channel, called, say, "rpm". It'll be device type "Test", "A to D", with a Timing of 0. The channel # doesn't really matter as long as its unique among any other Test devices channels you have. Then, in the Event tab for the "count" channel, put:

RPM.AddValue((count[0] - count[1])/(count.time[0] - count.time[1]) / 4000 * 60)

Again, feel free to change the 1 to 2, 3, or higher to smooth the signal some. Now you can just graph RPM vs Time.

Link to comment
Share on other sites

Thank you very much for your reply. It worked perfectly, very much appreciated.

I have one other brief question if that's ok: Say I wanted to multiply the rpm values by a constant which the user can type in, how would i do this please? I have tried inserting an edit box, in which the user can type the required value but I am struggling with being able to recall this value in an equation of say rpm*(the inputted value). In the literature it states that you set the channel under the properties of the edit box to which you want to assign the value, but i simply cannot get it to recall the value. Hope this makes sense! Any help would be much appreciated.

thanks again for your time

Link to comment
Share on other sites

First, read this post concerning using Edit boxes in main windows of DAQ applications:

http://www.azeotech.com/board/index.php?showtopic=3233

I recommend using a button instead, probably with a variable value control to display the current scale. But first you need a place to store the scale. Typically you'll just want to use a variable for this, but you could use another Test channel just like the RPM channel we created, except this time, make it a "D to A" I/O type. Set the Persist and History to 1 so it only keeps the latest value and it keeps the value after a reboot. Then, in the button, select the Set To action, and enter this new channel name. In your RPM expression, just add

* scale[0]

to the end of the math where scale is the name of your scale channel, so:

RPM.AddValue((count[0] - count[1])/(count.time[0] - count.time[1]) / 4000 * 60 * scale[0])

Link to comment
Share on other sites

Again, thanks for your help. you solved my issue with the buttons too! much appreciated.

I was wondering if it was possible you could point me in the right direction one more time please.

I am analysing the change in angular velocity of a shaft during a revolution. Thanks to your help I have managed to log the changing angular velocity however I was wondering if its possible plot angular velocity against revolved angle on a chart, and hence log both? I understand that the encoder maintains an absolute position of rotation, therefore the number is very large now for total number of revolutions, which I obtain from (count/ (number of pulses in a revolution). But do you know of a method whereby i could see an angle increasing from 0 deg ( at a reference starting point of my shaft) to 360 deg as the encoder spins around (the rpm is not constant therefore the angle rotated per timestep varies) and thus reset the angle to start at 0 again once it has revolved a whole revolution?

Any help would be much appreciated

Link to comment
Share on other sites

Well, first, as you probably know, you can do X-Y plots in DAQFactory by simply providing a different X expression than "Time" and changing the bottom axis to "Lin" from Date/Time.

As for taking a large angle measurement and just getting a 0-360 from it, just use the modulus operator. This gives the remainder of division and is a standard operator for most programming languages. In DAQFactory it is the % symbol, so you want something like:

angle % 360

You can do this right in the X expression for the graph.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.