How to type check message arguments for actionlib goals?

asked 2017-05-08 02:21:22 -0500

lindzey gravatar image

updated 2017-05-08 04:15:56 -0500

I'm working on a user interface that includes a way to send actionlib goals like rostopic pub (but also less verbosely). Since it's a user interface, I need a way to check for bad input before executing the command.

I'm using genpy.message.fill_message_args, but it doesn't do any type checking.

I next tried genpy.message.check_type, but it seems to fail sometimes, including on actionlib messages. In some cases, check_type correctly detects that there's a problem with the input types: (This is using Indigo on Ubuntu 14.04)

    > pa = geometry_msgs.msg.PoseArray()
    > pa.poses = [1, 2, 3]
    > genpy.message.check_type('', 'geometry_msgs/PoseArray', pa)
    >> SerializationError: field .poses[] must be of type [geometry_msgs/Pose]

    > ma = std_msgs.msg.UInt32MultiArray()
    > ma.data = ['a', 'b', 'c']
    > genpy.message.check_type('', 'std_msgs/UInt32MultiArray', ma)
    >> SerializationError: field .data[] must be unsigned integer type

However, in another, it does not:

    > sc = my_msgs.msg.SetCourseGoal()
    > sc.rotation = ['a', 'b', 'c']
    > genpy.message.check_type('', 'my_msgs/SetCourseGoal', sc)
    >> None

For this problematic message, rosmsg shows:

$ rosmsg show my_msgs/SetCourseGoal
float32[3] rotation
float32 distance

and the action file is:

$ cat SetCourse.action
float32[3] rotation
float32 distance
---
---

The best I've found so far is to actually try serializing the message to a throwaway buffer, and then catch the SerializationError at that point. If this is the only reliable way to catch type errors in message arguments, then why do the other functions exist? Otherwise, does this reflect an intentional difference in how ROS treats messages derived from a .action file vs. the .msg files? Is there a tool I'm missing?

edit retag flag offensive close merge delete