可以做出更多交互动作的四足八舵机机器人开发

一般来说,机器人使用的舵机越多,关节就越多,动作越灵活,就能做出更复杂的动作。

最近空闲时对机器人感了兴趣,目前做出了两足四舵机,四足四舵机,四足八舵机,复杂一些的还有4足12舵机,6足18舵机,两足6舵机8舵机等等,他们的控制原理是相通的,都可以通过控制舵机的角度来实现卧立行走等各种动作。

两足四舵机由于只有大腿和脚上的舵机,没有可以活动的膝盖,他们的原理是模仿鸭子,通过左右晃动身体,在重心切换时向前迈步,他们通过宽脚掌重心转换可以实现金鸡独立等招牌动作。两足8舵机或者6舵机是在4舵机的基础上加上了一个可以弯曲的膝盖,这使得他们可以像人一样通过抬膝提腿走路,而且完成招牌动作头顶地翻跟头,摔倒也能通过招牌动作自己爬起来。也有一种机器人是通过两轮,只需要两个舵机,使用平衡车原理,感觉也很有趣,有空时可以研究一下。这些机器人,都需要虑重心,简单的四轮就很轻松,几乎不用考虑过多的东西。

四足,六足随着舵机数增加,控制的复杂度也变大。四足十二舵机,每条腿上有三个舵机,可以做更多的动作,六足十八舵机估计复杂的是电源了,十二舵机以下还好,太多了,接线,电源都会变得十分复杂。

四足机器人算法参考了B站好几个大佬的,并且把arduio代码改成了android控制。

外形如下,每个腿两个舵机,比上一个项目多了一个舵机,除了控制脚,还可以控制腿。

我的项目都是使用了这种铝合金组装,我也没有3D打印机,可能后面会搞台,但暂时用来研究机器人,我觉得铝片要好于打印件,一是成本低,买了五十块这种铝片,B站上几乎所有的机器人不管两腿还是四腿都可以调试,二是外形开放,不需要设计电路板,买到什么就用什么,我只要把电路板用胶带沾到上面就可以使用,用完了还能取下来重复使用,这很适合我这种对硬件知之不多的人。三是我既可以使用手机做主控,也可以使用arduino做主控,还可以使用esp32做主控,可以更加灵活的做研究。

参考代码如下,主要参考B站winbuhome的代码,可以灵活的把他变成手机,esp32代码。原代码使用arduino,我在应用中把主控改成了esp32和手机。

//  --------                 --------
// |  D9    |               |  D7    |
// | joint9 |               | joint7 |
//  ----- --------     --------- -----
//       |  D8    |   |  D6    |
//       | joint8 |   | joint6 |
//        --------     --------
//       |  D2    |  |   D4    |
//       | joint2 |  |  joint4 |
//  ----- --------    --------- -----
// |  D3    |               |  D5    |
// | joint3 |               | joint5 |
//  --------                 --------
//                Front



#include <Servo.h>

// サーボ宣言
Servo joint2;  // 右前ヒップ
Servo joint3;  // 右前レッグ
Servo joint4;  // 左前ヒップ
Servo joint5;  // 左前レッグ
Servo joint6;  // 左後ヒップ
Servo joint7;  // 左後レッグ
Servo joint8;  // 右後ヒップ
Servo joint9;  // 右後レッグ
Servo neck_servo;  // ネックサーボ

// ホームポジション
int home_joint2 = 120;
int home_joint3 = 15;
int home_joint4 = 60;
int home_joint5 = 165;
int home_joint6 = 100;
int home_joint7 = 15;
int home_joint8 = 70;
int home_joint9 = 165;

#define neck_survoPin 10
#define trigPin 13
#define echoPin 12


void setup(){

  joint2.attach(2);
  joint3.attach(3);
  joint4.attach(4);
  joint5.attach(5);
  joint6.attach(6);
  joint7.attach(7);
  joint8.attach(8);
  joint9.attach(9);

  neck_servo.attach(neck_survoPin, 500, 2400);
  neck_servo.write(90);
  
  pinMode(echoPin,INPUT);
  pinMode(trigPin,OUTPUT);

  joint2.write(home_joint2);
  joint3.write(home_joint3);
  joint4.write(home_joint4);
  joint5.write(home_joint5);
  joint6.write(home_joint6);
  joint7.write(home_joint7);
  joint8.write(home_joint8);
  joint9.write(home_joint9);

  delay(3000);

  }



