Exemple #1
0
 def test_assorted_msgs(self):
     assortedmsgs = ["geometry_msgs/Pose", "actionlib_msgs/GoalStatus",
     "geometry_msgs/WrenchStamped", "stereo_msgs/DisparityImage",
     "nav_msgs/OccupancyGrid", "geometry_msgs/Point32", "std_msgs/String",
     "trajectory_msgs/JointTrajectoryPoint", "diagnostic_msgs/KeyValue",
     "visualization_msgs/InteractiveMarkerUpdate", "nav_msgs/GridCells",
     "sensor_msgs/PointCloud2"]
     for rostype in assortedmsgs:
         inst = ros_loader.get_message_instance(rostype)
         msg = c.extract_values(inst)
         self.do_test(msg, rostype)
         l = loads(dumps(msg))
         inst2 = ros_loader.get_message_instance(rostype)
         c.populate_instance(msg, inst2)
         self.assertEqual(inst, inst2)
 def test_assorted_msgs(self):
     assortedmsgs = ["geometry_msgs/Pose", "actionlib_msgs/GoalStatus",
     "geometry_msgs/WrenchStamped", "stereo_msgs/DisparityImage",
     "nav_msgs/OccupancyGrid", "geometry_msgs/Point32", "std_msgs/String",
     "trajectory_msgs/JointTrajectoryPoint", "diagnostic_msgs/KeyValue",
     "visualization_msgs/InteractiveMarkerUpdate", "nav_msgs/GridCells",
     "sensor_msgs/PointCloud2"]
     for rostype in assortedmsgs:
         inst = ros_loader.get_message_instance(rostype)
         msg = c.extract_values(inst)
         self.do_test(msg, rostype)
         l = loads(dumps(msg))
         inst2 = ros_loader.get_message_instance(rostype)
         c.populate_instance(msg, inst2)
         self.assertEqual(inst, inst2)
 def do_test(self, orig_msg, msgtype):
     for msg in [orig_msg, loads(dumps(orig_msg))]:
         inst = ros_loader.get_message_instance(msgtype)
         c.populate_instance(msg, inst)
         self.validate_instance(inst)
         extracted = c.extract_values(inst)
         for msg2 in [extracted, loads(dumps(extracted))]:
             self.msgs_equal(msg, msg2)
Exemple #4
0
def get_typedef_full_text(type):
    """ Returns the full text (similar to `gendeps --cat`) for the specified message type """
    # Get an instance of the service response class and get its typedef
    try:
        instance = ros_loader.get_message_instance(type)
        return instance._full_text
    except Exception:
        return ""
Exemple #5
0
 def do_test(self, orig_msg, msgtype):
     for msg in [orig_msg, loads(dumps(orig_msg))]:
         inst = ros_loader.get_message_instance(msgtype)
         c.populate_instance(msg, inst)
         self.validate_instance(inst)
         extracted = c.extract_values(inst)
         for msg2 in [extracted, loads(dumps(extracted))]:
             self.msgs_equal(msg, msg2)
 def test_irregular_msgnames(self):
     irregular = ["std_msgs//String", "//std_msgs/String",
      "/std_msgs//String", "/std_msgs/String", "//std_msgs//String",
      "/std_msgs/String/", "//std_msgs//String//", "std_msgs/String/",
      "std_msgs//String//"]
     for x in irregular:
         self.assertNotEqual(ros_loader.get_message_class(x), None)
         self.assertNotEqual(ros_loader.get_message_instance(x), None)
Exemple #7
0
 def test_irregular_msgnames(self):
     irregular = ["std_msgs//String", "//std_msgs/String",
                  "/std_msgs//String", "/std_msgs/String", "//std_msgs//String",
                  "/std_msgs/String/", "//std_msgs//String//", "std_msgs/String/",
                  "std_msgs//String//"]
     for x in irregular:
         self.assertNotEqual(ros_loader.get_message_class(x), None)
         self.assertNotEqual(ros_loader.get_message_instance(x), None)
Exemple #8
0
 def do_primitive_test(self, data_value, msgtype):
     for msg in [{"data": data_value}, loads(dumps({"data": data_value}))]:
         inst = ros_loader.get_message_instance(msgtype)
         c.populate_instance(msg, inst)
         self.assertEqual(inst.data, data_value)
         self.validate_instance(inst)
         extracted = c.extract_values(inst)
         for msg2 in [extracted, loads(dumps(extracted))]:
             self.msgs_equal(msg, msg2)
             self.assertEqual(msg["data"], msg2["data"])
             self.assertEqual(msg2["data"], inst.data)
 def do_primitive_test(self, data_value, msgtype):
     for msg in [{"data": data_value}, loads(dumps({"data": data_value}))]:
         inst = ros_loader.get_message_instance(msgtype)
         c.populate_instance(msg, inst)
         self.assertEqual(inst.data, data_value)
         self.validate_instance(inst)
         extracted = c.extract_values(inst)
         for msg2 in [extracted, loads(dumps(extracted))]:
             self.msgs_equal(msg, msg2)
             self.assertEqual(msg["data"], msg2["data"])
             self.assertEqual(msg2["data"], inst.data)
