摘要:本節介紹實現步進電機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,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90,0X88,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加速的逆過程去實現減速,可以實現代碼的簡化。
聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。
舉報投訴
-
步進電機
+關注
關注
151文章
3115瀏覽量
147648 -
生成器
+關注
關注
7文章
317瀏覽量
21061 -
s曲線
+關注
關注
0文章
6瀏覽量
5670
發布評論請先 登錄
相關推薦
基于凌陽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次下載
評論