void loop(){

  sithome();
  delay(2000);

  stand1();
  delay(2000);

  neckrotate();
  delay(2000);

  forward(5);
  delay(2000);

  backward(5);
  delay(2000);

  rightturn(5);
  delay(2000);

  leftturn(5);
  delay(2000);

  twist();
  delay(2000);

  sithome();
  delay(2000);

  stand1();
  delay(2000);

  stand2();
  delay(2000);

  stand3();
  delay(2000);

  downaction(4);
  delay(2000);

  wink(4);
  delay(2000);
 
}




// アイドルタイム
void idle(){
  delay(100);
  }


// ホーム立ち位置
void standhome(){
  joint2.write(home_joint2);
  joint3.write(home_joint3);
  joint4.write(home_joint4);
  joint5.write(home_joint5);
  joint6.write(home_joint6);
  joint7.write(home_joint7);
  joint8.write(home_joint8);
  joint9.write(home_joint9);
}


// 腕を伸ばし地面に接地
void sithome(){
    joint2.write(135);
    joint3.write(65);
    joint4.write(45);
    joint5.write(110);
    joint6.write(135);
    joint7.write(80);
    joint8.write(45);
    joint9.write(110);
}


// 起き上がる動作1
void stand1(){
  sithome();
  joint2.write(170);
  delay(300);
  joint2.write(home_joint2);
  delay(300);
  joint4.write(10);
  delay(300);
  joint4.write(home_joint4);
  delay(300);
  joint6.write(170);
  delay(300);
  joint6.write(home_joint6);
  delay(300);
  joint8.write(10);
  delay(300);
  joint8.write(home_joint8);
  delay(300);
  
  joint3.write(home_joint3);
  joint5.write(home_joint5);
  joint7.write(home_joint7);
  joint9.write(home_joint9);
}


// 起き上がる動作2
void stand2(){
  sithome();
  joint2.write(175);
  joint4.write(5);
  joint6.write(175);
  joint8.write(5);
  delay(600);
    
  joint2.write(home_joint2);
  joint4.write(home_joint4);
  joint6.write(home_joint6);
  joint8.write(home_joint8);
  delay(600);
  
  joint3.write(home_joint3);
  joint5.write(home_joint5);
  joint7.write(home_joint7);
  joint9.write(home_joint9);
}


// 起き上がる動作3
void stand3()
{ 
  sithome();
  int i;
  int j = 90;
  int k = 90;
  joint2.write(home_joint2);
  joint4.write(home_joint4);
  joint6.write(home_joint6);
  joint8.write(home_joint8);
  for(i = 90; i < 165; i++)
  {
    joint5.write(i);
    j = j - 1;
    joint3.write(j);
    delay(20);
  }
  
  for(i = 115; i < 165; i++)
  {
    joint9.write(i);
    k = k - 1;
    joint7.write(k);
    delay(20);
  }
}


// 素早くアップダウン(ステップ数)
void downaction(unsigned int step){
  while (step-- > 0){
  sithome();
  delay(100);
  standhome();
  delay(100);
  }
}


// 手を振る
void wink(unsigned int step){
  standhome();
  joint9.write(home_joint9-30);
  
  while (step-- > 0){
  joint5.write(30);
  joint4.write(home_joint4 + 60);
  delay(300);
  joint4.write(home_joint4 - 60);
  delay(300);
  }
}


// 体をクネクネ動かす
void twist(){
  joint3.write(home_joint3);
  joint5.write(home_joint5);
  joint7.write(home_joint7);
  joint9.write(home_joint9);
  
  for(int right=90;right<170;right++){
      joint2.write(right);
      joint6.write(right);
      joint4.write(right-90);
      joint8.write(right-90);
      delay(10);
  }

   for(int right=170;right>90;right--){
      joint2.write(right);
      joint6.write(right);
      joint4.write(right-90);
      joint8.write(right-90);
      delay(10);
  }

}


