Class: ROS::Publisher
Overview
Publisher interface of ROS. A publisher contains multi connection with subscribers. TCPROS protocol implementation is in ROS::TCPROS::Server. Here is sample code. You can shutdown publisher by using this instance (ROS::Publisher#shutdown)
node = ROS::Node.new('/rosruby/sample_publisher')
publisher = node.advertise('/chatter', Std_msgs::String)
sleep(1)
msg = Std_msgs::String.new
i = 0
while node.ok?
msg.data = "Hello, rosruby!: #{i}"
publisher.publish(msg)
i += 1
end
Instance Attribute Summary
Attributes inherited from Topic
#caller_id, #topic_name, #topic_type
Instance Method Summary (collapse)
-
- (TCPROS::Server) add_connection(caller_id)
add tcpros connection as server.
-
- (Array) get_connection_data
Connection data for slave api.
-
- (array) get_connection_info
Connection info for slave api.
-
- (Integer) get_number_of_subscribers
get number of subscribers to this publisher.
-
- (Publisher) initialize(caller_id, topic_name, topic_type, is_latched, host)
constructor
A new instance of Publisher.
-
- (Publisher) publish(message)
publish msg object.
-
- (nil) shutdown
user interface of shutdown this publisher.
Methods inherited from Topic
Constructor Details
- (Publisher) initialize(caller_id, topic_name, topic_type, is_latched, host)
Returns a new instance of Publisher
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
- (TCPROS::Server) add_connection(caller_id)
add tcpros connection as server
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 |
- (Array) get_connection_data
Returns connection data for slave api
80 81 82 83 84 |
# File 'lib/ros/publisher.rb', line 80 def get_connection_data @connections.map do |connection| [connection.id, connection.byte_sent, connection.num_sent, 1] end end |
- (array) get_connection_info
Returns connection info for slave api
87 88 89 90 91 92 93 |
# File 'lib/ros/publisher.rb', line 87 def get_connection_info info = [] @connections.each do |connection| info.push([connection.id, connection.caller_id, 'o', connection.protocol, @topic_name]) end info end |
- (Integer) get_number_of_subscribers
get number of subscribers to this publisher
75 76 77 |
# File 'lib/ros/publisher.rb', line 75 def get_number_of_subscribers @connections.length end |
- (Publisher) publish(message)
publish msg object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ros/publisher.rb', line 45 def publish() @seq += 1 @last_published_msg = if .has_header? .header.seq = @seq end @connections.each do |connection| connection.msg_queue.push() end self end |
- (nil) shutdown
user interface of shutdown this publisher
98 99 100 |
# File 'lib/ros/publisher.rb', line 98 def shutdown @manager.shutdown_publisher(self) end |