import rospy
from geometry_msgs.msg import Twist
def velocity_publisher():
rospy.init_node('velocity_publish',anonymous=True)
turtle_vel_pub=rospy.Publisher('/turtle1/cmd_vel',Twist,queue_size=10)
rate=rospy.Rate(10)
while not rospy.is_shutdown():
vel_msg=Twist()
vel_msg.linear.x=0.5
vel_msg.angular.z=0.2
turtle_vel_pub.publish(vel_msg)
rospy.loginfo("publish turtle velocity command[%0.2f m/s,%0.2f rad/s]",vel_msg.linear.x,vel_msg.angular.z)
rate.sleep()
if __name__=='__main__':
try:
velocity_publisher()
except rospy.ROSInterruptException:
pass
import rospy
from turtlesim.msg import Pose
def poseCallback(msg):
rospy.loginfo('turtle pose:x:%0.6f,y:%0.6f',msg.x,msg.y)
def pose_subscriber():
rospy.init_node('pose_subscriber',anonymous=True)
rospy.Subscriber('/turtle1/pose',Pose,poseCallback)
rospy.spin()
if __name__=='__main__':
pose_subscriber()