mirror of https://github.com/ArduPilot/ardupilot
uncrustify libraries/Filter/examples/Filter/Filter.pde
This commit is contained in:
parent
e742a26bd5
commit
70d18ec87c
|
@ -1,14 +1,14 @@
|
|||
/*
|
||||
Example of Filter library.
|
||||
Code by Randy Mackay and Jason Short. DIYDrones.com
|
||||
*/
|
||||
* Example of Filter library.
|
||||
* Code by Randy Mackay and Jason Short. DIYDrones.com
|
||||
*/
|
||||
|
||||
#include <FastSerial.h>
|
||||
#include <AP_Common.h>
|
||||
#include <AP_Math.h> // ArduPilot Mega Vector/Matrix math Library
|
||||
#include <Filter.h> // Filter library
|
||||
#include <ModeFilter.h> // ModeFilter class (inherits from Filter class)
|
||||
#include <AverageFilter.h> // AverageFilter class (inherits from Filter class)
|
||||
#include <AP_Math.h> // ArduPilot Mega Vector/Matrix math Library
|
||||
#include <Filter.h> // Filter library
|
||||
#include <ModeFilter.h> // ModeFilter class (inherits from Filter class)
|
||||
#include <AverageFilter.h> // AverageFilter class (inherits from Filter class)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Serial ports
|
||||
|
@ -27,76 +27,76 @@ AverageFilterUInt16_Size4 _temp_filter;
|
|||
// we need to ues FilterWithBuffer class because we want to access the individual elements
|
||||
void printFilter(FilterWithBufferInt16_Size5& filter)
|
||||
{
|
||||
for(uint8_t i=0; i < filter.get_filter_size(); i++)
|
||||
{
|
||||
Serial.printf("%d ",(int)filter.samples[i]);
|
||||
}
|
||||
Serial.println();
|
||||
for(uint8_t i=0; i < filter.get_filter_size(); i++)
|
||||
{
|
||||
Serial.printf("%d ",(int)filter.samples[i]);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Open up a serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// introduction
|
||||
Serial.printf("ArduPilot ModeFilter library test ver 1.0\n\n");
|
||||
// Open up a serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// Wait for the serial connection
|
||||
delay(500);
|
||||
// introduction
|
||||
Serial.printf("ArduPilot ModeFilter library test ver 1.0\n\n");
|
||||
|
||||
// Wait for the serial connection
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// Read Raw Temperature values
|
||||
void ReadTemp()
|
||||
{
|
||||
static uint8_t next_num = 0;
|
||||
static int32_t RawTemp = 0;
|
||||
uint8_t buf[2];
|
||||
uint16_t _temp_sensor;
|
||||
static int32_t RawTemp = 0;
|
||||
uint8_t buf[2];
|
||||
uint16_t _temp_sensor;
|
||||
|
||||
next_num++;
|
||||
buf[0] = next_num; //next_num;
|
||||
buf[1] = 0xFF;
|
||||
buf[0] = next_num; //next_num;
|
||||
buf[1] = 0xFF;
|
||||
|
||||
_temp_sensor = buf[0];
|
||||
_temp_sensor = (_temp_sensor << 8) | buf[1];
|
||||
_temp_sensor = buf[0];
|
||||
_temp_sensor = (_temp_sensor << 8) | buf[1];
|
||||
|
||||
RawTemp = _temp_filter.apply(_temp_sensor);
|
||||
|
||||
Serial.printf("RT: %ld\n",RawTemp);
|
||||
RawTemp = _temp_filter.apply(_temp_sensor);
|
||||
|
||||
Serial.printf("RT: %ld\n",RawTemp);
|
||||
}
|
||||
|
||||
//Main loop where the action takes place
|
||||
void loop()
|
||||
{
|
||||
uint8_t i = 0;
|
||||
int16_t filtered_value;
|
||||
int16_t filtered_value;
|
||||
|
||||
int16_t j;
|
||||
|
||||
for(j=0; j<0xFF; j++ ) {
|
||||
ReadTemp();
|
||||
}
|
||||
/*while( i < 9 ) {
|
||||
int16_t j;
|
||||
|
||||
// output to user
|
||||
Serial.printf("applying: %d\n",(int)rangevalue[i]);
|
||||
|
||||
// display original
|
||||
Serial.printf("before: ");
|
||||
printFilter(mfilter);
|
||||
|
||||
// apply new value and retrieved filtered result
|
||||
filtered_value = mfilter.apply(rangevalue[i]);
|
||||
|
||||
// display results
|
||||
Serial.printf("after: ");
|
||||
printFilter(mfilter);
|
||||
Serial.printf("The filtered value is: %d\n\n",(int)filtered_value);
|
||||
|
||||
i++;
|
||||
}*/
|
||||
delay(10000);
|
||||
for(j=0; j<0xFF; j++ ) {
|
||||
ReadTemp();
|
||||
}
|
||||
/*while( i < 9 ) {
|
||||
*
|
||||
* // output to user
|
||||
* Serial.printf("applying: %d\n",(int)rangevalue[i]);
|
||||
*
|
||||
* // display original
|
||||
* Serial.printf("before: ");
|
||||
* printFilter(mfilter);
|
||||
*
|
||||
* // apply new value and retrieved filtered result
|
||||
* filtered_value = mfilter.apply(rangevalue[i]);
|
||||
*
|
||||
* // display results
|
||||
* Serial.printf("after: ");
|
||||
* printFilter(mfilter);
|
||||
* Serial.printf("The filtered value is: %d\n\n",(int)filtered_value);
|
||||
*
|
||||
* i++;
|
||||
* }*/
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue