rospy.loginfo is not printing when node is started with a launch file
I did the very helpfull beginner tutorials and wanted to apply what I learned on a self written example. Therefore I wrote a package called "calculate" with a "calc_talker" node that calculates the fibonacci numbers and a "calc_listener" node that listens to them.
calc_talker:
#!/usr/bin/env python
import rospy
from calculate.msg import Calc
def talker():
pub = rospy.Publisher("Calc_Chatter", Calc, queue_size=100)
rospy.init_node("Calc_Talker", anonymous=True)
rate = rospy.Rate(10)
count = 3
number1 = 1
number2 = 1
while not rospy.is_shutdown():
result = number1 + number2
msg = Calc()
msg.first_number = number1
msg.second_number = number2
msg.result = f"The {count} fibonacci number is {result}"
number2 = number1
number1 = result
count = count + 1
rospy.loginfo(msg)
pub.publish(msg)
rate.sleep()
if __name__ == "__main__":
try:
talker()
except rospy.ROSInterruptException:
pass
#EoF
calc_listener:
#!/usr/bin/env python
import rospy
from calculate.msg import Calc
def callback(data):
msg = f"{data.result}. It was calculated from {data.first_number} and {data.second_number}"
rospy.loginfo(msg)
def listener():
rospy.init_node("Calc_Listener", anonymous=True)
rospy.Subscriber("Calc_Chatter", Calc, callback)
rospy.spin()
if __name__ == "__main__":
listener()
#EoF
When i start the nodes with rosrun i get the following example output:
rosrun calculate calc_talker.py:
[INFO] [1612869970.095087]: first_number: 1 second_number 1 result: "The 3 fibonacci number is 2"
rosrun calculate calc_listener.py:
[INFO] [1612869970]: The 3 fibonacci number is 2. It was calculated from 1.0 and 1.0
I wrote a simple launch file to launch both nodes:
<launch>
<group ns="talker">
<node pkg="calculate" name="my_calc_talker" type="calc_talker.py"/>
</group>
<group ns="listener">
<node pkg="calculate" name="my_calc_listener" type="calc_listener.py" output="screen"/>
</group>
</launch>
My Problem: When i add output="screen" to the calc_talker i get the expected log output. However i does not work when i add it to the calc_listener and i can not find out why. I am very grateful for your help!