SIM_ICEngine.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. simple internal combustion motor simulation class
  15. */
  16. #pragma once
  17. #include "SIM_Aircraft.h"
  18. namespace SITL {
  19. class ICEngine {
  20. public:
  21. const uint8_t throttle_servo;
  22. const int8_t choke_servo;
  23. const int8_t ignition_servo;
  24. const int8_t starter_servo;
  25. const float slew_rate; // percent-per-second
  26. ICEngine(uint8_t _throttle, int8_t _choke, int8_t _ignition, int8_t _starter, float _slew_rate) :
  27. throttle_servo(_throttle),
  28. choke_servo(_choke),
  29. ignition_servo(_ignition),
  30. starter_servo(_starter),
  31. slew_rate(_slew_rate)
  32. {}
  33. // update motor state
  34. float update(const struct sitl_input &input);
  35. private:
  36. float last_output;
  37. uint64_t start_time_us;
  38. uint64_t last_update_us;
  39. union state {
  40. struct {
  41. bool choke:1;
  42. bool ignition:1;
  43. bool starter:1;
  44. };
  45. uint8_t value;
  46. } state, last_state;
  47. bool overheat:1;
  48. };
  49. }