码迷,mamicode.com
首页 > 其他好文 > 详细

arduino控制dynamixel AX-12A的机械臂每个关节转45度

时间:2015-04-01 23:53:40      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:arduino

1.每个关节转45,往复循环


#include <ax12.h>

void setup()
{
  
    SetPosition(1,511); //set the position of servo # 1 to '511'
     SetPosition(2,511); 
      SetPosition(3,511);
       SetPosition(4,511); 
        SetPosition(5,400); 
    delay(100);//wait for servo to move
}

void loop()
{
        //increment from 511 to 664
          for(int i=511;i<664;i++)
         {
              //set the position of servo #1 to the current value of 'i'
              SetPosition(2,i);
              SetPosition(3,i);
              SetPosition(4,i);
              SetPosition(5,i-111);
              delay(10);//wait for servo to move
          }
          delay(1000);//wait for servo to move
          //decrement from 664 to 511
         for(int i=664;i>511;i--)
        {
            //set the position of servo #1 to the current value of 'i'
            SetPosition(2,i);
            SetPosition(3,i);
            SetPosition(4,i);
             SetPosition(5,i-111);
             delay(10);//wait for servo to move  
         }
        delay(1000);//wait for servo to move
  
}

2.之转一次,并归位

#include <ax12.h>
    
void setup()
{
  
    SetPosition(1,511); 
     SetPosition(2,511); 
      SetPosition(3,511);
       SetPosition(4,511); 
        SetPosition(5,400); 
    delay(100);
}

void loop()
{
   
        //increment from 0 to 1023
          for(int i=511;i<664;i++)
         {

              SetPosition(2,i);
              SetPosition(3,i);
              SetPosition(4,i);
              SetPosition(5,i-111);
              delay(10);
          }
          delay(1000);

         for(int i=664;i>511;i--)
        {

            SetPosition(2,i);
            SetPosition(3,i);
            SetPosition(4,i);
             SetPosition(5,i-111);
             delay(10);
         }
        delay(1000);
    }
  

总结:

开始不知到怎么跳出loop(),只能用这种方法了,不知道有没有什么语句可以直接跳出。

arduino控制dynamixel AX-12A的机械臂每个关节转45度

标签:arduino

原文地址:http://blog.csdn.net/hanshuning/article/details/44814835

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!