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

main.cpp

Committer:
flatbird
Date:
2015-03-13
Revision:
2:160c20430be3
Parent:
1:84af7a219830
Child:
4:4a46982a4cf2

File content as of revision 2:160c20430be3:

#include "mbed.h"
#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        "wotxwot"
#define SEC_TYPE    e_SEC_WPA2_AES
#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);
        return 1;
    }
    wait(0.5);
    
    ret = wifi.disconnect();
    if (ret != 0) {
        printf("ERROR: Failed to disconnect wifi %d\r\n", ret);
        return 1;
    }
    wait(0.3);

    wifi.connect(SSID, strlen(SSID), SEC_TYPE, SEC_KEY, strlen(SEC_KEY));
    if (ret != 0) {
        printf("ERROR: Failed to connect wifi %d\r\n", ret);
        return 1;
    }
    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();
}