mirror of
https://github.com/30hours/blah2.git
synced 2024-11-18 12:33:58 +00:00
Fix tracker segfault and var init from valgrind
This commit is contained in:
parent
8305c2d269
commit
097e0e8761
7 changed files with 76 additions and 21 deletions
|
@ -12,6 +12,7 @@ SET (PROJECT_TEST_DIR "${PROJECT_SOURCE_DIR}/test")
|
||||||
SET (PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/src")
|
SET (PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/src")
|
||||||
SET (PROJECT_BINARY_DIR "${PROJECT_ROOT}/bin")
|
SET (PROJECT_BINARY_DIR "${PROJECT_ROOT}/bin")
|
||||||
SET (PROJECT_BINARY_TEST_DIR "${PROJECT_ROOT}/bin/test")
|
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")
|
SET (PROJECT_LIB_DIR "${PROJECT_ROOT}/lib")
|
||||||
MESSAGE ("Source path: ${PROJECT_SOURCE_DIR}")
|
MESSAGE ("Source path: ${PROJECT_SOURCE_DIR}")
|
||||||
MESSAGE ("Binary path: ${PROJECT_BINARY_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/ambiguity/Ambiguity.cpp
|
||||||
${PROJECT_SOURCE_DIR}/process/meta/HammingNumber.cpp)
|
${PROJECT_SOURCE_DIR}/process/meta/HammingNumber.cpp)
|
||||||
target_link_libraries(testAmbiguity catch2 fftw3 fftw3_threads)
|
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}")
|
||||||
|
|
|
@ -269,8 +269,8 @@ int main(int argc, char **argv)
|
||||||
timing_helper(timing_name, timing_time, time, "detector");
|
timing_helper(timing_name, timing_time, time, "detector");
|
||||||
|
|
||||||
// tracker process
|
// tracker process
|
||||||
// track = tracker->process(detection, time[0]/1000);
|
track = tracker->process(detection, time[0]/1000);
|
||||||
// timing_helper(timing_name, timing_time, time, "tracker");
|
timing_helper(timing_name, timing_time, time, "tracker");
|
||||||
|
|
||||||
// output IqData meta data
|
// output IqData meta data
|
||||||
jsonIqData = x->to_json(time[0]/1000);
|
jsonIqData = x->to_json(time[0]/1000);
|
||||||
|
@ -305,12 +305,12 @@ int main(int argc, char **argv)
|
||||||
delete detection2;
|
delete detection2;
|
||||||
|
|
||||||
// output tracker data
|
// output tracker data
|
||||||
// jsonTracker = track->to_json(time[0]/1000);
|
jsonTracker = track->to_json(time[0]/1000);
|
||||||
// for (int i = 0; i < (jsonTracker.size() + MTU - 1) / MTU; i++)
|
for (int i = 0; i < (jsonTracker.size() + MTU - 1) / MTU; i++)
|
||||||
// {
|
{
|
||||||
// subdata = jsonTracker.substr(i * MTU, MTU);
|
subdata = jsonTracker.substr(i * MTU, MTU);
|
||||||
// socket_track.write_some(asio::buffer(subdata, subdata.size()), err);
|
socket_track.write_some(asio::buffer(subdata, subdata.size()), err);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// output radar data timer
|
// output radar data timer
|
||||||
timing_helper(timing_name, timing_time, time, "output_radar_data");
|
timing_helper(timing_name, timing_time, time, "output_radar_data");
|
||||||
|
|
|
@ -14,6 +14,7 @@ Capture::Capture(std::string _type, uint32_t _fs, uint32_t _fc, std::string _pat
|
||||||
fs = _fs;
|
fs = _fs;
|
||||||
fc = _fc;
|
fc = _fc;
|
||||||
path = _path;
|
path = _path;
|
||||||
|
replay = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Capture::process(IqData *buffer1, IqData *buffer2)
|
void Capture::process(IqData *buffer1, IqData *buffer2)
|
||||||
|
|
|
@ -70,6 +70,7 @@ RspDuo::RspDuo(uint32_t _fc, std::string _path)
|
||||||
dab_notch_fg = false;
|
dab_notch_fg = false;
|
||||||
chunk_time_nr = DEF_CHUNK_TIME_NR;
|
chunk_time_nr = DEF_CHUNK_TIME_NR;
|
||||||
path = _path;
|
path = _path;
|
||||||
|
capture = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string RspDuo::set_file(std::string path)
|
std::string RspDuo::set_file(std::string path)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
#include "rapidjson/writer.h"
|
#include "rapidjson/writer.h"
|
||||||
|
@ -124,7 +125,8 @@ void Track::promote(uint64_t index, uint32_t m, uint32_t n)
|
||||||
_m++;
|
_m++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// promote track to ACTIVE if passes test
|
|
||||||
|
// promote track to ACTIVE if passes threshold
|
||||||
if (_m >= m)
|
if (_m >= m)
|
||||||
{
|
{
|
||||||
state.at(index).at(state.at(index).size()-1) = STATE_ACTIVE;
|
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)
|
void Track::remove(uint64_t index)
|
||||||
{
|
{
|
||||||
id.erase(id.begin() + index);
|
// Check if the index is within bounds for each vector
|
||||||
state.erase(state.begin() + index);
|
if (index < id.size()) {
|
||||||
current.erase(current.begin() + index);
|
id.erase(id.begin() + index);
|
||||||
acceleration.erase(acceleration.begin() + index);
|
} else {
|
||||||
associated.erase(associated.begin() + index);
|
// 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)
|
std::string Track::to_json(uint64_t timestamp)
|
||||||
|
@ -171,17 +199,22 @@ std::string Track::to_json(uint64_t timestamp)
|
||||||
document.GetAllocator());
|
document.GetAllocator());
|
||||||
rapidjson::Value associatedDelay(rapidjson::kArrayType);
|
rapidjson::Value associatedDelay(rapidjson::kArrayType);
|
||||||
rapidjson::Value associatedDoppler(rapidjson::kArrayType);
|
rapidjson::Value associatedDoppler(rapidjson::kArrayType);
|
||||||
|
rapidjson::Value associatedState(rapidjson::kArrayType);
|
||||||
for (size_t j = 0; j < associated.at(i).size(); j++)
|
for (size_t j = 0; j < associated.at(i).size(); j++)
|
||||||
{
|
{
|
||||||
associatedDelay.PushBack(associated.at(i).at(j).get_delay().at(0),
|
associatedDelay.PushBack(associated.at(i).at(j).get_delay().at(0),
|
||||||
document.GetAllocator());
|
document.GetAllocator());
|
||||||
associatedDoppler.PushBack(associated.at(i).at(j).get_doppler().at(0),
|
associatedDoppler.PushBack(associated.at(i).at(j).get_doppler().at(0),
|
||||||
document.GetAllocator());
|
document.GetAllocator());
|
||||||
|
associatedState.PushBack(rapidjson::Value(state.at(i).at(j).c_str(),
|
||||||
|
document.GetAllocator()).Move(), document.GetAllocator());
|
||||||
}
|
}
|
||||||
object1.AddMember("associated_delay",
|
object1.AddMember("associated_delay",
|
||||||
associatedDelay, document.GetAllocator());
|
associatedDelay, document.GetAllocator());
|
||||||
object1.AddMember("associated_doppler",
|
object1.AddMember("associated_doppler",
|
||||||
associatedDoppler, document.GetAllocator());
|
associatedDoppler, document.GetAllocator());
|
||||||
|
object1.AddMember("associated_state",
|
||||||
|
associatedState, document.GetAllocator());
|
||||||
dataArray.PushBack(object1, document.GetAllocator());
|
dataArray.PushBack(object1, document.GetAllocator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,12 @@
|
||||||
/// @brief A class to store track data.
|
/// @brief A class to store track data.
|
||||||
/// @details The ID is 4 digit hexadecimal with 16^4 = 65536 combinations.
|
/// @details The ID is 4 digit hexadecimal with 16^4 = 65536 combinations.
|
||||||
/// @details The state can be TENTATIVE, ASSOCIATED, ACTIVE or COASTING.
|
/// @details The state can be TENTATIVE, ASSOCIATED, ACTIVE or COASTING.
|
||||||
/// @details Associated detections use null detections when no updates.
|
/// @details - TENTATIVE when a track is initialised.
|
||||||
/// @details Current is seperated from associated for smoothing.
|
/// @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
|
/// @author 30hours
|
||||||
/// @todo I feel promote() should be implemented in the tracker.
|
/// @todo I feel promote() should be implemented in the tracker.
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,8 @@ void Tracker::update(Detection *detection, uint64_t current)
|
||||||
// associate detections
|
// associate detections
|
||||||
if (delay[j] > delayPredict-1 &&
|
if (delay[j] > delayPredict-1 &&
|
||||||
delay[j] < delayPredict+1 &&
|
delay[j] < delayPredict+1 &&
|
||||||
doppler[j] > dopplerPredict-(2/cpi) &&
|
doppler[j] > dopplerPredict-1*(1/cpi) &&
|
||||||
doppler[j] < dopplerPredict+(2/cpi))
|
doppler[j] < dopplerPredict+1*(1/cpi))
|
||||||
{
|
{
|
||||||
Detection associated(delay[j], doppler[j], snr[j]);
|
Detection associated(delay[j], doppler[j], snr[j]);
|
||||||
track.set_current(i, associated);
|
track.set_current(i, associated);
|
||||||
|
@ -90,7 +90,7 @@ void Tracker::update(Detection *detection, uint64_t current)
|
||||||
doNotInitiate[j] = true;
|
doNotInitiate[j] = true;
|
||||||
state = "ASSOCIATED";
|
state = "ASSOCIATED";
|
||||||
track.set_state(i, state);
|
track.set_state(i, state);
|
||||||
// check for track promotion
|
// promote track if passes threshold
|
||||||
track.promote(i, m, n);
|
track.promote(i, m, n);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,11 @@ void Tracker::update(Detection *detection, uint64_t current)
|
||||||
state = "COASTING";
|
state = "COASTING";
|
||||||
track.set_state(i, state);
|
track.set_state(i, state);
|
||||||
}
|
}
|
||||||
|
else if (track.get_state(i) == "ASSOCIATED")
|
||||||
|
{
|
||||||
|
state = "TENTATIVE";
|
||||||
|
track.set_state(i, state);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
track.set_state(i, track.get_state(i));
|
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
|
// remove if tentative or coasting too long
|
||||||
if (track.get_nInactive(i) > nDelete)
|
if (track.get_nInactive(i) > nDelete)
|
||||||
{
|
{
|
||||||
track.remove(i+nRemove);
|
track.remove(i-nRemove);
|
||||||
nRemove++;
|
nRemove++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue