APM:Libraries
moduletest.c
Go to the documentation of this file.
1 /*
2  very simple example module
3  */
4 
5 #include <stdio.h>
6 #include <stdint.h>
7 #include <stdbool.h>
8 #include <math.h>
9 
10 #include <AP_Module_Structures.h>
11 
13 {
14  printf("setup_start called\n");
15 }
16 
18 {
19  printf("setup_complete called\n");
20 }
21 
22 
23 #define degrees(x) (x * 180.0 / M_PI)
24 
26 {
27  static uint64_t last_print_us;
28  if (state->time_us - last_print_us < 1000000UL) {
29  return;
30  }
31  last_print_us = state->time_us;
32  // print euler angles once per second
33  printf("AHRS_update (%.1f,%.1f,%.1f)\n",
34  degrees(state->eulers[0]),
35  degrees(state->eulers[1]),
36  degrees(state->eulers[2]));
37 }
38 
40 {
41  static uint64_t last_print_us;
42  if (state->time_us - last_print_us < 1000000UL) {
43  return;
44  }
45  last_print_us = state->time_us;
46  // print gyro rates once per second
47  printf("gyro (%.1f,%.1f,%.1f)\n",
48  degrees(state->gyro[0]),
49  degrees(state->gyro[1]),
50  degrees(state->gyro[2]));
51 }
52 
54 {
55  static uint64_t last_print_us;
56  static uint32_t counter;
57  static uint32_t fsync_count;
58  counter++;
59  if (state->fsync_set) {
60  fsync_count++;
61  }
62  if (state->time_us - last_print_us < 1000000UL) {
63  return;
64  }
65  last_print_us = state->time_us;
66  // print accels once per second
67  printf("accel (%.1f,%.1f,%.1f) %lu %lu\n",
68  state->accel[0],
69  state->accel[1],
70  state->accel[2],
71  (unsigned long)counter,
72  (unsigned long)fsync_count);
73 }
int printf(const char *fmt,...)
Definition: stdio.c:113
static uint8_t counter
void ap_hook_AHRS_update(const struct AHRS_state *state)
Definition: moduletest.c:25
void ap_hook_setup_complete(uint64_t time_us)
Definition: moduletest.c:17
void ap_hook_accel_sample(const struct accel_sample *state)
Definition: moduletest.c:53
static int state
Definition: Util.cpp:20
void ap_hook_gyro_sample(const struct gyro_sample *state)
Definition: moduletest.c:39
#define degrees(x)
Definition: moduletest.c:23
void ap_hook_setup_start(uint64_t time_us)
Definition: moduletest.c:12