-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RSDK-3323 - addSensorReading refactor #102
Changes from all commits
a553862
35ebe17
4413d4a
fb51495
f153d87
f9b5b95
e4f5337
9210f11
2fb0f26
ee44d9b
986e181
4bae5b8
758e84b
3c646d2
1a3d33a
e6e380d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -647,10 +647,34 @@ void SLAMServiceImpl::SaveMapWithTimestamp() { | |
} | ||
} | ||
|
||
bool SLAMServiceImpl::AddSensorReading( | ||
cartographer::sensor::TimedPointCloudData measurement) { | ||
cartographer::transform::Rigid3d tmp_global_pose; | ||
bool update_latest_global_pose = false; | ||
|
||
if (map_builder_mutex.try_lock()) { | ||
if (measurement.ranges.size() > 0) { | ||
nicksanford marked this conversation as resolved.
Show resolved
Hide resolved
|
||
trajectory_builder->AddSensorData(kRangeSensorId.id, measurement); | ||
auto local_poses = map_builder.GetLocalSlamResultPoses(); | ||
if (local_poses.size() > 0) { | ||
nicksanford marked this conversation as resolved.
Show resolved
Hide resolved
|
||
update_latest_global_pose = true; | ||
tmp_global_pose = map_builder.GetGlobalPose(trajectory_id, | ||
nicksanford marked this conversation as resolved.
Show resolved
Hide resolved
|
||
local_poses.back()); | ||
nicksanford marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
map_builder_mutex.unlock(); | ||
if (update_latest_global_pose) { | ||
std::lock_guard<std::mutex> lk(viam_response_mutex); | ||
latest_global_pose = tmp_global_pose; | ||
} | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
void SLAMServiceImpl::ProcessDataAndStartSavingMaps(double data_start_time) { | ||
// Prepare the trajectory builder and grab the active trajectory_id | ||
cartographer::mapping::TrajectoryBuilderInterface *trajectory_builder; | ||
int trajectory_id; | ||
{ | ||
std::lock_guard<std::mutex> lk(map_builder_mutex); | ||
// Set TrajectoryBuilder | ||
|
@@ -664,9 +688,6 @@ void SLAMServiceImpl::ProcessDataAndStartSavingMaps(double data_start_time) { | |
bool set_start_time = false; | ||
auto file = GetNextDataFile(); | ||
|
||
// Define tmp_global_pose here so it always has the previous pose | ||
cartographer::transform::Rigid3d tmp_global_pose = | ||
cartographer::transform::Rigid3d(); | ||
while (file != "") { | ||
// Ignore files that are not *.pcd files | ||
if (file.find(".pcd") == std::string::npos) { | ||
|
@@ -704,25 +725,10 @@ void SLAMServiceImpl::ProcessDataAndStartSavingMaps(double data_start_time) { | |
LOG(INFO) << "Starting to save maps..."; | ||
StartSaveMap(); | ||
} | ||
// Add data to the map_builder to add to the map | ||
{ | ||
std::lock_guard<std::mutex> lk(map_builder_mutex); | ||
auto measurement = map_builder.GetDataFromFile(file); | ||
if (measurement.ranges.size() > 0) { | ||
trajectory_builder->AddSensorData(kRangeSensorId.id, | ||
measurement); | ||
auto local_poses = map_builder.GetLocalSlamResultPoses(); | ||
if (local_poses.size() > 0) { | ||
tmp_global_pose = map_builder.GetGlobalPose( | ||
trajectory_id, local_poses.back()); | ||
} | ||
} | ||
} | ||
// Save a copy of the global pose | ||
{ | ||
std::lock_guard<std::mutex> lk(viam_response_mutex); | ||
latest_global_pose = tmp_global_pose; | ||
} | ||
// Add data to the map_builder to add to the map and save a copy of the | ||
// global pose | ||
auto measurement = map_builder.GetDataFromFile(file); | ||
AddSensorReading(measurement); | ||
|
||
// This log line is needed by rdk integration tests. | ||
VLOG(1) << "Passed sensor data to SLAM " << file; | ||
|
@@ -741,6 +747,8 @@ void SLAMServiceImpl::ProcessDataAndStartSavingMaps(double data_start_time) { | |
if (!use_live_data) { | ||
// We still want to optimize the map in localization mode, but we do not | ||
// need to update the backup of the map | ||
cartographer::transform::Rigid3d tmp_global_pose; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is happening outside the loop. This code is only executed in offline mode after we've processed all the data. |
||
bool update_latest_global_pose = false; | ||
if (action_mode != ActionMode::LOCALIZING) BackupLatestMap(); | ||
{ | ||
std::unique_lock<std::shared_mutex> optimization_lock( | ||
|
@@ -754,12 +762,13 @@ void SLAMServiceImpl::ProcessDataAndStartSavingMaps(double data_start_time) { | |
|
||
auto local_poses = map_builder.GetLocalSlamResultPoses(); | ||
if (local_poses.size() > 0) { | ||
update_latest_global_pose = true; | ||
tmp_global_pose = map_builder.GetGlobalPose(trajectory_id, | ||
local_poses.back()); | ||
} | ||
} | ||
|
||
{ | ||
if (update_latest_global_pose) { | ||
std::lock_guard<std::mutex> lk(viam_response_mutex); | ||
latest_global_pose = tmp_global_pose; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: In the implementation which makes it into CartoFacade you will need to detect the first time
AddSensorReading
has been called & set the start time on the map builder to be the time that the first lidar reading was taken.