展示会用に簡単にしています
Dependencies: ADXL345 AigamozuControlPackets_展示会 HMC5843 ITG3200 MBed_Adafruit-GPS-Library XBee agzIDLIST mbed
Fork of Aigamozu_Robot_March by
main.cpp@44:02873ac29052, 2017-03-17 (annotated)
- Committer:
- s1200058
- Date:
- Fri Mar 17 10:12:27 2017 +0000
- Revision:
- 44:02873ac29052
- Parent:
- 43:a05f2571151f
???????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kityann | 0:daab5accfd83 | 1 | /**********************************************/ |
kityann | 0:daab5accfd83 | 2 | // |
kityann | 0:daab5accfd83 | 3 | // |
kityann | 0:daab5accfd83 | 4 | // |
kityann | 0:daab5accfd83 | 5 | // Program name: Aigamozu ROBOT |
kityann | 0:daab5accfd83 | 6 | // Author: Mineta Kizuku |
s1200058 | 38:5cd6d4964f65 | 7 | // Yokokawa |
s1200058 | 21:76e7f36df4a9 | 8 | // |
kityann | 0:daab5accfd83 | 9 | // |
kityann | 0:daab5accfd83 | 10 | /**********************************************/ |
kityann | 0:daab5accfd83 | 11 | |
kityann | 0:daab5accfd83 | 12 | /**********************************************/ |
kityann | 0:daab5accfd83 | 13 | //更新情報 |
s1200058 | 40:656858844814 | 14 | //実験用プログラム |
s1200058 | 43:a05f2571151f | 15 | //Send_Status():ジャイロ・加速度データをXbeeに送り続けます。 |
s1200058 | 43:a05f2571151f | 16 | //Get_Status():受信したデータを表示します。 |
s1200058 | 40:656858844814 | 17 | //StatusRequestCommandを送るとflagが0から1になります。 |
kityann | 0:daab5accfd83 | 18 | /**********************************************/ |
kityann | 0:daab5accfd83 | 19 | |
kityann | 0:daab5accfd83 | 20 | #include "mbed.h" |
kityann | 0:daab5accfd83 | 21 | #include "XBee.h" |
kityann | 0:daab5accfd83 | 22 | #include "MBed_Adafruit_GPS.h" |
kityann | 0:daab5accfd83 | 23 | #include "AigamozuControlPackets.h" |
kityann | 0:daab5accfd83 | 24 | #include "agzIDLIST.h" |
kityann | 0:daab5accfd83 | 25 | #include "aigamozuSetting.h" |
s1200058 | 34:9c3192c00e41 | 26 | #include "math.h" |
kityann | 0:daab5accfd83 | 27 | |
s1200058 | 39:1634312cf621 | 28 | #include "HMC5843.h" |
s1200058 | 39:1634312cf621 | 29 | #include "ADXL345.h" |
s1200058 | 39:1634312cf621 | 30 | #include "ITG3200.h" |
s1200058 | 39:1634312cf621 | 31 | #include "setting.h" |
s1200058 | 39:1634312cf621 | 32 | |
s1200058 | 39:1634312cf621 | 33 | //************ID Number***************** |
s1200058 | 44:02873ac29052 | 34 | const char MyID = 'e'; |
s1200058 | 44:02873ac29052 | 35 | const char SenderIDc = 'J'; |
s1200058 | 39:1634312cf621 | 36 | //************ID Number***************** |
s1200058 | 39:1634312cf621 | 37 | |
kityann | 0:daab5accfd83 | 38 | ///////////////////////////////////////// |
kityann | 0:daab5accfd83 | 39 | // |
kityann | 0:daab5accfd83 | 40 | //Pin Setting |
kityann | 0:daab5accfd83 | 41 | // |
kityann | 0:daab5accfd83 | 42 | ///////////////////////////////////////// |
kityann | 0:daab5accfd83 | 43 | VNH5019 agz_motorShield(p21,p22,p23,p24,p25,p26); |
s1200058 | 39:1634312cf621 | 44 | HMC5843 cmp(p9, p10); // sda, scl |
s1200058 | 39:1634312cf621 | 45 | ADXL345 acc(p9, p10); // sda, scl |
s1200058 | 39:1634312cf621 | 46 | ITG3200 gyr(p9, p10); // sda, scl |
s1200058 | 39:1634312cf621 | 47 | setting set; |
kityann | 0:daab5accfd83 | 48 | |
kityann | 0:daab5accfd83 | 49 | |
kityann | 0:daab5accfd83 | 50 | ///////////////////////////////////////// |
kityann | 0:daab5accfd83 | 51 | // |
kityann | 0:daab5accfd83 | 52 | //Connection Setting |
kityann | 0:daab5accfd83 | 53 | // |
kityann | 0:daab5accfd83 | 54 | ///////////////////////////////////////// |
kityann | 0:daab5accfd83 | 55 | |
kityann | 0:daab5accfd83 | 56 | //Serial Connect Setting: PC <--> mbed |
kityann | 0:daab5accfd83 | 57 | Serial pc(USBTX, USBRX); |
kityann | 0:daab5accfd83 | 58 | |
kityann | 0:daab5accfd83 | 59 | //Serial Connect Setting: GPS <--> mbed |
kityann | 0:daab5accfd83 | 60 | Serial * gps_Serial; |
kityann | 0:daab5accfd83 | 61 | |
kityann | 0:daab5accfd83 | 62 | //Serial Connect Setting: XBEE <--> mbed |
kityann | 0:daab5accfd83 | 63 | XBee xbee(p13,p14); |
kityann | 0:daab5accfd83 | 64 | ZBRxResponse zbRx = ZBRxResponse(); |
kityann | 0:daab5accfd83 | 65 | |
kityann | 0:daab5accfd83 | 66 | //set up GPS module |
kityann | 0:daab5accfd83 | 67 | |
kityann | 0:daab5accfd83 | 68 | //set up AigamozuControlPackets library |
kityann | 0:daab5accfd83 | 69 | AigamozuControlPackets agz(agz_motorShield); |
kityann | 0:daab5accfd83 | 70 | |
kityann | 0:daab5accfd83 | 71 | |
s1200058 | 38:5cd6d4964f65 | 72 | |
s1200058 | 34:9c3192c00e41 | 73 | int change = 0; |
s1200058 | 39:1634312cf621 | 74 | //values x,y,z |
s1200058 | 39:1634312cf621 | 75 | int readings[3]; |
s1200058 | 39:1634312cf621 | 76 | //ID Buffer |
s1200058 | 39:1634312cf621 | 77 | char buffer[3]; |
s1200058 | 39:1634312cf621 | 78 | |
s1200058 | 39:1634312cf621 | 79 | int flag =0; |
s1200058 | 34:9c3192c00e41 | 80 | |
s1200058 | 2:886fac7f4399 | 81 | ///////////////////////////////////////// |
s1200058 | 2:886fac7f4399 | 82 | // |
s1200058 | 2:886fac7f4399 | 83 | //Plus Speed |
s1200058 | 2:886fac7f4399 | 84 | // |
s1200058 | 2:886fac7f4399 | 85 | //MNUAL_MODEの時にスピードを変える |
s1200058 | 2:886fac7f4399 | 86 | ///////////////////////////////////////// |
s1200058 | 2:886fac7f4399 | 87 | void Plus_Speed(uint8_t *packetdata){ |
s1200058 | 2:886fac7f4399 | 88 | |
s1200058 | 2:886fac7f4399 | 89 | if(agz.nowMode == MANUAL_MODE){ |
s1200058 | 2:886fac7f4399 | 90 | agz.changeSpeed(packetdata); |
s1200058 | 2:886fac7f4399 | 91 | } |
s1200058 | 2:886fac7f4399 | 92 | |
s1200058 | 2:886fac7f4399 | 93 | } |
kityann | 0:daab5accfd83 | 94 | |
kityann | 24:698d4e920d33 | 95 | |
s1200058 | 2:886fac7f4399 | 96 | |
s1200058 | 2:886fac7f4399 | 97 | ///////////////////////////////////////// |
s1200058 | 2:886fac7f4399 | 98 | // |
s1200058 | 2:886fac7f4399 | 99 | //New Mode |
s1200058 | 2:886fac7f4399 | 100 | // |
s1200058 | 2:886fac7f4399 | 101 | ///////////////////////////////////////// |
s1200058 | 2:886fac7f4399 | 102 | |
s1200058 | 2:886fac7f4399 | 103 | void New_Mode(uint8_t *packetdata){ |
s1200058 | 2:886fac7f4399 | 104 | |
s1200058 | 19:a806105ba365 | 105 | //bool result; |
s1200058 | 20:eee8ac8d1788 | 106 | agz.changeMode(packetdata); |
s1200058 | 2:886fac7f4399 | 107 | |
s1200058 | 2:886fac7f4399 | 108 | } |
kityann | 1:b2b950b916ce | 109 | |
kityann | 0:daab5accfd83 | 110 | |
kityann | 0:daab5accfd83 | 111 | ///////////////////////////////////////// |
kityann | 0:daab5accfd83 | 112 | // |
s1200058 | 39:1634312cf621 | 113 | //Send_Status |
s1200058 | 39:1634312cf621 | 114 | // |
s1200058 | 39:1634312cf621 | 115 | //リクエストがきたとき、自分の位置情報などを返信する |
s1200058 | 39:1634312cf621 | 116 | ///////////////////////////////////////// |
s1200058 | 39:1634312cf621 | 117 | void Send_Status(void){ |
s1200058 | 39:1634312cf621 | 118 | |
s1200058 | 39:1634312cf621 | 119 | XBeeAddress64 send_Address; |
s1200058 | 39:1634312cf621 | 120 | if(SenderIDc == '0'){ |
s1200058 | 39:1634312cf621 | 121 | send_Address = manager_Address; |
s1200058 | 39:1634312cf621 | 122 | } |
s1200058 | 39:1634312cf621 | 123 | if(SenderIDc >= 'A' && SenderIDc <= 'Z'){ |
s1200058 | 39:1634312cf621 | 124 | send_Address = robot_Address[SenderIDc - 'A']; |
s1200058 | 39:1634312cf621 | 125 | } |
s1200058 | 39:1634312cf621 | 126 | if(SenderIDc >= 'a' && SenderIDc <= 'z'){ |
s1200058 | 39:1634312cf621 | 127 | send_Address = base_Address[SenderIDc - 'a']; |
s1200058 | 39:1634312cf621 | 128 | } |
s1200058 | 39:1634312cf621 | 129 | //send normal data |
s1200058 | 39:1634312cf621 | 130 | //Create GPS Infomation Packet |
s1200058 | 41:55539183dbb0 | 131 | agz.SendDataCommand(MyID,SenderIDc,(int16_t)set.agzGyr.x,(int16_t)set.agzGyr.y, (int16_t)set.agzGyr.z, (int16_t)set.agzAcc.x,(int16_t)set.agzAcc.y,(int16_t)set.agzAcc.z, (uint8_t)flag); |
s1200058 | 44:02873ac29052 | 132 | |
s1200058 | 39:1634312cf621 | 133 | //debug |
s1200058 | 41:55539183dbb0 | 134 | printf("%d %d %d %d %d %d\n\r",(int16_t)set.agzGyr.x,(int16_t)set.agzGyr.y, (int16_t)set.agzGyr.z, (int16_t)set.agzAcc.x, (int16_t)set.agzAcc.y, (int16_t)set.agzAcc.z); |
s1200058 | 41:55539183dbb0 | 135 | for(int i = 0; i < 24; i++){ |
s1200058 | 39:1634312cf621 | 136 | printf("%d ", agz.packetData[i]); |
s1200058 | 39:1634312cf621 | 137 | } |
s1200058 | 39:1634312cf621 | 138 | printf("\n\r"); |
s1200058 | 39:1634312cf621 | 139 | |
s1200058 | 39:1634312cf621 | 140 | //Select Destination |
s1200058 | 39:1634312cf621 | 141 | ZBTxRequest tx64request(send_Address,agz.packetData,agz.getPacketLength()); |
s1200058 | 39:1634312cf621 | 142 | //Send -> Base |
s1200058 | 39:1634312cf621 | 143 | xbee.send(tx64request); |
s1200058 | 39:1634312cf621 | 144 | } |
s1200058 | 39:1634312cf621 | 145 | |
s1200058 | 42:69b4cb31aafc | 146 | void Get_Status(uint8_t *packetdata){ |
s1200058 | 42:69b4cb31aafc | 147 | |
s1200058 | 42:69b4cb31aafc | 148 | agz.GetData(&packetdata[8],&packetdata[10],&packetdata[12],&packetdata[14],&packetdata[16],&packetdata[18]); |
s1200058 | 42:69b4cb31aafc | 149 | printf("%d, %d, %d, %d, %d, %d, %d\n\r", agz.r_gx, agz.r_gy, agz.r_gz, agz.r_ax, agz.r_ay, agz.r_az, packetdata[20]); |
s1200058 | 42:69b4cb31aafc | 150 | |
s1200058 | 42:69b4cb31aafc | 151 | } |
s1200058 | 42:69b4cb31aafc | 152 | |
s1200058 | 44:02873ac29052 | 153 | void Send_Mannual(char c){ |
s1200058 | 44:02873ac29052 | 154 | |
s1200058 | 44:02873ac29052 | 155 | XBeeAddress64 send_Address; |
s1200058 | 44:02873ac29052 | 156 | if(SenderIDc == '0'){ |
s1200058 | 44:02873ac29052 | 157 | send_Address = manager_Address; |
s1200058 | 44:02873ac29052 | 158 | } |
s1200058 | 44:02873ac29052 | 159 | if(SenderIDc >= 'A' && SenderIDc <= 'Z'){ |
s1200058 | 44:02873ac29052 | 160 | send_Address = robot_Address[SenderIDc - 'A']; |
s1200058 | 44:02873ac29052 | 161 | } |
s1200058 | 44:02873ac29052 | 162 | if(SenderIDc >= 'a' && SenderIDc <= 'z'){ |
s1200058 | 44:02873ac29052 | 163 | send_Address = base_Address[SenderIDc - 'a']; |
s1200058 | 44:02873ac29052 | 164 | } |
s1200058 | 44:02873ac29052 | 165 | //send normal data |
s1200058 | 44:02873ac29052 | 166 | //Create GPS Infomation Packet |
s1200058 | 44:02873ac29052 | 167 | agz.CreateManualCommand(MyID,SenderIDc,c); |
s1200058 | 44:02873ac29052 | 168 | //Select Destination |
s1200058 | 44:02873ac29052 | 169 | ZBTxRequest tx64request(send_Address,agz.packetData,agz.getPacketLength()); |
s1200058 | 44:02873ac29052 | 170 | //Send -> Base |
s1200058 | 44:02873ac29052 | 171 | xbee.send(tx64request); |
s1200058 | 44:02873ac29052 | 172 | } |
s1200058 | 44:02873ac29052 | 173 | |
s1200058 | 44:02873ac29052 | 174 | |
s1200058 | 42:69b4cb31aafc | 175 | |
s1200058 | 39:1634312cf621 | 176 | ///////////////////////////////////////// |
s1200058 | 39:1634312cf621 | 177 | // |
s1200058 | 39:1634312cf621 | 178 | //Update Sensor |
s1200058 | 39:1634312cf621 | 179 | // |
s1200058 | 39:1634312cf621 | 180 | ///////////////////////////////////////// |
s1200058 | 39:1634312cf621 | 181 | |
s1200058 | 39:1634312cf621 | 182 | void update_gyro() { |
s1200058 | 39:1634312cf621 | 183 | set.setGyr((int16_t)gyr.getGyroX(),(int16_t)gyr.getGyroY(),(int16_t)gyr.getGyroZ()); |
s1200058 | 39:1634312cf621 | 184 | } |
s1200058 | 39:1634312cf621 | 185 | |
s1200058 | 39:1634312cf621 | 186 | void update_accel() { |
s1200058 | 39:1634312cf621 | 187 | acc.getOutput(readings); |
s1200058 | 39:1634312cf621 | 188 | set.setAcc(((int16_t)readings[0]), ((int16_t)readings[1]),((int16_t)readings[2])); |
s1200058 | 39:1634312cf621 | 189 | } |
s1200058 | 39:1634312cf621 | 190 | |
s1200058 | 39:1634312cf621 | 191 | void update_cmp(){ |
s1200058 | 39:1634312cf621 | 192 | cmp.readData(readings); |
s1200058 | 39:1634312cf621 | 193 | set.setCmp(((int16_t)readings[0]), ((int16_t)readings[1]),((int16_t)readings[2])); |
s1200058 | 39:1634312cf621 | 194 | } |
s1200058 | 39:1634312cf621 | 195 | |
s1200058 | 39:1634312cf621 | 196 | ///////////////////////////////////////// |
s1200058 | 39:1634312cf621 | 197 | // |
s1200058 | 39:1634312cf621 | 198 | //Set Up Sensor |
s1200058 | 39:1634312cf621 | 199 | // |
s1200058 | 39:1634312cf621 | 200 | ///////////////////////////////////////// |
s1200058 | 39:1634312cf621 | 201 | void setup_cmp() { |
s1200058 | 39:1634312cf621 | 202 | // Continuous mode, , 10Hz measurement rate. |
s1200058 | 39:1634312cf621 | 203 | // HMC5843_CONTINUOUS, HMC5843_10HZ_NORMAL HMC5843_1_0GA |
s1200058 | 39:1634312cf621 | 204 | cmp.setDefault(); |
s1200058 | 39:1634312cf621 | 205 | // Wait some time(Need at least 5ms) |
s1200058 | 39:1634312cf621 | 206 | wait(0.1); |
s1200058 | 39:1634312cf621 | 207 | cmp.getAddress(buffer); |
s1200058 | 39:1634312cf621 | 208 | pc.printf("cmp Id=%c%c%c \n\r",buffer[0],buffer[1],buffer[2]); |
s1200058 | 39:1634312cf621 | 209 | } |
s1200058 | 39:1634312cf621 | 210 | |
s1200058 | 39:1634312cf621 | 211 | bool setup_acc() { |
s1200058 | 39:1634312cf621 | 212 | // These are here to test whether any of the initialization fails. It will print the failure |
s1200058 | 39:1634312cf621 | 213 | if (acc.setPowerControl(0x00)) { |
s1200058 | 39:1634312cf621 | 214 | pc.printf("acc: didn't intitialize power control\n"); |
s1200058 | 39:1634312cf621 | 215 | return false; |
s1200058 | 39:1634312cf621 | 216 | } |
s1200058 | 39:1634312cf621 | 217 | wait(.001); |
s1200058 | 39:1634312cf621 | 218 | |
s1200058 | 39:1634312cf621 | 219 | //Full resolution, +/-16g, 4mg/LSB. |
s1200058 | 39:1634312cf621 | 220 | //if(acc.setDataFormatControl(0x0B)){ |
s1200058 | 39:1634312cf621 | 221 | if(acc.setDataFormatControl(0x09)){ // +/- 4G |
s1200058 | 39:1634312cf621 | 222 | pc.printf("didn't set data format\n"); |
s1200058 | 39:1634312cf621 | 223 | return false; } |
s1200058 | 39:1634312cf621 | 224 | wait(.001); |
s1200058 | 39:1634312cf621 | 225 | |
s1200058 | 39:1634312cf621 | 226 | //200Hz data rate. |
s1200058 | 39:1634312cf621 | 227 | if(acc.setDataRate(ADXL345_200HZ)){ |
s1200058 | 39:1634312cf621 | 228 | pc.printf("didn't set data rate\n"); |
s1200058 | 39:1634312cf621 | 229 | return false; } |
s1200058 | 39:1634312cf621 | 230 | wait(.001); |
s1200058 | 39:1634312cf621 | 231 | |
s1200058 | 39:1634312cf621 | 232 | //Measurement mode. |
s1200058 | 39:1634312cf621 | 233 | if(acc.setPowerControl(MeasurementMode)) { |
s1200058 | 39:1634312cf621 | 234 | pc.printf("didn't set the power control to measurement\n"); |
s1200058 | 39:1634312cf621 | 235 | return false; } |
s1200058 | 39:1634312cf621 | 236 | |
s1200058 | 39:1634312cf621 | 237 | pc.printf("Acc Id=%x \n\r", acc.getDeviceID()); |
s1200058 | 39:1634312cf621 | 238 | pc.printf("%c" ,13,10); |
s1200058 | 39:1634312cf621 | 239 | return true; |
s1200058 | 39:1634312cf621 | 240 | } |
s1200058 | 39:1634312cf621 | 241 | |
s1200058 | 39:1634312cf621 | 242 | void setup_gyr() { |
s1200058 | 39:1634312cf621 | 243 | //Set highest bandwidth. |
s1200058 | 39:1634312cf621 | 244 | gyr.setLpBandwidth(LPFBW_42HZ); |
s1200058 | 39:1634312cf621 | 245 | pc.printf("Gyro Id=%x \n\r", gyr.getWhoAmI()); |
s1200058 | 39:1634312cf621 | 246 | pc.printf("%c" ,13,10); |
s1200058 | 39:1634312cf621 | 247 | } |
s1200058 | 39:1634312cf621 | 248 | |
s1200058 | 39:1634312cf621 | 249 | ///////////////////////////////////////// |
s1200058 | 39:1634312cf621 | 250 | // |
kityann | 0:daab5accfd83 | 251 | //Main Processing |
kityann | 0:daab5accfd83 | 252 | // |
kityann | 0:daab5accfd83 | 253 | ///////////////////////////////////////// |
kityann | 0:daab5accfd83 | 254 | int main() { |
kityann | 0:daab5accfd83 | 255 | //start up time |
kityann | 0:daab5accfd83 | 256 | wait(3); |
kityann | 0:daab5accfd83 | 257 | //set pc frequency to 57600bps |
kityann | 0:daab5accfd83 | 258 | pc.baud(PC_BAUD_RATE); |
kityann | 0:daab5accfd83 | 259 | //set xbee frequency to 57600bps |
kityann | 0:daab5accfd83 | 260 | xbee.begin(XBEE_BAUD_RATE); |
kityann | 0:daab5accfd83 | 261 | |
kityann | 0:daab5accfd83 | 262 | |
kityann | 0:daab5accfd83 | 263 | //GPS setting |
kityann | 0:daab5accfd83 | 264 | gps_Serial = new Serial(p28,p27); |
kityann | 0:daab5accfd83 | 265 | Adafruit_GPS myGPS(gps_Serial); |
s1200058 | 39:1634312cf621 | 266 | setup_acc(); |
s1200058 | 39:1634312cf621 | 267 | setup_gyr(); |
s1200058 | 38:5cd6d4964f65 | 268 | |
s1200058 | 3:1ac506a96fd6 | 269 | Timer auto_Timer; |
s1200058 | 42:69b4cb31aafc | 270 | const int auto_Time = 200; //refresh time in ms |
kityann | 0:daab5accfd83 | 271 | |
s1200058 | 29:524684a1198f | 272 | wait_ms(2000); |
kityann | 0:daab5accfd83 | 273 | |
kityann | 0:daab5accfd83 | 274 | //interrupt start |
s1200058 | 3:1ac506a96fd6 | 275 | auto_Timer.start(); |
s1200058 | 30:7f6ebe2121d9 | 276 | agz.Move_Timer.start(); |
s1200058 | 29:524684a1198f | 277 | printf("start\n"); |
kityann | 1:b2b950b916ce | 278 | |
kityann | 0:daab5accfd83 | 279 | |
kityann | 0:daab5accfd83 | 280 | while (true) { |
kityann | 0:daab5accfd83 | 281 | |
kityann | 0:daab5accfd83 | 282 | //Check Xbee Buffer Available |
kityann | 0:daab5accfd83 | 283 | xbee.readPacket(); |
s1200058 | 39:1634312cf621 | 284 | |
s1200058 | 39:1634312cf621 | 285 | update_accel(); |
s1200058 | 39:1634312cf621 | 286 | update_gyro(); |
kityann | 0:daab5accfd83 | 287 | |
kityann | 0:daab5accfd83 | 288 | if (xbee.getResponse().isAvailable()) { |
kityann | 0:daab5accfd83 | 289 | xbee.getResponse().getZBRxResponse(zbRx); |
kityann | 0:daab5accfd83 | 290 | uint8_t *buf = zbRx.getFrameData(); |
kityann | 0:daab5accfd83 | 291 | |
kityann | 0:daab5accfd83 | 292 | if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) { |
kityann | 0:daab5accfd83 | 293 | xbee.getResponse().getZBRxResponse(zbRx); |
kityann | 0:daab5accfd83 | 294 | uint8_t *buf = zbRx.getFrameData();//フレームデータを格納する |
s1200058 | 21:76e7f36df4a9 | 295 | char Command_type = agz.checkCommnadType(buf);//コマンドタイプを取得する |
s1200058 | 42:69b4cb31aafc | 296 | uint8_t *buf1 = &buf[11]; |
kityann | 0:daab5accfd83 | 297 | |
kityann | 0:daab5accfd83 | 298 | //Check Command Type |
kityann | 0:daab5accfd83 | 299 | switch(Command_type){ |
kityann | 0:daab5accfd83 | 300 | //Get Request command |
s1200058 | 2:886fac7f4399 | 301 | case MANUAL:{ |
s1200058 | 12:48ef69b4f0e4 | 302 | Plus_Speed(buf); |
s1200058 | 2:886fac7f4399 | 303 | break; |
s1200058 | 2:886fac7f4399 | 304 | } |
s1200058 | 39:1634312cf621 | 305 | case STATUS_REQUEST:{ |
kityann | 0:daab5accfd83 | 306 | break; |
kityann | 0:daab5accfd83 | 307 | } |
s1200058 | 2:886fac7f4399 | 308 | case CHANGE_MODE:{ |
s1200058 | 12:48ef69b4f0e4 | 309 | New_Mode(buf); |
s1200058 | 42:69b4cb31aafc | 310 | if(flag == 0){ |
s1200058 | 42:69b4cb31aafc | 311 | flag = 1; |
s1200058 | 42:69b4cb31aafc | 312 | } |
s1200058 | 42:69b4cb31aafc | 313 | else{ |
s1200058 | 42:69b4cb31aafc | 314 | flag = 0; |
s1200058 | 42:69b4cb31aafc | 315 | } |
s1200058 | 2:886fac7f4399 | 316 | break; |
s1200058 | 2:886fac7f4399 | 317 | } |
s1200058 | 42:69b4cb31aafc | 318 | //status受信後 |
kityann | 1:b2b950b916ce | 319 | case RECEIVE_STATUS:{ |
s1200058 | 42:69b4cb31aafc | 320 | Get_Status(buf1); |
kityann | 1:b2b950b916ce | 321 | break; |
kityann | 1:b2b950b916ce | 322 | } |
kityann | 0:daab5accfd83 | 323 | default:{ |
kityann | 0:daab5accfd83 | 324 | break; |
kityann | 0:daab5accfd83 | 325 | } |
kityann | 0:daab5accfd83 | 326 | }//endswitch |
kityann | 0:daab5accfd83 | 327 | }//endifZB_RX_RESPONSE |
kityann | 0:daab5accfd83 | 328 | }//endifisAvailable |
s1200058 | 38:5cd6d4964f65 | 329 | |
s1200058 | 42:69b4cb31aafc | 330 | //200msごとにstatus送信 |
s1200058 | 41:55539183dbb0 | 331 | if(auto_Timer.read_ms() >= auto_Time){ |
s1200058 | 44:02873ac29052 | 332 | |
s1200058 | 44:02873ac29052 | 333 | char c; |
s1200058 | 44:02873ac29052 | 334 | auto_Timer.reset(); |
s1200058 | 44:02873ac29052 | 335 | if(pc.readable()) { |
s1200058 | 44:02873ac29052 | 336 | c = pc.getc(); |
s1200058 | 44:02873ac29052 | 337 | Send_Mannual(c); |
s1200058 | 44:02873ac29052 | 338 | pc.printf("send mannual command\n\r"); |
s1200058 | 44:02873ac29052 | 339 | } |
s1200058 | 42:69b4cb31aafc | 340 | //Send_Status(); |
s1200058 | 29:524684a1198f | 341 | } |
s1200058 | 29:524684a1198f | 342 | |
s1200058 | 29:524684a1198f | 343 | } |
s1200058 | 34:9c3192c00e41 | 344 | |
kityann | 0:daab5accfd83 | 345 | } |