diff --git a/CMakeLists.txt b/CMakeLists.txt index 7837952..8f8f8d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ SET (PROJECT_TEST_DIR "${PROJECT_SOURCE_DIR}/test") SET (PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/src") SET (PROJECT_BINARY_DIR "${PROJECT_ROOT}/bin") SET (PROJECT_BINARY_TEST_DIR "${PROJECT_ROOT}/bin/test") +SET (PROJECT_BINARY_TEST_UNIT_DIR "${PROJECT_ROOT}/bin/test/unit") SET (PROJECT_LIB_DIR "${PROJECT_ROOT}/lib") MESSAGE ("Source path: ${PROJECT_SOURCE_DIR}") MESSAGE ("Binary path: ${PROJECT_BINARY_DIR}") @@ -90,4 +91,14 @@ add_executable(testAmbiguity ${PROJECT_SOURCE_DIR}/process/ambiguity/Ambiguity.cpp ${PROJECT_SOURCE_DIR}/process/meta/HammingNumber.cpp) target_link_libraries(testAmbiguity catch2 fftw3 fftw3_threads) -set_target_properties(testAmbiguity PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_TEST_DIR}") +set_target_properties(testAmbiguity PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_TEST_UNIT_DIR}") + +add_executable(testTracker + ${PROJECT_TEST_DIR}/unit/process/tracker/TestTracker.cpp + ${PROJECT_SOURCE_DIR}/data/Detection.cpp + ${PROJECT_SOURCE_DIR}/data/Track.cpp + ${PROJECT_SOURCE_DIR}/process/tracker/Tracker.cpp) +target_link_libraries(testTracker catch2) +set_target_properties(testTracker PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_TEST_UNIT_DIR}") diff --git a/src/blah2.cpp b/src/blah2.cpp index d7d84b2..aa4d5e8 100644 --- a/src/blah2.cpp +++ b/src/blah2.cpp @@ -269,8 +269,8 @@ int main(int argc, char **argv) timing_helper(timing_name, timing_time, time, "detector"); // tracker process - // track = tracker->process(detection, time[0]/1000); - // timing_helper(timing_name, timing_time, time, "tracker"); + track = tracker->process(detection, time[0]/1000); + timing_helper(timing_name, timing_time, time, "tracker"); // output IqData meta data jsonIqData = x->to_json(time[0]/1000); @@ -305,12 +305,12 @@ int main(int argc, char **argv) delete detection2; // output tracker data - // jsonTracker = track->to_json(time[0]/1000); - // for (int i = 0; i < (jsonTracker.size() + MTU - 1) / MTU; i++) - // { - // subdata = jsonTracker.substr(i * MTU, MTU); - // socket_track.write_some(asio::buffer(subdata, subdata.size()), err); - // } + jsonTracker = track->to_json(time[0]/1000); + for (int i = 0; i < (jsonTracker.size() + MTU - 1) / MTU; i++) + { + subdata = jsonTracker.substr(i * MTU, MTU); + socket_track.write_some(asio::buffer(subdata, subdata.size()), err); + } // output radar data timer timing_helper(timing_name, timing_time, time, "output_radar_data"); diff --git a/src/capture/Capture.cpp b/src/capture/Capture.cpp index 488ea13..a6521f9 100644 --- a/src/capture/Capture.cpp +++ b/src/capture/Capture.cpp @@ -14,6 +14,7 @@ Capture::Capture(std::string _type, uint32_t _fs, uint32_t _fc, std::string _pat fs = _fs; fc = _fc; path = _path; + replay = false; } void Capture::process(IqData *buffer1, IqData *buffer2) diff --git a/src/capture/rspduo/RspDuo.cpp b/src/capture/rspduo/RspDuo.cpp index b9f168a..d7fc1cd 100644 --- a/src/capture/rspduo/RspDuo.cpp +++ b/src/capture/rspduo/RspDuo.cpp @@ -70,6 +70,7 @@ RspDuo::RspDuo(uint32_t _fc, std::string _path) dab_notch_fg = false; chunk_time_nr = DEF_CHUNK_TIME_NR; path = _path; + capture = false; } std::string RspDuo::set_file(std::string path) diff --git a/src/data/Track.cpp b/src/data/Track.cpp index a2dde54..1bf6e5c 100644 --- a/src/data/Track.cpp +++ b/src/data/Track.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "rapidjson/document.h" #include "rapidjson/writer.h" @@ -124,7 +125,8 @@ void Track::promote(uint64_t index, uint32_t m, uint32_t n) _m++; } } - // promote track to ACTIVE if passes test + + // promote track to ACTIVE if passes threshold if (_m >= m) { state.at(index).at(state.at(index).size()-1) = STATE_ACTIVE; @@ -134,11 +136,37 @@ void Track::promote(uint64_t index, uint32_t m, uint32_t n) void Track::remove(uint64_t index) { - id.erase(id.begin() + index); - state.erase(state.begin() + index); - current.erase(current.begin() + index); - acceleration.erase(acceleration.begin() + index); - associated.erase(associated.begin() + index); + // Check if the index is within bounds for each vector + if (index < id.size()) { + id.erase(id.begin() + index); + } else { + // Throw an exception if the index is out of bounds + throw std::out_of_range("Index out of bounds for 'id' vector"); + } + + if (index < state.size()) { + state.erase(state.begin() + index); + } else { + throw std::out_of_range("Index out of bounds for 'state' vector"); + } + + if (index < current.size()) { + current.erase(current.begin() + index); + } else { + throw std::out_of_range("Index out of bounds for 'current' vector"); + } + + if (index < acceleration.size()) { + acceleration.erase(acceleration.begin() + index); + } else { + throw std::out_of_range("Index out of bounds for 'acceleration' vector"); + } + + if (index < associated.size()) { + associated.erase(associated.begin() + index); + } else { + throw std::out_of_range("Index out of bounds for 'associated' vector"); + } } std::string Track::to_json(uint64_t timestamp) @@ -171,17 +199,22 @@ std::string Track::to_json(uint64_t timestamp) document.GetAllocator()); rapidjson::Value associatedDelay(rapidjson::kArrayType); rapidjson::Value associatedDoppler(rapidjson::kArrayType); + rapidjson::Value associatedState(rapidjson::kArrayType); for (size_t j = 0; j < associated.at(i).size(); j++) { associatedDelay.PushBack(associated.at(i).at(j).get_delay().at(0), document.GetAllocator()); associatedDoppler.PushBack(associated.at(i).at(j).get_doppler().at(0), document.GetAllocator()); + associatedState.PushBack(rapidjson::Value(state.at(i).at(j).c_str(), + document.GetAllocator()).Move(), document.GetAllocator()); } object1.AddMember("associated_delay", associatedDelay, document.GetAllocator()); object1.AddMember("associated_doppler", associatedDoppler, document.GetAllocator()); + object1.AddMember("associated_state", + associatedState, document.GetAllocator()); dataArray.PushBack(object1, document.GetAllocator()); } } diff --git a/src/data/Track.h b/src/data/Track.h index ae7bada..016bf4f 100644 --- a/src/data/Track.h +++ b/src/data/Track.h @@ -3,8 +3,12 @@ /// @brief A class to store track data. /// @details The ID is 4 digit hexadecimal with 16^4 = 65536 combinations. /// @details The state can be TENTATIVE, ASSOCIATED, ACTIVE or COASTING. -/// @details Associated detections use null detections when no updates. -/// @details Current is seperated from associated for smoothing. +/// @details - TENTATIVE when a track is initialised. +/// @details - TENTATIVE when an ASSOCIATED track fails to associate. +/// @details - ASSOCIATED when a TENTATIVE track has an associated detection. +/// @details - ACTIVE when track passes the promotion threshold. +/// @details - COASTING when an ACTIVE track fails to associate. +/// @details Current track is used for smoothing output. /// @author 30hours /// @todo I feel promote() should be implemented in the tracker. diff --git a/src/process/tracker/Tracker.cpp b/src/process/tracker/Tracker.cpp index 50dd32b..ea6436d 100644 --- a/src/process/tracker/Tracker.cpp +++ b/src/process/tracker/Tracker.cpp @@ -80,8 +80,8 @@ void Tracker::update(Detection *detection, uint64_t current) // associate detections if (delay[j] > delayPredict-1 && delay[j] < delayPredict+1 && - doppler[j] > dopplerPredict-(2/cpi) && - doppler[j] < dopplerPredict+(2/cpi)) + doppler[j] > dopplerPredict-1*(1/cpi) && + doppler[j] < dopplerPredict+1*(1/cpi)) { Detection associated(delay[j], doppler[j], snr[j]); track.set_current(i, associated); @@ -90,7 +90,7 @@ void Tracker::update(Detection *detection, uint64_t current) doNotInitiate[j] = true; state = "ASSOCIATED"; track.set_state(i, state); - // check for track promotion + // promote track if passes threshold track.promote(i, m, n); break; } @@ -103,6 +103,11 @@ void Tracker::update(Detection *detection, uint64_t current) state = "COASTING"; track.set_state(i, state); } + else if (track.get_state(i) == "ASSOCIATED") + { + state = "TENTATIVE"; + track.set_state(i, state); + } else { track.set_state(i, track.get_state(i)); @@ -112,7 +117,7 @@ void Tracker::update(Detection *detection, uint64_t current) // remove if tentative or coasting too long if (track.get_nInactive(i) > nDelete) { - track.remove(i+nRemove); + track.remove(i-nRemove); nRemove++; } }