Skip to content

Commit 2422344

Browse files
committed
set tcp to have sleep of 300 ms because of no status for feedback to follow
1 parent 0a16ca4 commit 2422344

File tree

7 files changed

+120
-47
lines changed

7 files changed

+120
-47
lines changed

build/lib/pyUR/realtime/realtime_statuses.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'''
66
_program_state : float = None
77
_robot_mode : float = None
8+
_digital_outputs: list = None
89

910
_q_act_base:float = None
1011
_q_act_shoulder:float = None
@@ -13,7 +14,13 @@
1314
_q_act_wrist2: float = None
1415
_q_act_wrist3:float = None
1516

16-
_digital_outputs: list = None
17+
_tool_act_x:float = None
18+
_tool_act_y:float = None
19+
_tool_act_z:float = None
20+
_tool_act_rx:float = None
21+
_tool_act_ry:float = None
22+
_tool_act_rz:float = None
23+
1724

1825
'''
1926
Class for unpacking status from robot
@@ -26,9 +33,10 @@ def __init__():
2633
:param status: status to unpack
2734
'''
2835
def unpack(data:bytes):
29-
global _program_state, _robot_mode, _q_act_base,\
30-
_q_act_shoulder,_q_act_elbow,_q_act_wrist1,_q_act_wrist2,_q_act_wrist3,\
31-
_digital_outputs
36+
global _program_state, _robot_mode,_digital_outputs,\
37+
_q_act_base,_q_act_shoulder,_q_act_elbow,_q_act_wrist1,_q_act_wrist2,_q_act_wrist3,\
38+
_tool_act_x,_tool_act_y,_tool_act_z,_tool_act_rx,_tool_act_ry,_tool_act_rz
39+
3240

3341
packlen = (struct.unpack('!i', data[0:4]))[0]
3442
if packlen == 1220: #for version 5.10 package
@@ -70,6 +78,15 @@ def unpack(data:bytes):
7078
_q_act_wrist2 = (struct.unpack('!d', data[35*8:36*8]))[0]
7179
_q_act_wrist3 = (struct.unpack('!d', data[36*8:37*8]))[0]
7280

81+
# actual robot position coordinates - x,y,z,rx,ry,rz
82+
_tool_act_x = (struct.unpack('!d', data[55*8:56*8]))[0]
83+
_tool_act_y = (struct.unpack('!d', data[56*8:57*8]))[0]
84+
_tool_act_z = (struct.unpack('!d', data[57*8:58*8]))[0]
85+
_tool_act_rx = (struct.unpack('!d', data[58*8:59*8]))[0]
86+
_tool_act_ry = (struct.unpack('!d', data[59*8:60*8]))[0]
87+
_tool_act_rz = (struct.unpack('!d', data[60*8:61*8]))[0]
88+
89+
7390
def get_program_state():
7491
global _program_state
7592
return _program_state
@@ -79,14 +96,17 @@ def get_robot_mode():
7996
return _robot_mode
8097

8198
def get_q_act_joint_positions():
82-
global _q_act_base, _q_act_shoulder, _q_act_elbow,\
83-
_q_act_wrist1, _q_act_wrist2, _q_act_wrist3
99+
global _q_act_base, _q_act_shoulder, _q_act_elbow,_q_act_wrist1, _q_act_wrist2, _q_act_wrist3
84100
return list[_q_act_base, _q_act_shoulder, _q_act_elbow, _q_act_wrist1, _q_act_wrist2, _q_act_wrist3]
85101

86102
def get_digital_outputs():
87103
global _digital_outputs
88104
return _digital_outputs
89105

106+
def get_robot_act_pose():
107+
global _tool_act_x, _tool_act_y, _tool_act_z, _tool_act_rx, _tool_act_ry, _tool_act_rz
108+
return list[_tool_act_x, _tool_act_y, _tool_act_z, _tool_act_rx, _tool_act_ry, _tool_act_rz]
109+
90110
def _double_to_8bit_list(d):
91111
# Convert the integer to its binary representation as a string
92112
binary_str = bin(int(d))[2:].zfill(8)

build/lib/pyURControl/ur_control.py

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ def break_release():
4141
'''
4242
set tcp
4343
:param tcp_offset: tcp offset
44+
:param delay: delay for command to be executed 0.3s by default
4445
'''
45-
def set_tcp(tcp_offset: list=[0, 0, 0, 0, 0, 0]):
46+
def set_tcp(tcp_offset: list=[0, 0, 0, 0, 0, 0], delay: float=0.3):
4647
realtime.send(realtime_commands.set_tcp(tcp_offset))
48+
sleep(delay) # set sleep for command to be executed
4749

4850
'''
4951
set payload
@@ -79,11 +81,21 @@ def move_linear_pose(pose: list=[0, 0, 0, 0, 0, 0], a: float=1.4, v: float=1.05,
7981
_wait_robot_move_done()
8082

8183
'''
82-
wait for robot to finish moving
84+
get program state
85+
:1 - normal
86+
:2 - running
8387
'''
84-
def _wait_robot_move_done():
85-
_robot_started_moving()
86-
_robot_done_moving()
88+
def _get_program_state() -> float:
89+
# Receive responce
90+
responce = realtime.receive_status()
91+
92+
# Unpack responce
93+
realtime_statuses.unpack(responce)
94+
95+
# Get program state
96+
prgstate = realtime_statuses.get_program_state()
97+
return prgstate
98+
8799
'''
88100
robot started moving
89101
'''
@@ -105,26 +117,43 @@ def _robot_done_moving() -> bool:
105117
sleep(0.001)
106118

107119
'''
108-
get program state
109-
:1 - normal
110-
:2 - running
120+
wait for robot to finish moving
121+
'''
122+
def _wait_robot_move_done():
123+
_robot_started_moving()
124+
_robot_done_moving()
125+
126+
'''
127+
set digital output
128+
:param output: output number 0-7
129+
:param value: output value
111130
'''
112-
def _get_program_state():
131+
def set_digital_output(output: int=0, value: bool=False):
132+
realtime.send(realtime_commands.set_digital_output(output, value))
133+
_wait_digital_output_is_set(output, value)
134+
135+
'''
136+
get digital outputs
137+
'''
138+
def get_digital_outputs() -> list:
113139
# Receive responce
114140
responce = realtime.receive_status()
115141

116142
# Unpack responce
117143
realtime_statuses.unpack(responce)
118144

119145
# Get program state
120-
prgstate = realtime_statuses.get_program_state()
121-
return prgstate
146+
digital_outputs = realtime_statuses.get_digital_outputs()
147+
return digital_outputs
122148

123149
'''
124-
set digital output
150+
wait for digital output to be set
125151
:param output: output number 0-7
126152
:param value: output value
127153
'''
128-
def set_digital_output(output: int=0, value: bool=False):
129-
print(realtime_commands.set_digital_output(output, value))
130-
realtime.send(realtime_commands.set_digital_output(output, value))
154+
def _wait_digital_output_is_set(output: int=0, value: bool=False):
155+
while True:
156+
digital_outputs = get_digital_outputs()
157+
if digital_outputs[output] == value:
158+
break
159+
sleep(0.001)
286 Bytes
Binary file not shown.

dist/pyURControl-0.0.1.tar.gz

295 Bytes
Binary file not shown.

main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def program():
2121

2222
def PickAndPlace():
2323
# set tcp
24-
ur_control.set_tcp([0, 0, 0.1, 0, 0, 0])
25-
sleep(0.3)
24+
ur_control.set_tcp([0, 0, 0.2, 0, 0, 0])
2625

2726
# set payload if there is any
2827
ur_control.set_payload(0, [0, 0, 0], [0,0,0,0,0,0])
@@ -45,6 +44,7 @@ def PickAndPlace():
4544
# pick the piece - close gripper
4645
ur_control.set_digital_output(0, True)
4746
ur_control.set_digital_output(1, False)
47+
##
4848
ur_control.move_joint_with_pose(list(map(add,p2_pick,p2_offset_leave)), a=1.4, v=1.05, t=0, r=0) # move to p2_pick with offset to leave
4949

5050
# Place
@@ -53,6 +53,7 @@ def PickAndPlace():
5353
# place the piece - open gripper
5454
ur_control.set_digital_output(0, False)
5555
ur_control.set_digital_output(1, True)
56+
##
5657
ur_control.move_joint_with_pose(list(map(add,p3_place,p3_offset_leave)), a=1.4, v=1.05, t=0, r=0) # move to p3_place with offset to leave
5758

5859

src/pyUR/realtime/realtime_statuses.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'''
66
_program_state : float = None
77
_robot_mode : float = None
8+
_digital_outputs: list = None
89

910
_q_act_base:float = None
1011
_q_act_shoulder:float = None
@@ -13,7 +14,13 @@
1314
_q_act_wrist2: float = None
1415
_q_act_wrist3:float = None
1516

16-
_digital_outputs: list = None
17+
_tool_act_x:float = None
18+
_tool_act_y:float = None
19+
_tool_act_z:float = None
20+
_tool_act_rx:float = None
21+
_tool_act_ry:float = None
22+
_tool_act_rz:float = None
23+
1724

1825
'''
1926
Class for unpacking status from robot
@@ -26,9 +33,10 @@ def __init__():
2633
:param status: status to unpack
2734
'''
2835
def unpack(data:bytes):
29-
global _program_state, _robot_mode, _q_act_base,\
30-
_q_act_shoulder,_q_act_elbow,_q_act_wrist1,_q_act_wrist2,_q_act_wrist3,\
31-
_digital_outputs
36+
global _program_state, _robot_mode,_digital_outputs,\
37+
_q_act_base,_q_act_shoulder,_q_act_elbow,_q_act_wrist1,_q_act_wrist2,_q_act_wrist3,\
38+
_tool_act_x,_tool_act_y,_tool_act_z,_tool_act_rx,_tool_act_ry,_tool_act_rz
39+
3240

3341
packlen = (struct.unpack('!i', data[0:4]))[0]
3442
if packlen == 1220: #for version 5.10 package
@@ -70,6 +78,15 @@ def unpack(data:bytes):
7078
_q_act_wrist2 = (struct.unpack('!d', data[35*8:36*8]))[0]
7179
_q_act_wrist3 = (struct.unpack('!d', data[36*8:37*8]))[0]
7280

81+
# actual robot position coordinates - x,y,z,rx,ry,rz
82+
_tool_act_x = (struct.unpack('!d', data[55*8:56*8]))[0]
83+
_tool_act_y = (struct.unpack('!d', data[56*8:57*8]))[0]
84+
_tool_act_z = (struct.unpack('!d', data[57*8:58*8]))[0]
85+
_tool_act_rx = (struct.unpack('!d', data[58*8:59*8]))[0]
86+
_tool_act_ry = (struct.unpack('!d', data[59*8:60*8]))[0]
87+
_tool_act_rz = (struct.unpack('!d', data[60*8:61*8]))[0]
88+
89+
7390
def get_program_state():
7491
global _program_state
7592
return _program_state
@@ -79,14 +96,17 @@ def get_robot_mode():
7996
return _robot_mode
8097

8198
def get_q_act_joint_positions():
82-
global _q_act_base, _q_act_shoulder, _q_act_elbow,\
83-
_q_act_wrist1, _q_act_wrist2, _q_act_wrist3
99+
global _q_act_base, _q_act_shoulder, _q_act_elbow,_q_act_wrist1, _q_act_wrist2, _q_act_wrist3
84100
return list[_q_act_base, _q_act_shoulder, _q_act_elbow, _q_act_wrist1, _q_act_wrist2, _q_act_wrist3]
85101

86102
def get_digital_outputs():
87103
global _digital_outputs
88104
return _digital_outputs
89105

106+
def get_robot_act_pose():
107+
global _tool_act_x, _tool_act_y, _tool_act_z, _tool_act_rx, _tool_act_ry, _tool_act_rz
108+
return list[_tool_act_x, _tool_act_y, _tool_act_z, _tool_act_rx, _tool_act_ry, _tool_act_rz]
109+
90110
def _double_to_8bit_list(d):
91111
# Convert the integer to its binary representation as a string
92112
binary_str = bin(int(d))[2:].zfill(8)

src/pyURControl/ur_control.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ def break_release():
4141
'''
4242
set tcp
4343
:param tcp_offset: tcp offset
44+
:param delay: delay for command to be executed 0.3s by default
4445
'''
45-
def set_tcp(tcp_offset: list=[0, 0, 0, 0, 0, 0]):
46+
def set_tcp(tcp_offset: list=[0, 0, 0, 0, 0, 0], delay: float=0.3):
4647
realtime.send(realtime_commands.set_tcp(tcp_offset))
48+
sleep(delay) # set sleep for command to be executed
4749

4850
'''
4951
set payload
@@ -79,11 +81,21 @@ def move_linear_pose(pose: list=[0, 0, 0, 0, 0, 0], a: float=1.4, v: float=1.05,
7981
_wait_robot_move_done()
8082

8183
'''
82-
wait for robot to finish moving
84+
get program state
85+
:1 - normal
86+
:2 - running
8387
'''
84-
def _wait_robot_move_done():
85-
_robot_started_moving()
86-
_robot_done_moving()
88+
def _get_program_state() -> float:
89+
# Receive responce
90+
responce = realtime.receive_status()
91+
92+
# Unpack responce
93+
realtime_statuses.unpack(responce)
94+
95+
# Get program state
96+
prgstate = realtime_statuses.get_program_state()
97+
return prgstate
98+
8799
'''
88100
robot started moving
89101
'''
@@ -105,20 +117,11 @@ def _robot_done_moving() -> bool:
105117
sleep(0.001)
106118

107119
'''
108-
get program state
109-
:1 - normal
110-
:2 - running
120+
wait for robot to finish moving
111121
'''
112-
def _get_program_state() -> float:
113-
# Receive responce
114-
responce = realtime.receive_status()
115-
116-
# Unpack responce
117-
realtime_statuses.unpack(responce)
118-
119-
# Get program state
120-
prgstate = realtime_statuses.get_program_state()
121-
return prgstate
122+
def _wait_robot_move_done():
123+
_robot_started_moving()
124+
_robot_done_moving()
122125

123126
'''
124127
set digital output

0 commit comments

Comments
 (0)