Projekt

Ogólne

Profil

zad2.py

Skrypt bazowy do zadania 2 - Wojtek Dudek, 2020-02-29 16:18

Pobierz (738 B)

 
1
#!/usr/bin/env python
2
import rospy
3
from geometry_msgs.msg import Twist
4
from turtlesim.msg  import Pose
5

    
6
global new_vel
7
new_vel = Twist()
8
def callback(pose):
9
        global new_vel
10
        new_vel = Twist()
11
        rospy.loginfo("Pozycja x: %8.2f",pose.x)
12
        rospy.loginfo("Pozycja y: %8.2f",pose.y)
13
        rospy.loginfo("Pozycja theta: %8.2f",pose.theta)
14
        new_vel.linear.x = pose.x + 0.01
15

    
16

    
17
if __name__== "__main__":
18
        global new_vel
19
        new_vel = Twist()
20
        rospy.init_node('zad2', anonymous=True)
21
        print("ready")
22
        pub = rospy.Publisher('/turtle1/cmd_vel', Twist, queue_size=10)
23
        rospy.Subscriber( '/turtle1/pose' , Pose, callback)
24
        
25
        rate=rospy.Rate(10) # 10Hz
26
        while not rospy.is_shutdown():
27
                pub.publish(new_vel)#wyslaniepredkoscizadanej
28
                rate.sleep()
29

    
30
        print("END")