Skip to content

Commit

Permalink
Merge pull request #2 from hganchev/addGetDigitalInputsFunc
Browse files Browse the repository at this point in the history
add: get digital inputs to rt statuses and ur_control
  • Loading branch information
hganchev authored Aug 4, 2023
2 parents 7e2b896 + 6fc4042 commit e0d2b2b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
1 change: 1 addition & 0 deletions ToDo.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
- other?
* [] Examples
- ~~pick and place~~
- path following (generated from G-code) with force control
- more examples?
13 changes: 12 additions & 1 deletion src/pyUR/realtime/realtime_statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
_program_state : float = None
_robot_mode : float = None
_digital_outputs: list = None
_digital_inputs : list = None

_q_act_base:float = None
_q_act_shoulder:float = None
Expand Down Expand Up @@ -33,7 +34,7 @@ def __init__():
:param status: status to unpack
'''
def unpack(data:bytes):
global _program_state, _robot_mode,_digital_outputs,\
global _program_state, _robot_mode,_digital_outputs,_digital_inputs,\
_q_act_base,_q_act_shoulder,_q_act_elbow,_q_act_wrist1,_q_act_wrist2,_q_act_wrist3,\
_tool_act_x,_tool_act_y,_tool_act_z,_tool_act_rx,_tool_act_ry,_tool_act_rz

Expand All @@ -47,6 +48,9 @@ def unpack(data:bytes):
# robot mode
_robot_mode = (struct.unpack('!d', data[94*8:95*8]))[0]

# digital inputs
_digital_inputs = _double_to_8bit_list(struct.unpack('!d', data[85*8:86*8])[0])

# digital outputs
_digital_outputs = _double_to_8bit_list((struct.unpack('!d', data[130*8:131*8]))[0])

Expand All @@ -67,6 +71,9 @@ def unpack(data:bytes):
# robot mode
_robot_mode = (struct.unpack('!d', data[94*8:95*8]))[0]

# digital inputs
_digital_inputs = _double_to_8bit_list(struct.unpack('!d', data[85*8:86*8])[0])

# digital outputs
_digital_outputs = _double_to_8bit_list(struct.unpack('!d', data[130*8:131*8])[0])

Expand Down Expand Up @@ -103,6 +110,10 @@ def get_digital_outputs():
global _digital_outputs
return _digital_outputs

def get_digital_inputs():
global _digital_inputs
return _digital_inputs

def get_robot_act_pose():
global _tool_act_x, _tool_act_y, _tool_act_z, _tool_act_rx, _tool_act_ry, _tool_act_rz
return list[_tool_act_x, _tool_act_y, _tool_act_z, _tool_act_rx, _tool_act_ry, _tool_act_rz]
Expand Down
30 changes: 29 additions & 1 deletion src/pyURControl/ur_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,32 @@ def _wait_digital_output_is_set(output: int=0, value: bool=False):
digital_outputs = get_digital_outputs()
if digital_outputs[output] == value:
break
sleep(0.001)
sleep(0.001)

'''
get digital inputs
'''
def get_digital_inputs() -> list:
# Receive responce
responce = realtime.receive_status()

# Unpack responce
realtime_statuses.unpack(responce)

# Get program state
digital_inputs = realtime_statuses.get_digital_inputs()
return digital_inputs

'''
get digital input
:param input: input number 0-7
'''
def get_digital_input(input: int=0) -> bool:
# Receive responce
responce = realtime.receive_status()

# Unpack responce
realtime_statuses.unpack(responce)

digital_inputs = get_digital_inputs()
return digital_inputs[input]

0 comments on commit e0d2b2b

Please sign in to comment.