|
|
View previous topic :: View next topic |
Author |
Message |
wangine
Joined: 07 Jul 2009 Posts: 98 Location: Curtea de Arges, Romania
|
recursive complementary filter |
Posted: Mon Jul 25, 2011 11:31 am |
|
|
I have been working with pointers, but at the structures.
I tried to apply complimentary Recursive filter in the example of Matthias Toussaint but without success.
I understand the error and to be honest I do not understand how it should be no argument function to call.
From what I understand:
angle / / angle from gyro already integrated
Rate / / conversion rate, time between conversions
* filter / / return value them after being filtered.
The error is: *** Error 12 "I: \ PIC_Lucru \ dspic33FJ128MC804 \ Kalman_1_test_1 \ 2 \ src \ complementary_f.c" Line 14 (17.18): Undefined identifier - comp_filter_step
I tried to call static.
Code: | // Filter 'object' definition
//
typedef struct
{
float hp_x0, hp_x1;
float hp_y0;
float lp_x0, lp_x1;
float lp_y0;
float hp_last;
float hp_int;
} CompFilter;
// very simple complimentary filter
// (0.25% nyquist hp-lp combination)
//
float comp_filter_step( CompFilter *filter,
float angle,
float rate );
float comp_filter_step( CompFilter *filter,
float raw_angle,
float raw_angle_rate )
{
// highpass filter angle rate from gyro
//
filter->hp_x0 = filter->hp_x1;
filter->hp_x1 = raw_angle_rate * (1.0f/1.003927011f);
filter->hp_y0 = filter->hp_x1 - filter->hp_x0 +
0.9921767002f*filter->hp_y0;
// integrate angle rate using trapezoidal rule
//
filter->hp_int -= 0.5f*(filter->hp_last +
filter->hp_y0);
filter->hp_last = filter->hp_y0;
// lowpass filter angle from accelerometer
//
filter->lp_x0 = filter->lp_x1;
filter->lp_x1 = raw_angle * (1.0f/2.556465999e+02f);
float lp = filter->lp_y0 = filter->lp_x0 +
filter->lp_x1 +
0.9921767002f*filter->lp_y0;
return lp + filter->hp_int;
} |
Code: | void testa ()
{
comp_filter_step(is,23,44);
} |
are lost in this |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 25, 2011 10:37 pm |
|
|
Here is a demo program that shows how to create a structure, and
how to pass a pointer to it in a function. I added some printf statements
to prove to you that it's working. You can run it in MPLAB simulator
and see the output. I didn't look at the internal code in your step
function. I was only concerned with showing how to pass a structure pointer.
Code: |
#include <18F452.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
// Typedef the structure.
typedef struct
{
float hp_x0, hp_x1;
float hp_y0;
float lp_x0, lp_x1;
float lp_y0;
float hp_last;
float hp_int;
}CompFilter_t; // The '_t' at the end shows it is a data type.
// Create one instance of the structure and name it 'CompFilter'.
CompFilter_t CompFilter;
float comp_filter_step( CompFilter_t *filter,
float raw_angle,
float raw_angle_rate )
{
// Display the contents of the structure to show that
// the structure pointer is working.
printf("%7.3f \r", filter->hp_x0);
printf("%7.3f \r", filter->hp_x1);
printf("%7.3f \r", filter->hp_y0);
printf("%7.3f \r", filter->lp_x0);
printf("%7.3f \r", filter->lp_x1);
printf("%7.3f \r", filter->lp_y0);
printf("%7.3f \r", filter->hp_last);
printf("%7.3f \r", filter->hp_int);
// highpass filter angle rate from gyro
//
filter->hp_x0 = filter->hp_x1;
filter->hp_x1 = raw_angle_rate * (1.0f/1.003927011f);
filter->hp_y0 = filter->hp_x1 - filter->hp_x0 +
0.9921767002f*filter->hp_y0;
// integrate angle rate using trapezoidal rule
//
filter->hp_int -= 0.5f*(filter->hp_last +
filter->hp_y0);
filter->hp_last = filter->hp_y0;
// lowpass filter angle from accelerometer
//
filter->lp_x0 = filter->lp_x1;
filter->lp_x1 = raw_angle * (1.0f/2.556465999e+02f);
float lp = filter->lp_y0 = filter->lp_x0 +
filter->lp_x1 +
0.9921767002f*filter->lp_y0;
return lp + filter->hp_int;
}
//==========================================
void main()
{
// Load the structure instance with some nominal values.
CompFilter.hp_x0 = 1.23;
CompFilter.hp_x1 = 2.34;
CompFilter.hp_y0 = 3.45;
CompFilter.lp_x0 = 4.56;
CompFilter.lp_x1 = 5.67;
CompFilter.lp_y0 = 6.78;
CompFilter.hp_last = 7.89;
CompFilter.hp_int = 8.90;
// Call the step function and pass it the address of the
// structure instance. Note the '&'.
comp_filter_step(&CompFilter, 23, 44);
while(1);
} |
|
|
|
wangine
Joined: 07 Jul 2009 Posts: 98 Location: Curtea de Arges, Romania
|
|
Posted: Wed Jul 27, 2011 12:34 pm |
|
|
Thank you.
I appreciate your work, those who respond so quickly.
Thanks again. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|