Skip to content

Commit 0a16ca4

Browse files
committed
debug
1 parent 5f8c023 commit 0a16ca4

File tree

13 files changed

+119
-28
lines changed

13 files changed

+119
-28
lines changed

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"request": "launch",
1111
"program": "${file}",
1212
"console": "integratedTerminal",
13-
"justMyCode": true
13+
"justMyCode": false,
14+
"purpose": ["debug-test"]
1415
}
1516
]
1617
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# __all__=["dashboard", "dashboard_commands", "dashboard_statuses"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# __all__=["realtime", "realtime_commands", "realtime_statuses"]
679 Bytes
Binary file not shown.

dist/pyURControl-0.0.1.tar.gz

673 Bytes
Binary file not shown.

main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ def PickAndPlace():
4343
ur_control.move_joint_with_pose(list(map(add,p2_pick,p2_offset_approach)), a=1.4, v=1.05, t=0, r=0) # move to p2_pick with offset for approach
4444
ur_control.move_linear_pose(p2_pick, a=1.4, v=1.05, t=0, r=0) # move to p2_pick with linear motion
4545
# pick the piece - close gripper
46+
ur_control.set_digital_output(0, True)
47+
ur_control.set_digital_output(1, False)
4648
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
4749

4850
# Place
4951
ur_control.move_joint_with_pose(list(map(add,p3_place,p3_offset_approach)), a=1.4, v=1.05, t=0, r=0) # move to p3_place with offset for approach
5052
ur_control.move_linear_pose(p3_place, a=1.4, v=1.05, t=0, r=0) # move to p3_place with linear motion
5153
# place the piece - open gripper
54+
ur_control.set_digital_output(0, False)
55+
ur_control.set_digital_output(1, True)
5256
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
5357

5458

