SIM_Sprayer.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 sprayer simulation class
  15. */
  16. #pragma once
  17. #include "stdint.h"
  18. #include <AP_Param/AP_Param.h>
  19. #include "SITL_Input.h"
  20. namespace SITL {
  21. class Sprayer {
  22. public:
  23. Sprayer() {
  24. AP_Param::setup_object_defaults(this, var_info);
  25. };
  26. // update sprayer state
  27. void update(const struct sitl_input &input);
  28. float payload_mass() const { return static_cast<float>(capacity); }; // kg; water, so kg=l
  29. static const struct AP_Param::GroupInfo var_info[];
  30. bool is_enabled() const {return static_cast<bool>(sprayer_enable);}
  31. private:
  32. AP_Int8 sprayer_enable; // enable sprayer sim
  33. AP_Int8 sprayer_pump_pin;
  34. AP_Int8 sprayer_spin_pin;
  35. const uint32_t report_interval = 1000000; // microseconds
  36. uint64_t last_report_us;
  37. const float pump_max_rate = 0.01f; // litres/second
  38. const float pump_slew_rate = 20.0f; // percent/second
  39. float last_pump_output; // percentage
  40. const float spinner_max_rate = 3600.0f; // degrees/second
  41. const float spinner_slew_rate = 20.0f; // percent/second
  42. float last_spinner_output; // percentage
  43. double capacity = 0.25; // litres
  44. uint64_t last_update_us;
  45. bool should_report();
  46. bool zero_report_done = false;
  47. };
  48. }