-
Notifications
You must be signed in to change notification settings - Fork 0
/
go_straight_v2.py
45 lines (35 loc) · 1.16 KB
/
go_straight_v2.py
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
#!/usr/bin/env python
import rospy
from geometry_msgs.msg import Twist
from nav_msgs.msg import Odometry
class goGoal():
def __init__(self):
rospy.init_node("go_goal")
self.goal_location = 5.0
self.current_location = 0.0
self.control = True
rospy.Subscriber("/odom", Odometry, self.odom_callback)
pub = rospy.Publisher("/cmd_vel", Twist, queue_size=10)
vel_msg = Twist()
rate = rospy.Rate(10)#10 time in 1 second
while not rospy.is_shutdown():
if self.control:
vel_msg.linear.x = 0.5
pub.publish(vel_msg)
else:
vel_msg.linear.x = 0.0
pub.publish(vel_msg)
rospy.loginfo("Goal Reached")
rate.sleep()
def odom_callback(self, msg):
#print(msg.pose.pose.position.x)
#pass
self.current_location = msg.pose.pose.position.x
if self.current_location < self.goal_location:
self.control = True
else:
self.control = False
try:
goGoal()
except rospy.ROSInterruptException:
print("Ros Node is Done")