
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
Revision 2:160c20430be3, committed 2015-03-13
- Comitter:
- flatbird
- Date:
- Fri Mar 13 15:52:18 2015 +0900
- Parent:
- 1:84af7a219830
- Child:
- 3:cf908b263ade
- Commit message:
- added to call WebSocketServer from main.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Mar 13 14:36:43 2015 +0900 +++ b/main.cpp Fri Mar 13 15:52:18 2015 +0900 @@ -2,17 +2,26 @@ #include "SNIC_WifiInterface.h" #include "SNIC_Core.h" #include "SNIC_UartMsgUtil.h" +#include "WebSocketServer.h" +#if defined(TARGET_LPC1768) +#include "PowerControl/EthernetPowerControl.h" +#endif -#define SSID "" +#define SSID "wotxwot" #define SEC_TYPE e_SEC_WPA2_AES -#define SEC_KEY "" +#define SEC_KEY "wotpasswd" // tx, rx, cts, rts, reset, alarm=NC, baud=115200 C_SNIC_WifiInterface wifi(p9, p10, NC, NC, p30); int main() { +#if defined(TARGET_LPC1768) + PHY_PowerDown(); +#endif int ret = 0; + printf("connecting wifi\r\n"); + ret = wifi.init(); if (ret != 0) { printf("ERROR: Failed to init wifi %d\r\n", ret); @@ -34,6 +43,18 @@ } wait(0.5); + wifi.setIPConfig(true); + wait(0.5); + printf("WiFi connected: %s\r\n", wifi.getIPAddress()); + + WebSocketServer server; + + if (!server.init(80)) { + printf("Failed to init server\r\n"); + return 1; + } + + server.run(); }