ROS 프로그래밍 3

Jaewon·2021년 6월 4일
1

ROS

목록 보기
9/9
post-custom-banner

거북이 8자 주행

pub-8.py

#!/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()

pub-sub-8.launch

<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자로 주행하긴 한다!

post-custom-banner

0개의 댓글