Professional Documents
Culture Documents
Wa0001.
Wa0001.
NAME : VARSHINI J
REG NO: 21BRS1126
PROCEDURE:
Use the vim terminal to enter the codes of publisher and subscriber and run them on
different terminals using python3 filename.
VIM:
:x and esc to save & exit
i to edit
esc to get back to normal
:q! to exit without saving
CODE:
PUBLISHER:
#!/usr/bin/env python3
import rospy
from std_msgs.msg import Float32,Int32
def publisher():
rospy.init_node('publisher_
pub = rospy.Publisher('sum_square', Float32, queue_size=10)
a = float(input("Enter value for a: "))
b = float(input("Enter value for b: "))
c = float(input("Enter value for c: "))
sum_squared = (a + b + c)**2
if __name__ == '__main__':
try:
publisher()
except rospy.ROSInterruptException:
pass
SUBSCRIBER:
#!/usr/bin/env python3
import rospy
from std_msgs.msg import Float32,Int32
def callback(data):
rospy.loginfo("Received: %s", data.data)
def subscriber():
rospy.init_node('subscriber_
rospy.Subscriber('sum_square', Float32, callback)
rospy.spin()
if __name__ == '__main__':
subscriber()
publisher:
subscriber:
OUTPUT:
RESULT:
Thus the program was executed successfully.