質問編集履歴
2
プログラムを削除しました
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
0-180,180-0度回したい
|
body
CHANGED
@@ -5,81 +5,4 @@
|
|
5
5
|
お願いします...
|
6
6
|
```
|
7
7
|
なし
|
8
|
-
```
|
8
|
+
```
|
9
|
-
|
10
|
-
###該当のソースコード
|
11
|
-
```ここに言語を入力
|
12
|
-
|
13
|
-
byte sendbuf[9];
|
14
|
-
int txden = 13; // txden はデジタルピン13
|
15
|
-
|
16
|
-
void setup() {
|
17
|
-
Serial.begin(115200);
|
18
|
-
pinMode(txden, OUTPUT);
|
19
|
-
digitalWrite(txden, LOW);
|
20
|
-
torque_on(0); //IDOのトルク ON
|
21
|
-
}
|
22
|
-
|
23
|
-
void loop() {
|
24
|
-
double theta0 = constrain(target*100, -maxAngle*100, maxAngle*100);
|
25
|
-
int theta = (int) theta0; // 目標角度を整数型に直す
|
26
|
-
sMove(90,theta,180); // パケットの生成及び送信
|
27
|
-
delay(1); // 1[ms]待つ
|
28
|
-
}
|
29
|
-
|
30
|
-
void sMove(int sld, int sPos, int sTime) {
|
31
|
-
byte sum;
|
32
|
-
|
33
|
-
// パケット生成
|
34
|
-
sendbuf[0] = 0x09; // コマンドの総データバイト数
|
35
|
-
sendbuf[1] = 0x06; // コマンド(SET POSITION)
|
36
|
-
sendbuf[2] = 0x00; // オプション
|
37
|
-
sendbuf[3] = sld; // サーボID
|
38
|
-
sendbuf[4] = 0x50;
|
39
|
-
sendbuf[5] = 0x46;
|
40
|
-
sendbuf[6] = 0xB8;
|
41
|
-
sendbuf[7] = 0x0B;
|
42
|
-
|
43
|
-
// チェックサムの計算
|
44
|
-
sum = sendbuf[0];
|
45
|
-
for (int i = 1; i < 8; i++) {
|
46
|
-
sum += sendbuf[i];
|
47
|
-
}
|
48
|
-
sendbuf[8] = lowByte(sum); // チェックサム
|
49
|
-
|
50
|
-
// 送信
|
51
|
-
digitalWrite(txden, HIGH);
|
52
|
-
Serial.write(sendbuf, 8);
|
53
|
-
Serial.flush(); //送信が終わるまで待つ
|
54
|
-
digitalWrite(txden, LOW);
|
55
|
-
}
|
56
|
-
|
57
|
-
void torque_on(int sld) {
|
58
|
-
byte sum;
|
59
|
-
|
60
|
-
// パケット生成
|
61
|
-
sendbuf[0] = 0x08; // コマンドの総データバイト数
|
62
|
-
sendbuf[1] = 0x04; // コマンド(WRITE)
|
63
|
-
sendbuf[2] = 0x00; // オプション
|
64
|
-
sendbuf[3] = sld; // サーボID
|
65
|
-
sendbuf[4] = 0xA0;
|
66
|
-
sendbuf[5] = 0x0F;
|
67
|
-
|
68
|
-
// チェックサムの計算
|
69
|
-
sum = sendbuf[0];
|
70
|
-
for (int i = 1; i < 6; i++) {
|
71
|
-
sum += sendbuf[i];
|
72
|
-
}
|
73
|
-
sendbuf[7] = lowByte(sum); // チェックサム
|
74
|
-
|
75
|
-
// 送信
|
76
|
-
digitalWrite(txden, HIGH);
|
77
|
-
Serial.write(sendbuf, 7);
|
78
|
-
Serial.flush(); //送信が終わるまで待つ
|
79
|
-
digitalWrite(txden, LOW);
|
80
|
-
}
|
81
|
-
```
|
82
|
-
|
83
|
-
###試したこと
|
84
|
-
###補足情報(言語/FW/ツール等のバージョンなど)
|
85
|
-
Arduinoです.
|
1
パケット生成とloopの中身です
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
###サーボモータ
|
1
|
+
###サーボモータの目標30度回したいです...
|
2
2
|
|
3
3
|
###一瞬動いただけで回らずにモーターがウィーンと音を出しているだけです.
|
4
4
|
どこか違うのでしょうか.
|
@@ -9,31 +9,22 @@
|
|
9
9
|
|
10
10
|
###該当のソースコード
|
11
11
|
```ここに言語を入力
|
12
|
-
|
12
|
+
|
13
13
|
byte sendbuf[9];
|
14
14
|
int txden = 13; // txden はデジタルピン13
|
15
|
-
Servo myservo;
|
16
|
-
int pos = 0;
|
17
15
|
|
18
16
|
void setup() {
|
19
17
|
Serial.begin(115200);
|
20
18
|
pinMode(txden, OUTPUT);
|
21
19
|
digitalWrite(txden, LOW);
|
22
20
|
torque_on(0); //IDOのトルク ON
|
23
|
-
myservo.attach(13, 1500, 1900);
|
24
21
|
}
|
25
22
|
|
26
23
|
void loop() {
|
24
|
+
double theta0 = constrain(target*100, -maxAngle*100, maxAngle*100);
|
25
|
+
int theta = (int) theta0; // 目標角度を整数型に直す
|
27
|
-
|
26
|
+
sMove(90,theta,180); // パケットの生成及び送信
|
28
|
-
{
|
29
|
-
myservo.write(pos);
|
30
|
-
delay(1500);
|
31
|
-
}
|
32
|
-
|
27
|
+
delay(1); // 1[ms]待つ
|
33
|
-
{
|
34
|
-
myservo.write(pos);
|
35
|
-
delay(1500);
|
36
|
-
}
|
37
28
|
}
|
38
29
|
|
39
30
|
void sMove(int sld, int sPos, int sTime) {
|
@@ -44,10 +35,10 @@
|
|
44
35
|
sendbuf[1] = 0x06; // コマンド(SET POSITION)
|
45
36
|
sendbuf[2] = 0x00; // オプション
|
46
37
|
sendbuf[3] = sld; // サーボID
|
47
|
-
sendbuf[4] =
|
38
|
+
sendbuf[4] = 0x50;
|
48
|
-
sendbuf[5] =
|
39
|
+
sendbuf[5] = 0x46;
|
49
|
-
|
40
|
+
sendbuf[6] = 0xB8;
|
50
|
-
sendbuf[7] =
|
41
|
+
sendbuf[7] = 0x0B;
|
51
42
|
|
52
43
|
// チェックサムの計算
|
53
44
|
sum = sendbuf[0];
|
@@ -71,27 +62,24 @@
|
|
71
62
|
sendbuf[1] = 0x04; // コマンド(WRITE)
|
72
63
|
sendbuf[2] = 0x00; // オプション
|
73
64
|
sendbuf[3] = sld; // サーボID
|
74
|
-
sendbuf[4] =
|
65
|
+
sendbuf[4] = 0xA0;
|
75
|
-
sendbuf[5] = 0x28; // アドレス(SERVO_TORQUE_ON)
|
76
|
-
sendbuf[
|
66
|
+
sendbuf[5] = 0x0F;
|
77
67
|
|
78
68
|
// チェックサムの計算
|
79
69
|
sum = sendbuf[0];
|
80
|
-
for (int i = 1; i <
|
70
|
+
for (int i = 1; i < 6; i++) {
|
81
71
|
sum += sendbuf[i];
|
82
72
|
}
|
83
73
|
sendbuf[7] = lowByte(sum); // チェックサム
|
84
74
|
|
85
75
|
// 送信
|
86
76
|
digitalWrite(txden, HIGH);
|
87
|
-
Serial.write(sendbuf,
|
77
|
+
Serial.write(sendbuf, 7);
|
88
78
|
Serial.flush(); //送信が終わるまで待つ
|
89
79
|
digitalWrite(txden, LOW);
|
90
80
|
}
|
91
81
|
```
|
92
82
|
|
93
83
|
###試したこと
|
94
|
-
他のPMWの方法を試しましたが同じ結果になります...
|
95
|
-
|
96
84
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
97
85
|
Arduinoです.
|