-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1352.py
More file actions
49 lines (45 loc) · 1.48 KB
/
Copy path1352.py
File metadata and controls
49 lines (45 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
import math
def move_turtle():
# Starts a new node
rospy.init_node('node_turtle_revolve', anonymous=True)
vel_publisher = rospy.Publisher('/turtle1/cmd_vel', Twist, queue_size=10)
vel_msg = Twist()
#Velocity Initialization
distance = 12.8
vel_msg.linear.x = 1
vel_msg.linear.y = 0
vel_msg.linear.z = 0
vel_msg.angular.x = 0
vel_msg.angular.y = 0
vel_msg.angular.z = 0.5
while not rospy.is_shutdown():
#Setting the current time for distance calculus
t0 = rospy.Time.now().to_sec()
current_distance = 0
#Loop to move the turtle in an specified distance
while(current_distance < distance):
#Publish the velocity
vel_publisher.publish(vel_msg)
#Takes actual time to velocity calculus
t1=rospy.Time.now().to_sec()
#Calculates distance
current_distance=(t1-t0)
#Loging Message and current distance
rospy.loginfo("Moving in a Circle")
rospy.loginfo(current_distance)
#After the loop, stops the robot
vel_msg.linear.x = 0
vel_msg.angular.z = 0
#Force the robot to stop
vel_publisher.publish(vel_msg)
#Loging Message and Break Loop
rospy.loginfo("goal reached")
break
if __name__ == '__main__':
try:
#Staring
move_turtle()
except rospy.ROSInterruptException: pass