APM:Libraries
Derivative.cpp
Go to the documentation of this file.
1 /*
2  * Example sketch to demonstrate use of DerivativeFilter library.
3  */
4 
5 #include <AP_HAL/AP_HAL.h>
6 #include <Filter/Filter.h>
8 
9 void setup();
10 void loop();
11 
13 
14 #define USE_NOISE 0
15 
17 
18 // setup routine
19 void setup() {}
20 
21 static float noise(void)
22 {
23 #if USE_NOISE
24  return ((random() % 100)-50) * 0.001f;
25 #else
26  return 0;
27 #endif
28 }
29 
30 // Main loop where the action takes place
31 void loop()
32 {
33  hal.scheduler->delay(50);
34  float t = AP_HAL::millis() * 1.0e-3f;
35  float s = sinf(t);
36  s += noise();
37  uint32_t t1 = AP_HAL::micros();
38  derivative.update(s, t1);
39  float output = derivative.slope() * 1.0e6f;
40  hal.console->printf("%f %f %f %f\n", (double)t, (double)output, (double)s, (double)cosf(t));
41 }
42 
43 AP_HAL_MAIN();
AP_HAL::UARTDriver * console
Definition: HAL.h:110
void update(T sample, uint32_t timestamp)
virtual void delay(uint16_t ms)=0
virtual void printf(const char *,...) FMT_PRINTF(2
Definition: BetterStream.cpp:5
#define f(i)
uint32_t millis()
Definition: system.cpp:157
const HAL & get_HAL()
void setup()
Definition: Derivative.cpp:19
AP_HAL_MAIN()
DerivativeFilter< float, 11 > derivative
Definition: Derivative.cpp:16
static float noise(void)
Definition: Derivative.cpp:21
void loop()
Definition: Derivative.cpp:31
uint32_t micros()
Definition: system.cpp:152
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
Definition: Derivative.cpp:12
AP_HAL::Scheduler * scheduler
Definition: HAL.h:114