Repository navigation
Expand file tree
/
Copy pathclients.py
More file actions
executable file
·130 lines (106 loc) · 3.54 KB
/
Copy pathclients.py
File metadata and controls
executable file
·130 lines (106 loc) · 3.54 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python3
import rospy
import time
from arm_controller.srv import *
from std_msgs.msg import Float32, Int16
NAMESPACE = "/arm"
# SERVICE TOPIC
SERVICE_CMD = NAMESPACE + "/arm_cmd"
SERVICE_STOP = NAMESPACE + "/x_stop"
def clientVision(resultVision: bool):
"""Service proxy for Vision (OAK-D-LITE)."""
rate = rospy.Rate(1)
try:
global visionResp
rospy.wait_for_service('Vision')
service: Vision = rospy.ServiceProxy(
'Vision', Vision)
visionResp = service(resultVision)
rate.sleep()
except rospy.ServiceException as e:
print("Service call failed: %s" % e)
def clientArm(dist_x: Float32, dist_y: Float32, dist_z: Float32,
rpm_y: Int16, rpm_z: Int16, cmd_x: bool):
"""Service proxy for /arm/arm_cmd (robotic arm)."""
rate = rospy.Rate(1)
global armResp
try:
rospy.wait_for_service(SERVICE_CMD)
service: Arm = rospy.ServiceProxy(
SERVICE_CMD, Arm)
armResp = service(dist_x, dist_y, dist_z, rpm_y, rpm_z, cmd_x)
rate.sleep()
except rospy.ServiceException as e:
print("Service call failed: %s" % e)
def clientNav(resultNav: bool):
"""Service proxy for Nav (Navigation)."""
rate = rospy.Rate(1)
global navResp
try:
rospy.wait_for_service('Nav')
service: Nav = rospy.ServiceProxy(
'Nav', Nav)
navResp = service(resultNav)
rate.sleep()
except rospy.ServiceException as e:
print("Service call failed: %s" % e)
def clientHMI(resultHMI: bool):
"""Service proxy for HMI."""
rate = rospy.Rate(1)
global hmiResp
try:
rospy.wait_for_service('HMI')
service: HMI = rospy.ServiceProxy(
'HMI', HMI)
hmiResp = service(resultHMI)
rate.sleep()
except rospy.ServiceException as e:
print("Service call failed: %s" % e)
def clientStop():
"""Service proxy for /arm/x_stop (stopping)."""
rate = rospy.Rate(1)
global stopResp
try:
rospy.wait_for_service(SERVICE_STOP)
service: Stop = rospy.ServiceProxy(
SERVICE_STOP, Stop)
stopResp = service()
rate.sleep()
except rospy.ServiceException as e:
print("Service call failed: %s" % e)
def clientButton():
"""Service proxy for buttonStatus."""
rate = rospy.Rate(1)
global buttonResp
try:
rospy.wait_for_service('buttonStatus')
service: buttonStatus = rospy.ServiceProxy(
'buttonStatus', buttonStatus)
buttonResp = service(True)
rate.sleep()
except rospy.ServiceException as e:
print("Service call failed: %s" % e)
if __name__ == "__main__":
rospy.init_node("Server")
global visionResp, buttonResp, stopResp, hmiResp, navResp, armResp
clientNav(True)
clientVision(True)
if visionResp.z == True:
clientArm(0, visionResp.x, visionResp.y , 300, 200, False)
timeY = visionResp.x*420
timeZ = visionResp.y*160
if timeY >= timeZ:
time.sleep(timeY)
elif timeZ >= timeY:
time.sleep(timeZ)
clientArm(0, 0, 0 , 300, 200, True)
time.sleep(15)
clientArm(0, 0, 0 , 300, 200, False)
time.sleep(2)
clientArm(0, -visionResp.x, -visionResp.y, 300, 200, False)
clientArm(0,0.05,0,300,200,False)
# clientVision(True)
# if visionResp.z == True:
# clientArm(0, visionResp.x, visionResp.y , 300, 120, False)
# time.sleep(26)
# clientArm(0, 0, 0 , 300, 120, True)