zcancmder_v2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
3.3 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #pragma once
  2. #include <map>
  3. #include "api/api.hpp"
  4. #include "api\i_zcan_cmder_master.hpp"
  5. #include "cmdid.hpp"
  6. namespace iflytop {
  7. class ZModuleDeviceManager {
  8. private:
  9. map<uint16_t, ZIModule *> m_modulers;
  10. IZcanCmderMaster *m_cancmder = nullptr;
  11. public:
  12. void initialize();
  13. void registerModule(uint16_t id, ZIModule *module);
  14. /*******************************************************************************
  15. * ZIModule *
  16. *******************************************************************************/
  17. int32_t module_stop(uint16_t id);
  18. int32_t module_break(uint16_t id);
  19. int32_t module_get_last_exec_status(uint16_t id, int32_t *status);
  20. int32_t module_get_status(uint16_t id, int32_t *status);
  21. int32_t module_set_param(uint16_t id, int32_t param_id, int32_t param_value);
  22. int32_t module_get_param(uint16_t id, int32_t param_id, int32_t *param_value);
  23. int32_t module_readio(uint16_t id, int32_t *io);
  24. int32_t module_writeio(uint16_t id, int32_t io);
  25. int32_t module_read_adc(uint16_t id, int32_t adcindex, int32_t *adc);
  26. int32_t module_get_error(uint16_t id, int32_t *iserror);
  27. int32_t module_clear_error(uint16_t id);
  28. /*******************************************************************************
  29. * ZIMotor *
  30. *******************************************************************************/
  31. int32_t motor_enable(uint16_t id, int32_t enable);
  32. int32_t motor_rotate(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acc);
  33. int32_t motor_move_by(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acc);
  34. int32_t motor_move_to(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acc);
  35. int32_t motor_rotate_acctime(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acctime);
  36. int32_t motor_move_by_acctime(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acctime);
  37. int32_t motor_move_to_acctime(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acctime);
  38. int32_t motor_move_to_zero_forward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  39. int32_t motor_move_to_zero_backward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  40. int32_t motor_move_to_with_torque(uint16_t id, int32_t pos, int32_t torque);
  41. /*******************************************************************************
  42. * ZIXYMotor *
  43. *******************************************************************************/
  44. int32_t xymotor_enable(uint16_t id, int32_t enable);
  45. int32_t xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t motor_velocity);
  46. int32_t xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t motor_velocity);
  47. private:
  48. template <typename T>
  49. int32_t findModule(uint16_t id, T **module) {
  50. auto it = m_modulers.find(id);
  51. if (it == m_modulers.end()) {
  52. return err::kmodule_not_found;
  53. }
  54. T *_module = dynamic_cast<T *>(it->second);
  55. if (_module == nullptr) {
  56. return err::koperation_not_support;
  57. }
  58. *module = _module;
  59. return 0;
  60. }
  61. };
  62. } // namespace iflytop