forward

Dependencies:   VNH5019

Fork of AigamozuControlPackets by aigamozu

Committer:
s1200058
Date:
Sat May 16 06:49:43 2015 +0000
Revision:
27:acadce784e2b
Parent:
24:ed71894a6952
Child:
28:e0f016828bb1
2014/05/16

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 23:e5dcf0d15879 75 agzCov.x = cov_lati / 10000.0/60.0;
kityann 23:e5dcf0d15879 76 agzCov.y = cov_longi / 10000.0/60.0;
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
s1200058 24:ed71894a6952 118 void AigamozuControlPackets::createReceiveStatusCommand(uint8_t fromID,uint8_t toID,int state, 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
s1200058 24:ed71894a6952 130
s1200058 24:ed71894a6952 131 uint8_t tmp[] = {'A','G','S','R','F',fromID,'T',toID,'S', state,71,80,83,
kityann 17:a6fa8cc96d94 132 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 133 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 134 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 135 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 136 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 137 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 138 65,71,69};
m5171135 2:3f2d4f53ceed 139 for(int i = 0; i < RECEIVE_STATUS_COMMNAD_LENGTH; ++i) packetData[i] = tmp[i];
m5171135 2:3f2d4f53ceed 140 packetLength = RECEIVE_STATUS_COMMNAD_LENGTH;
m5171135 0:2b8b56ac7a82 141 }
m5171135 0:2b8b56ac7a82 142
kityann 13:a5bc425540a7 143
m5171135 2:3f2d4f53ceed 144
m5171135 2:3f2d4f53ceed 145 //////////////////////////////
m5171135 2:3f2d4f53ceed 146 // Using createPacket //
m5171135 2:3f2d4f53ceed 147 //////////////////////////////
m5171135 4:04dadf67ecb6 148 uint8_t AigamozuControlPackets::checkCommnadType(uint8_t* buf){
m5171135 4:04dadf67ecb6 149 return buf[14];
m5171135 4:04dadf67ecb6 150 }
m5171135 2:3f2d4f53ceed 151
m5171135 2:3f2d4f53ceed 152 uint8_t* AigamozuControlPackets::getPacketData(){
m5171135 2:3f2d4f53ceed 153 return packetData;
m5171135 2:3f2d4f53ceed 154 }
m5171135 2:3f2d4f53ceed 155
m5171135 2:3f2d4f53ceed 156 int AigamozuControlPackets::getPacketLength(){
m5171135 2:3f2d4f53ceed 157 return packetLength;
m5171135 0:2b8b56ac7a82 158 }
m5171135 0:2b8b56ac7a82 159
m5171135 5:3f51eeb5aedc 160 void AigamozuControlPackets::changeSpeed(uint8_t* buf){
m5171135 5:3f51eeb5aedc 161 if(nowMode == MANUAL_MODE){
m5171135 5:3f51eeb5aedc 162 manualCount =0;
m5171135 5:3f51eeb5aedc 163 _agzSheild.changeSpeed(buf[20],buf[21],buf[23],buf[24]);
m5171135 5:3f51eeb5aedc 164 }
m5171135 5:3f51eeb5aedc 165 }
m5171135 4:04dadf67ecb6 166
m5171135 6:f164a716be46 167 //////////////////////////////
m5171135 6:f164a716be46 168 // each mode interrupt //
m5171135 6:f164a716be46 169 //////////////////////////////
m5171135 6:f164a716be46 170
m5171135 6:f164a716be46 171 void AigamozuControlPackets::manualMode(){
m5171135 6:f164a716be46 172 manualCount++;
m5171135 6:f164a716be46 173 if(manualCount > 10){
m5171135 6:f164a716be46 174 _agzSheild.changeSpeed(0,0,0,0);
m5171135 6:f164a716be46 175 manualCount = 0;
m5171135 6:f164a716be46 176 }
m5171135 6:f164a716be46 177 }
m5171135 6:f164a716be46 178
m5171135 6:f164a716be46 179
m5171135 5:3f51eeb5aedc 180 void AigamozuControlPackets::randomAuto(){
m5171135 2:3f2d4f53ceed 181
m5171135 5:3f51eeb5aedc 182 randomCount++;
m5171135 5:3f51eeb5aedc 183
m5171135 5:3f51eeb5aedc 184 if(randomCount < 10) _agzSheild.changeSpeed(1,128,1,128);
m5171135 5:3f51eeb5aedc 185 else if(randomCount < 11) _agzSheild.changeSpeed(2,128,2,128);
m5171135 5:3f51eeb5aedc 186 else randomCount = 0;
m5171135 5:3f51eeb5aedc 187
m5171135 5:3f51eeb5aedc 188 }
s1200058 20:fec2d6dec897 189 bool AigamozuControlPackets::gpsAuto(){
m5171135 5:3f51eeb5aedc 190
kityann 10:e77c664ee5e2 191 /*
kityann 10:e77c664ee5e2 192 _agzSheild.changeSpeed(2,128,2,128):for moving robot
kityann 10:e77c664ee5e2 193 */
kityann 10:e77c664ee5e2 194
kityann 10:e77c664ee5e2 195 Timer Automove_Timer;
kityann 10:e77c664ee5e2 196
kityann 10:e77c664ee5e2 197 bool out_flag = true;
kityann 10:e77c664ee5e2 198 static bool out_count_flag = false;
kityann 13:a5bc425540a7 199
s1200058 20:fec2d6dec897 200 if(AigamozuControlPackets::checkGpsHit(basePointKalman[0],basePointKalman[1],basePointKalman[2],agzPointKalman)){
kityann 10:e77c664ee5e2 201 out_flag = false;
kityann 10:e77c664ee5e2 202 out_count_flag = false;
s1200058 20:fec2d6dec897 203 }else if(AigamozuControlPackets::checkGpsHit(basePointKalman[2],basePointKalman[3],basePointKalman[0],agzPointKalman)){
kityann 10:e77c664ee5e2 204 out_flag = false;
kityann 10:e77c664ee5e2 205 out_count_flag = false;
kityann 10:e77c664ee5e2 206 }else{//if robot is out
kityann 10:e77c664ee5e2 207 out_flag = true;
m5171135 7:200ce5c1f486 208 }
m5171135 7:200ce5c1f486 209
kityann 10:e77c664ee5e2 210 //if robot is out:
kityann 10:e77c664ee5e2 211 if(out_flag == true || out_count_flag == false){
kityann 10:e77c664ee5e2 212 Automove_Timer.reset();
kityann 10:e77c664ee5e2 213 out_count_flag = true;
kityann 10:e77c664ee5e2 214 }
s1200058 27:acadce784e2b 215 if(nowMode == AUTO_GPS_MODE){
kityann 10:e77c664ee5e2 216 if(out_flag){
kityann 17:a6fa8cc96d94 217 if(Automove_Timer.read_ms() < 5000){
kityann 17:a6fa8cc96d94 218 _agzSheild.changeSpeed(2,64,2,64);//back
kityann 17:a6fa8cc96d94 219 }else if(Automove_Timer.read_ms() < 6000){
kityann 17:a6fa8cc96d94 220 _agzSheild.changeSpeed(1,64,2,64);//straight
kityann 17:a6fa8cc96d94 221 }else if(Automove_Timer.read_ms() >= 6000){
kityann 10:e77c664ee5e2 222 out_count_flag=false;
kityann 13:a5bc425540a7 223 out_flag=false;
kityann 10:e77c664ee5e2 224 }
kityann 10:e77c664ee5e2 225 }else{
kityann 10:e77c664ee5e2 226 //if robot is inner
kityann 10:e77c664ee5e2 227 _agzSheild.changeSpeed(1,64,1,64);//straight
kityann 10:e77c664ee5e2 228 }
s1200058 27:acadce784e2b 229 }
s1200058 20:fec2d6dec897 230
s1200058 20:fec2d6dec897 231 return out_flag;
kityann 10:e77c664ee5e2 232
kityann 10:e77c664ee5e2 233 }
m5171135 7:200ce5c1f486 234
m5171135 7:200ce5c1f486 235
m5171135 7:200ce5c1f486 236 //Update Robot Point
kityann 11:4d71c9cc3b4a 237 void AigamozuControlPackets::reNewRobotPoint(long latitudeH,long latitudeL,long longitudeH,long longitudeL){
kityann 18:01882120e6cf 238 agzPoint.x = (double)latitudeH + (double)(latitudeL / 10000.0/60.0);
kityann 18:01882120e6cf 239 agzPoint.y = (double)longitudeH +(double)(longitudeL / 10000.0/60.0);
m5171135 7:200ce5c1f486 240
m5171135 7:200ce5c1f486 241 }
kityann 11:4d71c9cc3b4a 242
kityann 11:4d71c9cc3b4a 243 //Updata Base Point
kityann 19:13b24b50800e 244 void AigamozuControlPackets::reNewBasePoint(int id, uint8_t *latitude,uint8_t *longitude){
kityann 19:13b24b50800e 245 UNION_double_char lat,longi;
kityann 19:13b24b50800e 246 for(int i = 0;i < 8;i++){
kityann 19:13b24b50800e 247 lat.char_value[i]=latitude[i];
kityann 19:13b24b50800e 248 }
kityann 19:13b24b50800e 249 for(int i = 0;i < 8;i++){
kityann 19:13b24b50800e 250 longi.char_value[i]=longitude[i];
kityann 19:13b24b50800e 251 }
kityann 19:13b24b50800e 252 basePoint[id].x = lat.double_value;
kityann 19:13b24b50800e 253 basePoint[id].y = longi.double_value;
kityann 11:4d71c9cc3b4a 254 }
m5171135 7:200ce5c1f486 255
kityann 13:a5bc425540a7 256 //Update Robot Point
kityann 13:a5bc425540a7 257 void AigamozuControlPackets::reNewRobotPointKalman(long latitudeH,long latitudeL,long longitudeH,long longitudeL){
kityann 18:01882120e6cf 258 agzPointKalman.x = (double)latitudeH + (double)(latitudeL / 10000.0/60.0);
kityann 18:01882120e6cf 259 agzPointKalman.y = (double)longitudeH +(double)(longitudeL / 10000.0/60.0);
kityann 13:a5bc425540a7 260
kityann 13:a5bc425540a7 261 }
kityann 13:a5bc425540a7 262
kityann 13:a5bc425540a7 263 //Updata Base Point
kityann 19:13b24b50800e 264 void AigamozuControlPackets::reNewBasePointKalman(int id, uint8_t *latitude,uint8_t *longitude){
kityann 19:13b24b50800e 265 UNION_double_char lat,longi;
kityann 19:13b24b50800e 266 for(int i = 0;i < 8;i++){
kityann 19:13b24b50800e 267 lat.char_value[i]=latitude[i];
kityann 19:13b24b50800e 268 }
kityann 19:13b24b50800e 269 for(int i = 0;i < 8;i++){
kityann 19:13b24b50800e 270 longi.char_value[i]=longitude[i];
kityann 19:13b24b50800e 271 }
kityann 19:13b24b50800e 272
kityann 19:13b24b50800e 273 basePointKalman[id].x = lat.double_value;
kityann 19:13b24b50800e 274 basePointKalman[id].y = longi.double_value;
kityann 13:a5bc425540a7 275 }
kityann 13:a5bc425540a7 276
m5171135 7:200ce5c1f486 277
m5171135 7:200ce5c1f486 278 //Check Hit Point Area
m5171135 7:200ce5c1f486 279 bool AigamozuControlPackets::checkGpsHit( vertex2D A, vertex2D B, vertex2D C, vertex2D P){
m5171135 7:200ce5c1f486 280 vector2D AB = AigamozuControlPackets::sub_vector(B, A);
m5171135 7:200ce5c1f486 281 vector2D BP = AigamozuControlPackets::sub_vector(P, B);
m5171135 7:200ce5c1f486 282
m5171135 7:200ce5c1f486 283 vector2D BC = AigamozuControlPackets::sub_vector(C, B);
m5171135 7:200ce5c1f486 284 vector2D CP = AigamozuControlPackets::sub_vector(P, C);
m5171135 7:200ce5c1f486 285
m5171135 7:200ce5c1f486 286 vector2D CA = AigamozuControlPackets::sub_vector(A, C);
m5171135 7:200ce5c1f486 287 vector2D AP = AigamozuControlPackets::sub_vector(P, A);
m5171135 7:200ce5c1f486 288
m5171135 7:200ce5c1f486 289 double c1 = AB.x * BP.y - AB.y * BP.x;
m5171135 7:200ce5c1f486 290 double c2 = BC.x * CP.y - BC.y * CP.x;
m5171135 7:200ce5c1f486 291 double c3 = CA.x * AP.y - CA.y * AP.x;
m5171135 7:200ce5c1f486 292
m5171135 7:200ce5c1f486 293 if( ( c1 > 0 && c2 > 0 && c3 > 0 ) || ( c1 < 0 && c2 < 0 && c3 < 0 ) ) {
m5171135 7:200ce5c1f486 294 return true;
m5171135 5:3f51eeb5aedc 295 }
m5171135 6:f164a716be46 296
m5171135 7:200ce5c1f486 297 return false;
m5171135 7:200ce5c1f486 298
m5171135 7:200ce5c1f486 299 }
m5171135 7:200ce5c1f486 300
m5171135 7:200ce5c1f486 301 vector2D AigamozuControlPackets::sub_vector( const vector2D& a, const vector2D& b )
m5171135 7:200ce5c1f486 302 {
m5171135 7:200ce5c1f486 303 vector2D ret;
m5171135 7:200ce5c1f486 304 ret.x = a.x - b.x;
m5171135 7:200ce5c1f486 305 ret.y = a.y - b.y;
m5171135 7:200ce5c1f486 306 return ret;
m5171135 7:200ce5c1f486 307 }
m5171135 7:200ce5c1f486 308
m5171135 7:200ce5c1f486 309
m5171135 7:200ce5c1f486 310
m5171135 5:3f51eeb5aedc 311
m5171135 6:f164a716be46 312 //////////////////////////////
m5171135 6:f164a716be46 313 // Mode change //
m5171135 6:f164a716be46 314 //////////////////////////////
m5171135 2:3f2d4f53ceed 315 bool AigamozuControlPackets::changeMode(uint8_t *buf){
m5171135 2:3f2d4f53ceed 316
m5171135 6:f164a716be46 317 //reset
m5171135 5:3f51eeb5aedc 318 _agzSheild.changeSpeed(0,0,0,0);
m5171135 6:f164a716be46 319 eachModeInt.detach();
m5171135 5:3f51eeb5aedc 320
m5171135 6:f164a716be46 321 //Select Mode
s1200058 27:acadce784e2b 322 switch(buf[0]){
m5171135 2:3f2d4f53ceed 323 case 0:
m5171135 2:3f2d4f53ceed 324 nowMode = STANDBY_MODE;
m5171135 2:3f2d4f53ceed 325 break;
m5171135 2:3f2d4f53ceed 326
m5171135 2:3f2d4f53ceed 327 case 1:
m5171135 6:f164a716be46 328 eachModeInt.attach(this,&AigamozuControlPackets::manualMode,1.0);
m5171135 2:3f2d4f53ceed 329 nowMode = MANUAL_MODE;
m5171135 2:3f2d4f53ceed 330 break;
m5171135 2:3f2d4f53ceed 331
m5171135 2:3f2d4f53ceed 332 case 2:
kityann 11:4d71c9cc3b4a 333 //nowMode = AUTO_MODE;
kityann 11:4d71c9cc3b4a 334 //eachModeInt.attach(this,&AigamozuControlPackets::randomAuto,1.0);
s1200058 20:fec2d6dec897 335 //eachModeInt.attach(this,&AigamozuControlPackets::gpsAuto,2.0);
kityann 11:4d71c9cc3b4a 336 nowMode = AUTO_GPS_MODE;
m5171135 2:3f2d4f53ceed 337 break;
m5171135 4:04dadf67ecb6 338
m5171135 4:04dadf67ecb6 339 case 3:
s1200058 20:fec2d6dec897 340 //eachModeInt.attach(this,&AigamozuControlPackets::gpsAuto,0.2);
m5171135 4:04dadf67ecb6 341 nowMode = AUTO_GPS_MODE;
m5171135 4:04dadf67ecb6 342 break;
m5171135 4:04dadf67ecb6 343
m5171135 6:f164a716be46 344 default:
m5171135 6:f164a716be46 345 nowMode = STANDBY_MODE;
m5171135 6:f164a716be46 346 break;
m5171135 5:3f51eeb5aedc 347
m5171135 2:3f2d4f53ceed 348 }
m5171135 2:3f2d4f53ceed 349 return false;
m5171135 2:3f2d4f53ceed 350 }
m5171135 5:3f51eeb5aedc 351
m5171135 5:3f51eeb5aedc 352
m5171135 2:3f2d4f53ceed 353