APM:Libraries
LowPassFilter2p.cpp
Go to the documentation of this file.
1 /*
2  * Example sketch to demonstrate use of LowPassFilter2p library.
3  * Code by Randy Mackay and Andrew Tridgell
4  */
5 
6 #include <AP_HAL/AP_HAL.h>
7 #include <Filter/Filter.h> // Filter library
9 
10 void loop();
11 
13 
14 // craete an instance with 800Hz sample rate and 30Hz cutoff
16 
17 // setup routine
18 static void setup()
19 {
20  // introduction
21  hal.console->printf("ArduPilot LowPassFilter2p test\n\n");
22 }
23 
24 void loop()
25 {
26  for(int16_t i = 0; i < 300; i++ ) {
27 
28  // new data value
29  const float new_value = sinf((float)i * 2 * M_PI * 5 / 50.0f); // 5hz
30 
31  // output to user
32  hal.console->printf("applying: %6.4f", (double)new_value);
33 
34  // apply new value and retrieved filtered result
35  const float filtered_value = low_pass_filter.apply(new_value);
36 
37  // display results
38  hal.console->printf("\toutput: %6.4f\n", (double)filtered_value);
39 
40  hal.scheduler->delay(10);
41  }
42  hal.scheduler->delay(10000);
43 }
44 
45 AP_HAL_MAIN();
void loop()
static void setup()
AP_HAL::UARTDriver * console
Definition: HAL.h:110
T apply(const T &sample)
virtual void delay(uint16_t ms)=0
virtual void printf(const char *,...) FMT_PRINTF(2
Definition: BetterStream.cpp:5
#define f(i)
const HAL & get_HAL()
A class to implement a second order low pass filter.
AP_HAL_MAIN()
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
static LowPassFilter2pFloat low_pass_filter(800, 30)
#define M_PI
Definition: definitions.h:10
AP_HAL::Scheduler * scheduler
Definition: HAL.h:114