Wallbot_CaaS
Dependencies: MPU6050 mbed PID
Fork of BLE_MPU6050_test6_challenge_sb by
main.cpp@6:9fd87d75a24b, 2018-05-17 (annotated)
- Committer:
- c201075
- Date:
- Thu May 17 02:30:58 2018 +0000
- Revision:
- 6:9fd87d75a24b
- Parent:
- 5:eeabd90b6d62
- Child:
- 7:5aa479fe5d0b
??????????????RPM????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:8468a4403fea | 1 | #include "mbed.h" |
jksoft | 0:8468a4403fea | 2 | #include "MPU6050.h" |
jksoft | 0:8468a4403fea | 3 | #include "BLEDevice.h" |
jksoft | 0:8468a4403fea | 4 | #include "wallbotble.h" |
c201075 | 6:9fd87d75a24b | 5 | //#include "RCBController.h" |
c201075 | 6:9fd87d75a24b | 6 | //#include "Adafruit_LEDBackpack.h" |
c201075 | 6:9fd87d75a24b | 7 | //#include "Adafruit_GFX.h" |
c201075 | 6:9fd87d75a24b | 8 | //#include "pictLIB.h" |
jksoft | 0:8468a4403fea | 9 | |
jksoft | 0:8468a4403fea | 10 | |
c201075 | 4:6b4563aaee2c | 11 | #define DEBUG |
jksoft | 0:8468a4403fea | 12 | |
jksoft | 0:8468a4403fea | 13 | Serial pc(USBTX, USBRX); |
jksoft | 0:8468a4403fea | 14 | BLEDevice ble; |
jksoft | 0:8468a4403fea | 15 | MPU6050 mpu; |
jksoft | 0:8468a4403fea | 16 | wallbotble wb; |
jksoft | 0:8468a4403fea | 17 | |
jksoft | 0:8468a4403fea | 18 | myI2C i2c(P0_22,P0_21); |
jksoft | 0:8468a4403fea | 19 | |
jksoft | 0:8468a4403fea | 20 | /**************************************************************************/ |
jksoft | 0:8468a4403fea | 21 | /*! |
jksoft | 0:8468a4403fea | 22 | @brief Program entry point |
jksoft | 0:8468a4403fea | 23 | */ |
jksoft | 0:8468a4403fea | 24 | /**************************************************************************/ |
jksoft | 0:8468a4403fea | 25 | int main(void) |
jksoft | 0:8468a4403fea | 26 | { |
jksoft | 0:8468a4403fea | 27 | |
c201075 | 4:6b4563aaee2c | 28 | int16_t ax, ay, az; |
c201075 | 4:6b4563aaee2c | 29 | int16_t gx, gy, gz; |
c201075 | 4:6b4563aaee2c | 30 | |
c201075 | 4:6b4563aaee2c | 31 | //mpu.initialize(); |
jksoft | 0:8468a4403fea | 32 | |
c201075 | 4:6b4563aaee2c | 33 | pc.baud(115200); |
c201075 | 4:6b4563aaee2c | 34 | pc.printf("Start\n\r"); |
jksoft | 0:8468a4403fea | 35 | |
jksoft | 0:8468a4403fea | 36 | |
c201075 | 6:9fd87d75a24b | 37 | //ble.init(); |
c201075 | 4:6b4563aaee2c | 38 | //イベント時のコールバック関数 |
c201075 | 6:9fd87d75a24b | 39 | //ble.onConnection(onConnected); |
c201075 | 6:9fd87d75a24b | 40 | //ble.onDisconnection(onDisconnected); |
c201075 | 6:9fd87d75a24b | 41 | //ble.onDataWritten(onDataWritten); |
c201075 | 4:6b4563aaee2c | 42 | |
jksoft | 0:8468a4403fea | 43 | /* setup advertising */ |
c201075 | 4:6b4563aaee2c | 44 | //クラシックBTはサポートせず、BLEデバイスとして認識してもらう |
c201075 | 6:9fd87d75a24b | 45 | //ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); |
c201075 | 4:6b4563aaee2c | 46 | //デバイスがセントラルに接続可能であることを設定 |
c201075 | 6:9fd87d75a24b | 47 | //ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
c201075 | 4:6b4563aaee2c | 48 | //LOCAL NAMEの設定、BLEでは終端記号は不要なので-1する |
c201075 | 6:9fd87d75a24b | 49 | //ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,(const uint8_t *)"mbed WallbotBLE", sizeof("mbed WallbotBLE") - 1); |
c201075 | 4:6b4563aaee2c | 50 | //16Bit短縮UUIDの設定 |
c201075 | 6:9fd87d75a24b | 51 | //ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS,(const uint8_t *)RCBController_service_uuid, sizeof(RCBController_service_uuid)); |
c201075 | 4:6b4563aaee2c | 52 | //Advertiseパケットの送信周期 |
c201075 | 6:9fd87d75a24b | 53 | //ble.setAdvertisingInterval(160); /* 100ms; in multiples of 0.625ms. */ |
jksoft | 0:8468a4403fea | 54 | |
c201075 | 4:6b4563aaee2c | 55 | //サービスの登録 |
c201075 | 6:9fd87d75a24b | 56 | //ble.addService(RCBControllerService); |
c201075 | 4:6b4563aaee2c | 57 | |
c201075 | 4:6b4563aaee2c | 58 | //Advertizeの開始 |
c201075 | 6:9fd87d75a24b | 59 | //ble.startAdvertising(); |
jksoft | 0:8468a4403fea | 60 | |
c201075 | 5:eeabd90b6d62 | 61 | //wb.move(30,30); |
c201075 | 5:eeabd90b6d62 | 62 | pc.printf("auto calibrate start\n\r"); |
c201075 | 5:eeabd90b6d62 | 63 | wb.auto_calibrate(); |
c201075 | 6:9fd87d75a24b | 64 | #ifdef DEBUG |
c201075 | 5:eeabd90b6d62 | 65 | for(int i = 0 ; i < 4 ; i++) |
c201075 | 5:eeabd90b6d62 | 66 | { |
c201075 | 5:eeabd90b6d62 | 67 | pc.printf("(%d,%d) ",wb._calibratedMinimum[i],wb._calibratedMaximum[i]); |
c201075 | 5:eeabd90b6d62 | 68 | } |
c201075 | 5:eeabd90b6d62 | 69 | pc.printf("\n\rauto calibrate end\n\r"); |
c201075 | 6:9fd87d75a24b | 70 | #endif |
jksoft | 0:8468a4403fea | 71 | |
c201075 | 5:eeabd90b6d62 | 72 | #if 0 //エンコーダキャリブレーション用コード |
c201075 | 4:6b4563aaee2c | 73 | BusIn enc(P0_8,P0_10,P0_6,P0_7); |
c201075 | 4:6b4563aaee2c | 74 | enc.mode(PullNone); |
c201075 | 4:6b4563aaee2c | 75 | while(1){ |
c201075 | 4:6b4563aaee2c | 76 | char c = enc.read(); |
c201075 | 4:6b4563aaee2c | 77 | pc.putc(c); |
c201075 | 4:6b4563aaee2c | 78 | wait_ms(10); |
c201075 | 4:6b4563aaee2c | 79 | } |
c201075 | 4:6b4563aaee2c | 80 | #endif |
c201075 | 5:eeabd90b6d62 | 81 | |
jksoft | 0:8468a4403fea | 82 | while (true) { |
c201075 | 4:6b4563aaee2c | 83 | //mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); |
c201075 | 4:6b4563aaee2c | 84 | #ifdef DEBUG |
c201075 | 6:9fd87d75a24b | 85 | pc.printf("Pulse(%d,%d) RPM(%.2f,%.2f) ",wb._left_pulses,wb._right_pulses,wb.left_rpm,wb.right_rpm); |
c201075 | 5:eeabd90b6d62 | 86 | pc.printf("LinePos:%d ",wb.GetLinePosition()); |
c201075 | 6:9fd87d75a24b | 87 | //pc.printf("calib(%d,%d,%d,%d)",wb.sensor_values[0],wb.sensor_values[1],wb.sensor_values[2],wb.sensor_values[3]); |
c201075 | 4:6b4563aaee2c | 88 | //pc.printf("MPU6050(%d;%d;%d;%d;%d;%d)\n\r",ax,ay,az,gx,gy,gz); |
c201075 | 5:eeabd90b6d62 | 89 | pc.printf("\n\r"); |
c201075 | 4:6b4563aaee2c | 90 | wait_ms(10); |
c201075 | 4:6b4563aaee2c | 91 | #endif |
jksoft | 0:8468a4403fea | 92 | } |
jksoft | 0:8468a4403fea | 93 | } |
jksoft | 0:8468a4403fea | 94 |