00001 """autogenerated by genmsg_py from RumbleControl.msg. Do not edit."""
00002 import roslib.message
00003 import struct
00004
00005 import wiimote.msg
00006
00007 class RumbleControl(roslib.message.Message):
00008 _md5sum = "264ec2f3013a512070cd67c42486214e"
00009 _type = "wiimote/RumbleControl"
00010 _has_header = False
00011 _full_text = """# Message to control the Wiimote rumble (vibrator).
00012 # We simply use a TimedSwitch. So rumble can
00013 # be turned on (switch_mode == 1), off (switch_mode == 0),
00014 # or pulsed with a timing pattern (switch_mode == -1).
00015 # Number of times the cycle is repeated: num_cycles
00016 # (-1: repeat till next RumbleControl message). pulse_pattern
00017 # contains the time on/off pattern. (see also TimedSwitch.msg)
00018
00019 TimedSwitch rumble
00020
00021
00022 ================================================================================
00023 MSG: wiimote/TimedSwitch
00024 # TimedSwitch allows sender to:
00025 # o turn a switch on,
00026 # o turn a switch off, and
00027 # o repeat an on/off pattern forever or for a
00028 # given number of times.
00029 # Fields (refer to definitions of constants in the definition body):
00030 # o switch_mode:
00031 # ON: turn on (num_cycles and pulse_pattern fields are ignored)
00032 # OFF: turn off (num_cycles and pulse_pattern fields are ignored)
00033 # NO_CHANGE: leave LED in its current state
00034 # REPEAT: repeat an on/off pattern for as long
00035 # as is indicated in the num_cycles field. The
00036 # pattern is defined in the pulse_pattern field.
00037 #
00038 # o num_cycles:
00039 # n>=0: run the pattern that is defined in pulse_pattern
00040 # n times.
00041 # n==FOREVER: run the pattern that is defined in pulse_pattern
00042 # until a new TimedSwitch message is sent.
00043 #
00044 # o pulse_pattern:
00045 # A series of time durations in fractions of a second. The
00046 # first number is the duration for having the switch on.
00047 # The second number is the duration for which the switch
00048 # is off. The third is an 'on' period again, etc.
00049 # A pattern is terminated with the end of the array.
00050 #
00051 # Example: [1,1] specifies an on-off sequence of 1 second.
00052
00053 int8 ON = 1
00054 int8 OFF = 0
00055 int8 NO_CHANGE = -2
00056 int8 REPEAT = -1
00057 int8 FOREVER = -1
00058
00059 int8 switch_mode
00060 int32 num_cycles
00061 float32[] pulse_pattern
00062
00063 """
00064 __slots__ = ['rumble']
00065 _slot_types = ['wiimote/TimedSwitch']
00066
00067 def __init__(self, *args, **kwds):
00068 """
00069 Constructor. Any message fields that are implicitly/explicitly
00070 set to None will be assigned a default value. The recommend
00071 use is keyword arguments as this is more robust to future message
00072 changes. You cannot mix in-order arguments and keyword arguments.
00073
00074 The available fields are:
00075 rumble
00076
00077 @param args: complete set of field values, in .msg order
00078 @param kwds: use keyword arguments corresponding to message field names
00079 to set specific fields.
00080 """
00081 if args or kwds:
00082 super(RumbleControl, self).__init__(*args, **kwds)
00083
00084 if self.rumble is None:
00085 self.rumble = wiimote.msg.TimedSwitch()
00086 else:
00087 self.rumble = wiimote.msg.TimedSwitch()
00088
00089 def _get_types(self):
00090 """
00091 internal API method
00092 """
00093 return self._slot_types
00094
00095 def serialize(self, buff):
00096 """
00097 serialize message into buffer
00098 @param buff: buffer
00099 @type buff: StringIO
00100 """
00101 try:
00102 _x = self
00103 buff.write(_struct_bi.pack(_x.rumble.switch_mode, _x.rumble.num_cycles))
00104 length = len(self.rumble.pulse_pattern)
00105 buff.write(_struct_I.pack(length))
00106 pattern = '<%sf'%length
00107 buff.write(struct.pack(pattern, *self.rumble.pulse_pattern))
00108 except struct.error, se: self._check_types(se)
00109 except TypeError, te: self._check_types(te)
00110
00111 def deserialize(self, str):
00112 """
00113 unpack serialized message in str into this message instance
00114 @param str: byte array of serialized message
00115 @type str: str
00116 """
00117 try:
00118 if self.rumble is None:
00119 self.rumble = wiimote.msg.TimedSwitch()
00120 end = 0
00121 _x = self
00122 start = end
00123 end += 5
00124 (_x.rumble.switch_mode, _x.rumble.num_cycles,) = _struct_bi.unpack(str[start:end])
00125 start = end
00126 end += 4
00127 (length,) = _struct_I.unpack(str[start:end])
00128 pattern = '<%sf'%length
00129 start = end
00130 end += struct.calcsize(pattern)
00131 self.rumble.pulse_pattern = struct.unpack(pattern, str[start:end])
00132 return self
00133 except struct.error, e:
00134 raise roslib.message.DeserializationError(e)
00135
00136
00137 def serialize_numpy(self, buff, numpy):
00138 """
00139 serialize message with numpy array types into buffer
00140 @param buff: buffer
00141 @type buff: StringIO
00142 @param numpy: numpy python module
00143 @type numpy module
00144 """
00145 try:
00146 _x = self
00147 buff.write(_struct_bi.pack(_x.rumble.switch_mode, _x.rumble.num_cycles))
00148 length = len(self.rumble.pulse_pattern)
00149 buff.write(_struct_I.pack(length))
00150 pattern = '<%sf'%length
00151 buff.write(self.rumble.pulse_pattern.tostring())
00152 except struct.error, se: self._check_types(se)
00153 except TypeError, te: self._check_types(te)
00154
00155 def deserialize_numpy(self, str, numpy):
00156 """
00157 unpack serialized message in str into this message instance using numpy for array types
00158 @param str: byte array of serialized message
00159 @type str: str
00160 @param numpy: numpy python module
00161 @type numpy: module
00162 """
00163 try:
00164 if self.rumble is None:
00165 self.rumble = wiimote.msg.TimedSwitch()
00166 end = 0
00167 _x = self
00168 start = end
00169 end += 5
00170 (_x.rumble.switch_mode, _x.rumble.num_cycles,) = _struct_bi.unpack(str[start:end])
00171 start = end
00172 end += 4
00173 (length,) = _struct_I.unpack(str[start:end])
00174 pattern = '<%sf'%length
00175 start = end
00176 end += struct.calcsize(pattern)
00177 self.rumble.pulse_pattern = numpy.frombuffer(str[start:end], dtype=numpy.float32, count=length)
00178 return self
00179 except struct.error, e:
00180 raise roslib.message.DeserializationError(e)
00181
00182 _struct_I = roslib.message.struct_I
00183 _struct_bi = struct.Struct("<bi")