Class: Sensor_msgs::Joy

Inherits:
ROS::Message
  • Object
show all
Defined in:
lib/sensor_msgs/Joy.rb

Constant Summary collapse

@@struct_L3 =
::ROS::Struct.new("L3")
@@struct_L =
::ROS::Struct.new("L")
@@slot_types =
['Header','float32[]','int32[]']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Joy

Constructor. You can set the default values using keyword operators.

Parameters:

  • args (Hash) (defaults to: {})

    keyword for initializing values

Options Hash (args):

  • :header (Header)

    initialize value

  • :axes (float32[])

    initialize value

  • :buttons (int32[])

    initialize value



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/sensor_msgs/Joy.rb', line 60

def initialize(args={})
  # message fields cannot be None, assign default values for those that are
  if args[:header]
    @header = args[:header]
  else
    @header = Std_msgs::Header.new
  end
  if args[:axes]
    @axes = args[:axes]
  else
    @axes = []
  end
  if args[:buttons]
    @buttons = args[:buttons]
  else
    @buttons = []
  end
end

Instance Attribute Details

#axesObject

Returns the value of attribute axes.



47
48
49
# File 'lib/sensor_msgs/Joy.rb', line 47

def axes
  @axes
end

#buttonsObject

Returns the value of attribute buttons.



47
48
49
# File 'lib/sensor_msgs/Joy.rb', line 47

def buttons
  @buttons
end

#headerObject

Returns the value of attribute header.



47
48
49
# File 'lib/sensor_msgs/Joy.rb', line 47

def header
  @header
end

Class Method Details

.md5sumObject



9
10
11
# File 'lib/sensor_msgs/Joy.rb', line 9

def self.md5sum
  "5a9ea5f83505693b71e785041e67a8bb"
end

.typeObject



13
14
15
# File 'lib/sensor_msgs/Joy.rb', line 13

def self.type
  "sensor_msgs/Joy"
end

Instance Method Details

#_get_typesString

internal API method

Returns:

  • (String)

    Message type string.



81
82
83
# File 'lib/sensor_msgs/Joy.rb', line 81

def _get_types
  @slot_types
end

#deserialize(str) ⇒ Object

unpack serialized message in str into this message instance

@param [String] str: byte array of serialized message


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/sensor_msgs/Joy.rb', line 109

def deserialize(str)

  begin
    if @header == nil
      @header = Std_msgs::Header.new
    end
    end_point = 0
    start = end_point
    end_point += ROS::Struct::calc_size('L3')
    (@header.seq, @header.stamp.secs, @header.stamp.nsecs,) = @@struct_L3.unpack(str[start..(end_point-1)])
    start = end_point
    end_point += 4
    (length,) = @@struct_L.unpack(str[start..(end_point-1)])
    start = end_point
    end_point += length
    @header.frame_id = str[start..(end_point-1)]
    start = end_point
    end_point += 4
    (length,) = @@struct_L.unpack(str[start..(end_point-1)])
    pattern = "f#{length}"
    start = end_point
    end_point += ROS::Struct::calc_size("#{pattern}")
    @axes = str[start..(end_point-1)].unpack(pattern)
    start = end_point
    end_point += 4
    (length,) = @@struct_L.unpack(str[start..(end_point-1)])
    pattern = "l#{length}"
    start = end_point
    end_point += ROS::Struct::calc_size("#{pattern}")
    @buttons = str[start..(end_point-1)].unpack(pattern)
    return self
  rescue => exception
    raise "message DeserializationError: #{exception}" #most likely buffer underfill
  end
end

#has_header?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/sensor_msgs/Joy.rb', line 17

def has_header?
  true
end

#message_definitionObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sensor_msgs/Joy.rb', line 21

def message_definition
  "# Reports the state of a joysticks axes and buttons.
Header header           # timestamp in the header is the time the data is received from the joystick
float32[] axes          # the axes measurements from a joystick
int32[] buttons         # the buttons measurements from a joystick 

================================================================================
MSG: std_msgs/Header
# Standard metadata for higher-level stamped data types.
# This is generally used to communicate timestamped data 
# in a particular coordinate frame.
# 
# sequence ID: consecutively increasing ID 
uint32 seq
#Two-integer timestamp that is expressed as:
# * stamp.secs: seconds (stamp_secs) since epoch
# * stamp.nsecs: nanoseconds since stamp_secs
# time-handling sugar is provided by the client library
time stamp
#Frame this data is associated with
# 0: no frame
# 1: global frame
string frame_id

"
end

#serialize(buff) ⇒ Object

serialize message into buffer

Parameters:

  • buff (IO)

    buffer



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/sensor_msgs/Joy.rb', line 87

def serialize(buff)
  begin
    buff.write(@@struct_L3.pack(@header.seq, @header.stamp.secs, @header.stamp.nsecs))
    _x = @header.frame_id
    length = _x.length
    buff.write([length, _x].pack("La#{length}"))
    length = @axes.length
    buff.write(@@struct_L.pack(length))
    pattern = "f#{length}"
    buff.write(*@axes.pack(pattern))
    length = @buttons.length
    buff.write(@@struct_L.pack(length))
    pattern = "l#{length}"
    buff.write(*@buttons.pack(pattern))
  rescue => exception
    raise "some erro in serialize: #{exception}"

  end
end