| View previous topic :: View next topic |
| Author |
Message |
lba_821103
Joined: 18 Oct 2007 Posts: 10
|
Posted: Wed Nov 28, 2007 3:06 am Post subject: why it obtain current_velocity with the method? |
|
|
Firstly, Thanking you for your helping last time.
Could you explain the mean of obtain the current_velocity with the below method? You'd better detail explain the math meaning with the method. thank you!
#define FILTER_SHIFT 1
static int32_t filter_reg = 0;
static int16_t filter_update(int16_t input)
{
// Update the filter with the current input.
filter_reg = filter_reg - (filter_reg >> FILTER_SHIFT) + input;
// Scale output for unity gain.
return (int16_t) (filter_reg >> FILTER_SHIFT);
}
filtered_position = filter_update(current_position);
// Use the filtered position to determine velocity.
current_velocity = filtered_position - previous_position;
previous_position = filtered_position; |
|
| Back to top |
|
 |
ginge Site Admin
Joined: 14 Jan 2006 Posts: 1028 Location: Manchester, UK
|
Posted: Wed Nov 28, 2007 9:24 am Post subject: |
|
|
Hi lba,
What is happening here is a simple digital filter. The article listed in the source code explains in detail how the filter portion works
http://www.edn.com/index.asp?layout=article&articleid=CA6335310
In mathematical terms it is
y(n)=(1-2^–k)*y(n–1)+x(n), where x is the input, y is the output, and n is the sample index. Parameter k is the shifting value, which in our case is FILTER_SHIFT. ( equation borrowed directly from the article) This determines the bandwidth of the sampling. With FILTER_SHIFT == 1 we get a bandwidth of 0.1197 over 3 samples.
As for your question about the current_velocity...
Firstly we take a running average of the position using filter_update then we subtract the last position from the current average position. This will tell us the amount of positional units moved each sample.
An example of this might be:-
Sample 1: filtered_position = 400
Sample 2: filtered_position = 410 previous position = Sample (n)-1 or (400)
current_velocity = filtered_position - previous position
current_velocity = 410 - 400
current_velocity = 10
So in the example above, we have a speed of 10 units per sample, where each sample is 10ms. So the current velocity is 10 units/ms.
Let me know if you need clarification of the filtering equations, the article is clearer than I could ever be.
Barry _________________ http://www.headfuzz.co.uk/
http://www.robotfuzz.co.uk/ |
|
| Back to top |
|
 |
lba_821103
Joined: 18 Oct 2007 Posts: 10
|
Posted: Fri Nov 30, 2007 2:37 am Post subject: current_velocity=filter_position-previous_position? |
|
|
Thank you for your helping.
I still don't know filter_position-previous_position that is the value of current_velocity. From what you provide the article ,I don't find the principium of calculate the current_velocity.
You can explain the mean of current_velocity=filter_position-previous_position. |
|
| Back to top |
|
 |
lba_821103
Joined: 18 Oct 2007 Posts: 10
|
Posted: Fri Nov 30, 2007 7:35 am Post subject: |
|
|
Thank you for your helping!
My classmate have read the article and explain the meaning of method for you. I also clear about the method. Thank you again! |
|
| Back to top |
|
 |
ginge Site Admin
Joined: 14 Jan 2006 Posts: 1028 Location: Manchester, UK
|
Posted: Fri Nov 30, 2007 9:03 am Post subject: |
|
|
Hi lba,
Velocity is a measure of distance over time, so filter_position-previous_position is how much the servo has moved since the last measurement. Each measurement is taken 10ms apart, so time = 10ms.
In Math terms...
speed = distance/time
Factoring in OpenServo terms...
current_velocity = (filter_position-previous_position)/time
current_velocity = (filter_position-previous_position)/10ms
If we use the example I posted above...
current_velocity = (410-400)/10ms
current_velocity = 10/10ms
current_velocity = 1 unit per ms
I hope this clarifies it a little.
Barry _________________ http://www.headfuzz.co.uk/
http://www.robotfuzz.co.uk/ |
|
| Back to top |
|
 |
|