Skip to content
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

Add odometry term to optimization problem (wip) #456

Merged
merged 11 commits into from
Aug 21, 2017

Conversation

Mofef
Copy link
Contributor

@Mofef Mofef commented Aug 16, 2017

This is to address #370 , but it's still work in progress. However since there are a lot of changes related to odometry happening these days I felt it's better to come forward with some intermediate state to avoid double work.
A detailed review on this is probably a waste of time but i'm happy for some directions

Unaddressed problems are:

  • New parameters should be extracted to configuration files.
  • So far I don't pay attention to the time stamps.
  • Removing the old consecutive scan distance minimization terms results in a broken trajectory
  • The translational scaling factor seams to take whatever lower bound I offer it without a visible effect to the map. So probably I have a mistake in the problem formulation.
  • Probably hard bounds on those parameters are not the best way to go. A penalty with a scaling parameter could be better.
  • Maybe you prefer odometry parameters to stay outside of cartographer entirely. I could then remove the related code from this PR and open a new issue.

@@ -164,6 +164,15 @@ void SparsePoseGraph::AddImuData(const int trajectory_id,
});
}

void SparsePoseGraph::AddOdometerData(const int trajectory_id,
const sensor::OdometryData odometry_data) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty line?

@@ -97,6 +97,9 @@ class SparsePoseGraph : public mapping::SparsePoseGraph {
override EXCLUDES(mutex_);
std::vector<Constraint> constraints() override EXCLUDES(mutex_);

void AddOdometerData(const int trajectory_id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move right after AddImuData() similar to the .cc file?

@@ -23,6 +23,7 @@
#include <memory>
#include <string>
#include <vector>
#include <cartographer/sensor/odometry_data.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: This belongs to the next group of includes in alphabetical order.

@@ -78,6 +79,9 @@ class OptimizationProblem {
int num_trimmed_nodes(int trajectory_id) const;
int num_trimmed_submaps(int trajectory_id) const;

void AddOdometerData(const int trajectory_id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move right after to AddImuData() as in the .cc?

@@ -22,6 +22,7 @@
#include <map>
#include <set>
#include <vector>
#include <cartographer/sensor/odometry_data.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: Move to the next block of includes.

.pose,
0.3, 30.})),
nullptr /* loss function */,
C_nodes[trajectory_id][odometry_data_index - 1].data(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong: indices of nodes and odometry data are different in general since usually odometry has a higher frequency. I think what you want to do is look at the time stamps of two consecutive nodes, then use the data in odometry_data_ to compute the relative change expected according to odometry. Since you most likely do not have the exact timestamp in the odometry data, you'd have to interpolate between two odometry poses, once for the timestamp of the first node and once for the timestamp of the second node.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks. I'm currently working on it.

@@ -81,6 +81,56 @@ class SpaCostFunction {
const Constraint::Pose pose_;
};

class WarpedSpaCostFunction {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest leaving this out for now. Let's keep the focus of this PR on introducing odometry to the optimization. Adding scaling factors can be done in a follow up PR.

C_odometry[trajectory_id].data());
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we now tie together consecutive scans using odometry, the following code should be dropped/changed. As I see it odometry can take the place of

node_data_[trajectory_id][node_data_index - 1]
    .initial_point_cloud_pose.inverse() *
node_data_[trajectory_id][node_data_index]
    .initial_point_cloud_pose

I'd suggest changing the code to have one loop and either use a new computation of this relative pose using odometry if available, or the old code otherwise.

@wohe
Copy link
Member

wohe commented Aug 16, 2017

If you would like to merge a smaller PR sooner, feel free to send a PR containing just the code that moves odometry data to the optimization problem without making use of it yet.

@Mofef
Copy link
Contributor Author

Mofef commented Aug 17, 2017

Please take another look :)

@@ -78,6 +78,8 @@ class SparsePoseGraph : public mapping::SparsePoseGraph {

// Adds new IMU data to be used in the optimization.
void AddImuData(int trajectory_id, const sensor::ImuData& imu_data);
void AddOdometerData(const int trajectory_id,
const sensor::OdometryData data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take by const&? And please use the same argument name as in the implementation for readability: odometry_data. Similar in the optimization problem.

@@ -78,6 +78,8 @@ class SparsePoseGraph : public mapping::SparsePoseGraph {

// Adds new IMU data to be used in the optimization.
void AddImuData(int trajectory_id, const sensor::ImuData& imu_data);
void AddOdometerData(const int trajectory_id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the const of the const int argument? It is an implementation detail not needed in the header file. Similar in the optimization problem.

node_data_[trajectory_id][node_data_index].time) &&
odometry_data_[trajectory_id].Has(
node_data_[trajectory_id][node_data_index - 1].time)) {
problem.AddResidualBlock(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot of duplication. How about extracting the relative_pose, e.g.

const transform::Rigid2d relative_pose = odometry_available ? ... : ...
problem.AddResidualBlock(
...

@Mofef
Copy link
Contributor Author

Mofef commented Aug 18, 2017

Ok ready for another round :)

Copy link
Member

@wohe wohe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two nits.

@@ -59,6 +61,8 @@ class OptimizationProblem {
OptimizationProblem& operator=(const OptimizationProblem&) = delete;

void AddImuData(int trajectory_id, const sensor::ImuData& imu_data);
void AddOdometerData(int trajectory_id,
const sensor::OdometryData odometry_data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const&?

for (size_t trajectory_id = 0; trajectory_id != node_data_.size();
++trajectory_id) {
for (size_t node_data_index = 1;
node_data_index < node_data_[trajectory_id].size();
++node_data_index) {
bool odometry_available =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const?

@Mofef
Copy link
Contributor Author

Mofef commented Aug 18, 2017

Done

@wohe wohe merged commit 0ef372d into cartographer-project:master Aug 21, 2017
@jihoonl jihoonl deleted the optimization-odometry branch August 21, 2017 13:21
damienrg pushed a commit to damienrg/cartographer that referenced this pull request Nov 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants