S7 calculating velocity

ELake20

Lifetime Supporting Member
Join Date
Aug 2003
Location
N. Michigan
Posts
271
I'm working on calculating the velocity of a cylinder. The cylinder can extend and retract.

I've got a solution that I *think* works, but I'm concerned with accuracy and I'm always looking for a neater/cleaner way of doing things.

I'm using a clock bit (M10.2) which is from what I've read a 1S pulse timer. I one shot this and take the current position and store it.

Then I simply subtract the stored value from the actual value. I didn't bother dividing since my timebase is 1S.

I'll post the STL code (paste and convert to LAD)

A M 10.2
FP #bOneShot
JNB _009
L #rCylPos_Meters
T #rCylPos_Storage
_009: NOP 0
L #rCylPos_Storage
L #rCylPos_Meters
-R
T #rVelocity
NOP 0
Am I on the right track?

Thanks in advance

Edit: Uploaded image in LAD, didn't want to make people type stuff into the declaration table :)

velocity_calc.jpg
 
Last edited:
Is it 1sec ON and 1 sec OFF?
Than then you get a positive edge every 2 secs.In that case you need to divide by 2.
You also need to take direction in to account,because you will get a negative result and also the the 1st difference after the direction change will be wrong.
 
Last edited:
Oops....You are right. I could remove the one shot and just feed M10.2 in. When it drops out whatever value is left in there would be stored.

I found that Peter has a nice SCL example that nobody responded to awhile back, I'm going to play around with that tomorrow.
 
I found that Peter has a nice SCL example that nobody responded to awhile back, I'm going to play around with that tomorrow.
You should sample much faster to use the Savitsky-Golay method.
If you should sample every 0.1 seconds instead of every second.
More samples reduce the noise more but obviously require more multiples. The good part is that you will get updates every 0.1 second. A lot depends on what you are trying to do and the accuracy you need.

This is an example of how the SGfilter works. In this case the velocity or first derivative is computed at the middle of 9 points. This is called a symmetrical filter where there are n/2 points ahead and n/2 points behind. This means the velocity is delayed by 4 readings in this example. If you sampled every 0.1 seconds the delay would be 0.4 seconds
http://www.deltamotion.com/peter/Mathcad/Mathcad - holoborodko.pdf
I believe the example I posted was asymmetrical. It doesn't suffer from the delay but it doesn't reduce the noise as well.
 

Similar Topics

Seems like this should be a simple thing but I’m struggling with it. The basis is that I am trying to detect if a linear assembly is stopped or...
Replies
6
Views
3,106
I worked out a simple filter for calculating velocity. The advantage is that one gets some filtering with little or no phase delay. This method...
Replies
3
Views
4,766
This application has a motor with encoder feedback that drives a linear actuator that moves in/out, and is at roughly 45 degs from horiz. As the...
Replies
19
Views
1,369
I need to keep a running pass/fail yield of the previous 5,000 parts produced. I have used this formula before to calculate average: AvgValue =...
Replies
6
Views
2,158
Does anyone know how to calculate the savings from now needing to run an air compressor all day? Basically I have a design that replaced 6 * 1"...
Replies
26
Views
4,835
Back
Top Bottom