ROS - Publisher & Subscriber (Python)

preview_player
Показать описание
This video shows the demo of writing publisher and subscriber on ROS with Python.

========================================
Don't forget to click like and subscribe my channel.
Рекомендации по теме
Комментарии
Автор

While running this I got some error, it's not taking operators such as +, *, - etc via command line, can you please help me in this




#!/usr/bin/env python



import rospy

from rospy_tutorials.msg import Floats



def add(x, y):

return x + y

# This function subtracts two numbers

def subtract(x, y):

return x - y



# This function multiplies two numbers

def multiply(x, y):

return x * y



# This function divides two numbers

def divide(x, y):

return x / y



def publishMethod(Float_f, Float_s):

pub = rospy.Publisher('talker', Floats, queue_size=10)

rospy.init_node('publish_node', anonymous=True)

rate = rospy.Rate(1)

while not rospy.is_shutdown():

Float_f = input('Enter first number ')

Float_s = input('Enter second number ')



rospy.loginfo("Data is being sent")

print("Select operation.")

print("1.Add")

print("2.Subtract")

print("3.Multiply")

print("4.Divide")

while True:

# Take input from the user

choice = input("Enter choice(1/2/3/4): ")



# Check if choice is one of the four options

if choice in ('1', '2', '3', '4'):

Float_f = float(input("Enter first number: "))

Float_s = float(input("Enter second number: "))



if choice == '1':

print(Float_f, "+", Float_s, "=", add(Float_f, Float_s))



elif choice == '2':

print(Float_f, "-", Float_s, "=", subtract(Float_f, Float_s))



elif choice == '3':

print(Float_f, "*", Float_s, "=", multiply(Float_f, Float_s))



elif choice == '4':

print(Float_f, "/", Float_s, "=", divide(Float_f, Float_s))

break

else:

print("Invalid Input")







pub.publish(publishString4)

rate.sleep()



if __name__ == '__main__':

try:

publishMethod()

except rospy.ROSInterruptException:

pass

aaqibalone
Автор

what did you press for exiting publisher.py nano

hariharanramamurthy