-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocking_test.py
66 lines (52 loc) · 1.38 KB
/
docking_test.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
import rospy
from time import sleep
from std_msgs.msg import Empty
import tf
from geometry_msgs.msg import Twist
from ca_msg import Mode
rospy.init_node("docking_test")
dock_publisher = rospy.Publisher('dock',Empty, queue_size=10)
undock_publisher = rospy.Publiser('undock',Empty, queue_size=10)
velocity_publisher = rospy.Publiser('cmd_vel',Twist,queue_size=10)
rate = rospy.Rate(10.0)
listener = tf.TransformListener()
x = Empty()
vel_msg = Twist()
count = 0
def check_mode():
mode_msg = rospy.wait_for_message("roomba3/Mode", Mode)
check = False
if (mode == 1):
check = True
return check
def docking():
while not check_mode():
dock_publisher.publish(x)
rate.sleep()
if check_mode():
print("Roomba has Docked")
def undocking():
while check_mode():
undock_publisher.publish(x)
rate.sleep()
if check_mode() == False:
for i in range(0,5):
vel_msg.linear.x = -0.2
velocity_publisher(vel_msg)
rate.sleep()
print("Roomba is undocked")
while not rospy.is_shutdown():
user_dock = raw_input("Press Enter to dock or Press c to exit")
if user_dock == "":
docking()
if user_dock == 'c':
print("exiting")
break
user_dock = raw_input("Press Enter to undock or Press c to exit")
if user_dock == "":
undocking()
if user_dock == 'c'
print("exiting")
break
rate.sleep()