AP_Gripper.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #pragma once
  14. #include <AP_Param/AP_Param.h>
  15. class AP_Gripper_Backend;
  16. class AP_Gripper {
  17. public:
  18. AP_Gripper();
  19. AP_Gripper(const AP_Gripper &other) = delete;
  20. AP_Gripper &operator=(const AP_Gripper&) = delete;
  21. static AP_Gripper *get_singleton();
  22. static AP_Gripper *_singleton;
  23. // indicate whether this module is enabled or not
  24. bool enabled() const { return _enabled; }
  25. // initialise the gripper
  26. void init();
  27. // grab - move the servo to the grab position
  28. void grab();
  29. // release - move the servo output to the release position
  30. void release();
  31. // released - returns true if currently in released position
  32. bool released() const;
  33. // grabbed - returns true if currently in grabbed position
  34. bool grabbed() const;
  35. // update - should be called at at least 10hz
  36. void update();
  37. // valid - returns true if we have a gripper and it should work
  38. bool valid() const;
  39. static const struct AP_Param::GroupInfo var_info[];
  40. // parameters
  41. AP_Int8 _enabled; // grabber enable/disable
  42. typedef enum {
  43. STATE_GRABBING,
  44. STATE_RELEASING,
  45. STATE_GRABBED,
  46. STATE_RELEASED,
  47. } gripper_state;
  48. struct Backend_Config {
  49. AP_Int8 type; // grabber type (e.g. EPM or servo)
  50. AP_Int16 grab_pwm; // PWM value sent to Gripper to initiate grabbing the cargo
  51. AP_Int16 release_pwm; // PWM value sent to Gripper to release the cargo
  52. AP_Int16 neutral_pwm; // PWM value sent to gripper when not grabbing or releasing
  53. AP_Int8 regrab_interval; // Time in seconds that gripper will regrab the cargo to ensure grip has not weakend
  54. AP_Int16 uavcan_hardpoint_id;
  55. gripper_state state = STATE_RELEASED;
  56. } config;
  57. private:
  58. AP_Gripper_Backend *backend;
  59. };
  60. namespace AP {
  61. AP_Gripper *gripper();
  62. };