Module robpod.background
Global variables
var OFF-
Constant representing a disabled or LOW digital signal.
var ON-
Constant representing an enabled or HIGH digital signal.
Functions
def get_analog_input(index)-
Expand source code
def get_analog_input(index): """Read the current value of an analog input. Args: index (int): Index of the analog input. Returns: The current analog input value. """ return _robot.get_analog_input(index)Read the current value of an analog input.
Args
index:int- Index of the analog input.
Returns
The current analog input value.
def get_analog_input_mode(index)-
Expand source code
def get_analog_input_mode(index): """Retrieve the configured mode of an analog input. Args: index (int): Index of the analog input. Returns: The configured mode, value defined in AnalogMode. """ return _robot.get_analog_input_mode(index)Retrieve the configured mode of an analog input.
Args
index:int- Index of the analog input.
Returns
The configured mode, value defined in AnalogMode.
def get_analog_output(index)-
Expand source code
def get_analog_output(index): """Read the current value of an analog output. Args: index (int): Index of the analog output. Returns: The current analog output value. """ return _robot.get_analog_output(index)Read the current value of an analog output.
Args
index:int- Index of the analog output.
Returns
The current analog output value.
def get_analog_output_mode(index)-
Expand source code
def get_analog_output_mode(index): """Retrieve the configured mode of an analog output. Args: index (int): Index of the analog output. Returns: The configured mode, a value defined in AnalogMode. """ return _robot.get_analog_output_mode(index)Retrieve the configured mode of an analog output.
Args
index:int- Index of the analog output.
Returns
The configured mode, a value defined in AnalogMode.
def get_configurable_digital_input(index)-
Expand source code
def get_configurable_digital_input(index): """Read the state of a configurable digital input. Args: index (int): Index of the configurable digital input. Returns: bool: True if the input is ON, False if it is OFF. """ return _robot.get_digital_input(index)Read the state of a configurable digital input.
Args
index:int- Index of the configurable digital input.
Returns
bool- True if the input is ON, False if it is OFF.
def get_configurable_digital_output(index)-
Expand source code
def get_configurable_digital_output(index): """Read the state of a configurable digital output. Args: index (int): Index of the configurable digital output. Returns: bool: True if the output is ON, False if it is OFF. """ return _robot.get_configurable_digital_output(index)Read the state of a configurable digital output.
Args
index:int- Index of the configurable digital output.
Returns
bool- True if the output is ON, False if it is OFF.
def get_digital_input(index)-
Expand source code
def get_digital_input(index): """Read the state of a digital input. Args: index (int): Index of the digital input. Returns: bool: True if the input is ON, False if it is OFF. """ return _robot.get_digital_input(index)Read the state of a digital input.
Args
index:int- Index of the digital input.
Returns
bool- True if the input is ON, False if it is OFF.
def get_digital_output(index)-
Expand source code
def get_digital_output(index): """Read the state of a digital output. Args: index (int): Index of the digital output. Returns: bool: True if the output is ON, False if it is OFF. """ return _robot.get_digital_output(index)Read the state of a digital output.
Args
index:int- Index of the digital output.
Returns
bool- True if the output is ON, False if it is OFF.
def get_joint_pose()-
Expand source code
def get_joint_pose(): """Retrieve the current robot joint positions. Returns: float[6]: The current joint pose, as provided by the robot API. """ return _robot.get_joint_pose()Retrieve the current robot joint positions.
Returns
float[6]- The current joint pose, as provided by the robot API.
def get_joint_velocity()-
Expand source code
def get_joint_velocity(): """Retrieve the current robot joint velocities. Returns: float[6]: The current joint velocities. """ return _robot.get_joint_velocity()Retrieve the current robot joint velocities.
Returns
float[6]- The current joint velocities.
def get_mode()-
Expand source code
def get_mode(): """Get the current robot operational mode: AUTOMATIC, MANUAL, TEACHING. Returns: RobotMode: The current operational mode. """ return _robot.get_mode()Get the current robot operational mode: AUTOMATIC, MANUAL, TEACHING.
Returns
RobotMode- The current operational mode.
def get_program_name()-
Expand source code
def get_program_name(): """Retrieve the name of the currently selected or executing program. Returns: str: The program name """ return _robot.get_program_name()Retrieve the name of the currently selected or executing program.
Returns
str- The program name
def get_program_state()-
Expand source code
def get_program_state(): """Get the current program execution state. Returns: ProgramStatus: The current program state. """ return _robot.get_program_state() def get_register(index)-
Expand source code
def get_register(index): """Read the value of a robot register (modbus). Args: index (int): Index of the register to read. Returns: int: The current value of the specified register. """ return _robot.get_register(index)Read the value of a robot register (modbus).
Args
index:int- Index of the register to read.
Returns
int- The current value of the specified register.
def get_state()-
Expand source code
def get_state(): """Get the current robot state. Returns: RobotStatus: The current robot state. """ return _robot.get_state() def get_tcp_offset()-
Expand source code
def get_tcp_offset(): """Retrieve the configured offset of the tool center point (TCP). Returns: The TCP offset. """ return _robot.get_tcp_offset()Retrieve the configured offset of the tool center point (TCP).
Returns
The TCP offset.
def get_tcp_pose()-
Expand source code
def get_tcp_pose(): """Retrieve the current tool center point (TCP) pose in base coordinates. Returns: float[6]: The current TCP pose. """ return _robot.get_tcp_pose()Retrieve the current tool center point (TCP) pose in base coordinates.
Returns
float[6]- The current TCP pose.
def get_tcp_velocity()-
Expand source code
def get_tcp_velocity(): """Retrieve the current tool center point (TCP) velocity. Returns: float[6]: The current TCP velocity. """ return _robot.get_tcp_velocity()Retrieve the current tool center point (TCP) velocity.
Returns
float[6]- The current TCP velocity.
def get_tool_digital_input(index)-
Expand source code
def get_tool_digital_input(index): """Read the state of a tool digital input. Args: index (int): Index of the tool digital input. Returns: bool: True if the input is ON, False if it is OFF. """ return _robot.get_tool_digital_input(index)Read the state of a tool digital input.
Args
index:int- Index of the tool digital input.
Returns
bool- True if the input is ON, False if it is OFF.
def get_tool_digital_output(index)-
Expand source code
def get_tool_digital_output(index): """Read the state of a tool digital output. Args: index (int): Index of the tool digital output. Returns: bool: True if the output is ON, False if it is OFF. """ return _robot.get_tool_digital_output(index)Read the state of a tool digital output.
Args
index:int- Index of the tool digital output.
Returns
bool- True if the output is ON, False if it is OFF.
def log(value)-
Expand source code
def log(value): """Print a message with the current date and time.""" now = datetime.now() print(now.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]+": "+str(value))Print a message with the current date and time.
def loop(func=None, times=None, delay=1)-
Expand source code
def loop(func=None, times=None, delay=1): """Execute a function repeatedly with a delay between executions. The decorated function is called repeatedly until the specified number of executions is reached. If times is None, it runs indefinitely. This decorator can be used with or without parentheses. Args: func (callable, optional): Function to decorate. Usually omitted when passing decorator options. times (int, optional): Number of times to execute the function. If None, the function runs indefinitely. Defaults to None. delay (int | float, optional): Delay in seconds between executions. Defaults to 1. Returns: callable: A decorated function that repeatedly executes the wrapped function. Its return value is not propagated. Examples: Run a function indefinitely, once per second: @loop def monitor_robot(): print(get_state()) Execute a function ten times with a half-second delay: @loop(times=10, delay=0.5) def blink_output(): set_digital_output(0, ON) """ def decorator(func): @wraps(func) def wrapper(*args, **kwargs): count = 0 while times is None or count < times: func(*args, **kwargs) count += 1 time.sleep(delay) return wrapper if func is not None: return decorator(func) return decoratorExecute a function repeatedly with a delay between executions.
The decorated function is called repeatedly until the specified number of executions is reached. If times is None, it runs indefinitely.
This decorator can be used with or without parentheses.
Args
func:callable, optional- Function to decorate. Usually omitted when passing decorator options.
times:int, optional- Number of times to execute the function. If None, the function runs indefinitely. Defaults to None.
delay:int | float, optional- Delay in seconds between executions. Defaults to 1.
Returns
callable- A decorated function that repeatedly executes the
wrapped function. Its return value is not propagated.
Examples
Run a function indefinitely, once per second:
@loop def monitor_robot(): print(get_state())Execute a function ten times with a half-second delay:
@loop(times=10, delay=0.5) def blink_output(): set_digital_output(0, ON) def on(condition, duration=0)-
Expand source code
def on(condition, duration=0): """Create a rule that triggers once when a condition becomes true. The action executes once after the condition has remained true for at least the specified duration. The rule will not trigger again until the condition becomes false and then true again. Args: condition (callable): Function returning a truthy or falsy value. duration (float, optional): Minimum continuous time in seconds that the condition must remain true before the action runs. Defaults to 0, meaning the action runs on the first eligible evaluation after the condition becomes true. Returns: RuleWithDo: Builder used to configure the action and start the rule. Examples: Log once when the robot program enters the running state: on( lambda: get_program_state() == ProgramStatus.RUNNING ).do( lambda: log("RUNNING") ).start() Log once when the program enters the paused state: on( lambda: get_program_state() == ProgramStatus.PAUSED ).do( lambda: log("PAUSED") ).start() Log once when the program enters the stopped state: on( lambda: get_program_state() == ProgramStatus.STOPPED ).do( lambda: log("STOPPED") ).start() Trigger only if the robot remains paused for at least three seconds: on( lambda: get_program_state() == ProgramStatus.PAUSED, duration=3, ).do( lambda: log("Program has been paused for 3 seconds") ).start() Note: The condition is evaluated periodically, so the action may run slightly later than the specified duration due to the polling interval and execution time. """ rule = Rule(condition, fire_once=True, duration=duration) return RuleWithDo(rule)Create a rule that triggers once when a condition becomes true.
The action executes once after the condition has remained true for at least the specified duration. The rule will not trigger again until the condition becomes false and then true again.
Args
condition:callable- Function returning a truthy or falsy value.
duration:float, optional- Minimum continuous time in seconds that the condition must remain true before the action runs. Defaults to 0, meaning the action runs on the first eligible evaluation after the condition becomes true.
Returns
RuleWithDo- Builder used to configure the action and start the rule.
Examples
Log once when the robot program enters the running state:
on( lambda: get_program_state() == ProgramStatus.RUNNING ).do( lambda: log("RUNNING") ).start()Log once when the program enters the paused state:
on( lambda: get_program_state() == ProgramStatus.PAUSED ).do( lambda: log("PAUSED") ).start()Log once when the program enters the stopped state:
on( lambda: get_program_state() == ProgramStatus.STOPPED ).do( lambda: log("STOPPED") ).start()Trigger only if the robot remains paused for at least three seconds:
on( lambda: get_program_state() == ProgramStatus.PAUSED, duration=3, ).do( lambda: log("Program has been paused for 3 seconds") ).start()Note
The condition is evaluated periodically, so the action may run slightly later than the specified duration due to the polling interval and execution time.
def retry(func=None, max_retries=None, delay=1)-
Expand source code
def retry(func=None, max_retries=None, delay=1): """Retry a function when it raises an exception. The decorated function is executed repeatedly until it succeeds or the maximum number of retries is reached. A delay is applied between failed attempts. This decorator can be used with or without parentheses. Args: func (callable, optional): Function to decorate. Usually omitted when passing decorator options. max_retries (int, optional): Maximum number of retries after the initial attempt. If None, retries indefinitely. Defaults to None. delay (int | float, optional): Delay in seconds between failed attempts. Defaults to 1. Returns: callable: A decorated function that retries on exceptions and returns the wrapped function's result when successful. Raises: Exception: Re-raises the last exception when the maximum number of retries is reached. Examples: Retry indefinitely until the function succeeds: @retry def connect(): return establish_connection() Retry up to three times after the initial attempt: @retry(max_retries=3, delay=2) def read_sensor(): return sensor.read() """ def decorator(func): @wraps(func) def wrapper(*args, **kwargs): attempt = 0 while max_retries is None or attempt <= max_retries: try: return func(*args, **kwargs) except Exception: if max_retries is not None and attempt >= max_retries: raise attempt += 1 time.sleep(delay) return wrapper if func is not None: return decorator(func) return decoratorRetry a function when it raises an exception.
The decorated function is executed repeatedly until it succeeds or the maximum number of retries is reached. A delay is applied between failed attempts.
This decorator can be used with or without parentheses.
Args
func:callable, optional- Function to decorate. Usually omitted when passing decorator options.
max_retries:int, optional- Maximum number of retries after the initial attempt. If None, retries indefinitely. Defaults to None.
delay:int | float, optional- Delay in seconds between failed attempts. Defaults to 1.
Returns
callable- A decorated function that retries on exceptions and
returns the wrapped function's result when successful.
Raises
Exception- Re-raises the last exception when the maximum number of retries is reached.
Examples
Retry indefinitely until the function succeeds:
@retry def connect(): return establish_connection()Retry up to three times after the initial attempt:
@retry(max_retries=3, delay=2) def read_sensor(): return sensor.read() def set_analog_input_mode(index, mode)-
Expand source code
def set_analog_input_mode(index, mode): """Configure the operating mode of an analog input. Args: index (int): Index of the analog input. mode (str): Desired analog mode, such as AnalogMode.CURRENT or AnalogMode.VOLTAGE. """ return _robot.set_analog_input_mode(index, mode)Configure the operating mode of an analog input.
Args
index:int- Index of the analog input.
mode:str- Desired analog mode, such as AnalogMode.CURRENT or AnalogMode.VOLTAGE.
def set_analog_output(index, value)-
Expand source code
def set_analog_output(index, value): """Set the value of an analog output. Args: index (int): Index of the analog output. value (float): Analog value to assign to the output. The valid range depends on the configured output mode and robot API. """ return _robot.set_analog_output(index, value)Set the value of an analog output.
Args
index:int- Index of the analog output.
value:float- Analog value to assign to the output. The valid range depends on the configured output mode and robot API.
def set_analog_output_mode(index, mode)-
Expand source code
def set_analog_output_mode(index, mode): """Configure the operating mode of an analog output. Args: index (int): Index of the analog output. mode (str): Desired analog mode, such as AnalogMode.CURRENT or AnalogMode.VOLTAGE. """ return _robot.set_analog_output_mode(index, mode)Configure the operating mode of an analog output.
Args
index:int- Index of the analog output.
mode:str- Desired analog mode, such as AnalogMode.CURRENT or AnalogMode.VOLTAGE.
def set_configurable_digital_output(index, value)-
Expand source code
def set_configurable_digital_output(index, value): """Set the state of a configurable digital output. Args: index (int): Index of the configurable digital output. value (bool): Desired output state. Use ON or OFF. """ return _robot.set_configurable_digital_output(index, value)Set the state of a configurable digital output.
Args
index:int- Index of the configurable digital output.
value:bool- Desired output state. Use ON or OFF.
def set_digital_output(index, value)-
Expand source code
def set_digital_output(index, value): """Set the state of a digital output. Args: index (int): Index of the digital output. value (bool): Desired output state. Use ON or OFF. """ return _robot.set_digital_output(index, value)Set the state of a digital output.
Args
index:int- Index of the digital output.
value:bool- Desired output state. Use ON or OFF.
def set_register(index, value)-
Expand source code
def set_register(index, value): """Write a value to a robot register (modbus). Args: index (int): Index of the register to write. value (int): Value to store in the register. """ return _robot.set_register(index, value)Write a value to a robot register (modbus).
Args
index:int- Index of the register to write.
value:int- Value to store in the register.
def set_tool_digital_output(index, value)-
Expand source code
def set_tool_digital_output(index, value): """Set the state of a tool digital output. Args: index (int): Index of the tool digital output. value (bool): Desired output state. Use ON or OFF. """ return _robot.set_tool_digital_output(index, value)Set the state of a tool digital output.
Args
index:int- Index of the tool digital output.
value:bool- Desired output state. Use ON or OFF.
def wait_boot_completed(timeout=300)-
Expand source code
def wait_boot_completed(timeout=60*5): """Wait for the robot boot process to complete. Args: timeout (int): Maximum time to wait, in seconds. Defaults to 300 seconds (5 minutes). """ return _robot.wait_boot_completed(timeout)Wait for the robot boot process to complete.
Args
timeout:int- Maximum time to wait, in seconds. Defaults to 300 seconds (5 minutes).
def when(condition)-
Expand source code
def when(condition): """Create a rule that executes its action while a condition is true. The condition is evaluated approximately every 0.5 seconds. Whenever the condition evaluates to true, the action is executed. Therefore, the action may run repeatedly for as long as the condition remains true. Args: condition (callable): Function returning a truthy or falsy value. Returns: RuleWithDo: Builder used to configure the action and start the rule. Examples: Log repeatedly while the robot program is running: when( lambda: get_program_state() == ProgramStatus.RUNNING ).do( lambda: log("Program is running") ).start() Turn on an output while the program is running: when( lambda: get_program_state() == ProgramStatus.RUNNING ).do( lambda: set_digital_output(0, ON) ).start() Note: The action is not edge-triggered. If the condition stays true, it is executed on every evaluation, approximately twice per second with the default delay. """ rule = Rule(condition, fire_once=False) return RuleWithDo(rule)Create a rule that executes its action while a condition is true.
The condition is evaluated approximately every 0.5 seconds. Whenever the condition evaluates to true, the action is executed. Therefore, the action may run repeatedly for as long as the condition remains true.
Args
condition:callable- Function returning a truthy or falsy value.
Returns
RuleWithDo- Builder used to configure the action and start the rule.
Examples
Log repeatedly while the robot program is running:
when( lambda: get_program_state() == ProgramStatus.RUNNING ).do( lambda: log("Program is running") ).start()Turn on an output while the program is running:
when( lambda: get_program_state() == ProgramStatus.RUNNING ).do( lambda: set_digital_output(0, ON) ).start()Note
The action is not edge-triggered. If the condition stays true, it is executed on every evaluation, approximately twice per second with the default delay.
Classes
class AnalogMode-
Expand source code
class AnalogMode: """Analog signal modes.""" CURRENT = "CURRENT" VOLTAGE = "VOLTAGE"Analog signal modes.
Class variables
var CURRENTvar VOLTAGE
class DoosanRobotClient (host)-
Expand source code
class DoosanRobotClient(_RobotClient): def __init__(self, host): _RobotClient.__init__(self, host) # call parent constructor self.modbus_client = modbus.ModbusClient(host) def get_digital_input(self, index): return self.modbus_client.read_coils(1, -1 + index, 1)[0] def get_configurable_digital_input(self, index): return get_digital_input(index) def get_digital_output(self, index): return self.modbus_client.read_coils(1, 19 + index, 1)[0] def get_configurable_digital_output(self, index): return get_digital_output(index) def set_configurable_digital_output(self, index, value): return set_digital_output(index, value) def set_digital_output(self, index, value): return self.modbus_client.write_coils(1, 19 + index, [value]) def get_tool_digital_output(self, index): return self.modbus_client.read_coils(1, 41 + index, 1)[0] def get_tool_digital_input(self, index): return self.modbus_client.read_coils(1, 35 + index, 1)[0] def set_tool_digital_output(self, index, value): return self.modbus_client.write_coils(1, 41 + index, [value]) def get_joint_pose(self): values = self.modbus_client.read_holding_registers(1, 270, 6) result = [] for val in values: result.append((modbus.to_signed_value(val)/ 10)) return result def get_joint_velocity(self): values = self.modbus_client.read_holding_registers(1, 280, 6) result = [] for val in values: result.append((modbus.to_signed_value(val) / 10)) return result def get_tcp_pose(self): values = self.modbus_client.read_holding_registers(1, 400, 6) result = [] for val in values: result.append((modbus.to_signed_value(val) / 10)) return result def get_tcp_velocity(self): values = self.modbus_client.read_holding_registers(1, 410, 6) result = [] for val in values: result.append((modbus.to_signed_value(val) / 10)) return result def get_tcp_offset(self): values = self.modbus_client.read_holding_registers(1, 420, 6) result = [] for val in values: result.append((modbus.to_signed_value(val) / 10)) return result def get_register(self, index): return self.modbus_client.read_holding_registers(1, index, 1)[0] def set_register(self, index, value): return self.modbus_client.write_register(1, index, value) def get_state(self): status = self.modbus_client.read_holding_registers(1, 259, 1)[0] if status == 0 or status == 1 or status == 2: return RobotStatus.BACKDRIVE elif status == 3: return RobotStatus.SERVO_OFF elif status == 4: return RobotStatus.INITIALIZING elif status == 5: return RobotStatus.SAFETY_STOP elif status == 6: return RobotStatus.EMERGENCY_STOP elif status == 7 or status == 8 or status == 9 or status == 10: return RobotStatus.RECOVERY elif status == 11 or status == 12: return RobotStatus.SERVO_ON elif status == 13: return RobotStatus.FREE_DRIVE elif status == 14 or status == 15 or status == 16: return RobotStatus.SERVO_ON elif status == 17 or status == 18: return RobotStatus.SERVO_ON_REDUCED elif status == 19 or status == 20: return RobotStatus.FREE_DRIVE else: return RobotStatus.SERVO_OFF def get_program_state(self): raise Exception("Action not supported") def get_mode(self): status = self.modbus_client.read_holding_registers(1, 259, 1)[0] if status in [0, 1, 2, 3, 5, 6, 8, 9, 10, 11, 12, 13]: return RobotMode.MANUAL elif status in [7, 14, 15, 16, 17, 18]: return RobotMode.AUTOMATIC elif status in [19, 20]: return RobotMode.TEACHING else: return None def get_program_name(self): raise Exception("Action not supported") def get_analog_output(self, index): return self.modbus_client.read_holding_registers(1, 14 + index * 2, 1)[0] def set_analog_output(self, index, value): return self.modbus_client.write_register(1, 14 + index * 2, int(value)) def get_analog_output_mode(self, index): result = self.modbus_client.read_holding_registers(1, 15 + index * 2, 1)[0] return AnalogMode.CURRENT if result == 0 else AnalogMode.VOLTAGE def set_analog_output_mode(self, index, mode): mode = 0 if mode == AnalogMode.CURRENT else 1 return self.modbus_client.write_register(1, 15 + index * 2, mode) def get_analog_input(self, index): return self.modbus_client.read_holding_registers(1, 2 + index * 2, 1)[0] def get_analog_input_mode(self, index): result = self.modbus_client.read_holding_registers(1, 3 + index * 2, 1)[0] return AnalogMode.CURRENT if result == 0 else AnalogMode.VOLTAGE def set_analog_input_mode(self, index, mode): mode = 0 if mode == AnalogMode.CURRENT else 1 return self.modbus_client.write_register(1, 3 + index * 2, mode) def wait_boot_completed(self, timeout=60): deadline = time.time() + timeout while True: try: status = self.modbus_client.read_holding_registers(1, 259, 1)[0] if status == 0 or status == 4: raise Exception("Robot booting, status: "+str(status)) return True except : remaining = deadline - time.time() if remaining <= 0: raise TimeoutError("Robot did not become available within " + str(timeout) + " seconds") time.sleep(2)Ancestors
- robpod.background._RobotClient
Methods
def get_analog_input(self, index)-
Expand source code
def get_analog_input(self, index): return self.modbus_client.read_holding_registers(1, 2 + index * 2, 1)[0] def get_analog_input_mode(self, index)-
Expand source code
def get_analog_input_mode(self, index): result = self.modbus_client.read_holding_registers(1, 3 + index * 2, 1)[0] return AnalogMode.CURRENT if result == 0 else AnalogMode.VOLTAGE def get_analog_output(self, index)-
Expand source code
def get_analog_output(self, index): return self.modbus_client.read_holding_registers(1, 14 + index * 2, 1)[0] def get_analog_output_mode(self, index)-
Expand source code
def get_analog_output_mode(self, index): result = self.modbus_client.read_holding_registers(1, 15 + index * 2, 1)[0] return AnalogMode.CURRENT if result == 0 else AnalogMode.VOLTAGE def get_configurable_digital_input(self, index)-
Expand source code
def get_configurable_digital_input(self, index): return get_digital_input(index) def get_configurable_digital_output(self, index)-
Expand source code
def get_configurable_digital_output(self, index): return get_digital_output(index) def get_digital_input(self, index)-
Expand source code
def get_digital_input(self, index): return self.modbus_client.read_coils(1, -1 + index, 1)[0] def get_digital_output(self, index)-
Expand source code
def get_digital_output(self, index): return self.modbus_client.read_coils(1, 19 + index, 1)[0] def get_joint_pose(self)-
Expand source code
def get_joint_pose(self): values = self.modbus_client.read_holding_registers(1, 270, 6) result = [] for val in values: result.append((modbus.to_signed_value(val)/ 10)) return result def get_joint_velocity(self)-
Expand source code
def get_joint_velocity(self): values = self.modbus_client.read_holding_registers(1, 280, 6) result = [] for val in values: result.append((modbus.to_signed_value(val) / 10)) return result def get_mode(self)-
Expand source code
def get_mode(self): status = self.modbus_client.read_holding_registers(1, 259, 1)[0] if status in [0, 1, 2, 3, 5, 6, 8, 9, 10, 11, 12, 13]: return RobotMode.MANUAL elif status in [7, 14, 15, 16, 17, 18]: return RobotMode.AUTOMATIC elif status in [19, 20]: return RobotMode.TEACHING else: return None def get_program_name(self)-
Expand source code
def get_program_name(self): raise Exception("Action not supported") def get_program_state(self)-
Expand source code
def get_program_state(self): raise Exception("Action not supported") def get_register(self, index)-
Expand source code
def get_register(self, index): return self.modbus_client.read_holding_registers(1, index, 1)[0] def get_state(self)-
Expand source code
def get_state(self): status = self.modbus_client.read_holding_registers(1, 259, 1)[0] if status == 0 or status == 1 or status == 2: return RobotStatus.BACKDRIVE elif status == 3: return RobotStatus.SERVO_OFF elif status == 4: return RobotStatus.INITIALIZING elif status == 5: return RobotStatus.SAFETY_STOP elif status == 6: return RobotStatus.EMERGENCY_STOP elif status == 7 or status == 8 or status == 9 or status == 10: return RobotStatus.RECOVERY elif status == 11 or status == 12: return RobotStatus.SERVO_ON elif status == 13: return RobotStatus.FREE_DRIVE elif status == 14 or status == 15 or status == 16: return RobotStatus.SERVO_ON elif status == 17 or status == 18: return RobotStatus.SERVO_ON_REDUCED elif status == 19 or status == 20: return RobotStatus.FREE_DRIVE else: return RobotStatus.SERVO_OFF def get_tcp_offset(self)-
Expand source code
def get_tcp_offset(self): values = self.modbus_client.read_holding_registers(1, 420, 6) result = [] for val in values: result.append((modbus.to_signed_value(val) / 10)) return result def get_tcp_pose(self)-
Expand source code
def get_tcp_pose(self): values = self.modbus_client.read_holding_registers(1, 400, 6) result = [] for val in values: result.append((modbus.to_signed_value(val) / 10)) return result def get_tcp_velocity(self)-
Expand source code
def get_tcp_velocity(self): values = self.modbus_client.read_holding_registers(1, 410, 6) result = [] for val in values: result.append((modbus.to_signed_value(val) / 10)) return result def get_tool_digital_input(self, index)-
Expand source code
def get_tool_digital_input(self, index): return self.modbus_client.read_coils(1, 35 + index, 1)[0] def get_tool_digital_output(self, index)-
Expand source code
def get_tool_digital_output(self, index): return self.modbus_client.read_coils(1, 41 + index, 1)[0] def set_analog_input_mode(self, index, mode)-
Expand source code
def set_analog_input_mode(self, index, mode): mode = 0 if mode == AnalogMode.CURRENT else 1 return self.modbus_client.write_register(1, 3 + index * 2, mode) def set_analog_output(self, index, value)-
Expand source code
def set_analog_output(self, index, value): return self.modbus_client.write_register(1, 14 + index * 2, int(value)) def set_analog_output_mode(self, index, mode)-
Expand source code
def set_analog_output_mode(self, index, mode): mode = 0 if mode == AnalogMode.CURRENT else 1 return self.modbus_client.write_register(1, 15 + index * 2, mode) def set_configurable_digital_output(self, index, value)-
Expand source code
def set_configurable_digital_output(self, index, value): return set_digital_output(index, value) def set_digital_output(self, index, value)-
Expand source code
def set_digital_output(self, index, value): return self.modbus_client.write_coils(1, 19 + index, [value]) def set_register(self, index, value)-
Expand source code
def set_register(self, index, value): return self.modbus_client.write_register(1, index, value) def set_tool_digital_output(self, index, value)-
Expand source code
def set_tool_digital_output(self, index, value): return self.modbus_client.write_coils(1, 41 + index, [value]) def wait_boot_completed(self, timeout=60)-
Expand source code
def wait_boot_completed(self, timeout=60): deadline = time.time() + timeout while True: try: status = self.modbus_client.read_holding_registers(1, 259, 1)[0] if status == 0 or status == 4: raise Exception("Robot booting, status: "+str(status)) return True except : remaining = deadline - time.time() if remaining <= 0: raise TimeoutError("Robot did not become available within " + str(timeout) + " seconds") time.sleep(2)
class ProgramStatus-
Expand source code
class ProgramStatus: """Possible execution states of a robot program.""" STOPPED = "STOPPED" PAUSED = "PAUSED" RUNNING = "RUNNING"Possible execution states of a robot program.
Class variables
var PAUSEDvar RUNNINGvar STOPPED
class RobotMode-
Expand source code
class RobotMode: """Robot mode.""" MANUAL = "MANUAL" AUTOMATIC = "AUTOMATIC" TEACHING = "TEACHING"Robot mode.
Class variables
var AUTOMATICvar MANUALvar TEACHING
class RobotStatus-
Expand source code
class RobotStatus: """Possible states of the robot.""" INITIALIZING = "INITIALIZING" SERVO_OFF = "SERVO_OFF" IDLE = "IDLE" SERVO_ON = "SERVO_ON" SERVO_ON_REDUCED = "SERVO_ON_REDUCED" EMERGENCY_STOP = "EMERGENCY_STOP" SAFETY_STOP = "SAFETY_STOP" RECOVERY = "RECOVERY" BACKDRIVE = "BACKDRIVE" FREE_DRIVE = "FREE_DRIVE"Possible states of the robot.
Class variables
var BACKDRIVEvar EMERGENCY_STOPvar FREE_DRIVEvar IDLEvar INITIALIZINGvar RECOVERYvar SAFETY_STOPvar SERVO_OFFvar SERVO_ONvar SERVO_ON_REDUCED
class Rule (condition, fire_once=False, duration=0)-
Expand source code
class Rule: def __init__(self, condition, fire_once=False, duration=0): self.condition = condition self.action = None self.delay = 0.5 self.fire_once = fire_once self.duration = duration self.condition_started_at = None self.prev_condition = False def _run(self): while True: try: condition_value = self.condition() if self.fire_once: if condition_value: # OFF -> ON: start the timer if not self.prev_condition: self.condition_started_at = time.time() # Condition has remained ON for the required duration if ( self.condition_started_at is not None and time.time() - self.condition_started_at >= self.duration ): self.action() # Prevent firing again while condition stays ON self.condition_started_at = None else: # ON -> OFF: reset the timer self.condition_started_at = None else: if condition_value: self.action() self.prev_condition = condition_value time.sleep(self.delay) except Exception as e: time.sleep(self.delay) print(e) def _start(self): thread = threading.Thread(target=self._run) thread.daemon = False thread.start() class RuleWithDo (rule)-
Expand source code
class RuleWithDo: def __init__(self, rule): self._rule = rule def do(self, action): self._rule.action = action return RuleWithStart(self._rule)Methods
def do(self, action)-
Expand source code
def do(self, action): self._rule.action = action return RuleWithStart(self._rule)
class RuleWithStart (rule)-
Expand source code
class RuleWithStart: def __init__(self, rule): self._rule = rule def start(self): self._rule._start()Methods
def start(self)-
Expand source code
def start(self): self._rule._start()
class UrRobotClient (host)-
Expand source code
class UrRobotClient(_RobotClient): def __init__(self, host): _RobotClient.__init__(self, host) # call parent constructor self.modbus_client = modbus.ModbusClient(host) def get_digital_output(self, index): return self.modbus_client.read_coils(1, 16 + index, 1)[0] def get_digital_input(self, index): return self.modbus_client.read_coils(1, 0 + index, 1)[0] def get_configurable_digital_input(self, index): return self.modbus_client.read_coils(1, 128 + index, 1)[0] def get_configurable_digital_output(self, index): return self.modbus_client.read_coils(1, 136 + index, 1)[0] def set_configurable_digital_output(self, index, value): return self.modbus_client.write_coils(1, 136 + index, [value]) def set_digital_output(self, index, value): return self.modbus_client.write_coils(1, 16 + index, [value]) def get_tool_digital_input(self, index): return self.modbus_client.read_coils(1, 8 + index, 1)[0] def get_tool_digital_output(self, index): return self.modbus_client.read_coils(1, 34 + index, 1)[0] def set_tool_digital_output(self, index, value): return self.modbus_client.write_coils(1, 8 + index, [value]) def get_joint_velocity(self): values = self.modbus_client.read_holding_registers(1, 280, 6) result = [] for i in range(6): result.append(modbus.to_signed_value(values[i]) / 1000.0) return result def get_joint_pose(self): values = self.modbus_client.read_holding_registers(1, 270, 6) turns = self.modbus_client.read_holding_registers(1, 320, 6) result = [] for val, turn in zip(values, turns): result.append((modbus.to_signed_value(turn) * 2 * 3.1415 * 1000 + val) / 1000.0) return result def get_tcp_pose(self): values = self.modbus_client.read_holding_registers(1, 400, 6) result = [] for i in range(3): result.append(modbus.to_signed_value(values[i]) / 10000.0) for i in range(3,6): result.append(modbus.to_signed_value(values[i]) / 1000.0) return result def get_tcp_velocity(self): values = self.modbus_client.read_holding_registers(1, 410, 6) result = [] for i in range(6): result.append(modbus.to_signed_value(values[i]) / 1000.0) return result def get_tcp_offset(self): values = self.modbus_client.read_holding_registers(1, 420, 6) result = [] for i in range(6): result.append(modbus.to_signed_value(values[i]) / 1000.0) return result def get_register(self, index): return self.modbus_client.read_holding_registers(1, index, 1)[0] def set_register(self, index, value): return self.modbus_client.write_register(1, index, value) def get_state(self): safety_mode = self.modbus_client.read_holding_registers(1, 266, 1)[0] status = self.modbus_client.read_holding_registers(1, 258, 1)[0] if safety_mode == 1 or safety_mode == 2: if status == 3: return RobotStatus.SERVO_OFF elif status == 4 or status == 5: return RobotStatus.IDLE elif status == 6: return RobotStatus.BACKDRIVE elif status == 7: if safety_mode == 2: return RobotStatus.SERVO_ON_REDUCED else: return RobotStatus.SERVO_ON else: return RobotStatus.SERVO_OFF elif safety_mode == 6 or safety_mode == 7: return RobotStatus.EMERGENCY_STOP elif safety_mode == 4: return RobotStatus.EMERGENCY_STOP else: return RobotStatus.SAFETY_STOP def get_program_state(self): sock = socket.create_connection((self.host, 29999), timeout=3) # Read the Dashboard Server greeting greeting = sock.recv(4096).decode("utf-8").strip() # Send command sock.sendall("programState\n".encode()) # Read response response = sock.recv(4096).decode().strip() sock.close() if response.startswith("STOPPED"): return ProgramStatus.STOPPED elif response.startswith("PAUS"): return ProgramStatus.PAUSED else: return ProgramStatus.RUNNING def get_mode(self): sock = socket.create_connection((self.host, 29999), timeout=3) # Read the Dashboard Server greeting greeting = sock.recv(4096).decode("utf-8").strip() # Send command sock.sendall("get operational mode\n".encode()) # Read response response = sock.recv(4096).decode().strip() sock.close() if response.startswith("MANUAL"): return RobotMode.MANUAL elif response.startswith("AUTOMATIC"): return RobotMode.AUTOMATIC else: return None def get_program_name(self): sock = socket.create_connection((self.host, 29999), timeout=3) # Read the Dashboard Server greeting greeting = sock.recv(4096).decode("utf-8").strip() # Send command sock.sendall("get loaded program\n".encode()) # Read response response = sock.recv(4096).decode().strip() sock.close() if response.startswith("Loaded program:"): path = response[len("Loaded program:"):].strip() filename = os.path.basename(path) program_name = os.path.splitext(filename)[0] return program_name return None def to_analog_value(self, value, mode): if mode == AnalogMode.CURRENT: return 4 + (value / 65535.0) * 16 else: return (value / 65535.0) * 10 def get_analog_output(self, index): value = self.modbus_client.read_holding_registers(1, 16 + index * 2, 1)[0] mode = self.get_analog_output_mode(index) return self.to_analog_value(value, mode) def set_analog_output(self, index, value): mode = self.get_analog_output_mode(index) if mode == AnalogMode.CURRENT: value = (value - 4) * 65535 / 16.0 else: value = value * 65535 / 10.0 return self.modbus_client.write_register(1, 16 + index * 2, int(value)) def get_analog_output_mode(self, index): result = self.modbus_client.read_holding_registers(1, 17 + index * 2, 1)[0] return AnalogMode.CURRENT if result == 0 else AnalogMode.VOLTAGE def set_analog_output_mode(self, index, mode): mode = 0 if mode == AnalogMode.CURRENT else 1 return self.modbus_client.write_register(1, 17 + index * 2, mode) def get_analog_input_mode(self, index): result = self.modbus_client.read_holding_registers(1, 5 + index * 2, 1)[0] return AnalogMode.CURRENT if result == 0 else AnalogMode.VOLTAGE def get_analog_input(self, index): value = self.modbus_client.read_holding_registers(1, 4 + index * 2, 1)[0] mode = self.get_analog_input_mode(index) return self.to_analog_value(value, mode) def set_analog_input_mode(self, index, mode): mode = 0 if mode == AnalogMode.CURRENT else 1 return self.modbus_client.write_register(1, 5 + index * 2, mode) def wait_boot_completed(self, timeout=60): deadline = time.time() + timeout while True: try: self.get_program_name() return True except : remaining = deadline - time.time() if remaining <= 0: raise TimeoutError("Robot did not become available within " + str(timeout) + " seconds") time.sleep(2)Ancestors
- robpod.background._RobotClient
Methods
def get_analog_input(self, index)-
Expand source code
def get_analog_input(self, index): value = self.modbus_client.read_holding_registers(1, 4 + index * 2, 1)[0] mode = self.get_analog_input_mode(index) return self.to_analog_value(value, mode) def get_analog_input_mode(self, index)-
Expand source code
def get_analog_input_mode(self, index): result = self.modbus_client.read_holding_registers(1, 5 + index * 2, 1)[0] return AnalogMode.CURRENT if result == 0 else AnalogMode.VOLTAGE def get_analog_output(self, index)-
Expand source code
def get_analog_output(self, index): value = self.modbus_client.read_holding_registers(1, 16 + index * 2, 1)[0] mode = self.get_analog_output_mode(index) return self.to_analog_value(value, mode) def get_analog_output_mode(self, index)-
Expand source code
def get_analog_output_mode(self, index): result = self.modbus_client.read_holding_registers(1, 17 + index * 2, 1)[0] return AnalogMode.CURRENT if result == 0 else AnalogMode.VOLTAGE def get_configurable_digital_input(self, index)-
Expand source code
def get_configurable_digital_input(self, index): return self.modbus_client.read_coils(1, 128 + index, 1)[0] def get_configurable_digital_output(self, index)-
Expand source code
def get_configurable_digital_output(self, index): return self.modbus_client.read_coils(1, 136 + index, 1)[0] def get_digital_input(self, index)-
Expand source code
def get_digital_input(self, index): return self.modbus_client.read_coils(1, 0 + index, 1)[0] def get_digital_output(self, index)-
Expand source code
def get_digital_output(self, index): return self.modbus_client.read_coils(1, 16 + index, 1)[0] def get_joint_pose(self)-
Expand source code
def get_joint_pose(self): values = self.modbus_client.read_holding_registers(1, 270, 6) turns = self.modbus_client.read_holding_registers(1, 320, 6) result = [] for val, turn in zip(values, turns): result.append((modbus.to_signed_value(turn) * 2 * 3.1415 * 1000 + val) / 1000.0) return result def get_joint_velocity(self)-
Expand source code
def get_joint_velocity(self): values = self.modbus_client.read_holding_registers(1, 280, 6) result = [] for i in range(6): result.append(modbus.to_signed_value(values[i]) / 1000.0) return result def get_mode(self)-
Expand source code
def get_mode(self): sock = socket.create_connection((self.host, 29999), timeout=3) # Read the Dashboard Server greeting greeting = sock.recv(4096).decode("utf-8").strip() # Send command sock.sendall("get operational mode\n".encode()) # Read response response = sock.recv(4096).decode().strip() sock.close() if response.startswith("MANUAL"): return RobotMode.MANUAL elif response.startswith("AUTOMATIC"): return RobotMode.AUTOMATIC else: return None def get_program_name(self)-
Expand source code
def get_program_name(self): sock = socket.create_connection((self.host, 29999), timeout=3) # Read the Dashboard Server greeting greeting = sock.recv(4096).decode("utf-8").strip() # Send command sock.sendall("get loaded program\n".encode()) # Read response response = sock.recv(4096).decode().strip() sock.close() if response.startswith("Loaded program:"): path = response[len("Loaded program:"):].strip() filename = os.path.basename(path) program_name = os.path.splitext(filename)[0] return program_name return None def get_program_state(self)-
Expand source code
def get_program_state(self): sock = socket.create_connection((self.host, 29999), timeout=3) # Read the Dashboard Server greeting greeting = sock.recv(4096).decode("utf-8").strip() # Send command sock.sendall("programState\n".encode()) # Read response response = sock.recv(4096).decode().strip() sock.close() if response.startswith("STOPPED"): return ProgramStatus.STOPPED elif response.startswith("PAUS"): return ProgramStatus.PAUSED else: return ProgramStatus.RUNNING def get_register(self, index)-
Expand source code
def get_register(self, index): return self.modbus_client.read_holding_registers(1, index, 1)[0] def get_state(self)-
Expand source code
def get_state(self): safety_mode = self.modbus_client.read_holding_registers(1, 266, 1)[0] status = self.modbus_client.read_holding_registers(1, 258, 1)[0] if safety_mode == 1 or safety_mode == 2: if status == 3: return RobotStatus.SERVO_OFF elif status == 4 or status == 5: return RobotStatus.IDLE elif status == 6: return RobotStatus.BACKDRIVE elif status == 7: if safety_mode == 2: return RobotStatus.SERVO_ON_REDUCED else: return RobotStatus.SERVO_ON else: return RobotStatus.SERVO_OFF elif safety_mode == 6 or safety_mode == 7: return RobotStatus.EMERGENCY_STOP elif safety_mode == 4: return RobotStatus.EMERGENCY_STOP else: return RobotStatus.SAFETY_STOP def get_tcp_offset(self)-
Expand source code
def get_tcp_offset(self): values = self.modbus_client.read_holding_registers(1, 420, 6) result = [] for i in range(6): result.append(modbus.to_signed_value(values[i]) / 1000.0) return result def get_tcp_pose(self)-
Expand source code
def get_tcp_pose(self): values = self.modbus_client.read_holding_registers(1, 400, 6) result = [] for i in range(3): result.append(modbus.to_signed_value(values[i]) / 10000.0) for i in range(3,6): result.append(modbus.to_signed_value(values[i]) / 1000.0) return result def get_tcp_velocity(self)-
Expand source code
def get_tcp_velocity(self): values = self.modbus_client.read_holding_registers(1, 410, 6) result = [] for i in range(6): result.append(modbus.to_signed_value(values[i]) / 1000.0) return result def get_tool_digital_input(self, index)-
Expand source code
def get_tool_digital_input(self, index): return self.modbus_client.read_coils(1, 8 + index, 1)[0] def get_tool_digital_output(self, index)-
Expand source code
def get_tool_digital_output(self, index): return self.modbus_client.read_coils(1, 34 + index, 1)[0] def set_analog_input_mode(self, index, mode)-
Expand source code
def set_analog_input_mode(self, index, mode): mode = 0 if mode == AnalogMode.CURRENT else 1 return self.modbus_client.write_register(1, 5 + index * 2, mode) def set_analog_output(self, index, value)-
Expand source code
def set_analog_output(self, index, value): mode = self.get_analog_output_mode(index) if mode == AnalogMode.CURRENT: value = (value - 4) * 65535 / 16.0 else: value = value * 65535 / 10.0 return self.modbus_client.write_register(1, 16 + index * 2, int(value)) def set_analog_output_mode(self, index, mode)-
Expand source code
def set_analog_output_mode(self, index, mode): mode = 0 if mode == AnalogMode.CURRENT else 1 return self.modbus_client.write_register(1, 17 + index * 2, mode) def set_configurable_digital_output(self, index, value)-
Expand source code
def set_configurable_digital_output(self, index, value): return self.modbus_client.write_coils(1, 136 + index, [value]) def set_digital_output(self, index, value)-
Expand source code
def set_digital_output(self, index, value): return self.modbus_client.write_coils(1, 16 + index, [value]) def set_register(self, index, value)-
Expand source code
def set_register(self, index, value): return self.modbus_client.write_register(1, index, value) def set_tool_digital_output(self, index, value)-
Expand source code
def set_tool_digital_output(self, index, value): return self.modbus_client.write_coils(1, 8 + index, [value]) def to_analog_value(self, value, mode)-
Expand source code
def to_analog_value(self, value, mode): if mode == AnalogMode.CURRENT: return 4 + (value / 65535.0) * 16 else: return (value / 65535.0) * 10 def wait_boot_completed(self, timeout=60)-
Expand source code
def wait_boot_completed(self, timeout=60): deadline = time.time() + timeout while True: try: self.get_program_name() return True except : remaining = deadline - time.time() if remaining <= 0: raise TimeoutError("Robot did not become available within " + str(timeout) + " seconds") time.sleep(2)