摘要:本节介绍实现步进电机S曲线运动的代码
一、目标功能
实现步进电机转动总角度720°,其中加减速各90°
加速段:加速类型:S曲线
加速角度:角度为90°
起步速度:30RPM,
终止速度:500RPM
匀速段:匀速角度:角度为540°
匀速速度:500RPM
减速段:减速类型:S曲线
减速角度:角度为90°
起步速度:500RPM
终止速度:60RPM
二、生成器计算
加速参数计算
匀速参数计算,主要计算电机步数
减速参数计算
三、程序代码
//加速、匀速、减速步数#define step0 100#define step1 600#define step2 100unsigned int n=0;//步数计数变量unsigned int flag=0;//标志位,0:加速段 1:匀速段 2:减速段//加速段90°,30RPM-500RPMconst unsigned char codeTimeH0[100]={0XEC,0XEC,0XEC,0XED,0XED,0XED,0XEE,0XEE,0XEE,0XEF,0XEF,0XF0,0XF0,0XF1,0XF1,0XF2,0XF2,0XF3,0XF3,0XF4,0XF4,0XF5,0XF5,0XF6,0XF6,0XF7,0XF7,0XF8,0XF8,0XF8,0XF9,0XF9,0XFA,0XFA,0XFA,0XFB,0XFB,0XFB,0XFB,0XFC,0XFC,0XFC,0XFC,0XFD,0XFD,0XFD,0XFD,0XFD,0XFD,0XFD,0XFD,0XFD,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE};const unsigned char codeTimeL0[100]={0X78,0XB4,0XF5,0X3B,0X86,0XD6,0X2A,0X84,0XE4,0X48,0XB1,0X1F,0X92,0X9,0X83,0X1,0X82,0X5,0X8A,0X10,0X96,0X1C,0XA0,0X24,0XA5,0X23,0X9E,0X15,0X88,0XF7,0X61,0XC5,0X25,0X80,0XD5,0X26,0X71,0XB7,0XF9,0X36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X88,0X81,0X78,0X6F,0X64,0X59,0X4D,0X3F,0X31,0X21,0XF,0XFD,0XE8,0XD2,0XBA,0XA0,0X84,0X66,0X46,0X24,0X0,0XD9,0XB0,0X85,0X58,0X28,0XF7,0XC4,0X8F,0X59,0X21,0XE8,0XAE,0X74,0X3A,0X0,0XC6,0X8D,0X54,0X1D,0XE7,0XB3,0X81,0X50,0X22,0XF6,0XCB,0XA4,0X7E,0X5A,0X39,0X1A,0XFD,0XE2,0XC9,0XB2,0X9D,0X89,0X77,0X66,0X57,0X48,0X3C}; void main(){ while(1) { }}//定时器0中断程序void time0_int() interrupt 1{ //产生一个脉冲 PUL=1; _nop_();_nop_();nop_();nop_(); PUL=0; n++;//步数加1 switch (flag)//判断运动状态 { case0://加速段 { if(n==step0)//加速段完成 { n=0; flag=1; TH0=TimeH2[0];//装载定时寄存器匀速段初值 TL0=TimeL2[0]; } else { TH0=TimeH0[n];//装载定时寄存器加速段初值 TL0=TimeL0[n]; } }break; case1://匀速段 { TH0=TimeH2[0];//装载定时寄存器匀速段初值 TL0=TimeL2[0]; if(n==step1)//匀速段完成 { n=0; flag=2; TH0=TimeH2[n];//装载定时寄存器减速段初值 TL0=TimeL2[n]; } }break; case 2://减速段 { if(n==step2)//减速段完成 { n=0; flag=0; TR0=0; //电机停止 } else { TH0=TimeH2[n];//装载定时寄存器减速段初值 TL0=TimeL2[n]; } }break; default: break; }}
四.总结
通过上述计算,完成S曲线加减速运动。通过调整匀速运动的角度,加减速过程不变,可以实现总转动角度的变化,适用于总转角需要变化且需要较高速度的情况,并且满足总转角应大于加减速转角之和。
对于大多数情况,加减速的过程可以合并,即用S加速的逆过程去实现减速,可以实现代码的简化。
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。
举报投诉
-
步进电机
+关注
关注
150文章
3103浏览量
147403 -
生成器
+关注
关注
7文章
314浏览量
20994 -
s曲线
+关注
关注
0文章
6浏览量
5668
发布评论请先 登录
相关推荐
基于凌阳16位单片机SPCE061A悬挂运动控制系统
以凌阳16位单片机SPCE061A为控制核心,通过所需运动轨迹曲线的参数方程建立运动控制模型,按照算法对两组驱动步进电机进行控制,
发表于 03-07 16:00
有没有stm32,l6205驱动步进电机pid或者s曲线动态计算的实现代码,求上传!!!!!
有没有stm32,l6205驱动步进电机pid或者s曲线动态计算的实现代码,求上传!!!!!
发表于 12-20 16:32
步进电机S型曲线加减速算法是什么?如何去实现?
步进电机S型曲线加减速算法与实现Monte-Carlo2017-05-18 10:06:232653收藏2分类专栏:机器人
发表于 07-08 09:56
怎样去生成步进电机S曲线运动数组代码程序语言
程序功能:生成步进电机S曲线运动数组代码程序语言:VB6.0对应硬件线路连接见上章:https://blog.csdn.net/LuDanT
发表于 07-08 08:50
步进电机S型曲线加速的实现
之前做电机相关的项目比较少,最近有个项目涉及到步进电机的精确控制,参考了一些资料研究了一下S型曲线加减速,这里总结一下分享给大家。硬件是:S
发表于 11-25 10:51
•86次下载
评论