이충섭

feat : detect abnormal gps

...@@ -1251,6 +1251,8 @@ void EKF2::UpdateGpsSample(ekf2_timestamps_s &ekf2_timestamps) ...@@ -1251,6 +1251,8 @@ void EKF2::UpdateGpsSample(ekf2_timestamps_s &ekf2_timestamps)
1251 _ekf.setGpsData(gps_msg); 1251 _ekf.setGpsData(gps_msg);
1252 if(hold != int(gps_msg.time_usec/1000000)) 1252 if(hold != int(gps_msg.time_usec/1000000))
1253 { 1253 {
1254 + if(!check_warning())
1255 + {
1254 dm_read(DM_KEY_MISSION_STATE, 0, &mission, sizeof(mission_s)); 1256 dm_read(DM_KEY_MISSION_STATE, 0, &mission, sizeof(mission_s));
1255 hold=int(gps_msg.time_usec/1000000); 1257 hold=int(gps_msg.time_usec/1000000);
1256 if(hold%2==0) 1258 if(hold%2==0)
...@@ -1258,7 +1260,9 @@ void EKF2::UpdateGpsSample(ekf2_timestamps_s &ekf2_timestamps) ...@@ -1258,7 +1260,9 @@ void EKF2::UpdateGpsSample(ekf2_timestamps_s &ekf2_timestamps)
1258 calculate_inclination_target(); 1260 calculate_inclination_target();
1259 print_target_gps(); 1261 print_target_gps();
1260 //print_current_gps(gps_msg); 1262 //print_current_gps(gps_msg);
1261 - check_inclination(calculate_inclination_current(gps_msg)); 1263 + double check=calculate_inclination_current(gps_msg);
1264 + check_inclination(check);
1265 + }
1262 } 1266 }
1263 } 1267 }
1264 _gps_time_usec = gps_msg.time_usec; 1268 _gps_time_usec = gps_msg.time_usec;
...@@ -1269,15 +1273,26 @@ void EKF2::UpdateGpsSample(ekf2_timestamps_s &ekf2_timestamps) ...@@ -1269,15 +1273,26 @@ void EKF2::UpdateGpsSample(ekf2_timestamps_s &ekf2_timestamps)
1269 void EKF2::check_inclination(double check) 1273 void EKF2::check_inclination(double check)
1270 { 1274 {
1271 double origin=inclination[int(mission.current_seq)-1]; 1275 double origin=inclination[int(mission.current_seq)-1];
1272 - std:: cout << "origin : "<<origin<<"\tcheck : "<<check<<std::endl; 1276 + std:: cout << "(origin : "<<origin<<" | check : "<<check<<")";
1273 if(origin-1<=check && check <= origin+1) 1277 if(origin-1<=check && check <= origin+1)
1274 { 1278 {
1275 - std::cout<<"*----Good moving----*"<<std::endl; 1279 + std::cout<<"\t--- Good moving"<<std::endl;
1280 + warning_count=0;
1276 } 1281 }
1277 else 1282 else
1278 { 1283 {
1279 - std::cout<<"*----Bad moving----*"<<std::endl; 1284 + std::cout<<"\t--- Bad moving"<<std::endl;
1285 + warning_count++;
1286 + }
1287 +}
1288 +bool EKF2::check_warning()
1289 +{
1290 + if(warning_count>=15)
1291 + {
1292 + std::cout<<"* [abnormal moving detected] *"<<std::endl;
1293 + return true;
1280 } 1294 }
1295 + return false;
1281 } 1296 }
1282 void EKF2::print_current_gps(gps_message gps_msg) 1297 void EKF2::print_current_gps(gps_message gps_msg)
1283 { 1298 {
...@@ -1292,8 +1307,6 @@ void EKF2::calculate_inclination_target() ...@@ -1292,8 +1307,6 @@ void EKF2::calculate_inclination_target()
1292 struct mission_item_s next_mission_item {}; 1307 struct mission_item_s next_mission_item {};
1293 dm_read((dm_item_t)mission.dataman_id, i, &mission_item, sizeof(mission_item_s)); 1308 dm_read((dm_item_t)mission.dataman_id, i, &mission_item, sizeof(mission_item_s));
1294 dm_read((dm_item_t)mission.dataman_id, i+1, &next_mission_item, sizeof(mission_item_s)); 1309 dm_read((dm_item_t)mission.dataman_id, i+1, &next_mission_item, sizeof(mission_item_s));
1295 - //std:: cout << "next : "<<next_mission_item.lat<<std::endl;
1296 - //std:: cout << "curr : "<<mission_item.lat<<std::endl;
1297 x=next_mission_item.lat-mission_item.lat; 1310 x=next_mission_item.lat-mission_item.lat;
1298 y=next_mission_item.lon-mission_item.lon; 1311 y=next_mission_item.lon-mission_item.lon;
1299 std::cout.setf(std::ios::fixed); 1312 std::cout.setf(std::ios::fixed);
...@@ -1305,9 +1318,6 @@ void EKF2::calculate_inclination_target() ...@@ -1305,9 +1318,6 @@ void EKF2::calculate_inclination_target()
1305 { 1318 {
1306 inclination[i]=0.0; 1319 inclination[i]=0.0;
1307 } 1320 }
1308 - /*if(int(i)==int(mission.current_seq)-1){
1309 - std::cout <<"[inclina]#"<<i<<"\t"<<inclination[i]<<std::endl;
1310 - }*/
1311 } 1321 }
1312 } 1322 }
1313 double EKF2::calculate_inclination_current(gps_message gps_msg) 1323 double EKF2::calculate_inclination_current(gps_message gps_msg)
...@@ -1321,10 +1331,9 @@ double EKF2::calculate_inclination_current(gps_message gps_msg) ...@@ -1321,10 +1331,9 @@ double EKF2::calculate_inclination_current(gps_message gps_msg)
1321 } 1331 }
1322 std::cout.setf(std::ios::fixed); 1332 std::cout.setf(std::ios::fixed);
1323 std::cout.precision(7); 1333 std::cout.precision(7);
1324 - //std::cout << "[Mission] #"<<mission.current_seq<<"\t"<<check_inclination<<std::endl;
1325 return check_inclination; 1334 return check_inclination;
1326 } 1335 }
1327 -void EKF2::print_target_gps() 1336 +void EKF2::set_target_gps()
1328 { 1337 {
1329 std::cout.unsetf(std::ios::fixed); 1338 std::cout.unsetf(std::ios::fixed);
1330 for (size_t i = 0; i < mission.count; i++) { 1339 for (size_t i = 0; i < mission.count; i++) {
...@@ -1334,7 +1343,6 @@ void EKF2::print_target_gps() ...@@ -1334,7 +1343,6 @@ void EKF2::print_target_gps()
1334 target_lat=int32_t(mission_item.lat * long(pow(10,7))); 1343 target_lat=int32_t(mission_item.lat * long(pow(10,7)));
1335 target_lon=int32_t(mission_item.lon * long(pow(10,7))); 1344 target_lon=int32_t(mission_item.lon * long(pow(10,7)));
1336 target_alt=int32_t(mission_item.altitude * long(pow(10,4))); 1345 target_alt=int32_t(mission_item.altitude * long(pow(10,4)));
1337 - //std::cout<<"start\t#"<<i<< "(lat/lon/alt)\t" << target_lat<< "\t"<<target_lon<<"\t"<<target_alt<<std::endl;
1338 } 1346 }
1339 } 1347 }
1340 } 1348 }
......
...@@ -135,12 +135,14 @@ private: ...@@ -135,12 +135,14 @@ private:
135 void UpdateMagSample(ekf2_timestamps_s &ekf2_timestamps); 135 void UpdateMagSample(ekf2_timestamps_s &ekf2_timestamps);
136 void UpdateRangeSample(ekf2_timestamps_s &ekf2_timestamps); 136 void UpdateRangeSample(ekf2_timestamps_s &ekf2_timestamps);
137 void UpdateMagCalibration(const hrt_abstime &timestamp); 137 void UpdateMagCalibration(const hrt_abstime &timestamp);
138 - void print_target_gps(); 138 + void set_target_gps();
139 void print_current_gps(gps_message gps_msg); 139 void print_current_gps(gps_message gps_msg);
140 void calculate_inclination_target(); 140 void calculate_inclination_target();
141 double calculate_inclination_current(gps_message gps_msg); 141 double calculate_inclination_current(gps_message gps_msg);
142 void check_inclination(double check); 142 void check_inclination(double check);
143 + bool check_warning();
143 double* inclination=nullptr; 144 double* inclination=nullptr;
145 + int warning_count=0;
144 int32_t target_lat,target_lon,target_alt; 146 int32_t target_lat,target_lon,target_alt;
145 mission_s mission; 147 mission_s mission;
146 /* 148 /*
......