Simple WebSocket server to control a tank.

Dependencies:   SNICInterface_mod WebSocketServer mbed-rtos mbed PowerControl C12832

au Firefox OS WoTハッカソン on ホワイトデーで使用した、タンクを動かすプログラムです。 ゲームパッドでタンクを操縦します。

ゲームパッドは PC に接続し、ブラウザ上の Web アプリから Gamepad API で入力を取得します。 取得した入力データは WebSocket で mbed 上の WebSocket サーバに送信します。

WebSocket サーバのコードはライブラリ化したので、他のプログラムでもインポートして使えます。

使用した機材

  • LPC1768
  • Murata TypeYD
  • LPC1768 用アプリケーションボード
  • TAMIYA トラック&ホイールセット
  • TAMIYA ダブルキヤボックス(左右独立4速タイプ)
  • TAMIYA ユニバーサルプレート
  • TOSHIBA TA7291P x 2
  • その他、モバイルバッテリー、電池ボックス等

左右のモータードライバにそれぞれ LPC1768 の p12, p13 と p14, p15 のピンを割り当てていますが、必要に応じてコードを変更してください。

コントローラー側(Webアプリ)

https://github.com/chikoski/wotxwot-control

Firefox ブラウザで動作確認しています(他のブラウザでは動かないかも)。 ゲームパッドの左右のスティックの前後の操作が左右それぞれのモータの前転・後転に対応しています。

動いているところの動画

https://www.facebook.com/video.php?v=456620974491805

ハッカソンでは ARM 賞をいただきました!

(参考) au Firefox OS WoTハッカソン on ホワイトデー

http://au-fx.kddi.com/event/20150314/wot_hackathon0314.html

Committer:
flatbird
Date:
Sat Mar 14 00:14:40 2015 +0900
Revision:
7:6cfe0638b957
Parent:
6:79ecd4e53456
Child:
8:6635ca3b5a5c
add websocket data frame handling.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
flatbird 0:f7596ed7ab5c 1 #include "mbed.h"
flatbird 0:f7596ed7ab5c 2 #include "SNIC_WifiInterface.h"
flatbird 0:f7596ed7ab5c 3 #include "SNIC_Core.h"
flatbird 2:160c20430be3 4 #include "WebSocketServer.h"
flatbird 2:160c20430be3 5 #if defined(TARGET_LPC1768)
flatbird 2:160c20430be3 6 #include "PowerControl/EthernetPowerControl.h"
flatbird 2:160c20430be3 7 #endif
flatbird 0:f7596ed7ab5c 8
flatbird 2:160c20430be3 9 #define SSID "wotxwot"
flatbird 0:f7596ed7ab5c 10 #define SEC_TYPE e_SEC_WPA2_AES
flatbird 2:160c20430be3 11 #define SEC_KEY "wotpasswd"
flatbird 0:f7596ed7ab5c 12
flatbird 6:79ecd4e53456 13 static bool connectWiFi();
flatbird 6:79ecd4e53456 14
flatbird 0:f7596ed7ab5c 15 // tx, rx, cts, rts, reset, alarm=NC, baud=115200
flatbird 0:f7596ed7ab5c 16 C_SNIC_WifiInterface wifi(p9, p10, NC, NC, p30);
flatbird 0:f7596ed7ab5c 17
flatbird 0:f7596ed7ab5c 18 int main() {
flatbird 2:160c20430be3 19 #if defined(TARGET_LPC1768)
flatbird 2:160c20430be3 20 PHY_PowerDown();
flatbird 2:160c20430be3 21 #endif
flatbird 6:79ecd4e53456 22 while (!connectWiFi()) {
flatbird 6:79ecd4e53456 23 wait(3);
flatbird 0:f7596ed7ab5c 24 }
flatbird 2:160c20430be3 25
flatbird 0:f7596ed7ab5c 26 printf("WiFi connected: %s\r\n", wifi.getIPAddress());
flatbird 2:160c20430be3 27
flatbird 2:160c20430be3 28 WebSocketServer server;
flatbird 2:160c20430be3 29
flatbird 2:160c20430be3 30 if (!server.init(80)) {
flatbird 2:160c20430be3 31 printf("Failed to init server\r\n");
flatbird 2:160c20430be3 32 return 1;
flatbird 2:160c20430be3 33 }
flatbird 2:160c20430be3 34
flatbird 2:160c20430be3 35 server.run();
flatbird 0:f7596ed7ab5c 36 }
flatbird 0:f7596ed7ab5c 37
flatbird 6:79ecd4e53456 38 bool connectWiFi() {
flatbird 6:79ecd4e53456 39 printf("connecting wifi\r\n");
flatbird 6:79ecd4e53456 40
flatbird 6:79ecd4e53456 41 int ret = wifi.init();
flatbird 6:79ecd4e53456 42 if (ret != 0) {
flatbird 6:79ecd4e53456 43 printf("ERROR: Failed to init wifi %d\r\n", ret);
flatbird 6:79ecd4e53456 44 return false;
flatbird 6:79ecd4e53456 45 }
flatbird 6:79ecd4e53456 46 wait(0.5);
flatbird 6:79ecd4e53456 47
flatbird 6:79ecd4e53456 48 ret = wifi.disconnect();
flatbird 6:79ecd4e53456 49 if (ret != 0) {
flatbird 6:79ecd4e53456 50 printf("ERROR: Failed to disconnect wifi %d\r\n", ret);
flatbird 6:79ecd4e53456 51 return false;
flatbird 6:79ecd4e53456 52 }
flatbird 6:79ecd4e53456 53 wait(0.3);
flatbird 6:79ecd4e53456 54
flatbird 6:79ecd4e53456 55 wifi.connect(SSID, strlen(SSID), SEC_TYPE, SEC_KEY, strlen(SEC_KEY));
flatbird 6:79ecd4e53456 56 if (ret != 0) {
flatbird 6:79ecd4e53456 57 printf("ERROR: Failed to connect wifi %d\r\n", ret);
flatbird 6:79ecd4e53456 58 return false;
flatbird 6:79ecd4e53456 59 }
flatbird 6:79ecd4e53456 60 wait(0.5);
flatbird 6:79ecd4e53456 61
flatbird 6:79ecd4e53456 62 wifi.setIPConfig(true);
flatbird 6:79ecd4e53456 63 wait(0.5);
flatbird 6:79ecd4e53456 64
flatbird 6:79ecd4e53456 65 return true;
flatbird 6:79ecd4e53456 66 }
flatbird 6:79ecd4e53456 67