Ejemplo n.º 1
0
def message_publisher():
	rospy.init_node('message_publisher')
	pub = rospy.Publisher('complex', Complex, queue_size=5)
	rate = rospy.Rate(2)

	while not rospy.is_shutdown():
		msg = Complex()
		msg.real = random()
		msg.imaginary = random()
		
		pub.publish(msg)
		
		rate.sleep()
def msg_pub():
	rospy.init_node('message_publisher')
	pub = rospy.Publisher('complex',Complex,queue_size=1)
	rate = rospy.Rate(1)
	count = 0
	while not rospy.is_shutdown():
		msg = Complex()
		#Alternatively we can use keyword arguments to initialize the message class
		# msg = Complex(real=2.3,imaginary=4.6) or msg = Complex(real=1.2)
		msg.real = random()
		msg.imaginary = random()
		# rospy.loginfo("real = %f ,imaginary = %f", msg.real,msg.imaginary)
		rospy.loginfo("Complex number %d is %f + %fi", count, msg.real,msg.imaginary)

		pub.publish(msg)
		count +=1
		rate.sleep()
Ejemplo n.º 3
0
#!/usr/bin/env python

import rospy

from basics.msg import Complex

from random import random


rospy.init_node('message_publisher')

pub = rospy.Publisher('complex', Complex, queue_size=10)

rate = rospy.Rate(2)

while not rospy.is_shutdown():
    msg = Complex()
    msg.real = random()
    msg.imaginary = random()

    pub.publish(msg)
    rate.sleep()

Ejemplo n.º 4
0
#!/usr/bin/env python

import rospy

from basics.msg import Complex

from random import random

rospy.init_node('message_publisher')

pub = rospy.Publisher('complex', Complex, queue_size = 1)

rate = rospy.Rate(2)

while not rospy.is_shutdown():
    msg = Complex()
    msg.real = random()
    msg.imaginary = random()

    pub.publish()
    rate.sleep()