공부/HW

210310 스탭모터 S curve 가속 코드 구현

강경국 2021. 3. 12. 12:52
반응형

 

 

 

 

 

스탭모터의 가속 제어가 필요하여 검색하던 중 유용한 자료 발견!

스탭모터를 처음부터 빠른 속도로 돌리면 탈조가 나서 동작하지 않는 주파수대가 된다.

이것은 스탭모터 특성 그래프 참고! ^^

 

그래서 가속을 구현해야 하기에 아래 코드를 참고하여 구현해 보았다.

 

STM32 스탭 모터 Scurve 가속 코드 구현.

www.programmersought.com/article/85951804968/

 

STM32 stepper motor S curve acceleration code implementation - Programmer Sought

Equation of the S-curveThe graph in [-5, 5] is shown below: If you want to apply this curve to the acceleration and deceleration of the stepper motor, you need to translate the equation in the XY coordinate system and pull the curve up and down: The A comp

www.programmersought.com

자세한 내용은 위 링크 자료 참고.

이 사이트에 많은 좋은 자료가 있다. ^^

 

아래의 공식을 코드로 구현한 것이다.

 

 

온라인 컴파일러로 코드를 테스트 해 보았다.

 

 

아래는 결과를 그래프로 나타내 본 것.

이것을 역으로 적용하면 가속 구간으로 적용할 수 있다.

STM32의 출력 Period 를 반대로 주어야 하는 상황이라서 데이터를 반대로 나타내었다. ^^

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Online C compiler to run C program online
#include <stdio.h>
#include <math.h>
 
int main() {
    
    float fre[100];
    unsigned short period[100];
    float  len = 100;
    float fre_max = 18000;
    float fre_min = 1900;
    float flexible = 4;
    
    int i=0, j=0;
    float deno ;
    float melo ;
    float delt = fre_max-fre_min;
    for(; i<len; i++)
    {
        melo = flexible * (i-len/2/ (len/2);
        deno = 1.0 / (1 + expf(-melo));
        //expf is a library function of exponential(e) 
        fre[i] = delt * deno + fre_min;
        period[i] = (unsigned short)(10000000.0 / fre[i]); 
        // 10000000 is the timer driver frequency
        //printf("%d\n", period[i]);
        printf("%.0f, ", fre[i]);
        j++;        
        if(j > 9) {
            printf("\n");
            j = 0;            
        }
    }
 
    printf("\n");
 
    for(i=99; i>=0; i--)
    {
        printf("%.0f, ", fre[i]);
        j++;        
        if(j > 9) {
            printf("\n");
            j = 0;            
        }
    }
    
    return 0;
}
cs

 

 

 

 

 

728x90
반응형