src/pyUR/realtime/realtime_commands.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,18 @@ def pose_translate(pose1:list=[0, 0, 0, 0, 0, 0], pose2:list=[0, 0, 0, 0, 0, 0])
9191
'''
9292
def pose_inverse(pose:list=[0, 0, 0, 0, 0, 0]) -> str:
9393
return "pose_inv(p" + str(pose) + ")"
94+
95+
'''
96+
calculate sub pose of two poses
97+
:param pose1: pose position - [x, y, z, rx, ry, rz]
98+
:param pose2: pose position - [x, y, z, rx, ry, rz]
99+
'''
100+
def pose_sub(pose1:list=[0, 0, 0, 0, 0, 0], pose2:list=[0, 0, 0, 0, 0, 0]) -> str:
101+
return "pose_sub(p" + str(pose1) + ", p" + str(pose2) + ")"
102+
103+
'''
104+
set digital output
105+
:param output: output number - 0-7
106+
'''
107+
def set_digital_output(output:int=0, value:bool=False) -> str:
108+
return "set_standard_digital_out(" + str(output) + ", " + str(value) +")" + '\n'

src/pyUR/realtime/realtime_statuses.py

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
_program_state : float = None
77
_robot_mode : float = None
88

9-
_q_act_x:float = None
10-
_q_act_y:float = None
11-
_q_act_z:float = None
12-
_q_act_rx: float = None
13-
_q_act_ry: float = None
14-
_q_act_rz:float = None
9+
_q_act_base:float = None
10+
_q_act_shoulder:float = None
11+
_q_act_elbow:float = None
12+
_q_act_wrist1: float = None
13+
_q_act_wrist2: float = None
14+
_q_act_wrist3:float = None
15+
16+
_digital_outputs: list = None
1517

1618
'''
1719
Class for unpacking status from robot
@@ -24,30 +26,50 @@ def __init__():
2426
:param status: status to unpack
2527
'''
2628
def unpack(data:bytes):
27-
global _program_state, _robot_mode, _q_act_x,\
28-
_q_act_y,_q_act_x,_q_act_rx,_q_act_ry,_q_act_rz
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
2932

3033
packlen = (struct.unpack('!i', data[0:4]))[0]
3134
if packlen == 1220: #for version 5.10 package
3235
data = data[4:]
36+
# program state
3337
_program_state = (struct.unpack('!d', data[131*8:132*8]))[0]
38+
39+
# robot mode
40+
_robot_mode = (struct.unpack('!d', data[94*8:95*8]))[0]
41+
42+
# digital outputs
43+
_digital_outputs = _double_to_8bit_list((struct.unpack('!d', data[130*8:131*8]))[0])
44+
45+
# actual joint positions
46+
_q_act_base = (struct.unpack('!d', data[31*8:32*8]))[0]
47+
_q_act_shoulder = (struct.unpack('!d', data[32*8:33*8]))[0]
48+
_q_act_elbow = (struct.unpack('!d', data[33*8:34*8]))[0]
49+
_q_act_wrist1 = (struct.unpack('!d', data[34*8:35*8]))[0]
50+
_q_act_wrist2 = (struct.unpack('!d', data[35*8:36*8]))[0]
51+
_q_act_wrist3 = (struct.unpack('!d', data[36*8:37*8]))[0]
52+
3453
elif packlen == 1140: #for version 5.9 package
3554
data = data[4:]
36-
37-
# actual positions
38-
_q_act_x = (struct.unpack('!d', data[31*8:32*8]))[0]
39-
_q_act_y = (struct.unpack('!d', data[32*8:33*8]))[0]
40-
_q_act_z = (struct.unpack('!d', data[33*8:34*8]))[0]
41-
_q_act_rx = (struct.unpack('!d', data[34*8:35*8]))[0]
42-
_q_act_ry = (struct.unpack('!d', data[35*8:36*8]))[0]
43-
_q_act_rz = (struct.unpack('!d', data[36*8:37*8]))[0]
44-
45-
# program state
55+
56+
# program state - 0 -? 1 - normal 2 - running
4657
_program_state = (struct.unpack('!d', data[131*8:132*8]))[0]
4758

4859
# robot mode
4960
_robot_mode = (struct.unpack('!d', data[94*8:95*8]))[0]
5061

62+
# digital outputs
63+
_digital_outputs = _double_to_8bit_list(struct.unpack('!d', data[130*8:131*8])[0])
64+
65+
# actual joint positions
66+
_q_act_base = (struct.unpack('!d', data[31*8:32*8]))[0]
67+
_q_act_shoulder = (struct.unpack('!d', data[32*8:33*8]))[0]
68+
_q_act_elbow = (struct.unpack('!d', data[33*8:34*8]))[0]
69+
_q_act_wrist1 = (struct.unpack('!d', data[34*8:35*8]))[0]
70+
_q_act_wrist2 = (struct.unpack('!d', data[35*8:36*8]))[0]
71+
_q_act_wrist3 = (struct.unpack('!d', data[36*8:37*8]))[0]
72+
5173
def get_program_state():
5274
global _program_state
5375
return _program_state
@@ -56,7 +78,20 @@ def get_robot_mode():
5678
global _robot_mode
5779
return _robot_mode
5880

59-
def get_q_act_pose():
60-
global _q_act_x, _q_act_y, _q_act_z,\
61-
_q_act_rx, _q_act_ry, _q_act_rz
62-
return list[_q_act_x, _q_act_y, _q_act_z, _q_act_rx, _q_act_ry, _q_act_rz]
81+
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
84+
return list[_q_act_base, _q_act_shoulder, _q_act_elbow, _q_act_wrist1, _q_act_wrist2, _q_act_wrist3]
85+
86+
def get_digital_outputs():
87+
global _digital_outputs
88+
return _digital_outputs
89+
90+
def _double_to_8bit_list(d):
91+
# Convert the integer to its binary representation as a string
92+
binary_str = bin(int(d))[2:].zfill(8)
93+
94+
#Convert the binary string to a list of 0 and 1 values
95+
binary_array = [bool(int(bit)) for bit in binary_str]
96+
97+
return binary_array[::-1]

src/pyURControl.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ License-File: LICENSE.md
1616

1717
# python-ur-control
1818
This is package for basic control of Universal Robots using inbuild intefaces
19-
like Dashboard, Realtime, RTDE.
19+
like Dashboard, Realtime, RTDE. link to UR documentation: https://www.universal-robots.com/articles/ur/interface-communication/overview-of-client-interfaces/
2020

2121
>:warning: **The package is in developement. It can have some bugs or missed functionalities.
2222
I am open for project ideas or cooperation to make it better. **

src/pyURControl/ur_control.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def _robot_done_moving() -> bool:
109109
:1 - normal
110110
:2 - running
111111
'''
112-
def _get_program_state():
112+
def _get_program_state() -> float:
113113
# Receive responce
114114
responce = realtime.receive_status()
115115

@@ -118,4 +118,39 @@ def _get_program_state():
118118

119119
# Get program state
120120
prgstate = realtime_statuses.get_program_state()
121-
return prgstate
121+
return prgstate
122+
123+
'''
124+
set digital output
125+
:param output: output number 0-7
126+
:param value: output value
127+
'''
128+
def set_digital_output(output: int=0, value: bool=False):
129+
realtime.send(realtime_commands.set_digital_output(output, value))
130+
_wait_digital_output_is_set(output, value)
131+
132+
'''
133+
get digital outputs
134+
'''
135+
def get_digital_outputs() -> list:
136+
# Receive responce
137+
responce = realtime.receive_status()
138+
139+
# Unpack responce
140+
realtime_statuses.unpack(responce)
141+
142+
# Get program state
143+
digital_outputs = realtime_statuses.get_digital_outputs()
144+
return digital_outputs
145+
146+
'''
147+
wait for digital output to be set
148+
:param output: output number 0-7
149+
:param value: output value
150+
'''
151+
def _wait_digital_output_is_set(output: int=0, value: bool=False):
152+
while True:
153+
digital_outputs = get_digital_outputs()
154+
if digital_outputs[output] == value:
155+
break
156+
sleep(0.001)

0 commit comments

Comments
 (0)