forward

Dependencies:   VNH5019

Fork of AigamozuControlPackets by aigamozu

Committer:
s1200058
Date:
Wed May 13 06:28:14 2015 +0000
Revision:
20:fec2d6dec897
Parent:
19:13b24b50800e
Child:
21:be08b5c100fe
2015/05/13

Who changed what in which revision?

UserRevisionLine numberNew contents of line
m5171135 0:2b8b56ac7a82 1 #include "AigamozuControlPackets.h"
m5171135 0:2b8b56ac7a82 2 #include "VNH5019.h"
m5171135 0:2b8b56ac7a82 3
m5171135 6:f164a716be46 4 //////////////////////////////
m5171135 6:f164a716be46 5 // Init //
m5171135 6:f164a716be46 6 //////////////////////////////
m5171135 5:3f51eeb5aedc 7 AigamozuControlPackets::AigamozuControlPackets(VNH5019 agzSheild):_agzSheild(agzSheild){
m5171135 2:3f2d4f53ceed 8 packetData = new uint8_t[50];
m5171135 2:3f2d4f53ceed 9 packetLength = 0;
m5171135 7:200ce5c1f486 10 //--init base point--//
kityann 11:4d71c9cc3b4a 11 //basePoint[0].x = 13956.2655;
kityann 11:4d71c9cc3b4a 12 //basePoint[0].y = 3731.5060;
kityann 11:4d71c9cc3b4a 13 basePoint[0].x = 100.2655;
kityann 11:4d71c9cc3b4a 14 basePoint[0].y = 30.5060;
m5171135 7:200ce5c1f486 15
kityann 11:4d71c9cc3b4a 16 //basePoint[1].x = 13956.2898;
kityann 11:4d71c9cc3b4a 17 //basePoint[1].y = 3731.5055;
kityann 11:4d71c9cc3b4a 18 basePoint[1].x = 200.2898;
kityann 11:4d71c9cc3b4a 19 basePoint[1].y = 30.5055;
m5171135 7:200ce5c1f486 20
kityann 11:4d71c9cc3b4a 21 //basePoint[2].x = 13956.2915;
kityann 11:4d71c9cc3b4a 22 //basePoint[2].y = 3731.5245;
kityann 11:4d71c9cc3b4a 23 basePoint[2].x = 200.2915;
kityann 11:4d71c9cc3b4a 24 basePoint[2].y = 40.5245;
m5171135 7:200ce5c1f486 25
kityann 11:4d71c9cc3b4a 26 //basePoint[3].x = 13956.2680;
kityann 11:4d71c9cc3b4a 27 //basePoint[3].y = 3731.5248;
kityann 11:4d71c9cc3b4a 28 basePoint[3].x = 100.2680;
kityann 11:4d71c9cc3b4a 29 basePoint[3].y = 40.5248;
kityann 17:a6fa8cc96d94 30
kityann 17:a6fa8cc96d94 31 agzPoint.x=0;agzPoint.y=0;
kityann 17:a6fa8cc96d94 32 agzPointKalman.x=0;agzPointKalman.y=0;
kityann 17:a6fa8cc96d94 33 agzCov.x=0;agzCov.y=0;
m5171135 2:3f2d4f53ceed 34 }
m5171135 2:3f2d4f53ceed 35
kityann 17:a6fa8cc96d94 36 //////////////////////////////
kityann 17:a6fa8cc96d94 37 // get関数
kityann 17:a6fa8cc96d94 38 //////////////////////////////
kityann 17:a6fa8cc96d94 39 double AigamozuControlPackets::get_agzPoint_lati(){
kityann 17:a6fa8cc96d94 40 return agzPoint.x;
kityann 17:a6fa8cc96d94 41 }
kityann 17:a6fa8cc96d94 42 double AigamozuControlPackets::get_agzPoint_longi(){
kityann 17:a6fa8cc96d94 43 return agzPoint.y;
kityann 17:a6fa8cc96d94 44 }
kityann 17:a6fa8cc96d94 45 double AigamozuControlPackets::get_agzPointKalman_lati(){
kityann 17:a6fa8cc96d94 46 return agzPointKalman.x;
kityann 17:a6fa8cc96d94 47 }
kityann 17:a6fa8cc96d94 48 double AigamozuControlPackets::get_agzPointKalman_longi(){
kityann 17:a6fa8cc96d94 49 return agzPointKalman.y;
kityann 17:a6fa8cc96d94 50 }
kityann 17:a6fa8cc96d94 51 double AigamozuControlPackets::get_agzCov_lati(){
kityann 17:a6fa8cc96d94 52 return agzCov.x;
kityann 17:a6fa8cc96d94 53 }
kityann 17:a6fa8cc96d94 54 double AigamozuControlPackets::get_agzCov_longi(){
kityann 17:a6fa8cc96d94 55 return agzCov.y;
kityann 17:a6fa8cc96d94 56 }
s1200058 20:fec2d6dec897 57
s1200058 20:fec2d6dec897 58 double AigamozuControlPackets::get_basePoint_lati(int i){
s1200058 20:fec2d6dec897 59 return basePoint[i].x;
s1200058 20:fec2d6dec897 60 }
s1200058 20:fec2d6dec897 61 double AigamozuControlPackets::get_basePoint_longi(int i){
s1200058 20:fec2d6dec897 62 return basePoint[i].y;
s1200058 20:fec2d6dec897 63 }
kityann 19:13b24b50800e 64 double AigamozuControlPackets::get_basePointKalman_lati(int i){
kityann 19:13b24b50800e 65 return basePointKalman[i].x;
kityann 19:13b24b50800e 66 }
kityann 19:13b24b50800e 67 double AigamozuControlPackets::get_basePointKalman_longi(int i){
kityann 19:13b24b50800e 68 return basePointKalman[i].y;
kityann 19:13b24b50800e 69 }
kityann 19:13b24b50800e 70
m5171135 2:3f2d4f53ceed 71 //////////////////////////////
kityann 17:a6fa8cc96d94 72 // set関数
kityann 17:a6fa8cc96d94 73 //////////////////////////////
kityann 17:a6fa8cc96d94 74 void AigamozuControlPackets::set_agzCov(double cov_lati,double cov_longi){
kityann 17:a6fa8cc96d94 75 agzCov.x = cov_lati;
kityann 17:a6fa8cc96d94 76 agzCov.y = cov_longi;
kityann 17:a6fa8cc96d94 77 }
s1200058 20:fec2d6dec897 78
s1200058 20:fec2d6dec897 79 void AigamozuControlPackets::set_agzAutoGPS(){
s1200058 20:fec2d6dec897 80 agzPoint.x += 0.00001;
s1200058 20:fec2d6dec897 81 //agzPoint.y += 0.001;
s1200058 20:fec2d6dec897 82 }
s1200058 20:fec2d6dec897 83
s1200058 20:fec2d6dec897 84 void AigamozuControlPackets::set_agzKalmanGPS(){
s1200058 20:fec2d6dec897 85 agzPointKalman.x += 0.00001;
s1200058 20:fec2d6dec897 86 //agzPointKalman.y += 0.001;
s1200058 20:fec2d6dec897 87
s1200058 20:fec2d6dec897 88 }
kityann 17:a6fa8cc96d94 89 //////////////////////////////
m5171135 2:3f2d4f53ceed 90 // Controller/Base -> Robot //
m5171135 2:3f2d4f53ceed 91 //////////////////////////////
m5171135 4:04dadf67ecb6 92
m5171135 2:3f2d4f53ceed 93 void AigamozuControlPackets::createManualCommad(uint8_t fromID,uint8_t toID,uint8_t directionL,uint8_t pwmL,uint8_t directionR, uint8_t pwmR)
m5171135 2:3f2d4f53ceed 94 {
m5171135 2:3f2d4f53ceed 95 uint8_t tmp[] = {'A','G','S','M','F',fromID,'T',toID,'L',directionL,pwmL,'R',directionR,pwmR,'A','G','E'};
m5171135 2:3f2d4f53ceed 96 for(int i = 0; i < RECEIVE_STATUS_COMMNAD_LENGTH; ++i) packetData[i] = tmp[i];
m5171135 2:3f2d4f53ceed 97 packetLength = RECEIVE_STATUS_COMMNAD_LENGTH;
m5171135 2:3f2d4f53ceed 98 }
m5171135 2:3f2d4f53ceed 99
s1200058 9:4f675487f06b 100 void AigamozuControlPackets::createRequestCommand(uint8_t fromID,uint8_t toID)
m5171135 0:2b8b56ac7a82 101 {
m5171135 2:3f2d4f53ceed 102 uint8_t tmp[] = {'A','G','S','S','F',fromID,'T',toID,'A','G','E'};
m5171135 2:3f2d4f53ceed 103 for(int i = 0; i < REQUEST_COMMNAD_LENGTH; ++i) packetData[i] = tmp[i];
m5171135 2:3f2d4f53ceed 104 packetLength = REQUEST_COMMNAD_LENGTH;
m5171135 2:3f2d4f53ceed 105 }
m5171135 0:2b8b56ac7a82 106
m5171135 2:3f2d4f53ceed 107 void AigamozuControlPackets::createChangeModeCommand(uint8_t fromID,uint8_t toID,uint8_t,MODE mode){
m5171135 2:3f2d4f53ceed 108 uint8_t tmp[] = {'A','G','S','C','F',fromID,'T',toID,mode,'A','G','E'};
m5171135 2:3f2d4f53ceed 109 for(int i = 0; i < CHANGE_MODE_COMMAND_LENGTH; ++i) packetData[i] = tmp[i];
m5171135 2:3f2d4f53ceed 110 packetLength = CHANGE_MODE_COMMAND_LENGTH;
m5171135 2:3f2d4f53ceed 111 }
m5171135 2:3f2d4f53ceed 112
m5171135 2:3f2d4f53ceed 113
m5171135 2:3f2d4f53ceed 114 //////////////////////////////
m5171135 2:3f2d4f53ceed 115 // Robot -> Controller/Base //
m5171135 2:3f2d4f53ceed 116 //////////////////////////////
m5171135 2:3f2d4f53ceed 117
kityann 17:a6fa8cc96d94 118 void AigamozuControlPackets::createReceiveStatusCommand(uint8_t fromID,uint8_t toID,double latitude,double longitude,double latitudeKalman,double longitudeKalman,double covarLati,double covarLongi)
m5171135 2:3f2d4f53ceed 119 {
kityann 17:a6fa8cc96d94 120 UNION_double_char latitude_data,longitude_data, latitudeKalman_data, longitudeKalman_data;
kityann 17:a6fa8cc96d94 121 UNION_double_char covarLati_data,covarLongi_data;
m5171135 0:2b8b56ac7a82 122
kityann 17:a6fa8cc96d94 123 latitude_data.double_value=latitude;
kityann 17:a6fa8cc96d94 124 longitude_data.double_value=longitude;
kityann 18:01882120e6cf 125 latitudeKalman_data.double_value=latitudeKalman;
kityann 17:a6fa8cc96d94 126 longitudeKalman_data.double_value=longitudeKalman;
kityann 17:a6fa8cc96d94 127 covarLati_data.double_value=covarLati;
kityann 17:a6fa8cc96d94 128 covarLongi_data.double_value=covarLongi;
kityann 18:01882120e6cf 129
kityann 17:a6fa8cc96d94 130 uint8_t tmp[] = {'A','G','S','R','F',fromID,'T',toID,'S',nowMode,71,80,83,
kityann 17:a6fa8cc96d94 131 latitude_data.char_value[0],latitude_data.char_value[1],latitude_data.char_value[2],latitude_data.char_value[3],latitude_data.char_value[4],latitude_data.char_value[5],latitude_data.char_value[6],latitude_data.char_value[7],
kityann 17:a6fa8cc96d94 132 longitude_data.char_value[0],longitude_data.char_value[1],longitude_data.char_value[2],longitude_data.char_value[3],longitude_data.char_value[4],longitude_data.char_value[5],longitude_data.char_value[6],longitude_data.char_value[7],
kityann 17:a6fa8cc96d94 133 latitudeKalman_data.char_value[0],latitudeKalman_data.char_value[1],latitudeKalman_data.char_value[2],latitudeKalman_data.char_value[3],latitudeKalman_data.char_value[4],latitudeKalman_data.char_value[5],latitudeKalman_data.char_value[6],latitudeKalman_data.char_value[7],
kityann 17:a6fa8cc96d94 134 longitudeKalman_data.char_value[0],longitudeKalman_data.char_value[1],longitudeKalman_data.char_value[2],longitudeKalman_data.char_value[3],longitudeKalman_data.char_value[4],longitudeKalman_data.char_value[5],longitudeKalman_data.char_value[6],longitudeKalman_data.char_value[7],
kityann 17:a6fa8cc96d94 135 covarLati_data.char_value[0],covarLati_data.char_value[1],covarLati_data.char_value[2],covarLati_data.char_value[3],covarLati_data.char_value[4],covarLati_data.char_value[5],covarLati_data.char_value[6],covarLati_data.char_value[7],
kityann 17:a6fa8cc96d94 136 covarLongi_data.char_value[0],covarLongi_data.char_value[1],covarLongi_data.char_value[2],covarLongi_data.char_value[3],covarLongi_data.char_value[4],covarLongi_data.char_value[5],covarLongi_data.char_value[6],covarLongi_data.char_value[7],
kityann 17:a6fa8cc96d94 137 65,71,69};
m5171135 2:3f2d4f53ceed 138 for(int i = 0; i < RECEIVE_STATUS_COMMNAD_LENGTH; ++i) packetData[i] = tmp[i];
m5171135 2:3f2d4f53ceed 139 packetLength = RECEIVE_STATUS_COMMNAD_LENGTH;
m5171135 0:2b8b56ac7a82 140 }
m5171135 0:2b8b56ac7a82 141
kityann 13:a5bc425540a7 142
m5171135 2:3f2d4f53ceed 143
m5171135 2:3f2d4f53ceed 144 //////////////////////////////
m5171135 2:3f2d4f53ceed 145 // Using createPacket //
m5171135 2:3f2d4f53ceed 146 //////////////////////////////
m5171135 4:04dadf67ecb6 147 uint8_t AigamozuControlPackets::checkCommnadType(uint8_t* buf){
m5171135 4:04dadf67ecb6 148 return buf[14];
m5171135 4:04dadf67ecb6 149 }
m5171135 2:3f2d4f53ceed 150
m5171135 2:3f2d4f53ceed 151 uint8_t* AigamozuControlPackets::getPacketData(){
m5171135 2:3f2d4f53ceed 152 return packetData;
m5171135 2:3f2d4f53ceed 153 }
m5171135 2:3f2d4f53ceed 154
m5171135 2:3f2d4f53ceed 155 int AigamozuControlPackets::getPacketLength(){
m5171135 2:3f2d4f53ceed 156 return packetLength;
m5171135 0:2b8b56ac7a82 157 }
m5171135 0:2b8b56ac7a82 158
m5171135 5:3f51eeb5aedc 159 void AigamozuControlPackets::changeSpeed(uint8_t* buf){
m5171135 5:3f51eeb5aedc 160 if(nowMode == MANUAL_MODE){
m5171135 5:3f51eeb5aedc 161 manualCount =0;
m5171135 5:3f51eeb5aedc 162 _agzSheild.changeSpeed(buf[20],buf[21],buf[23],buf[24]);
m5171135 5:3f51eeb5aedc 163 }
m5171135 5:3f51eeb5aedc 164 }
m5171135 4:04dadf67ecb6 165
m5171135 6:f164a716be46 166 //////////////////////////////
m5171135 6:f164a716be46 167 // each mode interrupt //
m5171135 6:f164a716be46 168 //////////////////////////////
m5171135 6:f164a716be46 169
m5171135 6:f164a716be46 170 void AigamozuControlPackets::manualMode(){
m5171135 6:f164a716be46 171 manualCount++;
m5171135 6:f164a716be46 172 if(manualCount > 10){
m5171135 6:f164a716be46 173 _agzSheild.changeSpeed(0,0,0,0);
m5171135 6:f164a716be46 174 manualCount = 0;
m5171135 6:f164a716be46 175 }
m5171135 6:f164a716be46 176 }
m5171135 6:f164a716be46 177
m5171135 6:f164a716be46 178
m5171135 5:3f51eeb5aedc 179 void AigamozuControlPackets::randomAuto(){
m5171135 2:3f2d4f53ceed 180
m5171135 5:3f51eeb5aedc 181 randomCount++;
m5171135 5:3f51eeb5aedc 182
m5171135 5:3f51eeb5aedc 183 if(randomCount < 10) _agzSheild.changeSpeed(1,128,1,128);
m5171135 5:3f51eeb5aedc 184 else if(randomCount < 11) _agzSheild.changeSpeed(2,128,2,128);
m5171135 5:3f51eeb5aedc 185 else randomCount = 0;
m5171135 5:3f51eeb5aedc 186
m5171135 5:3f51eeb5aedc 187 }
s1200058 20:fec2d6dec897 188 bool AigamozuControlPackets::gpsAuto(){
m5171135 5:3f51eeb5aedc 189
kityann 10:e77c664ee5e2 190 /*
kityann 10:e77c664ee5e2 191 _agzSheild.changeSpeed(2,128,2,128):for moving robot
kityann 10:e77c664ee5e2 192 */
kityann 10:e77c664ee5e2 193
kityann 10:e77c664ee5e2 194 Timer Automove_Timer;
kityann 10:e77c664ee5e2 195
kityann 10:e77c664ee5e2 196 bool out_flag = true;
kityann 10:e77c664ee5e2 197 static bool out_count_flag = false;
kityann 13:a5bc425540a7 198
s1200058 20:fec2d6dec897 199 if(AigamozuControlPackets::checkGpsHit(basePointKalman[0],basePointKalman[1],basePointKalman[2],agzPointKalman)){
kityann 10:e77c664ee5e2 200 out_flag = false;
kityann 10:e77c664ee5e2 201 out_count_flag = false;
s1200058 20:fec2d6dec897 202 }else if(AigamozuControlPackets::checkGpsHit(basePointKalman[2],basePointKalman[3],basePointKalman[0],agzPointKalman)){
kityann 10:e77c664ee5e2 203 out_flag = false;
kityann 10:e77c664ee5e2 204 out_count_flag = false;
kityann 10:e77c664ee5e2 205 }else{//if robot is out
kityann 10:e77c664ee5e2 206 out_flag = true;
m5171135 7:200ce5c1f486 207 }
m5171135 7:200ce5c1f486 208
kityann 10:e77c664ee5e2 209 //if robot is out:
kityann 10:e77c664ee5e2 210 if(out_flag == true || out_count_flag == false){
kityann 10:e77c664ee5e2 211 Automove_Timer.reset();
kityann 10:e77c664ee5e2 212 out_count_flag = true;
kityann 10:e77c664ee5e2 213 }
kityann 10:e77c664ee5e2 214 if(out_flag){
kityann 17:a6fa8cc96d94 215 if(Automove_Timer.read_ms() < 5000){
kityann 17:a6fa8cc96d94 216 _agzSheild.changeSpeed(2,64,2,64);//back
kityann 17:a6fa8cc96d94 217 }else if(Automove_Timer.read_ms() < 6000){
kityann 17:a6fa8cc96d94 218 _agzSheild.changeSpeed(1,64,2,64);//straight
kityann 17:a6fa8cc96d94 219 }else if(Automove_Timer.read_ms() >= 6000){
kityann 10:e77c664ee5e2 220 out_count_flag=false;
kityann 13:a5bc425540a7 221 out_flag=false;
kityann 10:e77c664ee5e2 222 }
kityann 10:e77c664ee5e2 223 }else{
kityann 10:e77c664ee5e2 224 //if robot is inner
kityann 10:e77c664ee5e2 225 _agzSheild.changeSpeed(1,64,1,64);//straight
kityann 10:e77c664ee5e2 226 }
s1200058 20:fec2d6dec897 227
s1200058 20:fec2d6dec897 228 return out_flag;
kityann 10:e77c664ee5e2 229
kityann 10:e77c664ee5e2 230 }
m5171135 7:200ce5c1f486 231
m5171135 7:200ce5c1f486 232
m5171135 7:200ce5c1f486 233 //Update Robot Point
kityann 11:4d71c9cc3b4a 234 void AigamozuControlPackets::reNewRobotPoint(long latitudeH,long latitudeL,long longitudeH,long longitudeL){
kityann 18:01882120e6cf 235 agzPoint.x = (double)latitudeH + (double)(latitudeL / 10000.0/60.0);
kityann 18:01882120e6cf 236 agzPoint.y = (double)longitudeH +(double)(longitudeL / 10000.0/60.0);
m5171135 7:200ce5c1f486 237
m5171135 7:200ce5c1f486 238 }
kityann 11:4d71c9cc3b4a 239
kityann 11:4d71c9cc3b4a 240 //Updata Base Point
kityann 19:13b24b50800e 241 void AigamozuControlPackets::reNewBasePoint(int id, uint8_t *latitude,uint8_t *longitude){
kityann 19:13b24b50800e 242 UNION_double_char lat,longi;
kityann 19:13b24b50800e 243 for(int i = 0;i < 8;i++){
kityann 19:13b24b50800e 244 lat.char_value[i]=latitude[i];
kityann 19:13b24b50800e 245 }
kityann 19:13b24b50800e 246 for(int i = 0;i < 8;i++){
kityann 19:13b24b50800e 247 longi.char_value[i]=longitude[i];
kityann 19:13b24b50800e 248 }
kityann 19:13b24b50800e 249 basePoint[id].x = lat.double_value;
kityann 19:13b24b50800e 250 basePoint[id].y = longi.double_value;
kityann 11:4d71c9cc3b4a 251 }
m5171135 7:200ce5c1f486 252
kityann 13:a5bc425540a7 253 //Update Robot Point
kityann 13:a5bc425540a7 254 void AigamozuControlPackets::reNewRobotPointKalman(long latitudeH,long latitudeL,long longitudeH,long longitudeL){
kityann 18:01882120e6cf 255 agzPointKalman.x = (double)latitudeH + (double)(latitudeL / 10000.0/60.0);
kityann 18:01882120e6cf 256 agzPointKalman.y = (double)longitudeH +(double)(longitudeL / 10000.0/60.0);
kityann 13:a5bc425540a7 257
kityann 13:a5bc425540a7 258 }
kityann 13:a5bc425540a7 259
kityann 13:a5bc425540a7 260 //Updata Base Point
kityann 19:13b24b50800e 261 void AigamozuControlPackets::reNewBasePointKalman(int id, uint8_t *latitude,uint8_t *longitude){
kityann 19:13b24b50800e 262 UNION_double_char lat,longi;
kityann 19:13b24b50800e 263 for(int i = 0;i < 8;i++){
kityann 19:13b24b50800e 264 lat.char_value[i]=latitude[i];
kityann 19:13b24b50800e 265 }
kityann 19:13b24b50800e 266 for(int i = 0;i < 8;i++){
kityann 19:13b24b50800e 267 longi.char_value[i]=longitude[i];
kityann 19:13b24b50800e 268 }
kityann 19:13b24b50800e 269
kityann 19:13b24b50800e 270 basePointKalman[id].x = lat.double_value;
kityann 19:13b24b50800e 271 basePointKalman[id].y = longi.double_value;
kityann 13:a5bc425540a7 272 }
kityann 13:a5bc425540a7 273
m5171135 7:200ce5c1f486 274
m5171135 7:200ce5c1f486 275 //Check Hit Point Area
m5171135 7:200ce5c1f486 276 bool AigamozuControlPackets::checkGpsHit( vertex2D A, vertex2D B, vertex2D C, vertex2D P){
m5171135 7:200ce5c1f486 277 vector2D AB = AigamozuControlPackets::sub_vector(B, A);
m5171135 7:200ce5c1f486 278 vector2D BP = AigamozuControlPackets::sub_vector(P, B);
m5171135 7:200ce5c1f486 279
m5171135 7:200ce5c1f486 280 vector2D BC = AigamozuControlPackets::sub_vector(C, B);
m5171135 7:200ce5c1f486 281 vector2D CP = AigamozuControlPackets::sub_vector(P, C);
m5171135 7:200ce5c1f486 282
m5171135 7:200ce5c1f486 283 vector2D CA = AigamozuControlPackets::sub_vector(A, C);
m5171135 7:200ce5c1f486 284 vector2D AP = AigamozuControlPackets::sub_vector(P, A);
m5171135 7:200ce5c1f486 285
m5171135 7:200ce5c1f486 286 double c1 = AB.x * BP.y - AB.y * BP.x;
m5171135 7:200ce5c1f486 287 double c2 = BC.x * CP.y - BC.y * CP.x;
m5171135 7:200ce5c1f486 288 double c3 = CA.x * AP.y - CA.y * AP.x;
m5171135 7:200ce5c1f486 289
m5171135 7:200ce5c1f486 290 if( ( c1 > 0 && c2 > 0 && c3 > 0 ) || ( c1 < 0 && c2 < 0 && c3 < 0 ) ) {
m5171135 7:200ce5c1f486 291 return true;
m5171135 5:3f51eeb5aedc 292 }
m5171135 6:f164a716be46 293
m5171135 7:200ce5c1f486 294 return false;
m5171135 7:200ce5c1f486 295
m5171135 7:200ce5c1f486 296 }
m5171135 7:200ce5c1f486 297
m5171135 7:200ce5c1f486 298 vector2D AigamozuControlPackets::sub_vector( const vector2D& a, const vector2D& b )
m5171135 7:200ce5c1f486 299 {
m5171135 7:200ce5c1f486 300 vector2D ret;
m5171135 7:200ce5c1f486 301 ret.x = a.x - b.x;
m5171135 7:200ce5c1f486 302 ret.y = a.y - b.y;
m5171135 7:200ce5c1f486 303 return ret;
m5171135 7:200ce5c1f486 304 }
m5171135 7:200ce5c1f486 305
m5171135 7:200ce5c1f486 306
m5171135 7:200ce5c1f486 307
m5171135 5:3f51eeb5aedc 308
m5171135 6:f164a716be46 309 //////////////////////////////
m5171135 6:f164a716be46 310 // Mode change //
m5171135 6:f164a716be46 311 //////////////////////////////
m5171135 2:3f2d4f53ceed 312 bool AigamozuControlPackets::changeMode(uint8_t *buf){
m5171135 2:3f2d4f53ceed 313
m5171135 6:f164a716be46 314 //reset
m5171135 5:3f51eeb5aedc 315 _agzSheild.changeSpeed(0,0,0,0);
m5171135 6:f164a716be46 316 eachModeInt.detach();
m5171135 5:3f51eeb5aedc 317
m5171135 6:f164a716be46 318 //Select Mode
m5171135 2:3f2d4f53ceed 319 switch(buf[19]){
m5171135 2:3f2d4f53ceed 320 case 0:
m5171135 2:3f2d4f53ceed 321 nowMode = STANDBY_MODE;
m5171135 2:3f2d4f53ceed 322 break;
m5171135 2:3f2d4f53ceed 323
m5171135 2:3f2d4f53ceed 324 case 1:
m5171135 6:f164a716be46 325 eachModeInt.attach(this,&AigamozuControlPackets::manualMode,1.0);
m5171135 2:3f2d4f53ceed 326 nowMode = MANUAL_MODE;
m5171135 2:3f2d4f53ceed 327 break;
m5171135 2:3f2d4f53ceed 328
m5171135 2:3f2d4f53ceed 329 case 2:
kityann 11:4d71c9cc3b4a 330 //nowMode = AUTO_MODE;
kityann 11:4d71c9cc3b4a 331 //eachModeInt.attach(this,&AigamozuControlPackets::randomAuto,1.0);
s1200058 20:fec2d6dec897 332 //eachModeInt.attach(this,&AigamozuControlPackets::gpsAuto,2.0);
kityann 11:4d71c9cc3b4a 333 nowMode = AUTO_GPS_MODE;
m5171135 2:3f2d4f53ceed 334 break;
m5171135 4:04dadf67ecb6 335
m5171135 4:04dadf67ecb6 336 case 3:
s1200058 20:fec2d6dec897 337 //eachModeInt.attach(this,&AigamozuControlPackets::gpsAuto,0.2);
m5171135 4:04dadf67ecb6 338 nowMode = AUTO_GPS_MODE;
m5171135 4:04dadf67ecb6 339 break;
m5171135 4:04dadf67ecb6 340
m5171135 6:f164a716be46 341 default:
m5171135 6:f164a716be46 342 nowMode = STANDBY_MODE;
m5171135 6:f164a716be46 343 break;
m5171135 5:3f51eeb5aedc 344
m5171135 2:3f2d4f53ceed 345 }
m5171135 2:3f2d4f53ceed 346 return false;
m5171135 2:3f2d4f53ceed 347 }
m5171135 5:3f51eeb5aedc 348
m5171135 5:3f51eeb5aedc 349
m5171135 2:3f2d4f53ceed 350