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

Added Tf publisher #30

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Added Tf publisher #30

wants to merge 8 commits into from

Conversation

vikcp
Copy link

@vikcp vikcp commented Jun 7, 2019

Related to issue #29

I get an error "bad alloc" from the grid_compositor.cpp at line 66 when it tries to resize the "result_grid".

Thanks.

Copy link
Owner

@hrnr hrnr left a comment

Choose a reason for hiding this comment

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

See below a possible reason for your crashes. As always with multi-threaded code I would advise you to run it with thread sanitizer to check possible problems.

@@ -60,11 +60,14 @@ MapMerge::MapMerge() : subscriptions_size_(0)
robot_map_updates_topic_, "map_updates");
private_nh.param<std::string>("robot_namespace", robot_namespace_, "");
private_nh.param<std::string>("merged_map_topic", merged_map_topic, "map");
private_nh.param<std::string>("world_frame", world_frame_, "world");
private_nh.param<std::string>("world_frame", world_frame_, "map");
Copy link
Owner

Choose a reason for hiding this comment

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

is this intended?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, but it is because in my opinion each robot map should have the namespace of the robot, and then, the global map, just be called map.
But it is just how I imagine it. I can revert this change before the pull request.

{
if (!tf_current_flag_.test_and_set()) {
// need to recalculate stored transforms
auto transforms = pipeline_.getTransforms(); // this is thread-safe access
Copy link
Owner

Choose a reason for hiding this comment

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

this is not a thread-safe access AFAIK

Copy link
Owner

Choose a reason for hiding this comment

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

It think this may be the cause of the crash you experienced.

Copy link
Author

Choose a reason for hiding this comment

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

Ok! I'll have a look to this.

Copy link
Author

Choose a reason for hiding this comment

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

I have checked with TSan, and as you said, there was an issue there.
I have added a mutex to protect it.
With TSan I still have other warnings, however, I can't find the issue and I haven't experienced any other crashes.

@@ -387,6 +433,15 @@ void MapMerge::spin()
std::thread merging_thr([this]() { executemapMerging(); });
std::thread subscribing_thr([this]() { executetopicSubscribing(); });
std::thread estimation_thr([this]() { executeposeEstimation(); });
if (publish_tf) {
Copy link
Owner

Choose a reason for hiding this comment

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

could we make this similar to those above?

Copy link
Author

Choose a reason for hiding this comment

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

Done, I should have done it your way since the beginning.

}
}

std::vector<geometry_msgs::TransformStamped> MapMerge::StampTransforms(const std::vector<geometry_msgs::Transform> transforms_, const std::string& frame)
Copy link
Owner

Choose a reason for hiding this comment

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

functions start with lowercase letter. this function should be static inline non-member or static member as it does not access any member variables. names with trailing underscore indicate member variables and should not be used as arguments.

Copy link
Author

Choose a reason for hiding this comment

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

This function actually uses two member variables, which allow proper map naming. I changed the name of the transforms parameter not to confuse.
So should I leave this function as a member function as it uses two member variables or should I keep it static and pass the variables as parameters?

@cero10
Copy link

cero10 commented Aug 5, 2019

Is there a way I can get a version of the map merger where I can freely control the merged map's origin, by changing the initial poses of the robots? because I tried this branch but the merged map still has an offset.

@vikcp
Copy link
Author

vikcp commented Aug 6, 2019

Is there a way I can get a version of the map merger where I can freely control the merged map's origin, by changing the initial poses of the robots? because I tried this branch but the merged map still has an offset.

This PR does not involve the initial poses of the robot nor the creation of the merged map. It is just to publish the transforms between maps.

@andresjguevara
Copy link

Is this feature ready to be merged?

@hrnr
Copy link
Owner

hrnr commented Nov 10, 2019

@andresjguevara It would need couple of adjustments. Would you be interested to contribute those?

@vikcp
Copy link
Author

vikcp commented Nov 11, 2019

Hi,
I have been working on this feature for a while.
I finally find out how to get these transforms, because what I found was that OpenCV provides the proper rotation, but not the translation, so you need to manually reverse the process to obtain the translation.
I need to clean up the code, and then I can PR again to see if it fits here.
I'd need a couple of days

@vikcp
Copy link
Author

vikcp commented Nov 11, 2019

I have updated the PR with my last modifications.

@hrnr I have commented the "adjuster" because it was misleading the results. I don't know if you have other experience with this but it helped a lot no to add it in the loop.

@andresjguevara If the PR takes time or does not fit, you can use my fork of this work and try my branch called publish transforms, it should be working. However, take into account that no transform is given if the maps do not stitch and if the stitching is wrong it will provide wrong transforms.

@hrnr
Copy link
Owner

hrnr commented Nov 11, 2019

Thanks, I can take a look on Wednesday. I'm planing to release for Melodic, so it would be great to get your changes in.

@Xvdgeest
Copy link

This looks awesome, exactly what I need.
When will this feature be merged? Will it also be for kinetic?
Is there still help needed?

@Xvdgeest
Copy link

Thank you guys very much for putting the work in to get the transforms published. I cloned this branch and ran it on two mobile robots using rplidar and gmapping to create the (same) map. The robots are moving in the same area, thus seeing each other, which causes some disturbance.

I noticed that the transforms are very "jumpy". When the maps are merged (almost) correctly, The rotations align but the translation is off by a few meters. Also, the maps are drawn at (x,y)=(100,100), which is not a problem but it is a bit strange.
Screenshot_20191128_131114
Screenshot_20191128_131627

I'll see if I can find a solution, if you have any ideas, help would be greatly appreciated.

@vikcp
Copy link
Author

vikcp commented Nov 28, 2019

@Xvdgeest
Hi,
Regarding the "jumpy" transforms it might be cause for several reasons. One of them it could be due to the rate in which maps are updated and its new information processed. Are these transforms more stable once the map is closer to a completion and it does not expands anymore?
Regarding the initial position, the merged map is set initially at (0,0) but the maps that you are creating with gmapping can be initiated at a different position depending on the parameters that you use or your odometry values.
Please report any issues that you find so that we can all try to improve this feature.
Thank you!

@hrnr
Hi! Did you have time to check this PR?
It will be very helpful if you could have a look at the code.
Thank you!

@jkRaccoon
Copy link

@hrnr hi~! I`m still wait for this pr :)

@tristan-schwoerer
Copy link

@hrnr Is this viable to use? Would be amazing if we can get this PR approved then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants