Yosuke Kirihata / Mbed 2 deprecated Nucleo_roomba

Dependencies:   mbed

main.cpp

Committer:
YosukeK
Date:
2015-01-20
Revision:
0:32eb0835b5a3
Child:
1:aed433d882c9

File content as of revision 0:32eb0835b5a3:

#include "mbed.h"
#include "Roomba.h"
#include "EventArg.h"

/*
 * ルンバ向けイベント引数クラス
 */
class RoombaEventArg : public EventArg
{
    typedef EventArg base;
    
    public:
        RoombaEventArg() {
            leftWheetVelocity  = 0;
            rightWheelVelocity = 0;
        };
    
    public:
        int leftWheetVelocity;
        int rightWheelVelocity;
};

//
///*
// * ルンバ制御クラスの実装クラス
// */
//class ImplRoomba : protected Roomba {
//    typedef Roomba base;
//    
//    private:
//        DigitalOut _led;//Notify()で使用するLED:ルンバ状態を通知する
//    
//    public:
//        ImplRoomba(PinName tx, PinName rx, PinName led) :Roomba(tx, rx), _led(led){
//            _led = 0;
//            Roomba::attachSerialReceiveCallback();
//        }
//        
//        /*
//         * @bref 送信メソッド
//         */
//        virtual bool ImplRoomba::send(RoombaEventArg e) {
//            _led != _led;
//            base::start();
//            base::mode(Roomba::Full);//(Roomba::Mode::Full); If write struct Mode and no name enum, Compiler say no sutable constructor conver to enum...
//            base::drive(e.leftWheetVelocity, e.rightWheelVelocity);
//            
//            return true;
//        }
//        
//        /*
//         * @bref 状態通知メソッド
//         */        
//        virtual void ImplRoomba::notify(bool result) {
//            if (result == false) {
//                _led = 1;
//            } else {
//                _led = 0;    
//            }
//        }
//        
//        /*
//         * @bref 周期タイマコールバック
//         */
//        virtual void ImplRoomba::periodicCallback(RoombaEventArg e) {
//            base::periodicCallback(e);
//        }
//};


Ticker ticker;

Serial pc(SERIAL_TX, SERIAL_RX);

//匿名クラスでオーバーライドした書き方がしたい
//Roomba
Roomba roomba(SERIAL_TX, SERIAL_RX, LED1);/* = new Roomba: IRoomba {
    bool Roomba::send() {
        //start, mode, drive
        return true;
    }
    void Roomba::notify() {}
};*/

//Ticker no kawari.
int main() {
    //ticker.attach(roomba.periodicCallback, 0.1);
    
    //TODO:Serial receive message.
    
    while (true) {
        RoombaEventArg e;
        e.leftWheetVelocity = 20;
        e.rightWheelVelocity = 30;
        
        roomba.periodicCallback(e);
        wait_ms(100);
    }
}