Ask Your Question
0

Error : rospy.init_node() has already been called with different arguments:

asked 2021-02-12 06:01:45 -0600

tq1992 gravatar image

updated 2021-12-21 10:34:09 -0600

130s gravatar image

In my project i have one publisher file ( publish rpm for a wheel) and one subscriber file (calculate the speed of the wheel based on rpm value )

the code works fine until i try to publish the speed to another node called "speed" and it gives me this error rospy.init_node() has already been called with different arguments:

the subscriber file code as below:

import rospy
from std_msgs.msg import String , Float64
import math


def calculate_speed(rpm):
    radius = 5.1
    speed = rpm.data*2.0*(math.pi)*radius
    print(speed)

def rpm_subscriber():
    rospy.init_node('rpm_Subscriber_Node')
    rospy.Subscriber('rpm' , Float64 , calculate_speed)

def speed_publish():
    rospy.init_node("speed_Publisher_Node")
    pub = rospy.Publisher("speed" , Float64 , queue_size=10)

    rate = rospy.Rate(5)
    pub.publish(speed)

if __name__ == '__main__':
    rpm_subscriber()
    speed_publish()

    print('DONE')

please help i have been stuck here for an hours

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-02-12 10:59:44 -0600

mgruhler gravatar image

Well, the error is pretty clear. You have two calls to rospy.init_node() in your code. One executable equals one ROS node, and should thus only have one call to rospy.init_node(). You'd need to split your code into two executables, if this should be two nodes...

edit flag offensive delete link more

Comments

thanks man

tq1992 gravatar image tq1992  ( 2021-12-21 10:42:15 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2021-02-12 06:01:45 -0600

Seen: 203 times

Last updated: Dec 21 '21