-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbb8_move_custom_service_server.py
71 lines (65 loc) · 2.42 KB
/
bb8_move_custom_service_server.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
67
68
69
70
71
#! /usr/bin/env python
import rospy
from std_srvs.srv import Empty, EmptyResponse
from services_quiz.srv import BB8CustomServiceMessage, BB8CustomServiceMessageResponse
from geometry_msgs.msg import Twist
import time
def my_callback(request):
rospy.loginfo("The Service move_bb8_in_square_custom has been called")
radius = request.side
for i in range(request.repetitions):
rospy.loginfo("Moving forward...")
move_circle.linear.x = 0.2
move_circle.angular.z = 0
my_pub.publish(move_circle)
time.sleep(radius)
rospy.loginfo("Rotating...")
move_circle.linear.x = 0
move_circle.angular.z = 0.2
my_pub.publish(move_circle)
time.sleep(4)
rospy.loginfo("Moving forward...")
move_circle.linear.x = 0.2
move_circle.angular.z = 0
my_pub.publish(move_circle)
time.sleep(radius)
rospy.loginfo("Rotating...")
move_circle.linear.x = 0
move_circle.angular.z = 0.2
my_pub.publish(move_circle)
time.sleep(4)
rospy.loginfo("Moving forward...")
move_circle.linear.x = 0.2
move_circle.angular.z = 0
my_pub.publish(move_circle)
time.sleep(radius)
rospy.loginfo("Rotating...")
move_circle.linear.x = 0
move_circle.angular.z = 0.2
my_pub.publish(move_circle)
time.sleep(4)
rospy.loginfo("Moving forward...")
move_circle.linear.x = 0.2
move_circle.angular.z = 0
my_pub.publish(move_circle)
time.sleep(radius)
rospy.loginfo("Rotating...")
move_circle.linear.x = 0
move_circle.angular.z = 0.2
my_pub.publish(move_circle)
time.sleep(4)
rospy.loginfo("Stopping...")
move_circle.linear.x = 0
move_circle.angular.z = 0
my_pub.publish(move_circle)
time.sleep(2)
rospy.loginfo("Finished service move_bb8_in_square_custom")
response = BB8CustomServiceMessageResponse()
response.success = True
return response # the service Response class, in this case EmptyResponse
rospy.init_node('service_move_bb8_in_square_server')
my_service = rospy.Service('/move_bb8_in_square_custom', BB8CustomServiceMessage , my_callback)
my_pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
move_circle = Twist()
rospy.loginfo("Service /move_bb8_in_square_custom Ready")
rospy.spin() # mantain the service open.