本帖最后由 toofree 于 2018-9-14 08:46 编辑
【STM32电机培训】——5、任务3电机状态切换、正反转
任务目标:
本实验源程序基于上一贴,做了适当修改。
【STM32电机培训】——4、任务2电机设定程序修改PI参数
https://www.stmcu.org.cn/module/forum/forum.php?mod=viewthread&tid=617433&fromuid=307297
(出处: 意法半导体STM32/STM8技术社区)
新增包含了头文件“"SystemNDriveParams.h",新增了外部变量声明“extern STM_Handle_t STM[NBR_OF_MOTORS]”,电机正、反转速度设定做成了宏定义“INVERT”、“NONINVT”。
用户主程序,可以分为5块。初始状态设定、出错处理(详见注释)、周期性正反转切换、时基控制(定时0.1s)、LED闪灯灯。现在唯一有疑问的就是,这个“错误状态”反馈怎么玩,反馈给谁?对于本实验的意义,是想知道详细出错信息吗?
下载程序到开发套件中。打开Workbench界面,并与目标板套件连接
在“监控”窗口下,在打开“Plotter”绘图窗口。观察电机速度状态变化
局部放大,可以看到电机运行速度反馈丢失出错、清除错误、重启电机、重新建立速度反馈,正常工作。
在Workbench界面观察电机状态变化,一共出现过5种状态:Run、Idle、Start、Fault Over、Unknow,但是Unknow时间太短,未能抓图捕获。
Run状态
Idle状态
Start状态
Fault Over状态
从State_t的枚举类型定义来看,状态还有好多种。如果要搞明白,需要进一步研究。
- typedef enum
- {
- ICLWAIT = 12, /*!< Persistent state, the system is waiting for ICL
- deactivation. Is not possible to run the motor if
- ICL is active. Until the ICL is active the state is
- forced to ICLWAIT, when ICL become inactive the state
- is moved to IDLE */
- IDLE = 0, /*!< Persistent state, following state can be IDLE_START
- if a start motor command has been given or
- IDLE_ALIGNMENT if a start alignment command has been
- given */
- IDLE_ALIGNMENT = 1, /*!< "Pass-through" state containg the code to be executed
- only once after encoder alignment command.
- Next states can be ALIGN_CHARGE_BOOT_CAP or
- ALIGN_OFFSET_CALIB according the configuration. It
- can also be ANY_STOP if a stop motor command has been
- given. */
- ALIGN_CHARGE_BOOT_CAP = 13,/*!< Persistent state where the gate driver boot
- capacitors will be charged. Next states will be
- ALIGN_OFFSET_CALIB. It can also be ANY_STOP if a stop
- motor command has been given. */
- ALIGN_OFFSET_CALIB = 14,/*!< Persistent state where the offset of motor currents
- measurements will be calibrated. Next state will be
- ALIGN_CLEAR. It can also be ANY_STOP if a stop motor
- command has been given. */
- ALIGN_CLEAR = 15, /*!< "Pass-through" state in which object is cleared and
- set for the startup.
- Next state will be ALIGNMENT. It can also be ANY_STOP
- if a stop motor command has been given. */
- ALIGNMENT = 2, /*!< Persistent state in which the encoder are properly
- aligned to set mechanical angle, following state can
- only be ANY_STOP */
- IDLE_START = 3, /*!< "Pass-through" state containg the code to be executed
- only once after start motor command.
- Next states can be CHARGE_BOOT_CAP or OFFSET_CALIB
- according the configuration. It can also be ANY_STOP
- if a stop motor command has been given. */
- CHARGE_BOOT_CAP = 16, /*!< Persistent state where the gate driver boot
- capacitors will be charged. Next states will be
- OFFSET_CALIB. It can also be ANY_STOP if a stop motor
- command has been given. */
- OFFSET_CALIB = 17, /*!< Persistent state where the offset of motor currents
- measurements will be calibrated. Next state will be
- CLEAR. It can also be ANY_STOP if a stop motor
- command has been given. */
- CLEAR = 18, /*!< "Pass-through" state in which object is cleared and
- set for the startup.
- Next state will be START. It can also be ANY_STOP if
- a stop motor command has been given. */
- START = 4, /*!< Persistent state where the motor start-up is intended
- to be executed. The following state is normally
- START_RUN as soon as first validated speed is
- detected. Another possible following state is
- ANY_STOP if a stop motor command has been executed */
- START_RUN = 5, /*!< "Pass-through" state, the code to be executed only
- once between START and RUN states it’s intended to be
- here executed. Following state is normally RUN but
- it can also be ANY_STOP if a stop motor command has
- been given */
- RUN = 6, /*!< Persistent state with running motor. The following
- state is normally ANY_STOP when a stop motor command
- has been executed */
- ANY_STOP = 7, /*!< "Pass-through" state, the code to be executed only
- once between any state and STOP it’s intended to be
- here executed. Following state is normally STOP */
- STOP = 8, /*!< Persistent state. Following state is normally
- STOP_IDLE as soon as conditions for moving state
- machine are detected */
- STOP_IDLE = 9, /*!< "Pass-through" state, the code to be executed only
- once between STOP and IDLE it’s intended to be here
- executed. Following state is normally IDLE */
- FAULT_NOW = 10, /*!< Persistent state, the state machine can be moved from
- any condition directly to this state by
- STM_FaultProcessing method. This method also manage
- the passage to the only allowed following state that
- is FAULT_OVER */
- FAULT_OVER = 11 /*!< Persistent state where the application is intended to
- stay when the fault conditions disappeared. Following
- state is normally STOP_IDLE, state machine is moved as
- soon as the user has acknowledged the fault condition.
- */
- } State_t;
复制代码
好了,本贴任务3完成。
按照惯例,程序附上:
P-NUCLEO-IHM001_ zhengfan.rar
(8.99 MB, 下载次数: 55)
|
多谢捧场
羡慕你的HP3457和吉时利2000