ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Get path to built files programmatically

asked 2017-02-10 07:49:15 -0500

lucasw gravatar image

updated 2020-11-21 12:12:55 -0500

I have add_custom_commands to build files that will be loaded at run time by a ros node. Right now those files get put into build/my_package/. Is there a combination of a destination to provide cmake and something like ros::package::getPath() that will allow me to load the files regardless of whether using catkin_make install or devel.

The solution I don't want is to build the files into the source directory.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2017-02-10 22:29:28 -0500

lucasw gravatar image

updated 2017-02-10 22:34:23 -0500

A solution that doesn't involve build artifacts in the source tree could be to turn the generated files into a library or add it to the executable- convert the binary files into header files like http://stackoverflow.com/questions/87...

xxd -i my_cmake_generated_file.bin > my_cmake_generated_file.h

Which produces:

unsigned char my_cmake_generated_file[] = {
0x46, 0x53, 0x48, 0x04, 0xa4, 0x8b, 0xef, 0x49, 0x00, 0x00, 0x44, 0x00,
...
  0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00
};
unsigned int my_cmake_generated_file_len = 83;

And then code that loads a binary into a byte array could be simplified to just use this from the header file directly

edit flag offensive delete link more
0

answered 2017-02-10 10:11:11 -0500

joq gravatar image

You probably just need to install the built files:

install(FILES your_data your_parameters DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})

After that, I think getPath() should find them (not tested).

edit flag offensive delete link more

Comments

https://github.com/ros/ros/issues/65 makes it sound like I should just have a build folder in my source tree and have git ignore it.

lucasw gravatar image lucasw  ( 2017-02-10 21:54:45 -0500 )edit

I don't think that is what they were talking about. They were talking about how to address downloaded test files. See: http://docs.ros.org/jade/api/catkin/h...

joq gravatar image joq  ( 2017-02-11 11:35:33 -0500 )edit

The downloading of test files doesn't seem that different, http://answers.ros.org/question/63189... is almost the same case- there are files that need to be found at run time but getPath will point to the source package location when doing a non-install catkin_make.

lucasw gravatar image lucasw  ( 2017-02-14 05:52:17 -0500 )edit

Another solution that comes to mind is to bake the build location into the executable though cmake.

lucasw gravatar image lucasw  ( 2017-02-14 05:54:46 -0500 )edit

Also from http://answers.ros.org/question/10976... it sounds like roslaunch <param name="file_dir" value="$(find my_package)/... will point to a share directory, but like the other comments linked to I wish I could use catkin_find through a C++ api.

lucasw gravatar image lucasw  ( 2017-02-14 06:02:12 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-02-10 07:49:15 -0500

Seen: 562 times

Last updated: Feb 10 '17