Ask Your Question
1

How to get versions in package.xml from roscpp codes

asked 2016-04-14 17:14:22 -0600

okku gravatar image

Hi. I would like to know if there is a way to get versions inside roscpp codes. I want to print out the software version of node when it is launched, automatically referring manifest file. Any hints, comments are welcomed. Thanks in advance.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2016-04-24 22:36:51 -0600

ahendrix gravatar image

updated 2016-04-24 22:37:13 -0600

Buried deep in the catkin documentation there is a note that after calling catkin_pacakge(), the package version is available as a cmake variable that is named after your package: <packagename>_VERSION

You could make this available to C++ code using the add_definitions cmake command, like:

catkin_package(
    # any arguments to catkin_package here
)

add_definitions("-D${PROJECT_NAME}_VERSION=\"${${PROJECT_NAME}_VERSION}\"")

This uses the -D option to the compiler, which is equivalent to a #define.

You could use the version in your code as a string, for example:

ROS_INFO("Package version is %s", mypackage_VERSION); // replace mypackage with your package name
edit flag offensive delete link more

Comments

Cool! This is what I wanted. Worked perfectly on my ROS Indigo environment.

okku gravatar imageokku ( 2016-04-25 07:10:45 -0600 )edit
0

answered 2016-04-24 23:12:24 -0600

130s gravatar image

Another way to get the version defined in package.xml is to do the same/similar as rospack does. Example can be seen in this PR. It parses vector instance that contains info retrieved from parsed package.xml. Not intuitive nor convenient at all, but it's also C++.

edit flag offensive delete link more

Comments

For my study, thank you.

okku gravatar imageokku ( 2016-04-25 07:09:39 -0600 )edit
0

answered 2016-04-18 03:41:41 -0600

bluking gravatar image

You can use node handler to get the information of launch file, so you can add version information to your launch file.

edit flag offensive delete link more

Comments

It'll be much helpful, if you can read versions directly from package.xml, so that you don't have to write same version number to both xml and launch file. But thank you for information.

okku gravatar imageokku ( 2016-04-22 16:50:16 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2016-04-14 17:14:22 -0600

Seen: 558 times

Last updated: Apr 24 '16