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