Class: ROS::Publisher

Inherits:
Topic
  • Object
show all
Defined in:
lib/ros/publisher.rb

Overview

end

Instance Attribute Summary

Attributes inherited from Topic

#caller_id, #topic_name, #topic_type

Instance Method Summary collapse

Methods inherited from Topic

#close, #set_manager

Constructor Details

#initialize(caller_id, topic_name, topic_type, is_latched, host) ⇒ Publisher

Returns a new instance of Publisher.

Parameters:

  • caller_id (String)

    caller_id of this node

  • topic_name (String)

    name of topic to publish (String)

  • topic_type (Class)

    class of topic

  • is_latched (Boolean)

    latched topic?

  • host (String)

    host name of this node



34
35
36
37
38
39
# File 'lib/ros/publisher.rb', line 34

def initialize(caller_id, topic_name, topic_type, is_latched, host)
  super(caller_id, topic_name, topic_type)
  @host = host
  @is_latched = is_latched
  @seq = 0
end

Instance Method Details

#add_connection(caller_id) ⇒ TCPROS::Server

add tcpros connection as server

Parameters:

  • caller_id (String)

    caller_id of subscriber

Returns:



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ros/publisher.rb', line 61

def add_connection(caller_id) #:nodoc:
  connection = TCPROS::Server.new(@caller_id, @topic_name, @topic_type,
                                  :host=>@host,
                                  :latched=>@is_latched,
                                  :last_published_msg=>@last_published_msg)
  connection.start
  connection.id = "#{@topic_name}_out_#{@connection_id_number}"
  @connection_id_number += 1
  @connections.push(connection)
  return connection
end

#get_connection_dataArray

Returns connection data for slave api.

Returns:

  • (Array)

    connection data for slave api



74
75
76
77
78
# File 'lib/ros/publisher.rb', line 74

def get_connection_data
  @connections.map do |connection|
    [connection.id, connection.byte_sent, connection.num_sent, 1]
  end
end

#get_connection_infoarray

Returns connection info for slave api.

Returns:

  • (array)

    connection info for slave api



81
82
83
84
85
86
87
# File 'lib/ros/publisher.rb', line 81

def get_connection_info
  info = []
  @connections.each do |connection|
    info.push([connection.id, connection.caller_id, 'o', connection.protocol, @topic_name])
  end
  info
end

#publish(message) ⇒ Publisher

publish msg object

Parameters:

  • message (Class)

    instance of topic_type class

Returns:



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ros/publisher.rb', line 45

def publish(message)
  @seq += 1
  @last_published_msg = message
  if message.has_header?
    message.header.seq = @seq
  end
  @connections.each do |connection|
    connection.msg_queue.push(message)
  end
  self
end

#shutdownnil

user interface of shutdown this publisher

Returns:

  • (nil)

    nil



92
93
94
# File 'lib/ros/publisher.rb', line 92

def shutdown
  @manager.shutdown_publisher(self)
end