forward
Dependencies: VNH5019
Fork of AigamozuControlPackets by
AigamozuControlPackets.cpp@33:c11a9cb35840, 2015-05-19 (annotated)
- Committer:
- s1200058
- Date:
- Tue May 19 10:52:06 2015 +0000
- Revision:
- 33:c11a9cb35840
- Parent:
- 32:cd68a37d1ee1
- Child:
- 34:08491a77e458
if nowMode change AUTO_GPS_MODE, timer is reset.
Who changed what in which revision?
User | Revision | Line number | New 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 | 31:8753fbab3f1f | 79 | /* |
s1200058 | 20:fec2d6dec897 | 80 | void AigamozuControlPackets::set_agzAutoGPS(){ |
s1200058 | 20:fec2d6dec897 | 81 | agzPoint.x += 0.00001; |
s1200058 | 20:fec2d6dec897 | 82 | //agzPoint.y += 0.001; |
s1200058 | 20:fec2d6dec897 | 83 | } |
s1200058 | 20:fec2d6dec897 | 84 | |
s1200058 | 20:fec2d6dec897 | 85 | void AigamozuControlPackets::set_agzKalmanGPS(){ |
s1200058 | 20:fec2d6dec897 | 86 | agzPointKalman.x += 0.00001; |
s1200058 | 20:fec2d6dec897 | 87 | //agzPointKalman.y += 0.001; |
s1200058 | 20:fec2d6dec897 | 88 | |
s1200058 | 20:fec2d6dec897 | 89 | } |
s1200058 | 31:8753fbab3f1f | 90 | */ |
kityann | 17:a6fa8cc96d94 | 91 | ////////////////////////////// |
m5171135 | 2:3f2d4f53ceed | 92 | // Controller/Base -> Robot // |
m5171135 | 2:3f2d4f53ceed | 93 | ////////////////////////////// |
m5171135 | 4:04dadf67ecb6 | 94 | |
m5171135 | 2:3f2d4f53ceed | 95 | void AigamozuControlPackets::createManualCommad(uint8_t fromID,uint8_t toID,uint8_t directionL,uint8_t pwmL,uint8_t directionR, uint8_t pwmR) |
m5171135 | 2:3f2d4f53ceed | 96 | { |
m5171135 | 2:3f2d4f53ceed | 97 | uint8_t tmp[] = {'A','G','S','M','F',fromID,'T',toID,'L',directionL,pwmL,'R',directionR,pwmR,'A','G','E'}; |
m5171135 | 2:3f2d4f53ceed | 98 | for(int i = 0; i < RECEIVE_STATUS_COMMNAD_LENGTH; ++i) packetData[i] = tmp[i]; |
m5171135 | 2:3f2d4f53ceed | 99 | packetLength = RECEIVE_STATUS_COMMNAD_LENGTH; |
m5171135 | 2:3f2d4f53ceed | 100 | } |
m5171135 | 2:3f2d4f53ceed | 101 | |
s1200058 | 9:4f675487f06b | 102 | void AigamozuControlPackets::createRequestCommand(uint8_t fromID,uint8_t toID) |
m5171135 | 0:2b8b56ac7a82 | 103 | { |
m5171135 | 2:3f2d4f53ceed | 104 | uint8_t tmp[] = {'A','G','S','S','F',fromID,'T',toID,'A','G','E'}; |
m5171135 | 2:3f2d4f53ceed | 105 | for(int i = 0; i < REQUEST_COMMNAD_LENGTH; ++i) packetData[i] = tmp[i]; |
m5171135 | 2:3f2d4f53ceed | 106 | packetLength = REQUEST_COMMNAD_LENGTH; |
m5171135 | 2:3f2d4f53ceed | 107 | } |
m5171135 | 0:2b8b56ac7a82 | 108 | |
m5171135 | 2:3f2d4f53ceed | 109 | void AigamozuControlPackets::createChangeModeCommand(uint8_t fromID,uint8_t toID,uint8_t,MODE mode){ |
m5171135 | 2:3f2d4f53ceed | 110 | uint8_t tmp[] = {'A','G','S','C','F',fromID,'T',toID,mode,'A','G','E'}; |
m5171135 | 2:3f2d4f53ceed | 111 | for(int i = 0; i < CHANGE_MODE_COMMAND_LENGTH; ++i) packetData[i] = tmp[i]; |
m5171135 | 2:3f2d4f53ceed | 112 | packetLength = CHANGE_MODE_COMMAND_LENGTH; |
m5171135 | 2:3f2d4f53ceed | 113 | } |
m5171135 | 2:3f2d4f53ceed | 114 | |
m5171135 | 2:3f2d4f53ceed | 115 | |
m5171135 | 2:3f2d4f53ceed | 116 | ////////////////////////////// |
m5171135 | 2:3f2d4f53ceed | 117 | // Robot -> Controller/Base // |
m5171135 | 2:3f2d4f53ceed | 118 | ////////////////////////////// |
m5171135 | 2:3f2d4f53ceed | 119 | |
s1200058 | 24:ed71894a6952 | 120 | 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 | 121 | { |
kityann | 17:a6fa8cc96d94 | 122 | UNION_double_char latitude_data,longitude_data, latitudeKalman_data, longitudeKalman_data; |
kityann | 17:a6fa8cc96d94 | 123 | UNION_double_char covarLati_data,covarLongi_data; |
m5171135 | 0:2b8b56ac7a82 | 124 | |
kityann | 17:a6fa8cc96d94 | 125 | latitude_data.double_value=latitude; |
kityann | 17:a6fa8cc96d94 | 126 | longitude_data.double_value=longitude; |
kityann | 18:01882120e6cf | 127 | latitudeKalman_data.double_value=latitudeKalman; |
kityann | 17:a6fa8cc96d94 | 128 | longitudeKalman_data.double_value=longitudeKalman; |
kityann | 17:a6fa8cc96d94 | 129 | covarLati_data.double_value=covarLati; |
kityann | 17:a6fa8cc96d94 | 130 | covarLongi_data.double_value=covarLongi; |
kityann | 18:01882120e6cf | 131 | |
s1200058 | 24:ed71894a6952 | 132 | |
s1200058 | 24:ed71894a6952 | 133 | uint8_t tmp[] = {'A','G','S','R','F',fromID,'T',toID,'S', state,71,80,83, |
kityann | 17:a6fa8cc96d94 | 134 | 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 | 135 | 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 | 136 | 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 | 137 | 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 | 138 | 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 | 139 | 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 | 140 | 65,71,69}; |
m5171135 | 2:3f2d4f53ceed | 141 | for(int i = 0; i < RECEIVE_STATUS_COMMNAD_LENGTH; ++i) packetData[i] = tmp[i]; |
m5171135 | 2:3f2d4f53ceed | 142 | packetLength = RECEIVE_STATUS_COMMNAD_LENGTH; |
m5171135 | 0:2b8b56ac7a82 | 143 | } |
m5171135 | 0:2b8b56ac7a82 | 144 | |
kityann | 13:a5bc425540a7 | 145 | |
m5171135 | 2:3f2d4f53ceed | 146 | |
m5171135 | 2:3f2d4f53ceed | 147 | ////////////////////////////// |
m5171135 | 2:3f2d4f53ceed | 148 | // Using createPacket // |
m5171135 | 2:3f2d4f53ceed | 149 | ////////////////////////////// |
m5171135 | 4:04dadf67ecb6 | 150 | uint8_t AigamozuControlPackets::checkCommnadType(uint8_t* buf){ |
m5171135 | 4:04dadf67ecb6 | 151 | return buf[14]; |
m5171135 | 4:04dadf67ecb6 | 152 | } |
m5171135 | 2:3f2d4f53ceed | 153 | |
m5171135 | 2:3f2d4f53ceed | 154 | uint8_t* AigamozuControlPackets::getPacketData(){ |
m5171135 | 2:3f2d4f53ceed | 155 | return packetData; |
m5171135 | 2:3f2d4f53ceed | 156 | } |
m5171135 | 2:3f2d4f53ceed | 157 | |
m5171135 | 2:3f2d4f53ceed | 158 | int AigamozuControlPackets::getPacketLength(){ |
m5171135 | 2:3f2d4f53ceed | 159 | return packetLength; |
m5171135 | 0:2b8b56ac7a82 | 160 | } |
m5171135 | 0:2b8b56ac7a82 | 161 | |
m5171135 | 5:3f51eeb5aedc | 162 | void AigamozuControlPackets::changeSpeed(uint8_t* buf){ |
m5171135 | 5:3f51eeb5aedc | 163 | if(nowMode == MANUAL_MODE){ |
m5171135 | 5:3f51eeb5aedc | 164 | manualCount =0; |
m5171135 | 5:3f51eeb5aedc | 165 | _agzSheild.changeSpeed(buf[20],buf[21],buf[23],buf[24]); |
m5171135 | 5:3f51eeb5aedc | 166 | } |
m5171135 | 5:3f51eeb5aedc | 167 | } |
m5171135 | 4:04dadf67ecb6 | 168 | |
m5171135 | 6:f164a716be46 | 169 | ////////////////////////////// |
m5171135 | 6:f164a716be46 | 170 | // each mode interrupt // |
m5171135 | 6:f164a716be46 | 171 | ////////////////////////////// |
m5171135 | 6:f164a716be46 | 172 | |
m5171135 | 6:f164a716be46 | 173 | void AigamozuControlPackets::manualMode(){ |
m5171135 | 6:f164a716be46 | 174 | manualCount++; |
m5171135 | 6:f164a716be46 | 175 | if(manualCount > 10){ |
m5171135 | 6:f164a716be46 | 176 | _agzSheild.changeSpeed(0,0,0,0); |
m5171135 | 6:f164a716be46 | 177 | manualCount = 0; |
m5171135 | 6:f164a716be46 | 178 | } |
m5171135 | 6:f164a716be46 | 179 | } |
m5171135 | 6:f164a716be46 | 180 | |
m5171135 | 6:f164a716be46 | 181 | |
m5171135 | 5:3f51eeb5aedc | 182 | void AigamozuControlPackets::randomAuto(){ |
m5171135 | 2:3f2d4f53ceed | 183 | |
m5171135 | 5:3f51eeb5aedc | 184 | randomCount++; |
m5171135 | 5:3f51eeb5aedc | 185 | |
m5171135 | 5:3f51eeb5aedc | 186 | if(randomCount < 10) _agzSheild.changeSpeed(1,128,1,128); |
m5171135 | 5:3f51eeb5aedc | 187 | else if(randomCount < 11) _agzSheild.changeSpeed(2,128,2,128); |
m5171135 | 5:3f51eeb5aedc | 188 | else randomCount = 0; |
m5171135 | 5:3f51eeb5aedc | 189 | |
m5171135 | 5:3f51eeb5aedc | 190 | } |
s1200058 | 32:cd68a37d1ee1 | 191 | |
s1200058 | 32:cd68a37d1ee1 | 192 | void AigamozuControlPackets::test_Auto(int flag){ |
s1200058 | 32:cd68a37d1ee1 | 193 | |
s1200058 | 32:cd68a37d1ee1 | 194 | if(flag == 0){ |
s1200058 | 32:cd68a37d1ee1 | 195 | _agzSheild.changeSpeed(1, 64, 1, 64); //straight |
s1200058 | 32:cd68a37d1ee1 | 196 | } |
s1200058 | 32:cd68a37d1ee1 | 197 | if(flag == 1){ |
s1200058 | 32:cd68a37d1ee1 | 198 | _agzSheild.changeSpeed(0, 64, 0, 64); |
s1200058 | 32:cd68a37d1ee1 | 199 | } |
s1200058 | 32:cd68a37d1ee1 | 200 | if(flag == 2){ |
s1200058 | 32:cd68a37d1ee1 | 201 | _agzSheild.changeSpeed(1, 64, 2, 64); //Turn Right |
s1200058 | 32:cd68a37d1ee1 | 202 | } |
s1200058 | 32:cd68a37d1ee1 | 203 | if(flag == 3){ |
s1200058 | 32:cd68a37d1ee1 | 204 | _agzSheild.changeSpeed(0, 64, 0, 64); |
s1200058 | 32:cd68a37d1ee1 | 205 | } |
s1200058 | 32:cd68a37d1ee1 | 206 | } |
s1200058 | 32:cd68a37d1ee1 | 207 | |
s1200058 | 20:fec2d6dec897 | 208 | bool AigamozuControlPackets::gpsAuto(){ |
m5171135 | 5:3f51eeb5aedc | 209 | |
kityann | 10:e77c664ee5e2 | 210 | /* |
kityann | 10:e77c664ee5e2 | 211 | _agzSheild.changeSpeed(2,128,2,128):for moving robot |
kityann | 10:e77c664ee5e2 | 212 | */ |
kityann | 10:e77c664ee5e2 | 213 | |
kityann | 10:e77c664ee5e2 | 214 | Timer Automove_Timer; |
kityann | 10:e77c664ee5e2 | 215 | |
kityann | 10:e77c664ee5e2 | 216 | bool out_flag = true; |
kityann | 10:e77c664ee5e2 | 217 | static bool out_count_flag = false; |
kityann | 13:a5bc425540a7 | 218 | |
s1200058 | 20:fec2d6dec897 | 219 | if(AigamozuControlPackets::checkGpsHit(basePointKalman[0],basePointKalman[1],basePointKalman[2],agzPointKalman)){ |
kityann | 10:e77c664ee5e2 | 220 | out_flag = false; |
kityann | 10:e77c664ee5e2 | 221 | out_count_flag = false; |
s1200058 | 20:fec2d6dec897 | 222 | }else if(AigamozuControlPackets::checkGpsHit(basePointKalman[2],basePointKalman[3],basePointKalman[0],agzPointKalman)){ |
kityann | 10:e77c664ee5e2 | 223 | out_flag = false; |
kityann | 10:e77c664ee5e2 | 224 | out_count_flag = false; |
kityann | 10:e77c664ee5e2 | 225 | }else{//if robot is out |
kityann | 10:e77c664ee5e2 | 226 | out_flag = true; |
m5171135 | 7:200ce5c1f486 | 227 | } |
m5171135 | 7:200ce5c1f486 | 228 | |
kityann | 10:e77c664ee5e2 | 229 | //if robot is out: |
kityann | 10:e77c664ee5e2 | 230 | if(out_flag == true || out_count_flag == false){ |
kityann | 10:e77c664ee5e2 | 231 | Automove_Timer.reset(); |
kityann | 10:e77c664ee5e2 | 232 | out_count_flag = true; |
kityann | 10:e77c664ee5e2 | 233 | } |
s1200058 | 32:cd68a37d1ee1 | 234 | /* if(nowMode == AUTO_GPS_MODE){ |
s1200058 | 32:cd68a37d1ee1 | 235 | |
s1200058 | 32:cd68a37d1ee1 | 236 | if(out_flag){ |
kityann | 17:a6fa8cc96d94 | 237 | if(Automove_Timer.read_ms() < 5000){ |
kityann | 17:a6fa8cc96d94 | 238 | _agzSheild.changeSpeed(2,64,2,64);//back |
kityann | 17:a6fa8cc96d94 | 239 | }else if(Automove_Timer.read_ms() < 6000){ |
s1200058 | 32:cd68a37d1ee1 | 240 | _agzSheild.changeSpeed(1,64,1,64);//straight |
kityann | 17:a6fa8cc96d94 | 241 | }else if(Automove_Timer.read_ms() >= 6000){ |
kityann | 10:e77c664ee5e2 | 242 | out_count_flag=false; |
kityann | 13:a5bc425540a7 | 243 | out_flag=false; |
kityann | 10:e77c664ee5e2 | 244 | } |
kityann | 10:e77c664ee5e2 | 245 | }else{ |
kityann | 10:e77c664ee5e2 | 246 | //if robot is inner |
kityann | 10:e77c664ee5e2 | 247 | _agzSheild.changeSpeed(1,64,1,64);//straight |
kityann | 10:e77c664ee5e2 | 248 | } |
s1200058 | 32:cd68a37d1ee1 | 249 | } |
s1200058 | 32:cd68a37d1ee1 | 250 | */ |
s1200058 | 20:fec2d6dec897 | 251 | return out_flag; |
kityann | 10:e77c664ee5e2 | 252 | |
kityann | 10:e77c664ee5e2 | 253 | } |
m5171135 | 7:200ce5c1f486 | 254 | |
m5171135 | 7:200ce5c1f486 | 255 | |
m5171135 | 7:200ce5c1f486 | 256 | //Update Robot Point |
kityann | 11:4d71c9cc3b4a | 257 | void AigamozuControlPackets::reNewRobotPoint(long latitudeH,long latitudeL,long longitudeH,long longitudeL){ |
kityann | 18:01882120e6cf | 258 | agzPoint.x = (double)latitudeH + (double)(latitudeL / 10000.0/60.0); |
kityann | 18:01882120e6cf | 259 | agzPoint.y = (double)longitudeH +(double)(longitudeL / 10000.0/60.0); |
m5171135 | 7:200ce5c1f486 | 260 | |
m5171135 | 7:200ce5c1f486 | 261 | } |
kityann | 11:4d71c9cc3b4a | 262 | |
kityann | 11:4d71c9cc3b4a | 263 | //Updata Base Point |
kityann | 19:13b24b50800e | 264 | void AigamozuControlPackets::reNewBasePoint(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 | basePoint[id].x = lat.double_value; |
kityann | 19:13b24b50800e | 273 | basePoint[id].y = longi.double_value; |
kityann | 11:4d71c9cc3b4a | 274 | } |
m5171135 | 7:200ce5c1f486 | 275 | |
kityann | 13:a5bc425540a7 | 276 | //Update Robot Point |
kityann | 13:a5bc425540a7 | 277 | void AigamozuControlPackets::reNewRobotPointKalman(long latitudeH,long latitudeL,long longitudeH,long longitudeL){ |
kityann | 18:01882120e6cf | 278 | agzPointKalman.x = (double)latitudeH + (double)(latitudeL / 10000.0/60.0); |
kityann | 18:01882120e6cf | 279 | agzPointKalman.y = (double)longitudeH +(double)(longitudeL / 10000.0/60.0); |
kityann | 13:a5bc425540a7 | 280 | |
kityann | 13:a5bc425540a7 | 281 | } |
kityann | 13:a5bc425540a7 | 282 | |
kityann | 13:a5bc425540a7 | 283 | //Updata Base Point |
kityann | 19:13b24b50800e | 284 | void AigamozuControlPackets::reNewBasePointKalman(int id, uint8_t *latitude,uint8_t *longitude){ |
kityann | 19:13b24b50800e | 285 | UNION_double_char lat,longi; |
kityann | 19:13b24b50800e | 286 | for(int i = 0;i < 8;i++){ |
kityann | 19:13b24b50800e | 287 | lat.char_value[i]=latitude[i]; |
kityann | 19:13b24b50800e | 288 | } |
kityann | 19:13b24b50800e | 289 | for(int i = 0;i < 8;i++){ |
kityann | 19:13b24b50800e | 290 | longi.char_value[i]=longitude[i]; |
kityann | 19:13b24b50800e | 291 | } |
kityann | 19:13b24b50800e | 292 | |
kityann | 19:13b24b50800e | 293 | basePointKalman[id].x = lat.double_value; |
kityann | 19:13b24b50800e | 294 | basePointKalman[id].y = longi.double_value; |
s1200058 | 31:8753fbab3f1f | 295 | } |
kityann | 13:a5bc425540a7 | 296 | |
m5171135 | 7:200ce5c1f486 | 297 | |
m5171135 | 7:200ce5c1f486 | 298 | //Check Hit Point Area |
m5171135 | 7:200ce5c1f486 | 299 | bool AigamozuControlPackets::checkGpsHit( vertex2D A, vertex2D B, vertex2D C, vertex2D P){ |
m5171135 | 7:200ce5c1f486 | 300 | vector2D AB = AigamozuControlPackets::sub_vector(B, A); |
m5171135 | 7:200ce5c1f486 | 301 | vector2D BP = AigamozuControlPackets::sub_vector(P, B); |
m5171135 | 7:200ce5c1f486 | 302 | |
m5171135 | 7:200ce5c1f486 | 303 | vector2D BC = AigamozuControlPackets::sub_vector(C, B); |
m5171135 | 7:200ce5c1f486 | 304 | vector2D CP = AigamozuControlPackets::sub_vector(P, C); |
m5171135 | 7:200ce5c1f486 | 305 | |
m5171135 | 7:200ce5c1f486 | 306 | vector2D CA = AigamozuControlPackets::sub_vector(A, C); |
m5171135 | 7:200ce5c1f486 | 307 | vector2D AP = AigamozuControlPackets::sub_vector(P, A); |
m5171135 | 7:200ce5c1f486 | 308 | |
m5171135 | 7:200ce5c1f486 | 309 | double c1 = AB.x * BP.y - AB.y * BP.x; |
m5171135 | 7:200ce5c1f486 | 310 | double c2 = BC.x * CP.y - BC.y * CP.x; |
m5171135 | 7:200ce5c1f486 | 311 | double c3 = CA.x * AP.y - CA.y * AP.x; |
m5171135 | 7:200ce5c1f486 | 312 | |
m5171135 | 7:200ce5c1f486 | 313 | if( ( c1 > 0 && c2 > 0 && c3 > 0 ) || ( c1 < 0 && c2 < 0 && c3 < 0 ) ) { |
m5171135 | 7:200ce5c1f486 | 314 | return true; |
m5171135 | 5:3f51eeb5aedc | 315 | } |
m5171135 | 6:f164a716be46 | 316 | |
m5171135 | 7:200ce5c1f486 | 317 | return false; |
m5171135 | 7:200ce5c1f486 | 318 | |
m5171135 | 7:200ce5c1f486 | 319 | } |
m5171135 | 7:200ce5c1f486 | 320 | |
m5171135 | 7:200ce5c1f486 | 321 | vector2D AigamozuControlPackets::sub_vector( const vector2D& a, const vector2D& b ) |
m5171135 | 7:200ce5c1f486 | 322 | { |
m5171135 | 7:200ce5c1f486 | 323 | vector2D ret; |
m5171135 | 7:200ce5c1f486 | 324 | ret.x = a.x - b.x; |
m5171135 | 7:200ce5c1f486 | 325 | ret.y = a.y - b.y; |
m5171135 | 7:200ce5c1f486 | 326 | return ret; |
m5171135 | 7:200ce5c1f486 | 327 | } |
m5171135 | 7:200ce5c1f486 | 328 | |
m5171135 | 7:200ce5c1f486 | 329 | |
m5171135 | 7:200ce5c1f486 | 330 | |
m5171135 | 5:3f51eeb5aedc | 331 | |
m5171135 | 6:f164a716be46 | 332 | ////////////////////////////// |
m5171135 | 6:f164a716be46 | 333 | // Mode change // |
m5171135 | 6:f164a716be46 | 334 | ////////////////////////////// |
m5171135 | 2:3f2d4f53ceed | 335 | bool AigamozuControlPackets::changeMode(uint8_t *buf){ |
m5171135 | 2:3f2d4f53ceed | 336 | |
m5171135 | 6:f164a716be46 | 337 | //reset |
m5171135 | 5:3f51eeb5aedc | 338 | _agzSheild.changeSpeed(0,0,0,0); |
m5171135 | 6:f164a716be46 | 339 | eachModeInt.detach(); |
m5171135 | 5:3f51eeb5aedc | 340 | |
m5171135 | 6:f164a716be46 | 341 | //Select Mode |
s1200058 | 29:3a2d87c10e43 | 342 | switch(buf[19]){ |
m5171135 | 2:3f2d4f53ceed | 343 | case 0: |
m5171135 | 2:3f2d4f53ceed | 344 | nowMode = STANDBY_MODE; |
m5171135 | 2:3f2d4f53ceed | 345 | break; |
m5171135 | 2:3f2d4f53ceed | 346 | |
m5171135 | 2:3f2d4f53ceed | 347 | case 1: |
m5171135 | 6:f164a716be46 | 348 | eachModeInt.attach(this,&AigamozuControlPackets::manualMode,1.0); |
m5171135 | 2:3f2d4f53ceed | 349 | nowMode = MANUAL_MODE; |
m5171135 | 2:3f2d4f53ceed | 350 | break; |
m5171135 | 2:3f2d4f53ceed | 351 | |
m5171135 | 2:3f2d4f53ceed | 352 | case 2: |
kityann | 11:4d71c9cc3b4a | 353 | //nowMode = AUTO_MODE; |
kityann | 11:4d71c9cc3b4a | 354 | //eachModeInt.attach(this,&AigamozuControlPackets::randomAuto,1.0); |
s1200058 | 20:fec2d6dec897 | 355 | //eachModeInt.attach(this,&AigamozuControlPackets::gpsAuto,2.0); |
kityann | 11:4d71c9cc3b4a | 356 | nowMode = AUTO_GPS_MODE; |
s1200058 | 33:c11a9cb35840 | 357 | Move_Timer.reset(); |
m5171135 | 2:3f2d4f53ceed | 358 | break; |
m5171135 | 4:04dadf67ecb6 | 359 | |
m5171135 | 4:04dadf67ecb6 | 360 | case 3: |
s1200058 | 20:fec2d6dec897 | 361 | //eachModeInt.attach(this,&AigamozuControlPackets::gpsAuto,0.2); |
m5171135 | 4:04dadf67ecb6 | 362 | nowMode = AUTO_GPS_MODE; |
s1200058 | 33:c11a9cb35840 | 363 | Move_Timer.reset(); |
m5171135 | 4:04dadf67ecb6 | 364 | break; |
m5171135 | 4:04dadf67ecb6 | 365 | |
m5171135 | 6:f164a716be46 | 366 | default: |
m5171135 | 6:f164a716be46 | 367 | nowMode = STANDBY_MODE; |
m5171135 | 6:f164a716be46 | 368 | break; |
m5171135 | 5:3f51eeb5aedc | 369 | |
m5171135 | 2:3f2d4f53ceed | 370 | } |
m5171135 | 2:3f2d4f53ceed | 371 | return false; |
m5171135 | 2:3f2d4f53ceed | 372 | } |
m5171135 | 5:3f51eeb5aedc | 373 | |
m5171135 | 5:3f51eeb5aedc | 374 | |
m5171135 | 2:3f2d4f53ceed | 375 |