您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

81 行
1.5KB

  1. #ifndef STEPPER_H
  2. #define STEPPER_H
  3. #include <stdint.h>
  4. #include "periph/gpio.h"
  5. #include "periph/uart.h"
  6. #include "sensor.h"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #define STEPPER_PARAM_VEL_MAX (25)
  11. #define STEPPER_PARAM_ACC_MAX (200)
  12. #define STEPPER_PARAM_VELOCITY_DEFAULT (0)
  13. #define STEPPER_PARAM_MICROSTEP_DEFAULT (16)
  14. #define STEPPER_PARAM_DIVISION_DEFAULT (200)
  15. #define STEPPER_PARAM_ANGLE_DEFAULT (0)
  16. #define STEPPER_PARAM_HOMING_ANGLE_DEFAULT (20)
  17. /**
  18. * @brief Status and error codes
  19. */
  20. enum {
  21. STEPPER_OK = 0,
  22. STEPPER_NO = -1,
  23. };
  24. /**
  25. * @brief Direction for stepper
  26. */
  27. typedef enum {
  28. STEPPER_FORWARD = 0x0,
  29. STEPPER_REVERSE = 0x1,
  30. } stepper_direction_t;
  31. /**
  32. * @brief Data structure holding the device parameters needed for initialization
  33. */
  34. typedef struct {
  35. gpio_t step_pin;
  36. gpio_t dir_pin;
  37. uint8_t uart;
  38. uint8_t vel_max;
  39. uint8_t acc_max;
  40. uint8_t microstep;
  41. uint16_t division;
  42. float angle;
  43. float velocity;
  44. sensor_t sensor;
  45. float homing_angle;
  46. } stepper_params_t;
  47. /**
  48. * @brief Device Descriptor for Stepper controller
  49. */
  50. typedef struct {
  51. stepper_params_t p;
  52. } stepper_t;
  53. int stepper_init(stepper_t *dev, const stepper_params_t *params);
  54. int stepper_set_velocity(stepper_t *dev, float *velocity);
  55. int stepper_homing(stepper_t *dev);
  56. int stepper_get_angle(stepper_t *dev, float *angle);
  57. int stepper_step(stepper_t *dev, stepper_direction_t *direction);
  58. #ifdef __cplusplus
  59. }
  60. #endif
  61. #endif /* STEPPER_H */