torque.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <= (CONFIG_THROTTLE_LOW_VALUE)) {
  17. return 0;
  18. }
  19. float delta = f_throttle - (CONFIG_THROTTLE_LOW_VALUE);
  20. float ration = delta / (CONFIG_THROTTLE_MAX_VALUE - CONFIG_THROTTLE_LOW_VALUE);
  21. return (PMSM_FOC_GetSpeedLimit() * ration);
  22. }
  23. float torque_target_from_throttle(float f_throttle) {
  24. if (f_throttle <= (CONFIG_THROTTLE_LOW_VALUE)) {
  25. return 0;
  26. }
  27. float delta = f_throttle - (CONFIG_THROTTLE_LOW_VALUE);
  28. float ration = delta / (CONFIG_THROTTLE_MAX_VALUE - CONFIG_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 (mc_is_epm()) {
  35. if (speed_Ref == 0.0f) {
  36. mc_throttle_epm_move(EPM_Dir_None);
  37. }else {
  38. mc_throttle_epm_move(EPM_Dir_Forward);
  39. }
  40. }else {
  41. PMSM_FOC_Set_Speed(speed_Ref);
  42. }
  43. }else if (run_mode == CTRL_MODE_TRQ) {
  44. if (mc_throttle_released()) {
  45. eCtrl_enable_eBrake(true);
  46. PMSM_FOC_Set_Torque(0);
  47. }else {
  48. float torque = torque_target_from_throttle(f_throttle);
  49. eCtrl_enable_eBrake(false);
  50. PMSM_FOC_Set_Torque(torque);
  51. }
  52. }else if (run_mode == CTRL_MODE_CURRENT_BRK) {
  53. if (!mc_throttle_released() || (mc_throttle_released() && (PMSM_FOC_GetSpeed() == 0.0f))) {
  54. eCtrl_enable_eBrake(false);
  55. }
  56. }
  57. }