이충섭

feat : caculate inclination among all of waypoints and between starting point and current position

...@@ -40,7 +40,7 @@ using math::constrain; ...@@ -40,7 +40,7 @@ using math::constrain;
40 using matrix::Eulerf; 40 using matrix::Eulerf;
41 using matrix::Quatf; 41 using matrix::Quatf;
42 using matrix::Vector3f; 42 using matrix::Vector3f;
43 - 43 +int static hold=0;
44 pthread_mutex_t ekf2_module_mutex = PTHREAD_MUTEX_INITIALIZER; 44 pthread_mutex_t ekf2_module_mutex = PTHREAD_MUTEX_INITIALIZER;
45 static px4::atomic<EKF2 *> _objects[EKF2_MAX_INSTANCES] {}; 45 static px4::atomic<EKF2 *> _objects[EKF2_MAX_INSTANCES] {};
46 #if !defined(CONSTRAINED_FLASH) 46 #if !defined(CONSTRAINED_FLASH)
...@@ -1509,19 +1509,83 @@ void EKF2::UpdateGpsSample(ekf2_timestamps_s &ekf2_timestamps) ...@@ -1509,19 +1509,83 @@ void EKF2::UpdateGpsSample(ekf2_timestamps_s &ekf2_timestamps)
1509 + vehicle_gps_position.vdop * vehicle_gps_position.vdop), 1509 + vehicle_gps_position.vdop * vehicle_gps_position.vdop),
1510 }; 1510 };
1511 _ekf.setGpsData(gps_msg); 1511 _ekf.setGpsData(gps_msg);
1512 - mission_s mission; 1512 + if(hold != int(gps_msg.time_usec/1000000))
1513 - dm_read(DM_KEY_MISSION_STATE, 0, &mission, sizeof(mission_s)); 1513 + {
1514 - for (size_t i = 0; i < mission.count; i++) { 1514 + dm_read(DM_KEY_MISSION_STATE, 0, &mission, sizeof(mission_s));
1515 - struct mission_item_s mission_item {}; 1515 + hold=int(gps_msg.time_usec/1000000);
1516 - dm_read((dm_item_t)mission.dataman_id, i, &mission_item, sizeof(mission_item_s)); 1516 + if(hold%2==0)
1517 - std::cout<<"target\t"<<i<< "(lat/lon/alt)\t" << mission_item.lat << "\t"<<mission_item.lon<<"\t"<<mission_item.altitude<<std::endl; 1517 + {
1518 + calculate_inclination_target();
1519 + print_target_gps();
1520 + //print_current_gps(gps_msg);
1521 + calculate_inclination_current(gps_msg);
1522 + }
1518 } 1523 }
1519 _gps_time_usec = gps_msg.time_usec; 1524 _gps_time_usec = gps_msg.time_usec;
1520 _gps_alttitude_ellipsoid = vehicle_gps_position.alt_ellipsoid; 1525 _gps_alttitude_ellipsoid = vehicle_gps_position.alt_ellipsoid;
1521 } 1526 }
1522 } 1527 }
1523 } 1528 }
1529 +void EKF2::print_current_gps(gps_message gps_msg)
1530 +{
1531 + std::cout<<"curre\t#"<<mission.current_seq<<"(lat/lon/alt)\t" << gps_msg.lat << "\t"<<gps_msg.lon<<"\t"<<gps_msg.alt<<std::endl;
1532 +}
1533 +void EKF2::calculate_inclination_target()
1534 +{
1535 + double x,y;
1536 + inclination=new double[int(mission.count)];
1537 + for (size_t i = 0; i < mission.count-1; i++) {
1538 + struct mission_item_s mission_item {};
1539 + struct mission_item_s next_mission_item {};
1540 + dm_read((dm_item_t)mission.dataman_id, i, &mission_item, sizeof(mission_item_s));
1541 + dm_read((dm_item_t)mission.dataman_id, i+1, &next_mission_item, sizeof(mission_item_s));
1542 + //std:: cout << "next : "<<next_mission_item.lat<<std::endl;
1543 + //std:: cout << "curr : "<<mission_item.lat<<std::endl;
1544 + x=next_mission_item.lat-mission_item.lat;
1545 + y=next_mission_item.lon-mission_item.lon;
1546 + std::cout.setf(std::ios::fixed);
1547 + std::cout.precision(7);
1548 + if(x!=0.0){
1549 + inclination[i]=y/x;
1550 + }
1551 + else
1552 + {
1553 + inclination[i]=0.0;
1554 + }
1555 + /*if(int(i)==int(mission.current_seq)-1){
1556 + std::cout <<"[inclina]#"<<i<<"\t"<<inclination[i]<<std::endl;
1557 + }*/
1558 + }
1559 +}
1560 +void EKF2::calculate_inclination_current(gps_message gps_msg)
1561 +{
1562 + double x,y;
1563 + double check_inclination=0;
1564 + x=target_lat-gps_msg.lat;
1565 + y=target_lon-gps_msg.lon;
1566 + if(x!=0.0){
1567 + check_inclination=y/x;
1568 + }
1569 + std::cout.setf(std::ios::fixed);
1570 + std::cout.precision(7);
1571 + std::cout << "[Mission] #"<<mission.current_seq<<"\t"<<check_inclination<<std::endl;
1524 1572
1573 +}
1574 +void EKF2::print_target_gps()
1575 +{
1576 + std::cout.unsetf(std::ios::fixed);
1577 +
1578 + for (size_t i = 0; i < mission.count; i++) {
1579 + struct mission_item_s mission_item {};
1580 + if(int(mission.current_seq)==int(i)){
1581 + dm_read((dm_item_t)mission.dataman_id, i, &mission_item, sizeof(mission_item_s));
1582 + target_lat=int32_t(mission_item.lat * long(pow(10,7)));
1583 + target_lon=int32_t(mission_item.lon * long(pow(10,7)));
1584 + target_alt=int32_t(mission_item.altitude * long(pow(10,4)));
1585 + //std::cout<<"start\t#"<<i<< "(lat/lon/alt)\t" << target_lat<< "\t"<<target_lon<<"\t"<<target_alt<<std::endl;
1586 + }
1587 + }
1588 +}
1525 void EKF2::UpdateMagSample(ekf2_timestamps_s &ekf2_timestamps) 1589 void EKF2::UpdateMagSample(ekf2_timestamps_s &ekf2_timestamps)
1526 { 1590 {
1527 const unsigned last_generation = _magnetometer_sub.get_last_generation(); 1591 const unsigned last_generation = _magnetometer_sub.get_last_generation();
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
43 #include "EKF2Selector.hpp" 43 #include "EKF2Selector.hpp"
44 44
45 #include <float.h> 45 #include <float.h>
46 - 46 +#include <dataman/dataman.h>
47 #include <containers/LockGuard.hpp> 47 #include <containers/LockGuard.hpp>
48 #include <drivers/drv_hrt.h> 48 #include <drivers/drv_hrt.h>
49 #include <lib/ecl/EKF/ekf.h> 49 #include <lib/ecl/EKF/ekf.h>
...@@ -155,14 +155,19 @@ private: ...@@ -155,14 +155,19 @@ private:
155 void UpdateRangeSample(ekf2_timestamps_s &ekf2_timestamps); 155 void UpdateRangeSample(ekf2_timestamps_s &ekf2_timestamps);
156 156
157 void UpdateMagCalibration(const hrt_abstime &timestamp); 157 void UpdateMagCalibration(const hrt_abstime &timestamp);
158 - 158 + void print_target_gps();
159 + void print_current_gps(gps_message gps_msg);
160 + void calculate_inclination_target();
161 + void calculate_inclination_current(gps_message gps_msg);
162 + double* inclination=nullptr;
163 + int32_t target_lat,target_lon,target_alt;
164 + mission_s mission;
159 /* 165 /*
160 * Calculate filtered WGS84 height from estimated AMSL height 166 * Calculate filtered WGS84 height from estimated AMSL height
161 */ 167 */
162 float filter_altitude_ellipsoid(float amsl_hgt); 168 float filter_altitude_ellipsoid(float amsl_hgt);
163 169
164 static constexpr float sq(float x) { return x * x; }; 170 static constexpr float sq(float x) { return x * x; };
165 -
166 const bool _replay_mode{false}; ///< true when we use replay data from a log 171 const bool _replay_mode{false}; ///< true when we use replay data from a log
167 const bool _multi_mode; 172 const bool _multi_mode;
168 int _instance{0}; 173 int _instance{0};
...@@ -176,6 +181,8 @@ private: ...@@ -176,6 +181,8 @@ private:
176 181
177 perf_counter_t _ecl_ekf_update_perf{perf_alloc(PC_ELAPSED, MODULE_NAME": ECL update")}; 182 perf_counter_t _ecl_ekf_update_perf{perf_alloc(PC_ELAPSED, MODULE_NAME": ECL update")};
178 perf_counter_t _ecl_ekf_update_full_perf{perf_alloc(PC_ELAPSED, MODULE_NAME": ECL full update")}; 183 perf_counter_t _ecl_ekf_update_full_perf{perf_alloc(PC_ELAPSED, MODULE_NAME": ECL full update")};
184 + perf_counter_t _imu_missed_perf{perf_alloc(PC_COUNT, MODULE_NAME": IMU message missed")};
185 + perf_counter_t _mag_missed_perf{perf_alloc(PC_COUNT, MODULE_NAME": mag message missed")};
179 186
180 // Used to check, save and use learned magnetometer biases 187 // Used to check, save and use learned magnetometer biases
181 hrt_abstime _mag_cal_last_us{0}; ///< last time the EKF was operating a mode that estimates magnetomer biases (uSec) 188 hrt_abstime _mag_cal_last_us{0}; ///< last time the EKF was operating a mode that estimates magnetomer biases (uSec)
......