torque.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "foc/core/torque.h"
  2. #include "foc/foc_config.h"
  3. #include "foc/motor/motor.h"
  4. #include "foc/core/e_ctrl.h"
  5. #include "foc/core/PMSM_FOC_Core.h"
  6. /*
  7. 通过查表获取对应扭矩和速度时的Id和IQ的分配
  8. */
  9. void torque_init(void) {
  10. }
  11. void torque_get_idq(float torque, float rpm, DQ_t *dq_out) {
  12. dq_out->d = 0;
  13. dq_out->q = torque;
  14. }
  15. float speed_target_from_throttle(float f_throttle) {
  16. if (f_throttle <= (THROTTLE_LOW_VALUE)) {
  17. return 0;
  18. }
  19. float delta = f_throttle - (THROTTLE_LOW_VALUE);
  20. float ration = delta / (THROTTLE_MAX_VALUE - THROTTLE_LOW_VALUE);
  21. return (PMSM_FOC_GetSpeedLimit() * ration);
  22. }
  23. float torque_target_from_throttle(float f_throttle) {
  24. if (f_throttle <= (THROTTLE_LOW_VALUE)) {
  25. return 0;
  26. }
  27. float delta = f_throttle - (THROTTLE_LOW_VALUE);
  28. float ration = delta / (THROTTLE_MAX_VALUE - THROTTLE_LOW_VALUE);
  29. return (PMSM_FOC_GetTorqueLimit() * ration);
  30. }
  31. void torque_speed_target(u8 run_mode, float f_throttle) {
  32. if (run_mode == CTRL_MODE_SPD) {
  33. float speed_Ref = speed_target_from_throttle(f_throttle);
  34. if (PMSM_FOC_is_epmMode()) {
  35. if (speed_Ref == 0.0f) {
  36. PMSM_FOC_Start_epmMove(false, EPM_Dir_None);
  37. }else {
  38. PMSM_FOC_Start_epmMove(true, EPM_Dir_Forward);
  39. }
  40. }
  41. PMSM_FOC_Set_Speed(speed_Ref);
  42. }else if (run_mode == CTRL_MODE_TRQ) {
  43. if (mc_throttle_released()) {
  44. eCtrl_enable_eBrake(true);
  45. }else {
  46. float torque = torque_target_from_throttle(f_throttle);
  47. eCtrl_enable_eBrake(false);
  48. PMSM_FOC_Set_Torque(torque);
  49. }
  50. }else if (run_mode == CTRL_MODE_CURRENT_BRK) {
  51. if (!mc_throttle_released() || (mc_throttle_released() && (PMSM_FOC_GetSpeed() == 0.0f))) {
  52. eCtrl_enable_eBrake(false);
  53. }
  54. }
  55. }