質問編集履歴
2
プログラムを削除しました
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
0-180,180-0度回したい
|
test
CHANGED
@@ -13,157 +13,3 @@
|
|
13
13
|
なし
|
14
14
|
|
15
15
|
```
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
###該当のソースコード
|
20
|
-
|
21
|
-
```ここに言語を入力
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
byte sendbuf[9];
|
26
|
-
|
27
|
-
int txden = 13; // txden はデジタルピン13
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
void setup() {
|
32
|
-
|
33
|
-
Serial.begin(115200);
|
34
|
-
|
35
|
-
pinMode(txden, OUTPUT);
|
36
|
-
|
37
|
-
digitalWrite(txden, LOW);
|
38
|
-
|
39
|
-
torque_on(0); //IDOのトルク ON
|
40
|
-
|
41
|
-
}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
void loop() {
|
46
|
-
|
47
|
-
double theta0 = constrain(target*100, -maxAngle*100, maxAngle*100);
|
48
|
-
|
49
|
-
int theta = (int) theta0; // 目標角度を整数型に直す
|
50
|
-
|
51
|
-
sMove(90,theta,180); // パケットの生成及び送信
|
52
|
-
|
53
|
-
delay(1); // 1[ms]待つ
|
54
|
-
|
55
|
-
}
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
void sMove(int sld, int sPos, int sTime) {
|
60
|
-
|
61
|
-
byte sum;
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
// パケット生成
|
66
|
-
|
67
|
-
sendbuf[0] = 0x09; // コマンドの総データバイト数
|
68
|
-
|
69
|
-
sendbuf[1] = 0x06; // コマンド(SET POSITION)
|
70
|
-
|
71
|
-
sendbuf[2] = 0x00; // オプション
|
72
|
-
|
73
|
-
sendbuf[3] = sld; // サーボID
|
74
|
-
|
75
|
-
sendbuf[4] = 0x50;
|
76
|
-
|
77
|
-
sendbuf[5] = 0x46;
|
78
|
-
|
79
|
-
sendbuf[6] = 0xB8;
|
80
|
-
|
81
|
-
sendbuf[7] = 0x0B;
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
// チェックサムの計算
|
86
|
-
|
87
|
-
sum = sendbuf[0];
|
88
|
-
|
89
|
-
for (int i = 1; i < 8; i++) {
|
90
|
-
|
91
|
-
sum += sendbuf[i];
|
92
|
-
|
93
|
-
}
|
94
|
-
|
95
|
-
sendbuf[8] = lowByte(sum); // チェックサム
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
// 送信
|
100
|
-
|
101
|
-
digitalWrite(txden, HIGH);
|
102
|
-
|
103
|
-
Serial.write(sendbuf, 8);
|
104
|
-
|
105
|
-
Serial.flush(); //送信が終わるまで待つ
|
106
|
-
|
107
|
-
digitalWrite(txden, LOW);
|
108
|
-
|
109
|
-
}
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
void torque_on(int sld) {
|
114
|
-
|
115
|
-
byte sum;
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
// パケット生成
|
120
|
-
|
121
|
-
sendbuf[0] = 0x08; // コマンドの総データバイト数
|
122
|
-
|
123
|
-
sendbuf[1] = 0x04; // コマンド(WRITE)
|
124
|
-
|
125
|
-
sendbuf[2] = 0x00; // オプション
|
126
|
-
|
127
|
-
sendbuf[3] = sld; // サーボID
|
128
|
-
|
129
|
-
sendbuf[4] = 0xA0;
|
130
|
-
|
131
|
-
sendbuf[5] = 0x0F;
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
// チェックサムの計算
|
136
|
-
|
137
|
-
sum = sendbuf[0];
|
138
|
-
|
139
|
-
for (int i = 1; i < 6; i++) {
|
140
|
-
|
141
|
-
sum += sendbuf[i];
|
142
|
-
|
143
|
-
}
|
144
|
-
|
145
|
-
sendbuf[7] = lowByte(sum); // チェックサム
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
// 送信
|
150
|
-
|
151
|
-
digitalWrite(txden, HIGH);
|
152
|
-
|
153
|
-
Serial.write(sendbuf, 7);
|
154
|
-
|
155
|
-
Serial.flush(); //送信が終わるまで待つ
|
156
|
-
|
157
|
-
digitalWrite(txden, LOW);
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
```
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
###試したこと
|
166
|
-
|
167
|
-
###補足情報(言語/FW/ツール等のバージョンなど)
|
168
|
-
|
169
|
-
Arduinoです.
|
1
パケット生成とloopの中身です
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
###サーボモータ
|
1
|
+
###サーボモータの目標30度回したいです...
|
2
2
|
|
3
3
|
|
4
4
|
|
@@ -20,15 +20,11 @@
|
|
20
20
|
|
21
21
|
```ここに言語を入力
|
22
22
|
|
23
|
-
|
23
|
+
|
24
24
|
|
25
25
|
byte sendbuf[9];
|
26
26
|
|
27
27
|
int txden = 13; // txden はデジタルピン13
|
28
|
-
|
29
|
-
Servo myservo;
|
30
|
-
|
31
|
-
int pos = 0;
|
32
28
|
|
33
29
|
|
34
30
|
|
@@ -42,33 +38,19 @@
|
|
42
38
|
|
43
39
|
torque_on(0); //IDOのトルク ON
|
44
40
|
|
45
|
-
myservo.attach(13, 1500, 1900);
|
46
|
-
|
47
41
|
}
|
48
42
|
|
49
43
|
|
50
44
|
|
51
45
|
void loop() {
|
52
46
|
|
53
|
-
|
47
|
+
double theta0 = constrain(target*100, -maxAngle*100, maxAngle*100);
|
54
48
|
|
55
|
-
|
49
|
+
int theta = (int) theta0; // 目標角度を整数型に直す
|
56
50
|
|
57
|
-
|
51
|
+
sMove(90,theta,180); // パケットの生成及び送信
|
58
52
|
|
59
|
-
delay(1500);
|
60
|
-
|
61
|
-
}
|
62
|
-
|
63
|
-
|
53
|
+
delay(1); // 1[ms]待つ
|
64
|
-
|
65
|
-
{
|
66
|
-
|
67
|
-
myservo.write(pos);
|
68
|
-
|
69
|
-
delay(1500);
|
70
|
-
|
71
|
-
}
|
72
54
|
|
73
55
|
}
|
74
56
|
|
@@ -90,13 +72,13 @@
|
|
90
72
|
|
91
73
|
sendbuf[3] = sld; // サーボID
|
92
74
|
|
93
|
-
sendbuf[4] =
|
75
|
+
sendbuf[4] = 0x50;
|
94
76
|
|
95
|
-
sendbuf[5] =
|
77
|
+
sendbuf[5] = 0x46;
|
96
78
|
|
97
|
-
|
79
|
+
sendbuf[6] = 0xB8;
|
98
80
|
|
99
|
-
sendbuf[7] =
|
81
|
+
sendbuf[7] = 0x0B;
|
100
82
|
|
101
83
|
|
102
84
|
|
@@ -144,11 +126,9 @@
|
|
144
126
|
|
145
127
|
sendbuf[3] = sld; // サーボID
|
146
128
|
|
147
|
-
sendbuf[4] = 0x0
|
129
|
+
sendbuf[4] = 0xA0;
|
148
130
|
|
149
|
-
sendbuf[5] = 0x28; // アドレス(SERVO_TORQUE_ON)
|
150
|
-
|
151
|
-
sendbuf[
|
131
|
+
sendbuf[5] = 0x0F;
|
152
132
|
|
153
133
|
|
154
134
|
|
@@ -156,7 +136,7 @@
|
|
156
136
|
|
157
137
|
sum = sendbuf[0];
|
158
138
|
|
159
|
-
for (int i = 1; i <
|
139
|
+
for (int i = 1; i < 6; i++) {
|
160
140
|
|
161
141
|
sum += sendbuf[i];
|
162
142
|
|
@@ -170,7 +150,7 @@
|
|
170
150
|
|
171
151
|
digitalWrite(txden, HIGH);
|
172
152
|
|
173
|
-
Serial.write(sendbuf,
|
153
|
+
Serial.write(sendbuf, 7);
|
174
154
|
|
175
155
|
Serial.flush(); //送信が終わるまで待つ
|
176
156
|
|
@@ -184,10 +164,6 @@
|
|
184
164
|
|
185
165
|
###試したこと
|
186
166
|
|
187
|
-
他のPMWの方法を試しましたが同じ結果になります...
|
188
|
-
|
189
|
-
|
190
|
-
|
191
167
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
192
168
|
|
193
169
|
Arduinoです.
|