[docs]classFeedbackLevel(object):"""Represents default valid feedback levels. .. autoattribute:: NONE .. autoattribute:: DONE """NONE=0"""Indicates no feedback is requested from the robot."""DONE=1"""Indicates completion feedback is requested from the robot. Completion feedback means the robot has executed the procedure. See :meth:`AbbClient.send_and_wait` for more details. """
[docs]classExecutionLevel(object):"""Defines the execution level of an instruction. .. autoattribute:: ROBOT .. autoattribute:: CONTROLLER """ROBOT=0"""Execute instruction on the robot task."""CONTROLLER=10"""Execute instruction on the ``controller`` task (only usable with custom instructions)."""
classInstructionException(Exception):"""Exception caused during/after the execution of an instruction."""def__init__(self,message,result):super(InstructionException,self).__init__('{}, RRC Reply={}'.format(message,result))self.result=resultclassTimeoutException(Exception):"""Timeout exception caused during execution of an instruction."""pass
[docs]classFutureResult(object):"""Represents a future result value. Futures are the result of asynchronous operations but allow to explicitely control when to block and wait for its completion."""
[docs]defresult(self,timeout=None):"""Return the feedback value returned by the instruction. If the instruction has not yet returned feedback, it will wait up to ``timeout`` seconds. If the ``timeout`` expires, the method will raise an exception. """ifnotself.done:ifnotself.event.wait(timeout):raiseTimeoutException('Timeout: future result not available')ifisinstance(self.value,Exception):raiseself.valuereturnself.value
[docs]classExternalAxes(object):"""Represents a configuration for external axes."""
[docs]def__init__(self,*values):"""Initialize a new object with the specified values for external axes. Parameters ---------- values : :obj:`list` List of floats indicating the external axis positions. """try:self.values=list(itertools.chain.from_iterable(values))exceptTypeError:self.values=list(values)
# Properties@propertydefeax_a(self):"""Value of the first external axis."""returnself[0]@eax_a.setterdefeax_a(self,value):self[0]=value@propertydefeax_b(self):"""Value of the second external axis."""returnself[1]@eax_b.setterdefeax_b(self,value):self[1]=value@propertydefeax_c(self):"""Value of the third external axis."""returnself[2]@eax_c.setterdefeax_c(self,value):self[2]=value@propertydefeax_d(self):"""Value of the fourth external axis."""returnself[3]@eax_d.setterdefeax_d(self,value):self[3]=value@propertydefeax_e(self):"""Value of the fifth external axis."""returnself[4]@eax_e.setterdefeax_e(self,value):self[4]=value@propertydefeax_f(self):"""Value of the sexth external axis."""returnself[5]@eax_f.setterdefeax_f(self,value):self[5]=value# List accessorsdef__repr__(self):return'ExternalAxes({})'.format([round(i,2)foriinself.values])def__len__(self):returnlen(self.values)def__getitem__(self,item):ifitem>=len(self.values):returnNonereturnself.values[item]def__setitem__(self,item,value):self.values[item]=valuedef__iter__(self):returniter(self.values)# Conversion methods
[docs]defto_configuration_primitive(self,joint_types,joint_names=None):"""Convert the ExternalAxes to a :class:`compas.robots.Configuration`, including the unit conversion from mm and degrees to meters and radians. Parameters ---------- joint_types : :obj:`list` List of integers representing the joint types of the corresponding external axes values. joint_names : :obj:`list` List of strings representing the joint names of the corresponding external axes values. Optional. Returns ------- :class:`compas.robots.Configuration` """joint_values=[_convert_unit_to_meters_radians(value,type_)forvalue,type_inzip(self.values,joint_types)]returnConfiguration(joint_values,joint_types,joint_names)
[docs]defto_configuration(self,robot,group=None):"""Convert the ExternalAxes to a :class:`compas.robots.Configuration`, including the unit conversion from mm and degrees to meters and radians. Parameters ---------- robot : :class:`compas_fab.robots.Robot` The robot to be configured. group : :obj:`str` The name of the group of joints to be included in the ``Configuration``. Optional. Defaults to the ``robot``'s main group name. Returns ------- :class:`compas.robots.Configuration` """joint_types=robot.get_configurable_joint_types(group)joint_names=robot.get_configurable_joint_names(group)returnself.to_configuration_primitive(joint_types,joint_names)
[docs]@classmethoddeffrom_configuration_primitive(cls,configuration,joint_names=None):"""Create an instance of ``ExternalAxes`` from a :class:`compas.robots.Configuration`, including the unit conversion from meters and radians to mm and degrees. Parameters ---------- configuration : :class:`compas.robots.Configuration` The configuration from which to create the ``ExternalAxes`` instance. joint_names : :obj:`list` An optional list of joint names from the ``configuration`` whose corresponding values will fill the ``ExternalAxes`` values. Returns ------- :class:`compas_rrc.ExternalAxes` """ifjoint_names:joint_values=[_convert_unit_to_mm_degrees(configuration[name],configuration.type_dict[name])fornameinjoint_names]else:joint_values=[_convert_unit_to_mm_degrees(value,type_)forvalue,type_inzip(configuration.joint_values,configuration.joint_types)]returncls(joint_values)
[docs]@classmethoddeffrom_configuration(cls,configuration,robot=None,group=None):"""Create an instance of ``ExternalAxes`` from a :class:`compas.robots.Configuration`, including the unit conversion from meters and radians to mm and degrees. Parameters ---------- configuration : :class:`compas.robots.Configuration` The configuration from which to create the ``ExternalAxes`` instance. robot : :class:`compas_fab.robots.Robot` The robot to be configured. Optional. group : :obj:`str` The name of the group of joints to be included in the ``ExternalAxes``. Optional. Defaults to the ``robot``'s main group name. Returns ------- :class:`compas_rrc.ExternalAxes` """joint_names=robot.get_configurable_joint_names(group)ifrobotelse[]returncls.from_configuration_primitive(configuration,joint_names)
[docs]classRobotJoints(object):"""Represents a configuration for robot joints"""
# Properties@propertydefrax_1(self):returnself[0]@rax_1.setterdefrax_1(self,value):self[0]=value@propertydefrax_2(self):returnself[1]@rax_2.setterdefrax_2(self,value):self[1]=value@propertydefrax_3(self):returnself[2]@rax_3.setterdefrax_3(self,value):self[2]=value@propertydefrax_4(self):returnself[3]@rax_4.setterdefrax_4(self,value):self[3]=value@propertydefrax_5(self):returnself[4]@rax_5.setterdefrax_5(self,value):self[4]=value@propertydefrax_6(self):returnself[5]@rax_6.setterdefrax_6(self,value):self[5]=value# List accessorsdef__repr__(self):return'RobotJoints({})'.format([round(i,2)foriinself.values])def__len__(self):returnlen(self.values)def__getitem__(self,item):ifitem>=len(self.values):returnNonereturnself.values[item]def__setitem__(self,item,value):self.values[item]=valuedef__iter__(self):returniter(self.values)# Conversion methods
[docs]defto_configuration_primitive(self,joint_types,joint_names=None):"""Convert the RobotJoints to a :class:`compas.robots.Configuration`, including the unit conversion from mm and degrees to meters and radians. Parameters ---------- joint_types : :obj:`list` List of integers representing the joint types of the corresponding internal axes values. joint_names : :obj:`list` List of strings representing the joint names of the corresponding internal axes values. Optional. Returns ------- :class:`compas.robots.Configuration` """joint_values=[_convert_unit_to_meters_radians(value,type_)forvalue,type_inzip(self.values,joint_types)]returnConfiguration(joint_values,joint_types,joint_names)
[docs]defto_configuration(self,robot,group=None):"""Convert the RobotJoints to a :class:`compas.robots.Configuration`, including the unit conversion from mm and degrees to meters and radians. Parameters ---------- robot : :class:`compas_fab.robots.Robot` The robot to be configured. group : :obj:`str` The name of the group of joints to be included in the ``Configuration``. Optional. Defaults to the ``robot``'s main group name. Returns ------- :class:`compas.robots.Configuration` """joint_types=robot.get_configurable_joint_types(group)joint_names=robot.get_configurable_joint_names(group)returnself.to_configuration_primitive(joint_types,joint_names)
[docs]@classmethoddeffrom_configuration_primitive(cls,configuration,joint_names=None):"""Create an instance of ``RobotJoints`` from a :class:`compas.robots.Configuration`, including the unit conversion from meters and radians to mm and degrees. Parameters ---------- configuration : :class:`compas.robots.Configuration` The configuration from which to create the ``RobotJoints`` instance. joint_names : :obj:`list` An optional list of joint names from the ``configuration`` whose corresponding values will fill the ``RobotJoints`` values. Returns ------- :class:`compas_rrc.RobotJoints` """ifjoint_names:joint_values=[_convert_unit_to_mm_degrees(configuration[name],configuration.type_dict[name])fornameinjoint_names]else:joint_values=[_convert_unit_to_mm_degrees(value,type_)forvalue,type_inzip(configuration.joint_values,configuration.joint_types)]returncls(joint_values)
[docs]@classmethoddeffrom_configuration(cls,configuration,robot=None,group=None):"""Create an instance of ``RobotJoints`` from a :class:`compas.robots.Configuration`, including the unit conversion from meters and radians to mm and degrees. Parameters ---------- configuration : :class:`compas.robots.Configuration` The configuration from which to create the ``ExternalAxes`` instance. robot : :class:`compas_fab.robots.Robot` The robot to be configured. Optional. group : :obj:`str` The name of the group of joints to be included in the ``ExternalAxes``. Optional. Defaults to the ``robot``'s main group name. Returns ------- :class:`compas_rrc.RobotJoints` """joint_names=robot.get_configurable_joint_names(group)ifrobotelse[]returncls.from_configuration_primitive(configuration,joint_names)