Robotics StackExchange | Archived questions

Check if python object is message in ROS2

In ROS1, it was possible to check if an object was a ROS Message by using genpy: python isinstance(obj, genpy.message.Message) However, I cannot seem to find the same functionality in ROS2. If we look at the __mro__ of the classes there does not seem to be anything to work with:

In ROS1 (noetic):

>>> from rospy_tutorials.srv import AddTwoIntsRequest
>>> AddTwoIntsRequest.__mro__
(<class 'rospy_tutorials.srv._AddTwoInts.AddTwoIntsRequest'>, <class 'genpy.message.Message'>, <class 'object'>)

In ROS2 (galactic):

>>> from example_interfaces.srv import AddTwoInts
>>> AddTwoInts.Request.__mro__
(<class 'example_interfaces.srv._add_two_ints.AddTwoInts_Request'>, <class 'object'>)

Have I missed something?

Asked by IƱigo moreno on 2023-02-02 06:04:59 UTC

Comments

Answers