moduletest.c 1.7 KB

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