-
Notifications
You must be signed in to change notification settings - Fork 12
Using designators
#Using Designators for an executive Using designators has several sides: simply using existing classes for designators and states, creating your own state with existing designators and finally writing custom designators.
import robot_smach_states.util.designators as ds
variable_des = ds.VariableDesignator("Original_value")
states.WritingState(robot, variable_des.writeable) #Indicate that this state can write to variable_des
states.NormalState(robot, varibale_des) #No special indication needed
entity_des = ds.EntityByIdDesignator(robot, id="abcdef1234", name="entity_des")
states.DoSomethingWithEntity(robot, entity_des)
empty_arm_des = ds.UnoccupiedArmDesignator(robot.arms, robot.arms[name="empty_arm_designator")
states.DoSomethingWithArm(robot, empty_arm_des)
current_item = ds.EntityByIdDesignator(robot, id="abcdef1234", name="entity_des")
#o place something, use the arms that is holding that thing
arm_with_item_designator = ds.ArmHoldingEntityDesignator(robot.arms, current_item, name="arm_with_item_designator")
states.DoSomethingWithArmThatHoldsAnItem(robot, empty_arm_des)
For example, the entityDes below should resolve to an EntityInfo. You can check the resolve_type of the designator and see if it matches. If it fails, you'll get an exception when the challenge starts.
import robot_smach_states.util.designators as ds
from ed.msg import EntityInfo
class SomeState(smach.State):
def __init__(self, robot, entityDes):
ds.check_resolve_type(entityDes, EntityInfo) #Check the resolve_type
self.entityDes = entityDes
#etc
def execute(self, userdata=None):
entity = self.entityDes.resolve()
if not entity:
#deal with it
For example, the entityDes below should resolve to an EntityInfo. You can check the resolve_type of the designator and see if it matches. If it fails, you'll get an exception when the challenge starts.
import robot_smach_states.util.designators as ds
class SomeState(smach.State):
def __init__(self, robot, variableDes):
ds.is_writeable(variableDes) #Check the resolve_type
self.variableDes = variableDes
#etc
def execute(self, userdata=None):
value = something
self.variableDes.write(value)
To implement your own designators, be sure to inherit from another designator class. That way, all checks and introspection stuff works out of the box.
import robot_smach_states.util.designators as ds
from ed.msg import EntityInfo
class EntityByIdDesignator(ds.Designator):
def __init__(self, robot, id, parse=True, name=None): #Passing a name is handy for introspection
super(EntityByIdDesignator, self).__init__(resolve_type=EntityInfo, name=name) #Specify the resolve_type and name for typechecks and introspection.
#etc
def _resolve(self): #Implement _resolve rather than resolve (notice the underscore). The resolve-method of the base class does typechecks.
entities = self.ed.get_entities(id=self.id_, parse=self.parse)
if entities:
return entities[0]('left'],)
else:
return None