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

Improve perception tutorial #633

Merged
merged 12 commits into from Jun 5, 2021

Conversation

v4hn
Copy link
Contributor

@v4hn v4hn commented Apr 27, 2021

I tried to address #631
and improved various aspects of this tutorial. It's still quite ugly in general
and actually segfaults for me locally, but that's hopefully just because of an issue in my custom PCL version?

Please review @simonschmeisser

EDIT: For the sake of completeness here is my gdb backtrace:

#0  0x00007ffff3946c20 in free () from /lib/libc.so.6
#1  0x00007ffff2d1816c in ?? () from /usr/lib/libpcl_sample_consensus.so.1.10
#2  0x00007ffff351eea1 in GOMP_parallel (fn=0x7ffff2d17fb0, data=0x7fffffffc8b0, num_threads=1, flags=0) at ../../../libgomp/parallel.c:171
#3  0x00007ffff2cfc423 in pcl::RandomSampleConsensus<pcl::PointXYZ>::computeModel(int) () from /usr/lib/libpcl_sample_consensus.so.1.10
#4  0x00007ffff46b219f in pcl::SACSegmentation<pcl::PointXYZ>::segment(pcl::PointIndices&, pcl::ModelCoefficients&) () from /usr/lib/libpcl_segmentation.so.1.10
#5  0x00000000004630a7 in CylinderSegment::removePlaneSurface (this=0x7fffffffd778, cloud=..., inliers_plane=...) at moveit_tutorials/doc/perception_pipeline/src/detect_and_add_cylinder_collision_object_demo.cpp:223
#6  0x00000000004580a9 in CylinderSegment::cloudCB (this=0x7fffffffd778, input=...) at moveit_tutorials/doc/perception_pipeline/src/detect_and_add_cylinder_collision_object_demo.cpp:290

@v4hn v4hn force-pushed the pr-improve-perception-pipeline branch 3 times, most recently from 2de10f7 to 3331dea Compare April 28, 2021 09:18
@simonschmeisser
Copy link
Contributor

What happened to the launchfile? 😆

Also I still get some warnings with the obstacle avoidance launchfile:

roslaunch moveit_tutorials obstacle_avoidance_demo.launch

[ INFO] [1619641423.033922611]: Loading robot model 'panda'...
[ WARN] [1619641423.034247609]: Link panda_leftfinger has visual geometry but no collision geometry. Collision geometry will be left empty. Fix your URDF file by explicitly specifying collision geometry.
[ WARN] [1619641423.034282222]: Link panda_rightfinger has visual geometry but no collision geometry. Collision geometry will be left empty. Fix your URDF file by explicitly specifying collision geometry.
[ERROR] [1619641423.432320913]: Transform error: Lookup would require extrapolation 0.093739482s into the past.  Requested time 1619641422.912770033 but the earliest data is at time 1619641423.006509542, when looking up transform from frame [panda_link1] to frame [camera_rgb_optical_frame]                                                                                                                                                                                    
[ERROR] [1619641423.432396877]: Transform cache was not updated. Self-filtering may fail.
[ INFO] [1619641423.685372414]: Loading robot model 'panda'...
[ WARN] [1619641423.685528053]: Link panda_leftfinger has visual geometry but no collision geometry. Collision geometry will be left empty. Fix your URDF file by explicitly specifying collision geometry.
[ WARN] [1619641423.685561210]: Link panda_rightfinger has visual geometry but no collision geometry. Collision geometry will be left empty. Fix your URDF file by explicitly specifying collision geometry.
[ INFO] [1619641423.812810514]: Starting planning scene monitor
[ INFO] [1619641423.815368518]: Listening to '/move_group/monitored_planning_scene'

@v4hn
Copy link
Contributor Author

v4hn commented Apr 28, 2021

I pointed out the "no collision geometry" errors to the panda team before when they changed their collision geometry and they ignored me.
Personally, I reverted the description locally to release 0.6.0-1 which still had sane models.

[ERROR] [1619641423.432320913]: Transform error: Lookup would require extrapolation 0.093739482s into the past. > Requested time 1619641422.912770033 but the earliest data is at time 1619641423.006509542, when looking up transform from frame [panda_link1] to frame [camera_rgb_optical_frame]
[ERROR] [1619641423.432396877]: Transform cache was not updated. Self-filtering may fail.

