你好,歡迎到訪My Blog!

最新網誌

編輯 關閉
網誌分類:K_Robot之開發 |
圖片
網誌日期:2009-06-13 00:52

o係制作servo sequencer board 既時候, 因為要同時輸出多個servo pwm signal,我地好多時都會先將 所有servo data  用 bubble sorting method 由小至大排好, 同時要用同樣方法搵出將servo output set 做 logic 0 既order, 然後將data save 係array. 當所有servo output set 做 logic 1 , 然後依照先前搵好既order同time delay 去 將servo output set 做 logic 0. 咁就大工告成

 

係visual c 測試用既program:

#include

#define array_size 8 //servo channel
#define offset 80 //servo position offset (80=500us)

unsigned int servo_flash[array_size]={0,1,2,3,4,5,6,7};//,8,9,10,11,12,13,14,15,16};   //B C D
//unsigned char hex[9]={0b00000000,0b00000001,0b00000010,0b00000100,0b00001000,0b00010000,0b00100000,0b01000000,0b10000000};


unsigned char servo_data[array_size]={254,127,3,127,5,127,9,127};//,127,13,127,76,127,200,127,127,89};  //increase content anti-clockwise,decrease content clockwise, neutral=127; ; //servo value

 

unsigned int servo_adjust[array_size];

unsigned int servo_out[array_size]; 
                                  

unsigned int servo_order[array_size];

 

unsigned char servo_orderB[array_size];
unsigned char servo_orderC[array_size];
unsigned char servo_orderD[array_size];

 


int main()
{
unsigned char i, j; 
unsigned int temp_order, temp;


      

        
        
         
        
        for (i=0;i         { 
                servo_adjust[i] = servo_data[i];
                servo_adjust[i] = servo_adjust[i];//*13/10+offset;
                servo_order[i]=servo_flash[i];
        
        }
       
   
        for (i=0;i         { 
       
                for (j = 1; j <= array_size-1; j++)
                {
                        if (servo_adjust[j] < servo_adjust[j-1])
                        { 
                        
                                temp = servo_adjust[j-1];
                                temp_order=servo_order[j-1];
                       
                                servo_adjust[j-1] = servo_adjust[j];
                                servo_order[j-1] = servo_order[j];
                       
                                servo_adjust[j] = temp;
                                servo_order[j] = temp_order;
                        }

               
                } 
               
        }
      
        servo_out[0]=servo_adjust[0]; 
       
       
        for (i = 1; i < array_size; i++)
        {
                servo_out[i]=servo_adjust[i]-servo_adjust[i-1];
       
        } 
      
   /*  
        for(i=0;i         { 
                servo_orderB[i]=hex[servo_order[i]/100 % 10];
                servo_orderC[i]=hex[servo_order[i] /10 % 10];
                servo_orderD[i]=hex[servo_order[i] % 10];
        }
       */

 


printf("servo_data\n\r\n\r");

for(i=0;i
{
printf("%5d",servo_adjust[i]);

}

 

printf("\n\r\n\rservo_order\n\r\n\r");

for(i=0;i
{
printf("order=%5d\n\r",servo_order[i]);

}


printf("\n\r\n\rservo_difference\n\r\n\r");

for(i=0;i
{
printf("d=%5d\n\r",servo_out[i]);

}

return 0;

 

 


}

將上面個加以修改,就可以放落 mcu 既program

Result;

參考資料:

http://www-ee.eng.hawaii.edu/Courses/EE150/Book/chap10/subsection2.1.2.2.html

引用(0)
  • 檢舉

    R-Wu 2009-07-07 13:17

    But how can I add the speed control to the servos?

更多網誌

網誌分類

瀏覽日期

2009
S M T W T F S
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