RPM_generic.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. /*
  14. * RPM_generic.cpp - RPM library example sketch
  15. *
  16. */
  17. #include <AP_RPM/AP_RPM.h>
  18. #include <AP_HAL/AP_HAL.h>
  19. void setup();
  20. void loop();
  21. const AP_HAL::HAL& hal = AP_HAL::get_HAL();
  22. static AP_RPM RPM;
  23. char sensor_state;
  24. void setup()
  25. {
  26. hal.console->printf("APM RPM library test\n\n\n");
  27. RPM.init();
  28. hal.console->printf("Detected %u RPM sensors\n\n", RPM.num_sensors());
  29. }
  30. void loop(void)
  31. {
  32. RPM.update();
  33. for (uint8_t ii = 0; ii < RPM.num_sensors(); ii++) {
  34. // Determine sensor state
  35. if (RPM.healthy(ii)) {
  36. // Healthy sensor
  37. sensor_state = 'h';
  38. } else if (RPM.enabled(ii)) {
  39. // Enabled but not healthy
  40. sensor_state = 'e';
  41. } else {
  42. // Not enabled, not healthy
  43. sensor_state = '-';
  44. }
  45. hal.console->printf("%u - (%c) RPM: %8.2f Quality: %.2f ",
  46. ii, sensor_state,
  47. (double)RPM.get_rpm(ii),
  48. (double)RPM.get_signal_quality(ii));
  49. if (ii+1 < RPM.num_sensors()) {
  50. // Print a seperating bar if more sensors to process
  51. hal.console->printf("| ");
  52. }
  53. }
  54. hal.scheduler->delay(100);
  55. hal.console->printf("\n");
  56. }
  57. AP_HAL_MAIN();