// 前進(ステップ数)
void forward(unsigned int step){
  while (step-- > 0){
  joint3.write(home_joint3+30);
  joint7.write(home_joint7+30);
  delay(100);
  joint2.write(home_joint2+30);
  joint8.write(home_joint8-30);
  joint4.write(home_joint4);
  joint6.write(home_joint6);
  delay(100);
  joint3.write(home_joint3);
  joint7.write(home_joint7);
  idle();
  
  joint5.write(home_joint5-30);
  joint9.write(home_joint9-30);
  delay(100);
  joint2.write(home_joint2);
  joint8.write(home_joint8);
  joint4.write(home_joint4-30);
  joint6.write(home_joint6+30);
  delay(100);
  joint5.write(home_joint5);
  joint9.write(home_joint9);
  idle();
  }
}


// 後退(ステップ数)
void backward(unsigned int step){
  while (step-- > 0){
  joint3.write(home_joint3+30);
  joint7.write(home_joint7+30);
  delay(100);
  joint2.write(home_joint2);
  joint8.write(home_joint8);
  joint4.write(home_joint4-30);
  joint6.write(home_joint6+30);
  delay(100);
  joint3.write(home_joint3);
  joint7.write(home_joint7);
  idle();
  
  joint5.write(home_joint5-30);
  joint9.write(home_joint9-30);
  delay(100);
  joint2.write(home_joint2+30);
  joint8.write(home_joint8-30);
  joint4.write(home_joint4);
  joint6.write(home_joint6);
  delay(100);
  joint5.write(home_joint5);
  joint9.write(home_joint9);
  idle();
  }
}


// 右回り(ステップ数)
void rightturn(unsigned int step){
  while (step-- > 0){
  joint5.write(home_joint5-30);
  joint9.write(home_joint9-30);
  delay(100);
  joint2.write(home_joint2+30);
  joint8.write(home_joint8-30);
  joint4.write(home_joint4-30);
  joint6.write(home_joint6+30);
  delay(100);
  joint5.write(home_joint5);
  joint9.write(home_joint9);
  idle();
  
  joint3.write(home_joint3+30);
  joint7.write(home_joint7+30);
  delay(100);
  joint2.write(home_joint2);
  joint8.write(home_joint8);
  joint4.write(home_joint4);
  joint6.write(home_joint6);
  delay(100);
  joint3.write(home_joint3);
  joint7.write(home_joint7);
  idle();
  }
}


// 左回り(ステップ数)
void leftturn(unsigned int step){
  while (step-- > 0){
  joint3.write(home_joint3+30);
  joint7.write(home_joint7+30);
  delay(100);
  joint2.write(home_joint2+30);
  joint8.write(home_joint8-30);
  joint4.write(home_joint4-30);
  joint6.write(home_joint6+30);
  delay(100);
  joint3.write(home_joint3);
  joint7.write(home_joint7);
  idle();
  
  joint5.write(home_joint5-30);
  joint9.write(home_joint9-30);
  delay(100);
  joint2.write(home_joint2);
  joint8.write(home_joint8);
  joint4.write(home_joint4);
  joint6.write(home_joint6);
  delay(100);
  joint5.write(home_joint5);
  joint9.write(home_joint9);
  idle();
  }
}

// 首を左右に動かす(センサーはOFF)
void neckrotate(){
  int i=90;
  while(i < 150){
    neck_servo.write(i);
    i++;
    delay(5);
  }
  while(i > 30){
    neck_servo.write(i);
    i--;
    delay(5);
  }
  while(i <= 90){
    neck_servo.write(i);
    i++;
    delay(5);
  }
}


// 首を左に回す
void neck_leftrotate(){
  int i=90;
  while(i < 150){
    neck_servo.write(i);
    i++;
    delay(5);
  }
}


// 首を右に回す
void neck_rightrotate(){
  int i=90;
  while(i > 30){
    neck_servo.write(i);
    i--;
    delay(5);
  }
}


// 首ホームポジション
void neck_home(){
  neck_servo.write(90);
}

B站演示:

【四足八舵机机器人-哔哩哔哩】 https://b23.tv/sZiiKv9

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值