Ask Your Question
0

How to check that message exists with catkin for conditional compilation (sensor_msgs/BatteryState)

asked 2016-01-10 17:01:56 -0500

vooon gravatar image

Hello, i want to add support for new message but i need some "how to" on detecting available messages with catkin.

I'm thinking to use cmake execute_process() for that. Some thing like that:

execute_process(
    COMMAND ${PYTHON_EXECUTABLE} -c "from sensor_msgs.msg import BatteryState"
    RESULT_VARIABLE BATTERY_STATE_RESULT
)

But maybe catkin already has some macro for that task?

edit retag flag offensive close merge delete

Comments

An alternative way would be to use something like rosmsg show sensor_msgs/BatteryState. Also there seems to be generated variables of the form <package_name>_MESSAGE_FILES which are the lists of paths. However, to get it you probably have to find_package first.

Boris gravatar imageBoris ( 2016-01-10 17:47:47 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-01-10 20:04:24 -0500

Dirk Thomas gravatar image

Within CMake you can access the list of message/service files of a package since every message package exports these information in via its CMake extras file. After calling:

find_package(std_msgs REQUIRED)

or

find_package(catkin REQUIRED COMPONENTS std_msgs)

the list of message files is available in the CMake variable:

std_msgs_MESSAGE_FILES
edit flag offensive delete link more

Comments

Looks like i need that code:

list(FIND sensor_msgs_MESSAGE_FILES "msg/BatteryState.msg" BATTERY_STATE_MSG_IDX)
if(${BATTERY_STATE_MSG_IDX} >= 0)
endif()
vooon gravatar imagevooon ( 2016-01-10 23:48:53 -0500 )edit
1

answered 2016-01-10 18:39:22 -0500

ahendrix gravatar image

This is tricky, because there are not a lot of good ways to do it.

Old versions of rosmsg show does not return an error code if the message does not exist, so that probably isn't the best choice.

The python messages aren't generated until the build step, so they may not exist at configure time, which means that a python script which tries to import messages will always fail the first time, even if the package contains the messages you're looking for.

I think the best way to do this would be to check which version of sensor_msgs you're building against from cmake, and use that as the conditional in your build. You can do this with the VERSION_GREATER or VERSION_LESS comparisons:

# cmake
find_package(catkin REQUIRED COMPONENTS
    sensor_msgs 
    # etc
)

if( ${sensor_msgs_VERSION} VERSION_LESS 2.42.3 ) # substitute the version you care about
    message("sensor_msgs too old; won't build foo")
else()
    # build cool new things
endif()

(This SHOULD work; but I haven't tested it. May need a little tweaking)

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-01-10 17:01:56 -0500

Seen: 149 times

Last updated: Jan 10 '16