Exemple #10
0
 def test_assorted_msgnames(self):
     assortedmsgs = ["geometry_msgs/Pose", "actionlib_msgs/GoalStatus",
                     "geometry_msgs/WrenchStamped", "stereo_msgs/DisparityImage",
                     "nav_msgs/OccupancyGrid", "geometry_msgs/Point32", "std_msgs/String",
                     "trajectory_msgs/JointTrajectoryPoint", "diagnostic_msgs/KeyValue",
                     "visualization_msgs/InteractiveMarkerUpdate", "nav_msgs/GridCells",
                     "sensor_msgs/PointCloud2"]
     for x in assortedmsgs:
         self.assertNotEqual(ros_loader.get_message_class(x), None)
         inst = ros_loader.get_message_instance(x)
         self.assertNotEqual(inst, None)
         self.assertEqual(x, inst._type)
 def test_assorted_msgnames(self):
     assortedmsgs = ["geometry_msgs/Pose", "actionlib_msgs/GoalStatus",
     "geometry_msgs/WrenchStamped", "stereo_msgs/DisparityImage",
     "nav_msgs/OccupancyGrid", "geometry_msgs/Point32", "std_msgs/String",
     "trajectory_msgs/JointTrajectoryPoint", "diagnostic_msgs/KeyValue",
     "visualization_msgs/InteractiveMarkerUpdate", "nav_msgs/GridCells",
     "sensor_msgs/PointCloud2"]
     for x in assortedmsgs:
         self.assertNotEqual(ros_loader.get_message_class(x), None)
         inst = ros_loader.get_message_instance(x)
         self.assertNotEqual(inst, None)
         self.assertEqual(x, inst._type)
    def test_time_msg_now(self):
        msg = {"data": "now"}
        msgtype = "std_msgs/Time"

        inst = ros_loader.get_message_instance(msgtype)
        c.populate_instance(msg, inst)
        currenttime = rospy.get_rostime()
        self.validate_instance(inst)
        extracted = c.extract_values(inst)
        print extracted
        self.assertIn("data", extracted)
        self.assertIn("secs", extracted["data"])
        self.assertIn("nsecs", extracted["data"])
        self.assertNotEqual(extracted["data"]["secs"], 0)
        self.assertLessEqual(extracted["data"]["secs"], currenttime.secs)
        self.assertGreaterEqual(currenttime.secs, extracted["data"]["secs"])
Exemple #13
0
    def test_time_msg_now(self):
        msg = {"data": "now"}
        msgtype = "std_msgs/Time"

        inst = ros_loader.get_message_instance(msgtype)
        c.populate_instance(msg, inst)
        currenttime = rospy.get_rostime()
        self.validate_instance(inst)
        extracted = c.extract_values(inst)
        print(extracted)
        self.assertIn("data", extracted)
        self.assertIn("secs", extracted["data"])
        self.assertIn("nsecs", extracted["data"])
        self.assertNotEqual(extracted["data"]["secs"], 0)
        self.assertLessEqual(extracted["data"]["secs"], currenttime.secs)
        self.assertGreaterEqual(currenttime.secs, extracted["data"]["secs"])
