{"id":420,"date":"2022-08-31T18:20:17","date_gmt":"2022-08-31T09:20:17","guid":{"rendered":"https:\/\/www.cs.k.tsukuba-tech.ac.jp\/labo\/koba\/?page_id=420"},"modified":"2022-08-31T18:31:35","modified_gmt":"2022-08-31T09:31:35","slug":"double_servo","status":"publish","type":"page","link":"https:\/\/www.cs.k.tsukuba-tech.ac.jp\/labo\/koba\/research\/sigaci_ws_in_hi2022\/double_servo\/","title":{"rendered":"\u304a\u307e\u3051\uff1a2\u3064\u306e\u30b5\u30fc\u30dc\u3092\u52d5\u304b\u3059"},"content":{"rendered":"\n<p>2\u3064\u30b5\u30fc\u30dc\u3092\u52d5\u304b\u305d\u3046\u3068\u3059\u308b\u3068\u3001ESP32\u5074\u3082\u5de5\u592b\u3057\u306a\u3051\u308c\u3070\u3044\u3051\u307e\u305b\u3093\u3088\u306d\u3002\u3068\u308a\u3042\u3048\u305a\u4e00\u3064\u306e\u30b5\u30f3\u30d7\u30eb\u3068\u3057\u3066\u4ee5\u4e0b\u306b\u4f8b\u3092\u6319\u3052\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>BluetoothSerial SerialBT;\nServo servo_s;            \/\/ \u30b5\u30fc\u30dc\u5909\u6570\uff11\u3064\u76ee\nServo servo_e;            \/\/ \u30b5\u30fc\u30dc\u5909\u6570\uff12\u3064\u76ee\n\nchar receivedChar;\nString inData;\nconst int SERVO_S = 12;   \/\/ \u30b5\u30fc\u30dc\u30e2\u30fc\u30bf\u30fc\u30d4\u30f3\uff11\u3064\u76ee\nconst int SERVO_E = 13;   \/\/ \u30b5\u30fc\u30dc\u30e2\u30fc\u30bf\u30fc\u30d4\u30f3\uff12\u3064\u76ee\u3002\u9069\u5b9c\u81ea\u5206\u306e\u74b0\u5883\u306b\u5408\u308f\u305b\u307e\u3059\nString angle&#91;2];             \/\/\u89d2\u5ea6\u683c\u7d0d\u7528\u306e\u914d\u5217\n\nint split(String data, char delimiter, String *dst){\/\/data\u306e\u6587\u5b57\u5217\u304b\u3089delimiter\u3067\u5206\u3051\u3066dst\u306e\u914d\u5217\u306b\u683c\u7d0d\u3059\u308b\u95a2\u6570\n    int index = 0;\n    int arraySize = (sizeof(data)\/sizeof((data)&#91;0]));  \n    int datalength = data.length();\n    dst&#91;0]=\"\";dst&#91;1]=\"\";\n    for (int i = 0; i &lt; datalength; i++) {\n        char tmp = data.charAt(i);\n        if ( tmp == delimiter ) {\n            index++;\n            if ( index &gt; (arraySize - 1)) return -1;\n        }\n        else dst&#91;index] += tmp;\n    }\n    return (index + 1);\/\/\u30c7\u30fc\u30bf\u6570\u3092\u30ea\u30bf\u30fc\u30f3\n}\n\nvoid setup() {\n  SerialBT.begin(\"double_servo\");\n  servo_s.attach(SERVO_S);  \/\/ \u30b5\u30fc\u30dc\u30e2\u30fc\u30bf\u30fc\u306e\u5236\u5fa1\u30d4\u30f3\u8a2d\u5b9a\n  servo_e.attach(SERVO_E);  \/\/ \u30b5\u30fc\u30dc\u30e2\u30fc\u30bf\u30fc\u306e\u5236\u5fa1\u30d4\u30f3\u8a2d\u5b9a\n  Serial.begin(115200);\n}\n\nvoid loop() {\n  while (SerialBT.available() ) {\n    receivedChar =(char)SerialBT.read();\n    inData += receivedChar;\n    if (receivedChar == '\\n'){\n      Serial.print(inData);\n      int index = split(inData, ',', angle);\n      Serial.print(angle&#91;0]);\n      Serial.print(',');\n      Serial.println(angle&#91;1]);\n      if(angle&#91;0]==\"s\"){\n        servo_s.write(angle&#91;1].toInt());\n      }else if(angle&#91;0]==\"e\"){\n        servo_e.write(angle&#91;1].toInt());\n      }\n      delay(20);\n      inData = \"\";\n    }\n  }\n}\n<\/code><\/pre>\n\n\n\n<p>\u9001\u4fe1\u3059\u308b\u5074\u306f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ser.write(str.encode(\"s,\"+str(int(angle_s))+\"\\n\"))\n        ser.write(str.encode(\"e,\"+str(int(angle_e))+\"\\n\"))\r\n<\/code><\/pre>\n\n\n\n<p>\u306e\u3088\u3046\u306b\u6587\u5b57\u5217\u3092\u8ffd\u52a0\u3057\u305f\u6570\u5b57\u3092\u9001\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2\u3064\u30b5\u30fc\u30dc\u3092\u52d5\u304b\u305d\u3046\u3068\u3059\u308b\u3068\u3001ESP32\u5074\u3082\u5de5\u592b\u3057\u306a\u3051\u308c\u3070\u3044\u3051\u307e\u305b\u3093\u3088\u306d\u3002\u3068\u308a\u3042\u3048\u305a\u4e00\u3064\u306e\u30b5\u30f3\u30d7\u30eb\u3068\u3057\u3066\u4ee5\u4e0b\u306b\u4f8b\u3092\u6319\u3052\u307e\u3059\u3002 \u9001\u4fe1\u3059\u308b\u5074\u306f \u306e\u3088\u3046\u306b\u6587\u5b57\u5217\u3092\u8ffd\u52a0\u3057\u305f\u6570\u5b57\u3092\u9001\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":247,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-420","page","type-page","status-publish","hentry","post-preview"],"_links":{"self":[{"href":"https:\/\/www.cs.k.tsukuba-tech.ac.jp\/labo\/koba\/wp-json\/wp\/v2\/pages\/420","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cs.k.tsukuba-tech.ac.jp\/labo\/koba\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.cs.k.tsukuba-tech.ac.jp\/labo\/koba\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.cs.k.tsukuba-tech.ac.jp\/labo\/koba\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cs.k.tsukuba-tech.ac.jp\/labo\/koba\/wp-json\/wp\/v2\/comments?post=420"}],"version-history":[{"count":3,"href":"https:\/\/www.cs.k.tsukuba-tech.ac.jp\/labo\/koba\/wp-json\/wp\/v2\/pages\/420\/revisions"}],"predecessor-version":[{"id":426,"href":"https:\/\/www.cs.k.tsukuba-tech.ac.jp\/labo\/koba\/wp-json\/wp\/v2\/pages\/420\/revisions\/426"}],"up":[{"embeddable":true,"href":"https:\/\/www.cs.k.tsukuba-tech.ac.jp\/labo\/koba\/wp-json\/wp\/v2\/pages\/247"}],"wp:attachment":[{"href":"https:\/\/www.cs.k.tsukuba-tech.ac.jp\/labo\/koba\/wp-json\/wp\/v2\/media?parent=420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}