<jupyter_start><jupyter_text>Solution for Exercise 2 First, create a new package called **exercise2** with dependencies **rospy** & **std_msgs**<jupyter_code>cd catkin_ws/src
catkin_create_pkg exercise2 rospy std_msgs<jupyter_output><empty_output><jupyter_text>Then, make **scripts** directory inside your package. Create a new file called **solution2.py** inside the scripts folder. Then,copy the following into it:<jupyter_code>#! /usr/bin/env python

import rospy
from std_msgs.msg import String

rospy.init_node("topic_publisher")
pub = rospy.Publisher('/hello', String, queue_size = 1)
rate = rospy.Rate(2)
name = '<NAME>'

while not rospy.is_shutdown():
    pub.publish(name)
    rate.sleep()<jupyter_output><empty_output><jupyter_text>After that, compile and run it. If it has no error, close the node and go into next steps. Make a new directory called **launch** inside the package. Then inside it, make the launch file called **solution2.launch** and copy the following into it:<jupyter_code><launch>
    <node pkg="exercise2" type="solution2.py" name="topic_publisher" output="screen"/>
</launch><jupyter_output><empty_output><jupyter_text>Compile again and run it.<jupyter_code>roslaunch exercise2 solution2.launch<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11305732484076433, 'fraction_numerical': 0.00875796178343949, 'mean_word_length': 6.7592592592592595, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '221938', 'license': 'MIT', 'n_tokens_mistral': 429, 'n_tokens_neox': 408, 'n_words': 118, 'path': 'Modules/Module 4 - ROS Topics/Solutions/Solution for Exercise 2.ipynb', 'repo_name': 'mlsdpk/ROS_Basic_Course', 'size': '1261'}