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

Revision history [back]

click to hide/show revision 1
initial version

answered 2012-06-14 00:59:33 -0500

joq gravatar image

If you look further down in rosversion, it only prints the distro name when invoked with the -d or --distro option. To get the ROS version string, invoke:

$ rosversion ros

On Fuerte, that returns 1.8.7 (without a newline), on Electric 1.6.9 (with a newline).

From a Python script, you can do that yourself:

import rospkg
version = rospkg.RosStack().get_stack_version('ros')

It works for other stacks, as well:

messages_version = rospkg.RosStack().get_stack_version('common_msgs')

In most cases, it is better not to test for a specific version number, but for the existence of some new API:

TimeReference = None
try:
    from sensor_msgs.msg import TimeReference
except ImportError:
    pass

Then, make your logic dependent on the existence of that message:

if TimeReference:
    tr_pub = rospy.Publisher('gps_time', TimeReference)
click to hide/show revision 2
mention where to find rospkg

If you look further down in rosversion, it only prints the distro name when invoked with the -d or --distro option. To get the ROS version string, invoke:

$ rosversion ros

On Fuerte, that returns 1.8.7 (without a newline), on Electric 1.6.9 (with a newline).

From a Python script, you can do that yourself:

import rospkg
version = rospkg.RosStack().get_stack_version('ros')

That uses the new distro-independent rospkg module. Get it like this:

sudo pip install -U rospkg

It works for other stacks, as well:

messages_version = rospkg.RosStack().get_stack_version('common_msgs')

In most cases, it is better not to test for a specific version number, but for the existence of some new API:API instead:

TimeReference = None
try:
    from sensor_msgs.msg import TimeReference
except ImportError:
    pass

Then, make your logic dependent on the existence of that message:

if TimeReference:
    tr_pub = rospy.Publisher('gps_time', TimeReference)