2026年1月11日 星期日

[OTTO Biped]OTTO雙足機器人藍芽通訊

 

Web 控制器:https://chengminlin2.github.io/OttoBLE/

範例一、前後退控制


Arduino程式:
 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
#include <Otto.h>
Otto Otto;
#include <SoftwareSerial.h>
SoftwareSerial mySerialBT(11,12);


String data = "";

#define LeftLeg 2 // left leg pin, servo[0]
#define RightLeg 3 // right leg pin, servo[1]
#define LeftFoot 4 // left foot pin, servo[2]
#define RightFoot 5 // right foot pin, servo[3]
#define Buzzer 13 //buzzer pin


void setup() {
  Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer);
Otto.home();

  mySerialBT.begin(9600);


}

void loop() {
    if (mySerialBT.available()) {
      data = mySerialBT.readStringUntil('\n');
      if (data.indexOf("forward") >= 0) {
        Otto.walk(1,1000,1); // FORWARD
      }
      if (data.indexOf("backward") >= 0) {
        Otto.walk(1,1000,1); // FORWARD
      }
    }

}

範例二、持續前進和後退

Arduino程式:

 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
49
50
51
52
53
#include <Otto.h>
Otto Otto;
#include <SoftwareSerial.h>
SoftwareSerial mySerialBT(11,12);


String data = "";
int command = 0;

#define LeftLeg 2 // left leg pin, servo[0]
#define RightLeg 3 // right leg pin, servo[1]
#define LeftFoot 4 // left foot pin, servo[2]
#define RightFoot 5 // right foot pin, servo[3]
#define Buzzer 13 //buzzer pin


void setup() {
  Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer);
Otto.home();

  mySerialBT.begin(9600);


}

void loop() {
    if (mySerialBT.available()) {
      data = mySerialBT.readStringUntil('\n');
      if (data.indexOf("stop") >= 0) {
        command = 0;
      }
      if (data.indexOf("forward") >= 0) {
        command = 1;
      }
      if (data.indexOf("backward") >= 0) {
        command = 2;
      }
    }
    // stop
    // forward
    switch (command) {
    case 0:
      Otto.home();
      break;
     case 1:
      Otto.walk(1,1000,1); // FORWARD
      break;
     case 2:
      Otto.walk(1,1000,-1); // BACKWARD
      break;
    }

}

沒有留言:

張貼留言