e_ctrl.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef EBRAKE_CTRL_H__
  2. #define EBRAKE_CTRL_H__
  3. #include "os/os_types.h"
  4. #include "foc/core/ramp_ctrl.h"
  5. typedef struct {
  6. float start;
  7. float target;
  8. float interpolation;
  9. float step_val;
  10. }e_Ramp;
  11. typedef struct {
  12. u16 ebrk_time; //能量回收,时间越短,刹车性能或者回收越好
  13. u16 accl_time; //加速时间(ms),时间越短,加速性能越好
  14. bool hw_brake;
  15. u64 brake_ts;//检测到刹车开始时间
  16. e_Ramp current;
  17. e_Ramp torque;
  18. e_Ramp speed;
  19. u16 ebrk_shadow;
  20. u16 accl_shadow;
  21. float current_shadow;
  22. float torque_shadow;
  23. float speed_shadow;
  24. }e_Ctrl;
  25. static void eRamp_init(e_Ramp *r) {
  26. r->start = 0;
  27. r->target = 0;
  28. r->interpolation = 0;
  29. r->step_val = 0;
  30. }
  31. static void eRamp_set_target(e_Ramp *r, float target) {
  32. r->target = target;
  33. }
  34. static void eRamp_set_step(e_Ramp *r, float step) {
  35. r->step_val = step;
  36. }
  37. static void eRamp_running(e_Ramp *r) {
  38. float target = r->interpolation + r->step_val;
  39. if (r->step_val < 0) {
  40. if (target < r->target) {
  41. target = r->target;
  42. }
  43. }else {
  44. if (target > r->target) {
  45. target = r->target;
  46. }
  47. }
  48. r->interpolation = target;
  49. }
  50. static float eRamp_get_intepolation(e_Ramp *r) {
  51. return r->interpolation;
  52. }
  53. static float eRamp_get_target(e_Ramp *r) {
  54. return r->target;
  55. }
  56. void eCtrl_init(u16 ebrk_time, u16 accl_time);
  57. void eCtrl_set_accl_brk(u16 accl_time, u16 ebrk_time);
  58. void eCtrl_brake_signal(bool hw_brake);
  59. void eCtrl_set_TgtCurrent(float c);
  60. void eCtrl_set_TgtTorque(float t);
  61. void eCtrl_set_TgtSpeed(float s);
  62. float eCtrl_get_RefSpeed(void);
  63. float eCtrl_get_RefCurrent(void);
  64. float eCtrl_get_RefTorque(void);
  65. float eCtrl_get_FinalSpeed(void);
  66. float eCtrl_get_FinalCurrent(void);
  67. float eCtrl_get_FinalTorque(void);
  68. void eCtrl_Running(void);
  69. #endif /* EBRAKE_CTRL_H__ */