$ cd xycar_ws/src/msg_send/src/
$ cp teacher.py teacher_int.py
$ gedit teacher_int.py
#!/usr/bin/env python
import rospy
from std_msgs.msg import Int32
rospy.init_node('teacher')
pub = rospy.Publisher('my_topic',Int32)
rate = rospy.Rate(2)
count = 1
while not rospy.is_shutdown():
pub.publish(count)
count = count + 1
rate.sleep()
$ cp student.py student_int.py
$ gedit student_int.py
#!/usr/bin/env python
import rospy
from std_msgs.msg import Int32
def callback(msg):
print msg.data
rospy.init_node('student')
pub = rospy.Subscriber('my_topic', Int32, callback)
rospy.spin()
$ cd ..
$ cd launch/
$ cp m_send.launch m_send_1n.launch
$ gedit m_send_1n.launch
<launch>
<node pkg="msg_send" type="teacher_int.py" name="teacher"/>
<node pkg="msg_send" type="student_int.py" name="student1" output="screen"/>
<node pkg="msg_send" type="student_int.py" name="student2" output="screen"/>
<node pkg="msg_send" type="student_int.py" name="student3" output="screen"/>
</launch>
$ cm
$ roslaunch msg_send m_send_1n.launch
$ cs
$ cd msg_send/launch/
$ cp m_send_1n.launch m_send_n1.launch
$ gedit m_send_n1.launch
<launch>
<node pkg="msg_send" type="teacher_int.py" name="teacher1"/>
<node pkg="msg_send" type="teacher_int.py" name="teacher2"/>
<node pkg="msg_send" type="teacher_int.py" name="teacher3"/>
<node pkg="msg_send" type="student_int.py" name="student" output="screen"/>
</launch>
$ roslaunch msg_send m_send_n1.launch
$ rqt_graph
$ cs
$ cd msg_send/launch/
$ cp m_send_n1.launch m_send_nn.launch
$ gedit m_send_nn.launch
<launch>
<node pkg="msg_send" type="teacher_int.py" name="teacher1"/>
<node pkg="msg_send" type="teacher_int.py" name="teacher2"/>
<node pkg="msg_send" type="teacher_int.py" name="teacher3"/>
<node pkg="msg_send" type="student_int.py" name="student1" output="screen"/>
<node pkg="msg_send" type="student_int.py" name="student2" output="screen"/>
<node pkg="msg_send" type="student_int.py" name="student3" output="screen"/>
</launch>
$ roslaunch msg_send m_send_nn.launch