Пример #1
0
 def addCustomConverter(self, converter):
     """ Register a new custom Converter.
         
         @raise:     rce.error.InternalError,
                     rce.util.interfaces.InterfaceError
     """
     verifyClass(IROSConverter, converter)
     
     if converter.MESSAGE_TYPE in self._customTypes:
         raise InternalError('There are multiple Converters given for '
                             'message type "{0}".'.format(
                                 converter.MESSAGE_TYPE))
     
     try:
         pkg, name = package_resource_name(converter.MESSAGE_TYPE)
     except ValueError:
         raise InternalError('msg type is not valid. Has to be of the from '
                             'pkg/msg, i.e. std_msgs/Int8.')
     
     self._customTypes[converter.MESSAGE_TYPE] = (converter,
         self._loader.loadMsg(pkg, name))
Пример #2
0
    def addCustomConverter(self, converter):
        """ Register a new custom Converter.

            @raise:     rce.error.InternalError,
                        rce.util.interfaces.InterfaceError
        """
        verifyClass(ICustomROSConverter, converter)

        if converter.MESSAGE_TYPE in self._customTypes:
            raise InternalError('There are multiple Converters given for '
                                'message type "{0}".'.format(
                                    converter.MESSAGE_TYPE))

        try:
            pkg, name = package_resource_name(converter.MESSAGE_TYPE)
        except ValueError:
            raise InternalError('msg type is not valid. Has to be of the from '
                                'pkg/msg, i.e. std_msgs/Int8.')

        self._customTypes[converter.MESSAGE_TYPE] = (converter,
            self._loader.loadMsg(pkg, name))
Пример #3
0
        return Time.from_sec(time.mktime(dt.timetuple()))

    def encode(self, rosMsg):
        """ Transform the rospy.rostime.Time instance to a string of the form
            'YYYY-MM-DDTHH:MM:SS.mmmmmm' (ISO 8601).
        """
        try:
            dt = datetime.fromtimestamp(rosMsg.to_sec())
        except AttributeError:
            raise TypeError('Received object is not a Time instance.')

        return (dt.isoformat(), {})


# Check custom time classes whether the interface is correctly implemented
verifyClass(ICustomROSConverter, _DurationConverter)
verifyClass(ICustomROSConverter, _TimeConverter)


class Converter(object):
    """ This class is used to provide a possibility to convert a ROS message to
        a JSON compatible format and back.

        To add customized Converters use the method 'addCustomConverter' and
        the class must implement the interface 'IROSConverter'.
        As an example view the class ImageConverter.
    """
    _BASE_TYPES = { 'bool'    : bool,
                    'byte'    : int,
                    'char'    : int,
                    'uint8'   : int,
Пример #4
0
        return Time.from_sec(time.mktime(dt.timetuple()))

    def encode(self, rosMsg):
        """ Transform the rospy.rostime.Time instance to a string of the form
            'YYYY-MM-DDTHH:MM:SS.mmmmmm' (ISO 8601).
        """
        try:
            dt = datetime.fromtimestamp(rosMsg.to_sec())
        except AttributeError:
            raise TypeError('Received object is not a Time instance.')

        return (dt.isoformat(), {})


# Check custom time classes whether the interface is correctly implemented
verifyClass(ICustomROSConverter, _DurationConverter)
verifyClass(ICustomROSConverter, _TimeConverter)


class Converter(object):
    """ This class is used to provide a possibility to convert a ROS message to
        a JSON compatible format and back.

        To add customized Converters use the method 'addCustomConverter' and
        the class must implement the interface 'IROSConverter'.
        As an example view the class ImageConverter.
    """
    _BASE_TYPES = { 'bool'    : bool,
                    'byte'    : int,
                    'char'    : int,
                    'uint8'   : int,