| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include "foc/core/torque.h"
- #include "foc/foc_config.h"
- #include "foc/motor/motor.h"
- #include "foc/core/e_ctrl.h"
- #include "foc/core/PMSM_FOC_Core.h"
- /*
- 通过查表获取对应扭矩和速度时的Id和IQ的分配
- */
- void torque_init(void) {
- }
- void torque_get_idq(float torque, float rpm, DQ_t *dq_out) {
- dq_out->d = 0;
- dq_out->q = torque;
- }
- float speed_target_from_throttle(float f_throttle) {
- if (f_throttle <= (CONFIG_THROTTLE_LOW_VALUE)) {
- return 0;
- }
- float delta = f_throttle - (CONFIG_THROTTLE_LOW_VALUE);
- float ration = delta / (CONFIG_THROTTLE_MAX_VALUE - CONFIG_THROTTLE_LOW_VALUE);
- return (PMSM_FOC_GetSpeedLimit() * ration);
- }
- float torque_target_from_throttle(float f_throttle) {
- if (f_throttle <= (CONFIG_THROTTLE_LOW_VALUE)) {
- return 0;
- }
- float delta = f_throttle - (CONFIG_THROTTLE_LOW_VALUE);
- float ration = delta / (CONFIG_THROTTLE_MAX_VALUE - CONFIG_THROTTLE_LOW_VALUE);
- return (PMSM_FOC_GetTorqueLimit() * ration);
- }
- void torque_speed_target(u8 run_mode, float f_throttle) {
- if (run_mode == CTRL_MODE_SPD) {
- float speed_Ref = speed_target_from_throttle(f_throttle);
- if (PMSM_FOC_is_epmMode()) {
- if (speed_Ref == 0.0f) {
- PMSM_FOC_Start_epmMove(false, EPM_Dir_None);
- }else {
- PMSM_FOC_Start_epmMove(true, EPM_Dir_Forward);
- }
- }
- PMSM_FOC_Set_Speed(speed_Ref);
- }else if (run_mode == CTRL_MODE_TRQ) {
- if (mc_throttle_released()) {
- eCtrl_enable_eBrake(true);
- PMSM_FOC_Set_Torque(0);
- }else {
- float torque = torque_target_from_throttle(f_throttle);
- eCtrl_enable_eBrake(false);
- PMSM_FOC_Set_Torque(torque);
- }
- }else if (run_mode == CTRL_MODE_CURRENT_BRK) {
- if (!mc_throttle_released() || (mc_throttle_released() && (PMSM_FOC_GetSpeed() == 0.0f))) {
- eCtrl_enable_eBrake(false);
- }
- }
- }
|