Exemple #14
0
 def test_std_msgnames(self):
     stdmsgs = ["std_msgs/Bool", "std_msgs/Byte", "std_msgs/ByteMultiArray",
                "std_msgs/ColorRGBA", "std_msgs/Duration", "std_msgs/Empty",
                "std_msgs/Float32", "std_msgs/Float32MultiArray", "std_msgs/Float64",
                "std_msgs/Header", "std_msgs/Int16", "std_msgs/Int16MultiArray",
                "std_msgs/Int32", "std_msgs/Int32MultiArray", "std_msgs/Int64",
                "std_msgs/Int64MultiArray", "std_msgs/Int8", "std_msgs/Int8MultiArray",
                "std_msgs/MultiArrayDimension", "std_msgs/MultiArrayLayout",
                "std_msgs/String", "std_msgs/Time", "std_msgs/UInt16",
                "std_msgs/UInt16MultiArray", "std_msgs/UInt32MultiArray",
                "std_msgs/UInt64MultiArray", "std_msgs/UInt32", "std_msgs/UInt64",
                "std_msgs/UInt8", "std_msgs/UInt8MultiArray"]
     for x in stdmsgs:
         self.assertNotEqual(ros_loader.get_message_class(x), None)
         inst = ros_loader.get_message_instance(x)
         self.assertNotEqual(inst, None)
         self.assertEqual(x, inst._type)
 def test_std_msgnames(self):
     stdmsgs = ["std_msgs/Bool", "std_msgs/Byte", "std_msgs/ByteMultiArray",
     "std_msgs/ColorRGBA", "std_msgs/Duration", "std_msgs/Empty",
     "std_msgs/Float32", "std_msgs/Float32MultiArray", "std_msgs/Float64",
     "std_msgs/Header", "std_msgs/Int16", "std_msgs/Int16MultiArray",
     "std_msgs/Int32", "std_msgs/Int32MultiArray", "std_msgs/Int64",
     "std_msgs/Int64MultiArray", "std_msgs/Int8", "std_msgs/Int8MultiArray",
     "std_msgs/MultiArrayDimension", "std_msgs/MultiArrayLayout",
     "std_msgs/String", "std_msgs/Time", "std_msgs/UInt16",
     "std_msgs/UInt16MultiArray", "std_msgs/UInt32MultiArray",
     "std_msgs/UInt64MultiArray", "std_msgs/UInt32", "std_msgs/UInt64",
     "std_msgs/UInt8", "std_msgs/UInt8MultiArray"]
     for x in stdmsgs:
         self.assertNotEqual(ros_loader.get_message_class(x), None)
         inst = ros_loader.get_message_instance(x)
         self.assertNotEqual(inst, None)
         self.assertEqual(x, inst._type)
Exemple #16
0
def get_typedef(type):
    """ A typedef is a dict containing the following fields:
         - string type
         - string[] fieldnames
         - string[] fieldtypes
         - int[] fieldarraylen
         - string[] examples 
    get_typedef will return a typedef dict for the specified message type """
    if type in atomics:
        # Atomics don't get a typedef
        return None

    if type in specials:
        # Specials get their type def mocked up
        return _get_special_typedef(type)

    # Fetch an instance and return its typedef
    instance = ros_loader.get_message_instance(type)
    return _get_typedef(instance)
def get_typedef(type):
    """ A typedef is a dict containing the following fields:
         - string type
         - string[] fieldnames
         - string[] fieldtypes
         - int[] fieldarraylen
         - string[] examples 
    get_typedef will return a typedef dict for the specified message type """
    if type in atomics:
        # Atomics don't get a typedef
        return None 
    
    if type in specials:
        # Specials get their type def mocked up
        return _get_special_typedef(type)
    
    # Fetch an instance and return its typedef
    instance = ros_loader.get_message_instance(type)    
    return _get_typedef(instance)
Exemple #18
0
def _to_inst(msg, rostype, roottype, inst=None, stack=[]):
    # Check if it's uint8[], and if it's a string, try to b64decode
    if rostype in ros_binary_types:
        return _to_binary_inst(msg)

    # Check the type for time or rostime
    if rostype in ros_time_types:
        return _to_time_inst(msg, rostype, inst)

    # Check to see whether this is a primitive type
    if rostype in ros_primitive_types:
        return _to_primitive_inst(msg, rostype, roottype, stack)

    # Check whether we're dealing with a list type
    if inst is not None and type(inst) in list_types:
        return _to_list_inst(msg, rostype, roottype, inst, stack)

    # Otherwise, the type has to be a full ros msg type, so msg must be a dict
    if inst is None:
        inst = ros_loader.get_message_instance(rostype)

    return _to_object_inst(msg, rostype, roottype, inst, stack)
def _to_inst(msg, rostype, roottype, inst=None, stack=[]):
    # Check if it's uint8[], and if it's a string, try to b64decode
    for binary_type, expression in ros_binary_types_list_braces:
        if expression.sub(binary_type, rostype) in ros_binary_types:
            return _to_binary_inst(msg)

    # Check the type for time or rostime
    if rostype in ros_time_types:
        return _to_time_inst(msg, rostype, inst)

    # Check to see whether this is a primitive type
    if rostype in ros_primitive_types:
        return _to_primitive_inst(msg, rostype, roottype, stack)

    # Check whether we're dealing with a list type
    if inst is not None and type(inst) in list_types:
        return _to_list_inst(msg, rostype, roottype, inst, stack)

    # Otherwise, the type has to be a full ros msg type, so msg must be a dict
    if inst is None:
        inst = ros_loader.get_message_instance(rostype)

    return _to_object_inst(msg, rostype, roottype, inst, stack)
Exemple #20
0
 def test_int8_msg(rostype, data):
     msg = {"data": data}
     inst = ros_loader.get_message_instance(rostype)
     c.populate_instance(msg, inst)
     self.validate_instance(inst)
     return inst.data
 def test_int8_msg(rostype, data):
     msg = {"data": data}
     inst = ros_loader.get_message_instance(rostype)
     c.populate_instance(msg, inst)
     self.validate_instance(inst)
     return inst.data