搜索
bottom↓
楼主: coleyao

步进电机S曲线加速数据计算小软件

  [复制链接]

出0入0汤圆

发表于 2017-3-18 17:04:29 | 显示全部楼层
不错 正好需要 下载来看看

出0入53汤圆

发表于 2017-4-11 15:56:25 | 显示全部楼层
coleyao 发表于 2012-8-20 05:59
理论上有两种办法:1)加装编码器,通过负反馈控制的方式控制加速度连续减小/增加,效果和控制方式和算 ...

你好,正要用步进电机加速度控制算法,刚刚接触了解不深,能否说说如何使用这个s曲线

出0入53汤圆

发表于 2017-4-11 16:28:32 | 显示全部楼层
coleyao 发表于 2012-8-21 05:40
//代码如下,不复杂的,谁有空可以试下单片机实时计算的可能性!
//本来是直接贴代码的,太费流量了,还 ...

我帮lz贴出来,
  1. object Form1: TForm1
  2.   Left = 164
  3.   Top = 116
  4.   Width = 854
  5.   Height = 581
  6.   Caption = #27493#36827#30005#26426'S'#26354#32447#29983#25104#24037#20855
  7.   Color = clBtnFace
  8.   Font.Charset = DEFAULT_CHARSET
  9.   Font.Color = clWindowText
  10.   Font.Height = -11
  11.   Font.Name = 'MS Sans Serif'
  12.   Font.Style = []
  13.   Icon.Data = {
  14.     0000010001002020100000000000E80200001600000028000000200000004000
  15.     0000010004000000000080020000000000000000000000000000000000000000
  16.     000000008000008000000080800080000000800080008080000080808000C0C0
  17.     C0000000FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00FFFF
  18.     FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  19.     FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  20.     FFF1FFFFFF11F1FFF111FFFFFFFFFFFFFFF1FFFFF1FF11FF1FFF1FFFFFFFFFFF
  21.     FFF1FFFFF1FFF1FF1FFF1FFFFFFFFFFFFFF1FFFFFF1111FF1FFF1FFFFFFFFFFF
  22.     FFF1FFFFFFFFF1FF1FFF1FFFFFFFFFFFFF1F1FFFF1FFF1FF1FFF1FFFFFFFFFFF
  23.     FF1F1FFFFF111FFFF111FFFFFFFFFFFFF1FFF1FFFFFFFFFFFFFFFFFFFFFFFFFF
  24.     F1FFF1FFFFFFFFFFFFFFFFFFFFFFFFFF1FFFFF1FFFFFFFFFFFFFFFFFFFFFFFFF
  25.     FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  26.     FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  27.     FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  28.     F111FFFFF111FFF1FFF111FFFFFFFFFF1FFF1FFF1FFF1FF1FF1FFF1FFFFFFFF1
  29.     FFFFF1FF1FFF1FF1FF1FFFFFFFFFFFF1FFFFFFFF1FFF1FF1FF11111FFFFFFFF1
  30.     FFFFFFFF1FFF1FF1FF1FFF1FFFFFFFF1FFFFFFFF1FFF1FF1FF1FFF1FFFFFFFF1
  31.     FFFFFFFFF111FFF1FFF111FFFFFFFFF1FFFFF1FFFFFFFFF1FFFFFFFFFFFFFFFF
  32.     1FFF1FFFFFFFFFF1FFFFFFFFFFFFFFFFF111FFFFFFFFFFF1FFFFFFFFFFFFFFFF
  33.     FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000
  34.     0000000000000000000000000000000000000000000000000000000000000000
  35.     0000000000000000000000000000000000000000000000000000000000000000
  36.     0000000000000000000000000000000000000000000000000000000000000000
  37.     000000000000000000000000000000000000000000000000000000000000}
  38.   OldCreateOrder = False
  39.   PixelsPerInch = 96
  40.   TextHeight = 13
  41.   object PageCont1: TPageControl
  42.     Left = 0
  43.     Top = 0
  44.     Width = 846
  45.     Height = 547
  46.     ActivePage = Main
  47.     Align = alClient
  48.     TabOrder = 0
  49.     object Main: TTabSheet
  50.       Caption = #20027#30028#38754
  51.       object Image1: TImage
  52.         Left = 280
  53.         Top = 0
  54.         Width = 558
  55.         Height = 519
  56.       end
  57.       object Label1: TLabel
  58.         Left = 5
  59.         Top = 20
  60.         Width = 89
  61.         Height = 13
  62.         Caption = #26230#25391#39057#29575'(HZ)'#65306
  63.       end
  64.       object Label2: TLabel
  65.         Left = 5
  66.         Top = 47
  67.         Width = 85
  68.         Height = 13
  69.         Caption = #26230#25391#21608#26399'('#31186')'#65306
  70.       end
  71.       object Label3: TLabel
  72.         Left = 5
  73.         Top = 74
  74.         Width = 92
  75.         Height = 13
  76.         Caption = #26426#22120#21608#26399#20998#39057#65306
  77.       end
  78.       object Label4: TLabel
  79.         Left = 5
  80.         Top = 101
  81.         Width = 78
  82.         Height = 13
  83.         Caption = #26426#22120#21608#26399'('#31186')'#65306
  84.       end
  85.       object Label5: TLabel
  86.         Left = 6
  87.         Top = 128
  88.         Width = 235
  89.         Height = 13
  90.         AutoSize = False
  91.         Caption = 'PWM'#32763#36716#21608#26399#21021#22987#20540'('#26426#22120#21608#26399#20493#25968')'#65306
  92.         ShowAccelChar = False
  93.         WordWrap = True
  94.       end
  95.       object Label6: TLabel
  96.         Left = 7
  97.         Top = 174
  98.         Width = 250
  99.         Height = 13
  100.         AutoSize = False
  101.         Caption = #26368#39640#36895#26102'PWM'#32763#36716#21608#26399'('#26426#22120#21608#26399#20493#25968')'#65306
  102.         ShowAccelChar = False
  103.         WordWrap = True
  104.       end
  105.       object Label7: TLabel
  106.         Left = 7
  107.         Top = 221
  108.         Width = 242
  109.         Height = 13
  110.         AutoSize = False
  111.         Caption = 'S'#26354#32447#21322#21608#26399'/'#36895#24230#19978#21319#26399#65288#27627#31186#65289#65306
  112.         ShowAccelChar = False
  113.         WordWrap = True
  114.       end
  115.       object Label8: TLabel
  116.         Left = 8
  117.         Top = 272
  118.         Width = 81
  119.         Height = 13
  120.         Caption = #21152#36895#24230#26012#29575#65306
  121.       end
  122.       object Label9: TLabel
  123.         Left = 8
  124.         Top = 301
  125.         Width = 48
  126.         Height = 13
  127.         Caption = #35282#36895#24230#65306
  128.       end
  129.       object Edit1: TEdit
  130.         Left = 98
  131.         Top = 16
  132.         Width = 165
  133.         Height = 21
  134.         TabOrder = 0
  135.         Text = '8000000'
  136.       end
  137.       object Edit2: TEdit
  138.         Left = 98
  139.         Top = 43
  140.         Width = 165
  141.         Height = 21
  142.         Font.Charset = DEFAULT_CHARSET
  143.         Font.Color = clRed
  144.         Font.Height = -11
  145.         Font.Name = 'MS Sans Serif'
  146.         Font.Style = []
  147.         ParentFont = False
  148.         ReadOnly = True
  149.         TabOrder = 1
  150.         Text = '1.25E-6'
  151.       end
  152.       object Edit3: TEdit
  153.         Left = 98
  154.         Top = 70
  155.         Width = 165
  156.         Height = 21
  157.         TabOrder = 2
  158.         Text = '1'
  159.       end
  160.       object Edit4: TEdit
  161.         Left = 98
  162.         Top = 97
  163.         Width = 165
  164.         Height = 21
  165.         Font.Charset = DEFAULT_CHARSET
  166.         Font.Color = clRed
  167.         Font.Height = -11
  168.         Font.Name = 'MS Sans Serif'
  169.         Font.Style = []
  170.         ParentFont = False
  171.         ReadOnly = True
  172.         TabOrder = 3
  173.         Text = '1.25E-6'
  174.       end
  175.       object Edit5: TEdit
  176.         Left = 99
  177.         Top = 147
  178.         Width = 165
  179.         Height = 21
  180.         Font.Charset = DEFAULT_CHARSET
  181.         Font.Color = clBlack
  182.         Font.Height = -11
  183.         Font.Name = 'MS Sans Serif'
  184.         Font.Style = []
  185.         ParentFont = False
  186.         TabOrder = 4
  187.         Text = '6000'
  188.       end
  189.       object Edit6: TEdit
  190.         Left = 100
  191.         Top = 193
  192.         Width = 165
  193.         Height = 21
  194.         Font.Charset = DEFAULT_CHARSET
  195.         Font.Color = clBlack
  196.         Font.Height = -11
  197.         Font.Name = 'MS Sans Serif'
  198.         Font.Style = []
  199.         ParentFont = False
  200.         TabOrder = 5
  201.         Text = '600'
  202.       end
  203.       object Edit7: TEdit
  204.         Left = 100
  205.         Top = 240
  206.         Width = 165
  207.         Height = 21
  208.         Font.Charset = DEFAULT_CHARSET
  209.         Font.Color = clBlack
  210.         Font.Height = -11
  211.         Font.Name = 'MS Sans Serif'
  212.         Font.Style = []
  213.         ParentFont = False
  214.         TabOrder = 6
  215.         Text = '200'
  216.       end
  217.       object Button1: TButton
  218.         Left = 162
  219.         Top = 368
  220.         Width = 90
  221.         Height = 25
  222.         Caption = #35745#31639#21450#32472#22270
  223.         TabOrder = 7
  224.         OnClick = Button1Click
  225.       end
  226.       object Button2: TButton
  227.         Left = 162
  228.         Top = 419
  229.         Width = 90
  230.         Height = 25
  231.         Caption = 'Excel'#25968#25454#36755#20986
  232.         TabOrder = 8
  233.         OnClick = Button2Click
  234.       end
  235.       object Edit8: TEdit
  236.         Left = 101
  237.         Top = 268
  238.         Width = 165
  239.         Height = 21
  240.         Font.Charset = DEFAULT_CHARSET
  241.         Font.Color = clRed
  242.         Font.Height = -11
  243.         Font.Name = 'MS Sans Serif'
  244.         Font.Style = []
  245.         ParentFont = False
  246.         ReadOnly = True
  247.         TabOrder = 9
  248.         Text = '1'
  249.       end
  250.       object RdGMode: TRadioGroup
  251.         Left = 8
  252.         Top = 352
  253.         Width = 129
  254.         Height = 105
  255.         Caption = #21152#36895#24230#27169#24335
  256.         ItemIndex = 0
  257.         Items.Strings = (
  258.           #19977#35282#24418
  259.           #27491#24358#27874)
  260.         TabOrder = 10
  261.       end
  262.       object Edit9: TEdit
  263.         Left = 101
  264.         Top = 297
  265.         Width = 165
  266.         Height = 21
  267.         Font.Charset = DEFAULT_CHARSET
  268.         Font.Color = clRed
  269.         Font.Height = -11
  270.         Font.Name = 'MS Sans Serif'
  271.         Font.Style = []
  272.         ParentFont = False
  273.         ReadOnly = True
  274.         TabOrder = 11
  275.         Text = '1'
  276.       end
  277.     end
  278.     object DataOut: TTabSheet
  279.       Caption = #36755#20986#25968#25454
  280.       ImageIndex = 1
  281.       object Memo1: TMemo
  282.         Left = 0
  283.         Top = 0
  284.         Width = 838
  285.         Height = 519
  286.         Align = alClient
  287.         ScrollBars = ssVertical
  288.         TabOrder = 0
  289.       end
  290.     end
  291.     object TabSheet1: TTabSheet
  292.       Caption = #29256#26412#21450#35828#26126
  293.       ImageIndex = 2
  294.       object Memo2: TMemo
  295.         Left = 0
  296.         Top = 0
  297.         Width = 838
  298.         Height = 519
  299.         Align = alClient
  300.         Lines.Strings = (
  301.           #36719#20214#29256#26412#65306#65297'.'#65296'.'#65296'.'#65296
  302.           #36719#20214#20316#32773#65306'ColeYao'
  303.           #20986#29256#26085#26399#65306'2012'#24180'8'#26376'19'#26085
  304.           #32852#31995#26041#24335#65306'ColeYao+126.com  ('#35831#23558#39'+'#39#25913#20026#39'@'#39')'
  305.           ''
  306.           '  1'#65289#36719#20214#20027#30028#38754#24038#20391#30340#21442#25968#40657#33394#30340#20026#24517#38656#39033#30446#65292#26410#22635#20889#26102#20026#32570#30465#39033#65292#32418#33394#30340#39033#30446#19981#21487#22635#20889#65292#30001#36719#20214#35745#31639#29983#25104#65307
  307.           '  2'#65289#36719#20214#20027#30028#38754#21491#20391#30340#26354#32447#21306#22495#20026#29983#25104#21518#30340#21152#36895#24230#26354#32447#65288#34013#33394#65289#21644#36895#24230#26354#32447#65288#32418#33394#65289#25928#26524#22270#65292#20379#25928#26524#35780#20272#20351#29992#65307
  308.           '  3'#65289#39#36755#20986#25968#25454#39' '#39029#38754#36755#20986#30340#25968#25454#20026'txt'#26684#24335#65292#35835#32773#21487#30452#25509#25335#36125#21518#20351#29992#65292#20351#29992#39'Excel'#25968#25454#36755#20986#39#25353#38190#21487#23558#39#36755#20986#25968#25454#39
  309.           #39029#38754#30340#25968#25454#21478#23384#20026'csv'#26684#24335#30340#25991#20214#65292#21487#20351#29992'WPS'#34920#26684#25110'EXCEL'#36719#20214#35835#21462#24182#22788#29702#12290
  310.           '  4'#65289#36719#20214#30001#20316#32773#21033#29992#19994#20313#26102#38388#21046#20316#32500#25252#65292#33879#20316#26435#24402#20316#32773#25152#26377#65292#20986#29256#30340#20027#35201#30446#30340#26159#20026#20102#26041#20415#35835#32773#65292#19981#23384#22312#20854#20182#20219#20309
  311.           #21830#19994#30446#22320#65292#20854#20182#20154#21487#20197#20219#24847#20256#25773#65292#20294#26410#32463#20316#32773#20801#35768#65292#35831#21247#23558#35813#36719#20214#29992#20110#21830#29992#12290
  312.           '  5'#65289#27493#36827#30005#26426#20316'S'#26354#32447#25511#21046#30340#21407#29702#26159#65306#21152#20943#36895#26399#38388#30340#21152#36895#24230#20026#20174#38646#36830#32493#21319#21040#26368#22823#20540#65292#20877#20174#26368#22823#20540#36830#32493#20943#23569#21040#38646#65292#22240#27492
  313.           #30005#26426#30340#36816#34892#19981#20250#22240#21147#19981#36830#32493#20135#29983#21160#37327#20256#36882#65292#20351#24471#36816#34892#26426#26500#21152#20943#36895#26399#38388#38750#24120#24179#31283#65292#22240#27492#38500#20102#19977#35282#24418#27874#21644#27491#24358#27874#20197#20026#20063
  314.           #21487#20197#26159#20854#23427#27874#24418#65292#19981#36807#26377#20102#36825#20004#31181#26041#24335#20135#29983#30340'S'#26354#32447#25968#25454#65292#24212#35813#26159#22815#29992#20102#12290)
  315.         ReadOnly = True
  316.         TabOrder = 0
  317.       end
  318.     end
  319.   end
  320.   object Timer1: TTimer
  321.     Interval = 300
  322.     OnTimer = Timer1Timer
  323.     Left = 284
  324.     Top = 40
  325.   end
  326.   object SaveDialog1: TSaveDialog
  327.     DefaultExt = 'csv '
  328.     Filter = 'csv'
  329.     Left = 244
  330.     Top = 304
  331.   end
  332. end
复制代码

  1. unit U_SMotor;

  2. interface

  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, ExtCtrls, StdCtrls, ComCtrls;

  6. type
  7. TLocation = record
  8.    X: Real;
  9.    Y: Real;
  10. end;

  11.   TForm1 = class(TForm)
  12.     PageCont1: TPageControl;
  13.     Main: TTabSheet;
  14.     DataOut: TTabSheet;
  15.     Image1: TImage;
  16.     Label1: TLabel;
  17.     Edit1: TEdit;
  18.     Label2: TLabel;
  19.     Edit2: TEdit;
  20.     Timer1: TTimer;
  21.     Edit3: TEdit;
  22.     Label3: TLabel;
  23.     Edit4: TEdit;
  24.     Label4: TLabel;
  25.     Edit5: TEdit;
  26.     Label5: TLabel;
  27.     Label6: TLabel;
  28.     Edit6: TEdit;
  29.     Memo1: TMemo;
  30.     Label7: TLabel;
  31.     Edit7: TEdit;
  32.     Button1: TButton;
  33.     Button2: TButton;
  34.     SaveDialog1: TSaveDialog;
  35.     Label8: TLabel;
  36.     Edit8: TEdit;
  37.     RdGMode: TRadioGroup;
  38.     Edit9: TEdit;
  39.     Label9: TLabel;
  40.     TabSheet1: TTabSheet;
  41.     Memo2: TMemo;
  42.     procedure Timer1Timer(Sender: TObject);
  43.     procedure Button2Click(Sender: TObject);
  44.     procedure Button1Click(Sender: TObject);
  45.   private
  46.     { Private declarations }
  47.   public
  48.     { Public declarations }
  49.   end;

  50. var
  51.   Form1: TForm1;
  52.   AccT:  array[1..10000] of Real;   //加速度数组
  53.   VT:    array[1..10000] of Real;   //速度数组
  54.   Tpwm:  array[1..10000] of Real;   //Pwm周期数组
  55.   T_His: array[1..10000] of Real;   //时间数组
  56.   nT_Idea: array[1..10000] of Real; //理论的Pwm值(机器周期整数倍)
  57.   nT_Real: array[1..10000] of Real; //实际的Pwm值(机器周期整数倍)
  58.   Inc_nT:  array[1..10000] of Real; //Pwm增量(机器周期整数倍)
  59.   AccelPointMatrix: array[1..10000] of  TLocation;
  60.   SpeedPointMatrix: array[1..10000] of  TLocation;
  61.   Act_ArrayLim: integer;
  62.   FreqOsc: Real;
  63.   TOsc   : Real;
  64.   DivTOsc: Real;
  65.   TMac   : Real;
  66.   InitPwmCount: Real;
  67.   MaxSpeedPwmC: Real;
  68.   TSpeedUp:     Real;
  69.   AccK,w_v: Real;  //a(t)=k*t; or a(t)=k*sin(wt) k系数和角速度
  70.   MaxAcc:       Real;
  71.   MaxSpeed:     Real;

  72. implementation

  73. {$R *.dfm}

  74. Procedure DrawXYControlPicture;
  75. var
  76. i,j,temx,temy: integer;
  77. begin
  78.    for i:=1 to Act_ArrayLim do   //计算曲线数据
  79.      begin
  80.        AccelPointMatrix[i].X:=T_His[i]*Form1.Image1.Width /T_His[Act_ArrayLim];
  81.        AccelPointMatrix[i].Y:=AccT[i]*Form1.Image1.Height/MaxAcc;
  82.        SpeedPointMatrix[i].X:=T_His[i]*Form1.Image1.Width /T_His[Act_ArrayLim];
  83.        SpeedPointMatrix[i].Y:=VT[i]*Form1.Image1.Height/MaxSpeed;
  84.      end;
  85.    for i:=1 to Form1.Image1.Width do   //将绘图区清空
  86.      begin
  87.        Form1.Image1.Canvas.Pen.Color:=clWhite;
  88.        Form1.Image1.Canvas.MoveTo(i,0);
  89.        Form1.Image1.Canvas.Lineto(i,Form1.Image1.Height);
  90.      end;
  91.    for i:=2 to Act_ArrayLim do
  92.      begin
  93.       temx:=trunc(AccelPointMatrix[i-1].X);
  94.       temy:=Form1.Image1.Height-(trunc(AccelPointMatrix[i-1].Y*0.95)+5);
  95.       if i=1 then Form1.Image1.Canvas.MoveTo(0,0)
  96.        else  Form1.Image1.Canvas.MoveTo(temx,temy);
  97.       Form1.Image1.Canvas.Pen.Color:=clBlue;
  98.       temx:=trunc(AccelPointMatrix[i].X);
  99.       temy:=Form1.Image1.Height-(trunc(AccelPointMatrix[i].Y*0.95)+5);
  100.       Form1.Image1.Canvas.LineTo(temx,temy);
  101.       temx:=trunc(SpeedPointMatrix[i-1].X);
  102.       temy:=Form1.Image1.Height-(trunc(SpeedPointMatrix[i-1].Y*0.95)+5);
  103.       if i=1 then Form1.Image1.Canvas.MoveTo(0,0)
  104.        else  Form1.Image1.Canvas.MoveTo(temx,temy);
  105.       Form1.Image1.Canvas.Pen.Color:=clRed;
  106.       temx:=trunc(SpeedPointMatrix[i].X);
  107.       temy:=Form1.Image1.Height-(trunc(SpeedPointMatrix[i].Y*0.95)+5);
  108.       Form1.Image1.Canvas.LineTo(temx,temy);
  109.      end;
  110. end;

  111. procedure TForm1.Timer1Timer(Sender: TObject);
  112. begin
  113.   if ABS(strtofloat(Edit1.Text))>0.0001 then  Edit2.Text:=floattostr(1/strtofloat(Edit1.Text));
  114.   Edit4.Text:=floattostr(strtofloat(Edit2.Text)*strtofloat(Edit3.Text));
  115.   if   (ABS(strtofloat(Edit6.Text))>0.0001) and (ABS(strtofloat(Edit5.Text))>0.0001)
  116.     and (ABS(strtofloat(Edit6.Text)-strtofloat(Edit5.Text))>0.0001) and  (strtofloat(Edit7.Text)>0.001)
  117.   then
  118.     begin
  119.      if RdGMode.ItemIndex=0 then
  120.        Edit8.Text:=floattostr(4*(1/(strtofloat(Edit6.Text)*strtofloat(Edit3.Text))-1/(strtofloat(Edit5.Text)*strtofloat(Edit3.Text)))/((strtofloat(Edit7.Text)/1000)*(strtofloat(Edit7.Text)/1000)))
  121.       else
  122.        begin
  123.          if  ABS(strtofloat(Edit7.Text))>0.01 then
  124.            Edit9.Text:=floattostr(2*Pi/(2*strtofloat(Edit7.Text)/1000));
  125.            Edit8.Text:=floattostr((1/strtofloat(Edit6.Text)-1/strtofloat(Edit5.Text))*strtofloat(Edit9.Text)/2);
  126.        end;
  127.     end;
  128.   end;


  129. procedure TForm1.Button2Click(Sender: TObject);
  130. begin
  131.     if SaveDialog1.Execute then
  132.    begin
  133.     memo1.Lines.SaveToFile(SaveDialog1.FileName);
  134.    end;
  135. end;

  136. procedure TForm1.Button1Click(Sender: TObject);
  137. Var
  138.    LoopI: integer;
  139.    Str_Line,s_Format: String;
  140. begin
  141. MaxAcc:=0;
  142. MaxSpeed:=0;
  143. FreqOsc:=strtofloat(Edit1.text);
  144. TOsc:=1/FreqOsc;
  145. DivTOsc:=strtofloat(Edit3.text);
  146. TMac:=TOsc*DivTOsc;
  147. InitPwmCount:=strtofloat(Edit5.text);
  148. MaxSpeedPwmC:=strtofloat(Edit6.text);
  149. TSpeedUp:=strtofloat(Edit7.text);
  150. AccK:=strtofloat(Edit8.text);
  151. w_v:=strtofloat(Edit9.text);
  152. nT_Idea[1]:=InitPwmCount;    //6000
  153. Tpwm[1]:=nT_Idea[1]*TMac;    //6000/8000000
  154. T_His[1]:=Tpwm[1];
  155. nT_Real[1]:=Int(nT_Idea[1]);
  156. AccT[1]:=6E-6;
  157. VT[1]:=1/nT_Idea[1];
  158. Inc_nT[1]:=0;
  159. Str_Line:='';
  160.      s_Format:='  '+ '时间            ';
  161.      Str_Line:=Str_Line+s_Format+',';
  162.      s_Format:='  '+'加速度           ';
  163.      Str_Line:=Str_Line+s_Format+',';
  164.      s_Format:='  '+'速度             ';
  165.      Str_Line:=Str_Line+s_Format+',';
  166.      s_Format:='  '+'PWM周期   ';
  167.      Str_Line:=Str_Line+s_Format+',';
  168.      s_Format:='  '+'PWM周期变化量';
  169.      Str_Line:=Str_Line+s_Format;
  170.      Memo1.Lines.Append(Str_Line);
  171.      Str_Line:='';
  172.      s_Format:='  '+ Format('%.9f',[T_His[1]]);
  173.      Str_Line:=Str_Line+s_Format+',';
  174.      s_Format:='  '+Format('%.9f',[AccT[1]]);
  175.      Str_Line:=Str_Line+s_Format+',';
  176.      s_Format:='  '+Format('%.9f',[VT[1]]);
  177.      Str_Line:=Str_Line+s_Format+',';
  178.      s_Format:='  '+ Format('%.4e',[nT_Real[1]]);
  179.      Str_Line:=Str_Line+s_Format+',';
  180.      s_Format:='  '+ Format('%.3e',[Inc_nT[1]]);
  181.      Str_Line:=Str_Line+s_Format;
  182.      Memo1.Lines.Append(Str_Line);
  183.      Str_Line:='';
  184.      if RdGMode.ItemIndex=0 then      //三角波加速度
  185.       begin
  186.          for LoopI:=2 to 10000 do
  187.            begin
  188.              AccT[LoopI]:=AccT[LoopI-1]+AccK*Tpwm[LoopI-1];
  189.              VT[LoopI]:=VT[LoopI-1]+AccT[LoopI-1]*Tpwm[LoopI-1];
  190.              nT_Idea[LoopI]:=1/VT[LoopI];
  191.              nT_Real[LoopI]:=Int(nT_Idea[LoopI]);
  192.              Inc_nT[LoopI]:=nT_Real[LoopI-1]-nT_Real[LoopI];
  193.              Tpwm[LoopI]:=nT_Idea[LoopI]*DivTOsc/FreqOsc;
  194.              T_His[LoopI]:=T_His[LoopI-1]+Tpwm[LoopI];
  195.              s_Format:='  '+ Format('%.9f',[T_His[LoopI]]);
  196.              Str_Line:=Str_Line+s_Format+',';
  197.              s_Format:='  '+ Format('%.9f',[AccT[LoopI]]);
  198.              Str_Line:=Str_Line+s_Format+',';
  199.              s_Format:='  '+ Format('%.9f',[VT[LoopI]]);
  200.              Str_Line:=Str_Line+s_Format+',';
  201.              s_Format:='  '+ Format('%.4e',[nT_Real[LoopI]]);
  202.              Str_Line:=Str_Line+s_Format+',';
  203.              s_Format:='  '+ Format('%.3e',[Inc_nT[LoopI]]);
  204.              Str_Line:=Str_Line+s_Format;
  205.              Memo1.Lines.Append(Str_Line);
  206.              Str_Line:='';
  207.              if (T_His[LoopI]*1000)>(TSpeedUp/2) then break;
  208.              if AccT[LoopI]>MaxAcc  then  MaxAcc:=AccT[LoopI];
  209.            end;
  210.           repeat
  211.              inc(LoopI);
  212.              AccT[LoopI]:=AccT[LoopI-1]-AccK*Tpwm[LoopI-1];
  213.              VT[LoopI]:=VT[LoopI-1]+AccT[LoopI-1]*Tpwm[LoopI-1];
  214.              nT_Idea[LoopI]:=1/VT[LoopI];
  215.              nT_Real[LoopI]:=Int(nT_Idea[LoopI]);
  216.              Inc_nT[LoopI]:=nT_Real[LoopI-1]-nT_Real[LoopI];
  217.              Tpwm[LoopI]:=nT_Idea[LoopI]*DivTOsc/FreqOsc;
  218.              T_His[LoopI]:=T_His[LoopI-1]+Tpwm[LoopI];
  219.              s_Format:='  '+ Format('%.9f',[T_His[LoopI]]);
  220.              Str_Line:=Str_Line+s_Format+',';
  221.              s_Format:='  '+Format('%.9f',[AccT[LoopI]]);
  222.              Str_Line:=Str_Line+s_Format+',';
  223.              s_Format:='  '+Format('%.9f',[VT[LoopI]]);
  224.              Str_Line:=Str_Line+s_Format+',';
  225.              s_Format:='  '+ Format('%.4e',[nT_Real[LoopI]]);
  226.              Str_Line:=Str_Line+s_Format+',';
  227.              s_Format:='  '+ Format('%.3e',[Inc_nT[LoopI]]);
  228.              Str_Line:=Str_Line+s_Format;
  229.              Memo1.Lines.Append(Str_Line);
  230.              Str_Line:='';
  231.              if  VT[LoopI]>MaxSpeed then MaxSpeed:=VT[LoopI];
  232.           until  (AccT[LoopI]<0);
  233.       end
  234.      else                          //正弦波加速度
  235.       begin
  236.          for LoopI:=2 to 10000 do
  237.            begin
  238.              VT[LoopI]:=VT[LoopI-1]+AccT[LoopI-1]*Tpwm[LoopI-1];
  239.              nT_Idea[LoopI]:=1/VT[LoopI];
  240.              nT_Real[LoopI]:=Int(nT_Idea[LoopI]);
  241.              Inc_nT[LoopI]:=nT_Real[LoopI-1]-nT_Real[LoopI];
  242.              Tpwm[LoopI]:=nT_Idea[LoopI]*DivTOsc/FreqOsc;
  243.              T_His[LoopI]:=T_His[LoopI-1]+Tpwm[LoopI];
  244.              AccT[LoopI]:=AccK*SIN(w_v*T_His[LoopI]);
  245.              s_Format:='  '+ Format('%.9f',[T_His[LoopI]]);
  246.              Str_Line:=Str_Line+s_Format+',';
  247.              s_Format:='  '+ Format('%.9f',[AccT[LoopI]]);
  248.              Str_Line:=Str_Line+s_Format+',';
  249.              s_Format:='  '+ Format('%.9f',[VT[LoopI]]);
  250.              Str_Line:=Str_Line+s_Format+',';
  251.              s_Format:='  '+ Format('%.4e',[nT_Real[LoopI]]);
  252.              Str_Line:=Str_Line+s_Format+',';
  253.              s_Format:='  '+ Format('%.3e',[Inc_nT[LoopI]]);
  254.              Str_Line:=Str_Line+s_Format;
  255.              Memo1.Lines.Append(Str_Line);
  256.              Str_Line:='';
  257.              if (T_His[LoopI]*1000)>(TSpeedUp/2) then break;
  258.              if AccT[LoopI]>MaxAcc  then  MaxAcc:=AccT[LoopI];
  259.            end;
  260.           repeat
  261.              inc(LoopI);
  262.              VT[LoopI]:=VT[LoopI-1]+AccT[LoopI-1]*Tpwm[LoopI-1];
  263.              nT_Idea[LoopI]:=1/VT[LoopI];
  264.              nT_Real[LoopI]:=Int(nT_Idea[LoopI]);
  265.              Inc_nT[LoopI]:=nT_Real[LoopI-1]-nT_Real[LoopI];
  266.              Tpwm[LoopI]:=nT_Idea[LoopI]*DivTOsc/FreqOsc;
  267.              T_His[LoopI]:=T_His[LoopI-1]+Tpwm[LoopI];
  268.              AccT[LoopI]:=AccK*SIN(w_v*T_His[LoopI]);
  269.              s_Format:='  '+ Format('%.9f',[T_His[LoopI]]);
  270.              Str_Line:=Str_Line+s_Format+',';
  271.              s_Format:='  '+Format('%.9f',[AccT[LoopI]]);
  272.              Str_Line:=Str_Line+s_Format+',';
  273.              s_Format:='  '+Format('%.9f',[VT[LoopI]]);
  274.              Str_Line:=Str_Line+s_Format+',';
  275.              s_Format:='  '+ Format('%.4e',[nT_Real[LoopI]]);
  276.              Str_Line:=Str_Line+s_Format+',';
  277.              s_Format:='  '+ Format('%.3e',[Inc_nT[LoopI]]);
  278.              Str_Line:=Str_Line+s_Format;
  279.              Memo1.Lines.Append(Str_Line);
  280.              Str_Line:='';
  281.              if  VT[LoopI]>MaxSpeed then MaxSpeed:=VT[LoopI];
  282.           until  (AccT[LoopI]<0);
  283.       end;
  284.    Act_ArrayLim:=LoopI-1;
  285.   DrawXYControlPicture;
  286. end;

  287. end.
复制代码

出0入0汤圆

发表于 2017-9-7 23:22:28 | 显示全部楼层
mark一下。

出0入0汤圆

发表于 2017-9-13 12:07:41 | 显示全部楼层
正弦波 加速度 比 三角形加速度  效果好一些吧?

出0入0汤圆

发表于 2017-9-20 18:50:54 | 显示全部楼层
向大神,学习!!

出0入0汤圆

 楼主| 发表于 2017-9-20 20:57:42 来自手机 | 显示全部楼层
wind2100 发表于 2017-9-13 12:07
正弦波 加速度 比 三角形加速度  效果好一些吧?

只是略好一点,区别不大,它们两个和PID反馈调节形成的效果差别略大,但是反馈调节通用性强,不要求最大最小速度值为定值,PID反馈调节的缺点是系数整定不好的话,效果可能会很差!

出0入0汤圆

发表于 2018-6-5 16:10:36 | 显示全部楼层
mark,赞楼主!!!

出0入0汤圆

发表于 2018-6-5 16:13:26 | 显示全部楼层
谢谢分享

出0入0汤圆

发表于 2019-5-20 14:33:07 | 显示全部楼层
不知道计算量大不大

出0入0汤圆

发表于 2019-9-20 09:58:35 来自手机 | 显示全部楼层
感谢分享

出0入0汤圆

发表于 2019-11-23 21:33:53 | 显示全部楼层
您好,请问为什么:nT_Idea[LoopI]:=1/VT[LoopI];

出675入8汤圆

发表于 2020-3-29 12:18:04 | 显示全部楼层
楼主厉害

出0入0汤圆

发表于 2020-4-2 16:34:17 | 显示全部楼层
步进电机S曲线加速  跟负载 , 步进电机参数,MCU 速度, 传动的轴都有关系

出0入0汤圆

发表于 2020-8-6 14:21:26 | 显示全部楼层
学习了,谢谢

出0入0汤圆

发表于 2020-8-30 13:31:15 | 显示全部楼层
楼主伟大,谢谢了

出0入0汤圆

发表于 2021-1-14 15:53:06 | 显示全部楼层

感谢分享,速度很快哦!
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-24 15:36

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表