torque.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. PMSM_FOC_Set_Speed(speed_Ref);
  35. }else if (run_mode == CTRL_MODE_TRQ) {
  36. if (mc_throttle_released()) {
  37. eCtrl_enable_eBrake(true);
  38. }else {
  39. float torque = torque_target_from_throttle(f_throttle);
  40. eCtrl_enable_eBrake(false);
  41. PMSM_FOC_Set_Torque(torque);
  42. }
  43. }
  44. }