Yosuke Kirihata / Mbed 2 deprecated Nucleo_CaitSith_Firmware_added_delayServo

Dependencies:   mbed

Fork of Nucleo_CaitSith_Firmware by Yosuke Kirihata

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Roomba.cpp Source File

Roomba.cpp

00001 #include <mbed.h>
00002 #include "Roomba.h"
00003 
00004 /**
00005  * @bref コンストラクタ
00006  * @param tx
00007  * @param rx
00008  */
00009 Roomba::Roomba(PinName tx, PinName rx):
00010     _s(tx, rx) {
00011     _mode = Roomba::Mode::Off;
00012 }
00013 
00014 
00015 /**
00016  * @bref start
00017  * @return  true
00018  */
00019 bool Roomba::start() {
00020     
00021     _s.putc(128);
00022     
00023     return true;
00024 }
00025 
00026 
00027 /**
00028  * @bref 操作モード変更メソッド
00029  * @param 操作モード
00030  * @return true
00031  */
00032 bool Roomba::mode(Roomba::Mode::EMode m) {
00033 
00034     _s.putc(132);//Full;
00035     
00036     return true;
00037 }
00038 
00039 
00040 /**
00041  * @bref 
00042  * @param true
00043  */
00044 bool Roomba::drive (int rightWheelVelocity, int leftWheelVelocity) {
00045     
00046     bool ret = false;
00047     
00048     char command[10];
00049 
00050     //_s.printf("%d, %d", rightWheelVelocity, leftWheelVelocity);
00051     
00052     if ((-500 <= rightWheelVelocity && rightWheelVelocity <= 500)
00053         && (-500 <= leftWheelVelocity && leftWheelVelocity <= 500)) {
00054 
00055         //_s.putc('d');
00056                 
00057         command[0] = 145;
00058         command[1] = (rightWheelVelocity & 0xFF00) >> 8;  //MSB
00059         command[2] = rightWheelVelocity & 0xFF;           //LSB
00060         command[3] = (leftWheelVelocity  & 0xFF00) >> 8;  //MSB
00061         command[4] = leftWheelVelocity  & 0xFF;           //LSB
00062         command[5] = '\0';
00063         
00064         //_s.putc('e');
00065         
00066         for (int i = 0; i < 5; i++) {
00067             _s.putc(command[i]);
00068         }
00069         
00070         //_s.putc('f');
00071         
00072         ret = true;
00073     } else {
00074         //_s.putc('g');           
00075     }
00076     
00077     return ret;
00078 }
00079 
00080 /**
00081  * @bref バッテリ状態
00082  * 実装未完了
00083  * @param true
00084  * @return 
00085  * @retval 
00086  */
00087 bool Roomba::battery(int* batteryCapacity) {
00088     bool ret = false;
00089     
00090     *batteryCapacity = 100;
00091     
00092     return ret;
00093 }