mc_interface.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**
  2. ******************************************************************************
  3. * @file mc_interface.h
  4. * @author Motor Control SDK Team, ST Microelectronics
  5. * @brief This file contains all definitions and functions prototypes for the
  6. * MC Interface component of the Motor Control SDK.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software component is licensed by ST under Ultimate Liberty license
  14. * SLA0044, the "License"; You may not use this file except in compliance with
  15. * the License. You may obtain a copy of the License at:
  16. * www.st.com/SLA0044
  17. *
  18. ******************************************************************************
  19. * @ingroup MCInterface
  20. */
  21. /* Define to prevent recursive inclusion -------------------------------------*/
  22. #ifndef __MC_INTERFACE_H
  23. #define __MC_INTERFACE_H
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif /* __cplusplus */
  27. /* Includes ------------------------------------------------------------------*/
  28. #include "mc_type.h"
  29. #include "state_machine.h"
  30. #include "speed_torq_ctrl.h"
  31. /** @addtogroup MCSDK
  32. * @{
  33. */
  34. /** @addtogroup MCInterface
  35. * @{
  36. */
  37. /* Exported types ------------------------------------------------------------*/
  38. typedef enum
  39. {
  40. MCI_BUFFER_EMPTY, /*!< If no buffered command has been
  41. called.*/
  42. MCI_COMMAND_NOT_ALREADY_EXECUTED, /*!< If the buffered command condition
  43. hasn't already occurred.*/
  44. MCI_COMMAND_EXECUTED_SUCCESFULLY, /*!< If the buffered command has been
  45. executed successfully.*/
  46. MCI_COMMAND_EXECUTED_UNSUCCESFULLY /*!< If the buffered command has been
  47. executed unsuccessfully.*/
  48. } MCI_CommandState_t ;
  49. typedef enum
  50. {
  51. MCI_NOCOMMANDSYET, /*!< No command has been set by the user.*/
  52. MCI_EXECSPEEDRAMP, /*!< ExecSpeedRamp command coming from the user.*/
  53. MCI_EXECTORQUERAMP, /*!< ExecTorqueRamp command coming from the user.*/
  54. MCI_SETCURRENTREFERENCES, /*!< SetCurrentReferences command coming from the
  55. user.*/
  56. } MCI_UserCommands_t;
  57. typedef struct
  58. {
  59. STM_Handle_t * pSTM; /*!< State machine object used by MCI.*/
  60. SpeednTorqCtrl_Handle_t * pSTC; /*!< Speed and torque controller object used by MCI.*/
  61. pFOCVars_t pFOCVars; /*!< Pointer to FOC vars used by MCI.*/
  62. MCI_UserCommands_t lastCommand; /*!< Last command coming from the user.*/
  63. int16_t hFinalSpeed; /*!< Final speed of last ExecSpeedRamp command.*/
  64. int16_t hFinalTorque; /*!< Final torque of last ExecTorqueRamp
  65. command.*/
  66. qd_t Iqdref; /*!< Current component of last
  67. SetCurrentReferences command.*/
  68. uint16_t hDurationms; /*!< Duration in ms of last ExecSpeedRamp or
  69. ExecTorqueRamp command.*/
  70. MCI_CommandState_t CommandState; /*!< The status of the buffered command.*/
  71. STC_Modality_t LastModalitySetByUser; /*!< The last STC_Modality_t set by the
  72. user. */
  73. } MCI_Handle_t;
  74. /* Exported functions ------------------------------------------------------- */
  75. void MCI_Init( MCI_Handle_t * pHandle, STM_Handle_t * pSTM, SpeednTorqCtrl_Handle_t * pSTC, pFOCVars_t pFOCVars );
  76. void MCI_ExecBufferedCommands( MCI_Handle_t * pHandle );
  77. void MCI_ExecSpeedRamp( MCI_Handle_t * pHandle, int16_t hFinalSpeed, uint16_t hDurationms );
  78. void MCI_ExecTorqueRamp( MCI_Handle_t * pHandle, int16_t hFinalTorque, uint16_t hDurationms );
  79. void MCI_SetCurrentReferences( MCI_Handle_t * pHandle, qd_t Iqdref );
  80. bool MCI_StartMotor( MCI_Handle_t * pHandle );
  81. bool MCI_StopMotor( MCI_Handle_t * pHandle );
  82. bool MCI_FaultAcknowledged( MCI_Handle_t * pHandle );
  83. bool MCI_EncoderAlign( MCI_Handle_t * pHandle );
  84. MCI_CommandState_t MCI_IsCommandAcknowledged( MCI_Handle_t * pHandle );
  85. State_t MCI_GetSTMState( MCI_Handle_t * pHandle );
  86. uint16_t MCI_GetOccurredFaults( MCI_Handle_t * pHandle );
  87. uint16_t MCI_GetCurrentFaults( MCI_Handle_t * pHandle );
  88. int16_t MCI_GetMecSpeedRefUnit( MCI_Handle_t * pHandle );
  89. int16_t MCI_GetAvrgMecSpeedUnit( MCI_Handle_t * pHandle );
  90. /*int16_t MCI_GetTorque( MCI_Handle_t * pHandle );*/
  91. int16_t MCI_GetPhaseCurrentAmplitude( MCI_Handle_t * pHandle );
  92. int16_t MCI_GetPhaseVoltageAmplitude( MCI_Handle_t * pHandle );
  93. STC_Modality_t MCI_GetControlMode( MCI_Handle_t * pHandle );
  94. int16_t MCI_GetImposedMotorDirection( MCI_Handle_t * pHandle );
  95. int16_t MCI_GetLastRampFinalSpeed( MCI_Handle_t * pHandle );
  96. bool MCI_RampCompleted( MCI_Handle_t * pHandle );
  97. bool MCI_StopSpeedRamp( MCI_Handle_t * pHandle );
  98. void MCI_StopRamp( MCI_Handle_t * pHandle );
  99. bool MCI_GetSpdSensorReliability( MCI_Handle_t * pHandle );
  100. int16_t MCI_GetAvrgMecSpeedUnit( MCI_Handle_t * pHandle );
  101. int16_t MCI_GetMecSpeedRefUnit( MCI_Handle_t * pHandle );
  102. ab_t MCI_GetIab( MCI_Handle_t * pHandle );
  103. alphabeta_t MCI_GetIalphabeta( MCI_Handle_t * pHandle );
  104. qd_t MCI_GetIqd( MCI_Handle_t * pHandle );
  105. qd_t MCI_GetIqdHF( MCI_Handle_t * pHandle );
  106. qd_t MCI_GetIqdref( MCI_Handle_t * pHandle );
  107. qd_t MCI_GetVqd( MCI_Handle_t * pHandle );
  108. alphabeta_t MCI_GetValphabeta( MCI_Handle_t * pHandle );
  109. int16_t MCI_GetElAngledpp( MCI_Handle_t * pHandle );
  110. int16_t MCI_GetTeref( MCI_Handle_t * pHandle );
  111. int16_t MCI_GetPhaseCurrentAmplitude( MCI_Handle_t * pHandle );
  112. int16_t MCI_GetPhaseVoltageAmplitude( MCI_Handle_t * pHandle );
  113. void MCI_SetIdref( MCI_Handle_t * pHandle, int16_t hNewIdref );
  114. void MCI_Clear_Iqdref( MCI_Handle_t * pHandle );
  115. /**
  116. * @}
  117. */
  118. /**
  119. * @}
  120. */
  121. #ifdef __cplusplus
  122. }
  123. #endif /* __cpluplus */
  124. #endif /* __MC_INTERFACE_H */
  125. /******************* (C) COPYRIGHT 2019 STMicroelectronics *****END OF FILE****/