#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
rospy.init_node('my_node', anonymous=True)
pub = rospy.Publisher('/turtle1/cmd_vel', Twist, queue_size=10)
msg = Twist()
msg.linear.x = 2.0
msg.linear.y = 0.0
msg.linear.z = 0.0
msg.angular.x = 0.0
msg.angular.y = 0.0
rate = rospy.Rate(1)
while not rospy.is_shutdown():
for _ in range(2):
msg.angular.z = 4.0
pub.publish(msg)
rate.sleep()
for _ in range(2):
msg.angular.z = -4.0
pub.publish(msg)
rate.sleep()
<launch>
<node pkg="turtlesim" type="turtlesim_node" name="turtlesim_node" />
<node pkg="my_pkg1" type="pub-8.py" name="pub_node" />
<node pkg="my_pkg1" type="sub.py" name="sub_node" output="screen" />
</launch>
roslaunch my_pkg1 pub-sub-8.launch
애매하지만 8자로 주행하긴 한다!