This repository was archived by the owner on Apr 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobotControl.ino
More file actions
158 lines (146 loc) · 3 KB
/
RobotControl.ino
File metadata and controls
158 lines (146 loc) · 3 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <vs-rc202.h>
#include "motion.hpp"
#include "number.hpp"
int sonicSensor;
void selectMotion()
{
switch(getMotionNumber())
{
case STOP:
playMotionOnce(stopMotion, 1);
break;
case rGO:
playMotionOnce(goStepRight, 3);
break;
case lGO:
playMotionOnce(goStepLeft, 3);
break;
case rBACK:
playMotionOnce(backStepRight, 3);
break;
case lBACK:
playMotionOnce(backStepLeft, 3);
break;
case RIGHT45:
playMotionOnce(turningRight45, 10);
break;
case RIGHT90:
playMotionOnce(turningRight90, 20);
break;
case LEFT45:
playMotionOnce(turningLeft45, 10);
break;
case LEFT90:
playMotionOnce(turningLeft90, 20);
break;
case rHAND:
playMotionOnce(waveRightHand, 3);
break;
case lHAND:
playMotionOnce(waveLeftHand, 3);
break;
case bHAND:
playMotionOnce(waveBothHand, 3);
break;
case rFACE:
playMotionOnce(turnRight, 2);
break;
case lFACE:
playMotionOnce(turnLeft, 2);
break;
}
}
void goSelect() //進ませる足を決定する
{
if(readServoPos(1) > -300)
{
setMotionNumber(rGO); //右足
}
else
{
setMotionNumber(lGO); //左足
}
}
void backSelect() //goSelect()とほぼ同じ
{
if(readServoPos(2) < -300)
{
setMotionNumber(rBACK);
}
else
{
setMotionNumber(lBACK);
}
}
void getCommand()
{
if(Serial.available())
{
char a = Serial.read(); //シリアルモニタからコマンドを受け取る
switch(a)
{
case 'x':
setMotionNumber(STOP);
break;
case 'w':
goSelect();
break;
case 's':
backSelect();
break;
case 'h':
setMotionNumber(RIGHT45);
break;
case 'j':
setMotionNumber(RIGHT90);
break;
case 'g':
setMotionNumber(LEFT45);
break;
case 'f':
setMotionNumber(LEFT90);
break;
case 'u':
setMotionNumber(rHAND);
break;
case 't':
setMotionNumber(lHAND);
break;
case 'y':
setMotionNumber(bHAND);
break;
case 'p':
setMotionNumber(rFACE);
break;
case 'o':
setMotionNumber(lFACE);
break;
}
Serial.print(a);
Serial.println();
Serial.println("Enter Command w, a, s, d, x");
Serial.print("$>");
}
}
void setup()
{
initLib(); //Initilize vs-rc202 library
servoEnable(1, 1);
servoEnable(2, 1);
servoEnable(3, 1);
servoEnable(4, 1);
servoEnable(5, 1);
servoEnable(6, 1);
servoEnable(9, 1);
servoEnable(10, 1);
setLedMode(9, 1);
setLedMode(10, 1);
Serial.begin(115200); //Initialize UART
}
void loop()
{
setLedBrightnessDirect(9, 0);
setLedBrightnessDirect(10, 0);
getCommand(); //コマンドを受け取ってピッコロボの動きを決める
selectMotion(); //ピッコロボを動かす
}