This one's a bit harder to fix because the transforms world->camera and world->robot are published independently and the logic will only wait for the former one before attempting the transforms for all individual robot transforms.
To fix this, the point data updaters would need to wait for valid robot transforms before starting up.
Everyone is invited to implement that feature in MoveIt. ;)

@simonschmeisser
Copy link
Contributor

You wrote something somewhere about not being able to reference a launchfile from another and this being the reason for the removal of said launchfile? Could you elaborate a bit?

@v4hn
Copy link
Contributor Author

v4hn commented May 3, 2021

You wrote something somewhere about not being able to reference a launchfile from another and this being the reason for the removal of said launchfile?

moveit_tutorials installs all its launch files to ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch (and in my opinion that makes sense for the installed package. But launch files in the source package lie with their respective tutorials in ${CATKIN_PACKAGE_SHARE_DESTINATION}/doc/<tutorial>/. So $(find <pkg>)/... includes in launch files can't work in both modes. In the end that reason was resolved by John in an independent discussion, because launch was extended in ROS lunar by a $(dirname) keyword that solves this exact situation and allows relative includes. (Horray)

I left this patch as-is though, because it actually makes sense to look at the full pointcloud/octomap and then start the node that recognizes and filters the cylinder.

@v4hn v4hn force-pushed the pr-improve-perception-pipeline branch from 3331dea to dd8a182 Compare May 3, 2021 10:48
@felixvd
Copy link
Contributor

felixvd commented May 3, 2021

I was just asked to run this blindly and it doesn't segfault for me on Ubuntu 18.04 (in the master-source container).

I didn't read this in detail, but my superficial impression is that the copy-pastable, executable lines should come first, and the explanation about the configuration and how to do it with a custom robot second.

@jspricke
Copy link
Contributor

jspricke commented May 3, 2021

works for me on Debian unstable as well.

Copy link
Member

@davetcoleman davetcoleman left a comment

Choose a reason for hiding this comment

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

Would be best if more of a perception expert also reviewed this, like @JStech

roslaunch moveit_tutorials detect_and_add_cylinder_collision_object_demo.launch
Keep the launch file from above running and run the code directly from moveit_tutorials: ::

rosrun moveit_tutorials detect_and_add_cylinder_collision_object_demo

KNOWN ISSUE - You may see the following error when running the demo ::
Copy link
Member

Choose a reason for hiding this comment

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

Does this PR address this issue, enough to remove this disclaimer? Below the fold it says "We are working on fixing it" which is not true, no one has commented on the linked issue in 3 years

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still seeing the errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The source of the error is that the shape updater used for self-filtering has to wait for transforms from the whole robot to the planning_frame.
The waiting time can be configured by a magic ROS parameter and I increased the value to 0.5 seconds.
That works well on my intel i5 laptop and I expected it would be enough time for the robot_state_publisher to publish the robot transforms even on a weak user machine.
@JStech Could you please try different values and see how much time is actually needed on your system to get rid of these errors?
Alternatively (or in addition) we could throttle the publish frequency of the point cloud and reduce the maximum iterations of the RANSAC runs to reduce some computational load.

Copy link
Contributor

Choose a reason for hiding this comment

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

This was sufficient to stop the errors for me:

diff --git a/doc/perception_pipeline/src/bag_publisher_maintain_time.cpp b/doc/perception_pipeline/src/bag_publisher_maintain_time.cpp
index fa40247..1ad1b96 100644
--- a/doc/perception_pipeline/src/bag_publisher_maintain_time.cpp
+++ b/doc/perception_pipeline/src/bag_publisher_maintain_time.cpp
@@ -71,7 +71,7 @@ int main(int argc, char** argv)
   ros::Rate loop_rate(0.2);
   while (ros::ok())
   {
-    point_cloud_ptr->header.stamp = ros::Time::now();
+    point_cloud_ptr->header.stamp = ros::Time::now() - ros::Duration(0.1);
     point_cloud_publisher.publish(*point_cloud_ptr);
     loop_rate.sleep();
   }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And increasing shape_transform_cache_lookup_wait_time to 0.6 seconds instead does not work?
I'm not happy with introducing a delay to the "camera driver".
If the driver is that perfect and can provide current data on the topic, MoveIt should be able to handle that, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Does that fix it reliably?

Copy link
Contributor Author

@v4hn v4hn May 22, 2021

Choose a reason for hiding this comment

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

Sorry for leaving this hanging out to dry for so long, I'm overwhelmed by all the open things to do in MoveIt and my strongly constraint personal availability.

What did fix it was adding a half second sleep before the publish loop.

I'm somewhat unsure what you mean here. Do you actually mean before the loop or before the publish call.
I just made the publisher latched (makes sense to me anyway with a 0.2s publish rate) and increased the queue size.
If you meant the first location, this should solve it as well.

I still wouldn't be happy to add a sleep to the second location because it artificially delays messages and if MoveIt can't handle perfect times we should fix that in MoveIt.
However, by now I'm more interested in finally getting this merged, so if you say the problem only disappears with a sleep before publishing, I'd add it for now with a note.

Please confirm @JStech .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ping @JStech

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, been busy here too. I mean before the loop:

  ros::Rate loop_rate(0.2);
  ros::Duration(0.5).sleep();
  while (ros::ok())
  ...

Copy link
Contributor

Choose a reason for hiding this comment

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

I also just pulled, built, and ran the latest version (cab19fd), and I still get the error. (And the delay still fixes it.)

Copy link
Contributor

@JStech JStech left a comment

Choose a reason for hiding this comment

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

Looks good to me--just a couple minor word choice things. I built and ran the code and it all worked.

Something that occurred to me while reading through it is it would be good to have a style guide for the tutorials, to specify how to format code and file names and package names etc.

roslaunch moveit_tutorials detect_and_add_cylinder_collision_object_demo.launch
Keep the launch file from above running and run the code directly from moveit_tutorials: ::

rosrun moveit_tutorials detect_and_add_cylinder_collision_object_demo

KNOWN ISSUE - You may see the following error when running the demo ::
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still seeing the errors.

@v4hn
Copy link
Contributor Author

v4hn commented May 3, 2021

Something that occurred to me while reading through it is it would be good to have a style guide for the tutorials, to specify how to format code and file names and package names etc.

👍 Please feel free to sketch out something and we can talk about it at a maintainer meeting.

@felixvd
Copy link
Contributor

felixvd commented May 19, 2021

It was posted in #641, for the record.

I haven't tested this but unless it introduces new errors, I would merge it anyway. It's definitely an improvement.

@v4hn v4hn force-pushed the pr-improve-perception-pipeline branch from c8008d6 to cab19fd Compare May 23, 2021 08:56
v4hn added 12 commits June 4, 2021 10:03
Start filter binary independent of the launch file.
That way users can actually see the full octomap before filtering.

Also, the naming did not make too much sense, so I renamed the c++ binary to address this.
whitespace after headings is cleaner in my opinion.
The other way around is very unusual.

The inverted transform was obtained via tf.transformations:

x=euler_matrix(1.92,0.2,0.0)
x[:,3]= [0.115, 0.427, 0.570, 1]

y=inv(x)
euler_from_matrix(y)
(-1.913576516039647, 0.06802709809607763, 0.1882209039815404)
y[0:2,3]
array([ 5.33862101e-04, -4.00291774e-01,  6.00183481e-01,  1.00000000e+00])
WHY did this ever work when the pointer was not allocated...

Also check ModelCoefficients for correct results.

Lastly, run estimation *EVERY TIME*, don't stop after first detection.
It's still not good, but at least it does not look for cylinders of size 1m anymore.
According to @JStech this is required to get rid of some hard-to-trace tf extrapolation errors.
They are hopefully fixed now.
@v4hn v4hn force-pushed the pr-improve-perception-pipeline branch from cab19fd to ad617bf Compare June 4, 2021 08:23
@v4hn
Copy link
Contributor Author

v4hn commented Jun 4, 2021

@JStech wrote:

I also just pulled, built, and ran the latest version (cab19fd), and I still get the error. (And the delay still fixes it.)

Ok. I just pushed such a sleep (above the Rate instantiation and longer though).
Please test this one last time and merge by squashing if it works for you now.

Copy link
Contributor

@JStech JStech left a comment

Choose a reason for hiding this comment

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

Yup, all good now.

@JStech
Copy link
Contributor

JStech commented Jun 4, 2021

merge by squashing if it works for you now.

I'm not a maintainer. (Just a pseudo-maintainer of MoveIt Calibration.)

@felixvd felixvd merged commit 7e88e34 into moveit:master Jun 5, 2021
130s added a commit to 130s/moveit2_tutorials that referenced this pull request Jun 22, 2023
130s added a commit to 130s/moveit2_tutorials that referenced this pull request Jun 28, 2023
130s added a commit to 130s/moveit2_tutorials that referenced this pull request Sep 27, 2023
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.

None yet

6 participants