def createBalanceTask(robot, application, taskName, ingain=1.):
    task = Task(taskName)
    task.add(application.featureCom.name)
    task.add(application.leftAnkle.name)
    task.add(application.rightAnkle.name)
    gain = GainAdaptive('gain' + taskName)
    gain.setConstant(ingain)
    plug(gain.gain, task.controlGain)
    plug(task.error, gain.error)
    return (task, gain)
def createBalanceTask (robot, application, taskName, ingain = 1.):
    task = Task (taskName)
    task.add (application.featureCom.name)
    task.add (application.leftAnkle.name)
    task.add (application.rightAnkle.name)
    gain = GainAdaptive('gain'+taskName)
    gain.setConstant(ingain)
    plug(gain.gain, task.controlGain)
    plug(task.error, gain.error)      
    return (task, gain)
class MetaTaskPose(object):
    def opPointExist(self, opPoint):
        sigsP = filter(lambda x: x.getName().split(':')[-1] == opPoint,
                       self.dyn.signals())
        sigsJ = filter(lambda x: x.getName().split(':')[-1] == 'J' + opPoint,
                       self.dyn.signals())
        return len(sigsP) == 1 & len(sigsJ) == 1

    def defineDynEntities(self, dyn):
        self.dyn = dyn

    def createOpPoint(self, opPoint, opPointRef='right-wrist'):
        self.opPoint = opPoint
        if self.opPointExist(opPoint):
            return
        self.dyn.createOpPoint(opPoint, opPointRef)

    def createFeature(self):
        self.feature = FeaturePose('feature' + self.name)
        self.feature.selec.value = '111111'

    def createTask(self):
        self.task = Task('task' + self.name)

    def createGain(self):
        self.gain = GainAdaptive('gain' + self.name)
        self.gain.set(0.1, 0.1, 125e3)

    def plugEverything(self):
        plug(self.dyn.signal(self.opPoint), self.feature.oMjb)
        plug(self.dyn.signal('J' + self.opPoint), self.feature.jbJjb)
        self.task.add(self.feature.name)
        plug(self.task.error, self.gain.error)
        plug(self.gain.gain, self.task.controlGain)

    def keep(self):
        self.feature.faMfb.recompute(self.dyn.position.time)
        self.feature.faMfbDes.value = self.feature.faMfb.value

    def __init__(self, name, dyn, opPoint, opPointRef='right-wrist'):
        self.name = name
        self.defineDynEntities(dyn)
        self.createOpPoint(opPoint, opPointRef)
        self.createFeature()
        self.createTask()
        self.createGain()
        self.plugEverything()

    @property
    def ref(self):
        return self.feature.faMfbDes.value

    @ref.setter
    def ref(self, m):
        self.feature.faMfbDes.value = m
def createPostureTask(robot, taskName, ingain=1.):
    robot.dynamic.position.recompute(0)
    feature = FeatureGeneric('feature' + taskName)
    featureDes = FeatureGeneric('featureDes' + taskName)
    featureDes.errorIN.value = robot.halfSitting
    plug(robot.dynamic.position, feature.errorIN)
    feature.setReference(featureDes.name)
    robotDim = len(robot.dynamic.position.value)
    feature.jacobianIN.value = matrixToTuple(identity(robotDim))
    task = Task(taskName)
    task.add(feature.name)
    gain = GainAdaptive('gain' + taskName)
    plug(gain.gain, task.controlGain)
    plug(task.error, gain.error)
    gain.setConstant(ingain)
    return (feature, featureDes, task, gain)
def createPostureTask (robot, taskName, ingain = 1.):
    robot.dynamic.position.recompute(0)
    feature    = FeatureGeneric('feature'+taskName)
    featureDes = FeatureGeneric('featureDes'+taskName)
    featureDes.errorIN.value = robot.halfSitting
    plug(robot.dynamic.position,feature.errorIN)
    feature.setReference(featureDes.name)
    robotDim = len(robot.dynamic.position.value)
    feature.jacobianIN.value = matrixToTuple( identity(robotDim) )
    task = Task (taskName)    
    task.add (feature.name)
    gain = GainAdaptive('gain'+taskName)    
    plug(gain.gain,task.controlGain)
    plug(task.error,gain.error)
    gain.setConstant(ingain)
    return (feature, featureDes, task, gain)
def createOperationalPointFeatureAndTask(robot, operationalPointName, featureName, taskName, ingain=.2):
    operationalPointMapped = operationalPointName
    jacobianName = 'J{0}'.format(operationalPointMapped)
    robot.dynamic.signal(operationalPointMapped).recompute(0)
    robot.dynamic.signal(jacobianName).recompute(0)
    feature = \
        FeaturePosition(featureName,
                        robot.dynamic.signal(operationalPointMapped),
                        robot.dynamic.signal(jacobianName),
                        robot.dynamic.signal(operationalPointMapped).value)
    task = Task(taskName)
    task.add(featureName)
    gain = GainAdaptive('gain' + taskName)
    gain.setConstant(ingain)
    plug(gain.gain, task.controlGain)
    plug(task.error, gain.error)
    return (feature, task, gain)
def createCenterOfMassFeatureAndTask(robot, featureName, featureDesName, taskName, selec='111', ingain=1.):
    robot.dynamic.com.recompute(0)
    robot.dynamic.Jcom.recompute(0)

    featureCom = FeatureGeneric(featureName)
    plug(robot.dynamic.com, featureCom.errorIN)
    plug(robot.dynamic.Jcom, featureCom.jacobianIN)
    featureCom.selec.value = selec
    featureComDes = FeatureGeneric(featureDesName)
    featureComDes.errorIN.value = robot.dynamic.com.value
    featureCom.setReference(featureComDes.name)
    taskCom = Task(taskName)
    taskCom.add(featureName)
    gainCom = GainAdaptive('gain' + taskName)
    gainCom.setConstant(ingain)
    plug(gainCom.gain, taskCom.controlGain)
    plug(taskCom.error, gainCom.error)
    return (featureCom, featureComDes, taskCom, gainCom)
Example #8
0
class MetaTaskDyn6d(MetaTask6d):
    def createTask(self):
        self.task = TaskDynPD('task'+self.name)
        self.task.dt.value = 1e-3
    def createGain(self):
        self.gain = GainAdaptive('gain'+self.name)
        self.gain.set(1050,45,125e3)
    def plugEverything(self):
        self.feature.setReference(self.featureDes.name)
        plug(self.dyn.signal(self.opPoint),self.feature.signal('position'))
        plug(self.dyn.signal('J'+self.opPoint),self.feature.signal('Jq'))
        self.task.add(self.feature.name)
        plug(self.dyn.velocity,self.task.qdot)
        plug(self.task.error,self.gain.error)
        plug(self.gain.gain,self.task.controlGain)
    
    def __init__(self,*args):
        MetaTask6d.__init__(self,*args)
Example #9
0
class MetaTaskKine6d(MetaTask6d):
    def createTask(self):
        self.task = Task('task' + self.name)

    def createGain(self):
        self.gain = GainAdaptive('gain' + self.name)
        self.gain.set(0.1, 0.1, 125e3)

    def plugEverything(self):
        self.feature.setReference(self.featureDes.name)
        plug(self.dyn.signal(self.opPoint), self.feature.signal('position'))
        plug(self.dyn.signal('J' + self.opPoint), self.feature.signal('Jq'))
        self.task.add(self.feature.name)
        plug(self.task.error, self.gain.error)
        plug(self.gain.gain, self.task.controlGain)

    def keep(self):
        self.feature.position.recompute(self.dyn.position.time)
        self.feature.keep()
def createOperationalPointFeatureAndTask(robot,
                                         operationalPointName,
                                         featureName,
                                         taskName,
                                         ingain=.2):
    operationalPointMapped = operationalPointName
    jacobianName = 'J{0}'.format(operationalPointMapped)
    robot.dynamic.signal(operationalPointMapped).recompute(0)
    robot.dynamic.signal(jacobianName).recompute(0)
    feature = \
        FeaturePosition(featureName,
                        robot.dynamic.signal(operationalPointMapped),
                        robot.dynamic.signal(jacobianName),
                        robot.dynamic.signal(operationalPointMapped).value)
    task = Task(taskName)
    task.add(featureName)
    gain = GainAdaptive('gain' + taskName)
    gain.setConstant(ingain)
    plug(gain.gain, task.controlGain)
    plug(task.error, gain.error)
    return (feature, task, gain)
Example #11
0
    def __init__(self, dyn, name="com"):
        self.dyn = dyn
        self.name = name
        # dyn.setProperty('ComputeCoM','true')

        self.feature = FeatureGeneric('feature' + name)
        self.featureDes = FeatureGeneric('featureDes' + name)
        self.gain = GainAdaptive('gain' + name)

        plug(dyn.com, self.feature.errorIN)
        plug(dyn.Jcom, self.feature.jacobianIN)
        self.feature.setReference(self.featureDes.name)
Example #12
0
class MetaTaskDyn6dRel(MetaTaskKine6dRel):
	def createTask(self):
		self.task = TaskDynPD('task'+self.name)
		self.task.dt.value = 1e-3
	def createGain(self):
		self.gain = GainAdaptive('gain'+self.name)
		self.gain.set(1050,45,125e3)
	def plugEverything(self):
		self.feature.setReference(self.featureDes.name)
		plug(self.dyn.signal(self.opPoint),self.feature.signal('position'))
		plug(self.dyn.signal('J'+self.opPoint),self.feature.signal('Jq'))
		plug(self.dyn.signal(self.opPointBase),self.feature.signal('positionRef'))
		plug(self.dyn.signal('J'+self.opPointBase),self.feature.signal('JqRef'))
		self.task.add(self.feature.name)
		plug(self.dyn.velocity,self.task.qdot)
		plug(self.task.error,self.gain.error)
		plug(self.gain.gain,self.task.controlGain)
	
	def __init__(self,*args):
		MetaTaskKine6dRel.__init__(self,*args)


	@property
	def opmodifBase(self):
		if not self.opPointModifBase.activ: return False
		else: return self.opPointModifBase.getTransformation()

	@opmodifBase.setter
	def opmodifBase(self,m):
		if isinstance(m,bool) and m==False:
			plug(self.dyn.signal(self.opPointBase),self.feature.signal('positionRef'))
			plug(self.dyn.signal('J'+self.opPointBase),self.feature.signal('JqRef'))
			self.opPointModifBase.activ = False
		else:
			if not self.opPointModifBase.activ:
				plug(self.opPointModifBase.signal('position'),self.feature.positionRef )
				plug(self.opPointModifBase.signal('jacobian'),self.feature.JqRef)
			self.opPointModifBase.setTransformation(m)
			self.opPointModifBase.activ = True
def createCenterOfMassFeatureAndTask(robot,
                                     featureName,
                                     featureDesName,
                                     taskName,
                                     selec='111',
                                     ingain=1.):
    robot.dynamic.com.recompute(0)
    robot.dynamic.Jcom.recompute(0)

    featureCom = FeatureGeneric(featureName)
    plug(robot.dynamic.com, featureCom.errorIN)
    plug(robot.dynamic.Jcom, featureCom.jacobianIN)
    featureCom.selec.value = selec
    featureComDes = FeatureGeneric(featureDesName)
    featureComDes.errorIN.value = robot.dynamic.com.value
    featureCom.setReference(featureComDes.name)
    taskCom = Task(taskName)
    taskCom.add(featureName)
    gainCom = GainAdaptive('gain' + taskName)
    gainCom.setConstant(ingain)
    plug(gainCom.gain, taskCom.controlGain)
    plug(taskCom.error, gainCom.error)
    return (featureCom, featureComDes, taskCom, gainCom)
    def __init__(self, dyn, config=None, name="config"):
        self.dyn = dyn
        self.name = name
        self.config = config

        self.feature = FeatureGeneric('feature' + name)
        self.featureDes = FeatureGeneric('featureDes' + name)
        self.gain = GainAdaptive('gain' + name)

        plug(dyn.position, self.feature.errorIN)
        robotDim = dyn.getDimension()
        self.feature.jacobianIN.value = matrixToTuple(identity(robotDim))
        self.feature.setReference(self.featureDes.name)
        if config is not None:
            self.feature.selec.value = toFlags(self.config)
Example #15
0
    def __init__ (self, sotrobot, gripper, position):
        from dynamic_graph.sot.core import Task, FeatureGeneric, GainAdaptive, Selec_of_vector
        from dynamic_graph.sot.core.matrix_util import matrixToTuple
        from dynamic_graph import plug
        from numpy import identity, hstack, zeros

        super(EEPosture, self).__init__()
        self.gripper = gripper

        # Get joint position in posture
        pinmodel = sotrobot.dynamic.model
        idJ = pinmodel.getJointId(gripper.sotjoint)
        assert idJ < pinmodel.njoints
        joint = sotrobot.dynamic.model.joints[idJ]
        assert joint.nq == len(position)

        idx_q = joint.idx_q + 1
        idx_v = joint.idx_v + 1

        n = "eeposture" + Posture.sep + gripper.name + Posture.sep + str(position)

        self.tp = Task ('task' + n)
        self.tp.dyn = sotrobot.dynamic
        self.tp.feature = FeaturePosture ('feature_' + n)

        plug(sotrobot.dynamic.position, self.tp.feature.state)
        q = list(sotrobot.dynamic.position.value)
        q[idx_v:idx_v + joint.nv] = position
        self.tp.feature.posture.value = q

        self.tp.gain = GainAdaptive("gain_"+n)
        robotDim = sotrobot.dynamic.getDimension()
        # for i in range (6, robotDim):
            # self.tp.feature.selectDof (i, False)
        # print idx_q, idx_v
        for i in range(joint.nv):
            self.tp.feature.selectDof (idx_v + i, True)
        self.tp.add(self.tp.feature.name)

        # Set the gain of the posture task
        setGain(self.tp.gain,(4.9,0.9,0.01,0.9))
        plug(self.tp.gain.gain, self.tp.controlGain)
        plug(self.tp.error, self.tp.gain.error)
        self.tasks = [ self.tp ]
Example #16
0
    def __init__(self, sotrobot, gripper, position):
        from dynamic_graph.sot.core import Task, GainAdaptive

        super(EEPosture, self).__init__()
        self.gripper = gripper
        self.jointNames = gripper.joints
        pinmodel = sotrobot.dynamic.model

        n = "eeposture" + Posture.sep + gripper.name + Posture.sep + str(
            list(position))

        self.tp = Task('task' + n)
        self.tp.dyn = sotrobot.dynamic
        self.tp.feature = FeaturePosture('feature_' + n)

        plug(sotrobot.dynamic.position, self.tp.feature.state)
        q = list(sotrobot.dynamic.position.value)
        # Define the reference and the selected DoF
        rank = 0
        ranks = []
        for name in self.jointNames:
            idJ = pinmodel.getJointId(name)
            assert idJ < pinmodel.njoints
            joint = pinmodel.joints[idJ]
            idx_v = joint.idx_v
            nv = joint.nv
            ranks += range(idx_v, idx_v + nv)
            q[idx_v:idx_v + nv] = position[rank:rank + nv]
            rank += nv
        assert rank == len(position)

        self.tp.feature.posture.value = q
        for i in ranks:
            self.tp.feature.selectDof(i, True)

        self.tp.gain = GainAdaptive("gain_" + n)
        self.tp.add(self.tp.feature.name)

        # Set the gain of the posture task
        setGain(self.tp.gain, (4.9, 0.9, 0.01, 0.9))
        plug(self.tp.gain.gain, self.tp.controlGain)
        plug(self.tp.error, self.tp.gain.error)
        if len(self.jointNames) > 0:
            self.tasks = [self.tp]
Example #17
0
    def __init__(self, name, sotrobot):
        super(Posture, self).__init__()
        from dynamic_graph.sot.core import Task, FeatureGeneric, GainAdaptive
        from dynamic_graph.sot.core.matrix_util import matrixToTuple
        from numpy import identity

        n = Posture.sep + name
        self.tp = Task('task' + n)
        self.tp.dyn = sotrobot.dynamic
        self.tp.feature = FeaturePosture('feature_' + n)

        q = list(sotrobot.dynamic.position.value)
        self.tp.feature.state.value = q
        self.tp.feature.posture.value = q

        robotDim = sotrobot.dynamic.getDimension()
        for i in range(6, robotDim):
            self.tp.feature.selectDof(i, True)
        self.tp.gain = GainAdaptive("gain_" + n)
        self.tp.add(self.tp.feature.name)

        # Connects the dynamics to the current feature of the posture task
        plug(sotrobot.dynamic.position, self.tp.feature.state)

        self.tp.setWithDerivative(True)

        # Set the gain of the posture task
        setGain(self.tp.gain, (4.9, 0.9, 0.01, 0.9))
        plug(self.tp.gain.gain, self.tp.controlGain)
        plug(self.tp.error, self.tp.gain.error)
        self.tasks = [self.tp]
        self.topics = {
            name: {
                "type": "vector",
                "topic": "/hpp/target/position",
                "signalGetters": [self._signalPositionRef]
            },
            "vel_" + name: {
                "type": "vector",
                "topic": "/hpp/target/velocity",
                "signalGetters": [self._signalVelocityRef]
            },
        }
Example #18
0
    def __init__(self, sotrobot, gripper, name_suffix):
        from dynamic_graph.sot.core import Task, GainAdaptive

        super(EndEffector, self).__init__()
        self.gripper = gripper
        self.jointNames = gripper.joints
        self.robot = sotrobot
        pinmodel = sotrobot.dynamic.model

        self.name = Posture.sep.join(["ee", gripper.name, name_suffix])

        self.tp = Task('task' + self.name)
        self.tp.dyn = sotrobot.dynamic
        self.tp.feature = FeaturePosture('feature_' + self.name)

        plug(sotrobot.dynamic.position, self.tp.feature.state)

        # Select the dofs
        self.tp.feature.posture.value = sotrobot.dynamic.position.value
        # Define the reference and the selected DoF
        self.jointRanks = []
        for name in self.jointNames:
            idJ = pinmodel.getJointId(name)
            assert idJ < pinmodel.njoints
            joint = pinmodel.joints[idJ]
            idx_v = joint.idx_v
            nv = joint.nv
            self.jointRanks.append((idx_v, nv))
        for idx_v, nv in self.jointRanks:
            for i in range(idx_v, idx_v + nv):
                self.tp.feature.selectDof(i, True)

        self.tp.gain = GainAdaptive("gain_" + self.name)
        self.tp.add(self.tp.feature.name)

        # Set the gain of the posture task
        setGain(self.tp.gain, (4.9, 0.9, 0.01, 0.9))
        plug(self.tp.gain.gain, self.tp.controlGain)
        plug(self.tp.error, self.tp.gain.error)
        if len(self.jointNames) > 0:
            self.tasks = [self.tp]
Example #19
0
    def __init__(self, dyn, joint, name=None):
        if name is None:
            name = "joint" + str(joint)
        self.dyn = dyn
        self.name = name
        self.joint = joint

        self.feature = FeatureGeneric('feature' + name)
        self.featureDes = FeatureGeneric('featureDes' + name)
        self.gain = GainAdaptive('gain' + name)

        self.selec = Selec_of_vector("selec" + name)
        self.selec.selec(joint, joint + 1)
        plug(dyn.position, self.selec.sin)
        plug(self.selec.sout, self.feature.errorIN)

        robotDim = len(dyn.position.value)
        Id = identity(robotDim)
        J = Id[joint:joint + 1]
        self.feature.jacobianIN.value = matrixToTuple(J)
        self.feature.setReference(self.featureDes.name)
Example #20
0
    def __init__ (self, name, sotrobot):
        super(Posture, self).__init__()
        from dynamic_graph.sot.core import Task, FeatureGeneric, GainAdaptive, Selec_of_vector
        from dynamic_graph.sot.core.matrix_util import matrixToTuple
        from dynamic_graph import plug
        from numpy import identity, hstack, zeros

        n = Posture.sep + name
        self.tp = Task ('task' + n)
        self.tp.dyn = sotrobot.dynamic
        self.tp.feature = FeatureGeneric('feature_'+n)
        self.tp.featureDes = FeatureGeneric('feature_des_'+n)
        self.tp.gain = GainAdaptive("gain_"+n)
        robotDim = sotrobot.dynamic.getDimension()
        self.tp.feature.jacobianIN.value = matrixToTuple( identity(robotDim) )
        self.tp.feature.setReference(self.tp.featureDes.name)
        self.tp.add(self.tp.feature.name)

        # Connects the dynamics to the current feature of the posture task
        plug(sotrobot.dynamic.position, self.tp.feature.errorIN)

        self.tp.setWithDerivative (True)

        # Set the gain of the posture task
        setGain(self.tp.gain,10)
        plug(self.tp.gain.gain, self.tp.controlGain)
        plug(self.tp.error, self.tp.gain.error)
        self.tasks = [ self.tp ]
        self.topics = {
                    name: {
                        "type": "vector",
                        "topic": "/hpp/target/position",
                        "signalGetters": [ self._signalPositionRef ] },
                    "vel_" + name: {
                        "type": "vector",
                        "topic": "/hpp/target/velocity",
                        "signalGetters": [ self._signalVelocityRef ] },
                }
Example #21
0
	def createGain(self):
		self.gain = GainAdaptive('gain'+self.name)
		self.gain.set(1050,45,125e3)
class MetaTaskVisualPoint(object):
    name = ''
    opPoint = ''
    dyn = 0
    task = 0
    feature = 0
    featureDes = 0
    proj = 0

    def opPointExist(self, opPoint):
        sigsP = filter(lambda x: x.getName().split(':')[-1] == opPoint,
                       self.dyn.signals())
        sigsJ = filter(lambda x: x.getName().split(':')[-1] == 'J' + opPoint,
                       self.dyn.signals())
        return len(sigsP) == 1 & len(sigsJ) == 1

    def defineDynEntities(self, dyn):
        self.dyn = dyn

    def createOpPoint(self, opPoint, opPointRef='right-wrist'):
        self.opPoint = opPoint
        if self.opPointExist(opPoint):
            return
        self.dyn.createOpPoint(opPoint, opPointRef)

    def createOpPointModif(self):
        self.opPointModif = OpPointModifier('opmodif' + self.name)
        plug(self.dyn.signal(self.opPoint),
             self.opPointModif.signal('positionIN'))
        plug(self.dyn.signal('J' + self.opPoint),
             self.opPointModif.signal('jacobianIN'))
        self.opPointModif.activ = False

    def createFeatures(self):
        self.feature = FeatureVisualPoint('feature' + self.name)
        self.featureDes = FeatureVisualPoint('feature' + self.name + '_ref')
        self.feature.selec.value = '11'

    def createTask(self):
        self.task = Task('task' + self.name)

    def createGain(self):
        self.gain = GainAdaptive('gain' + self.name)
        self.gain.set(0.1, 0.1, 125e3)

    def createProj(self):
        self.proj = VisualPointProjecter('proj' + self.name)

    def plugEverything(self):
        self.feature.setReference(self.featureDes.name)
        plug(self.dyn.signal(self.opPoint), self.proj.signal('transfo'))
        plug(self.proj.signal('point2D'), self.feature.signal('xy'))
        plug(self.proj.signal('depth'), self.feature.signal('Z'))
        plug(self.dyn.signal('J' + self.opPoint), self.feature.signal('Jq'))
        self.task.add(self.feature.name)
        plug(self.task.error, self.gain.error)
        plug(self.gain.gain, self.task.controlGain)

    def __init__(self, name, dyn, opPoint, opPointRef='right-wrist'):
        self.name = name
        self.defineDynEntities(dyn)
        self.createOpPoint(opPoint, opPointRef)
        self.createOpPointModif()
        self.createFeatures()
        self.createTask()
        self.createGain()
        self.createProj()
        self.plugEverything()

    @property
    def ref(self):
        return self.featureDes.xy.value

    @ref.setter
    def ref(self, m):
        self.featureDes.xy.value = m

    @property
    def target(self):
        return self.proj.point3D

    @target.setter
    def target(self, m):
        self.proj.point3D.value = m

    @property
    def opmodif(self):
        if not self.opPointModif.activ:
            return False
        else:
            return self.opPointModif.getTransformation()

    @opmodif.setter
    def opmodif(self, m):
        if isinstance(m, bool) and not m:
            plug(self.dyn.signal(self.opPoint), self.proj.signal('transfo'))
            plug(self.dyn.signal('J' + self.opPoint),
                 self.feature.signal('Jq'))
            self.opPointModif.activ = False
        else:
            if not self.opPointModif.activ:
                plug(self.opPointModif.signal('position'),
                     self.proj.signal('transfo'))
                plug(self.opPointModif.signal('jacobian'),
                     self.feature.signal('Jq'))
            self.opPointModif.setTransformation(m)
            self.opPointModif.activ = True

    def goto3D(self, point3D, gain=None, ref2D=None, selec=None):
        self.target = point3D
        if ref2D is not None:
            self.ref = ref2D
        if selec is not None:
            self.feature.selec.value = selec
        setGain(self.gain, gain)
 def createGain(self):
     self.gain = GainAdaptive('gain' + self.name)
     self.gain.set(0.1, 0.1, 125e3)
Example #24
0
tp.dyn = robot.dynamic
tp.feature = FeaturePosture('feature_' + n)

q = list(robot.device.robotState.value)
tp.feature.state.value = q
tp.feature.posture.value = q

robotDim = robot.dynamic.getDimension()
assert robotDim == len(q)

with_wheels = robotDim == 19

for i in range(8 if with_wheels else 6, robotDim):
    tp.feature.selectDof(i, True)

tp.gain = GainAdaptive("gain_" + n)
tp.add(tp.feature.name)

# Connects the dynamics to the current feature of the posture task
plug(robot.dynamic.position, tp.feature.state)

# Set the gain of the posture task
setGain(tp.gain, (4.9, 0.9, 0.01, 0.9))
plug(tp.gain.gain, tp.controlGain)
plug(tp.error, tp.gain.error)


def getJointIdxQ(name):
    model = robot.pinocchioModel
    jid = model.getJointId(name)
    return model.joints[jid].idx_q - 1
Example #25
0
from dynamic_graph.sot.core.matrix_util import matrixToTuple
from dynamic_graph.sot.tools import SimpleSeqPlay
from numpy import eye

from dynamic_graph.sot.core import Task, FeatureGeneric, GainAdaptive
from dynamic_graph.sot.core.meta_tasks import setGain
from dynamic_graph.sot.core.matrix_util import matrixToTuple
from numpy import identity, hstack, zeros

# Create the posture task
task_name = "posture_task"
taskPosture = Task(task_name)
taskPosture.dyn = robot.dynamic
taskPosture.feature = FeatureGeneric('feature_' + task_name)
taskPosture.featureDes = FeatureGeneric('feature_des_' + task_name)
taskPosture.gain = GainAdaptive("gain_" + task_name)
robotDim = robot.dynamic.getDimension()
first_6 = zeros((32, 6))
other_dof = identity(robotDim - 6)
jacobian_posture = hstack([first_6, other_dof])
taskPosture.feature.jacobianIN.value = matrixToTuple(jacobian_posture)
taskPosture.feature.setReference(taskPosture.featureDes.name)
taskPosture.add(taskPosture.feature.name)

# Create the sequence player
aSimpleSeqPlay = SimpleSeqPlay('aSimpleSeqPlay')
aSimpleSeqPlay.load(
    "/home/ostasse/devel-src/robotpkg-test3/install/share/pyrene-motions/identification/OEM_arms_60s_500Hz"
)
aSimpleSeqPlay.setTimeToStart(10.0)
# Connects the sequence player to the posture task
Example #26
0
class MetaTask6d(object):
    name = ''
    opPoint = ''
    dyn = 0
    task = 0
    feature = 0
    featureDes = 0

    def opPointExist(self, opPoint):
        sigsP = filter(lambda x: x.getName().split(':')[-1] == opPoint, self.dyn.signals())
        sigsJ = filter(lambda x: x.getName().split(':')[-1] == 'J' + opPoint, self.dyn.signals())
        return len(sigsP) == 1 & len(sigsJ) == 1

    def defineDynEntities(self, dyn):
        self.dyn = dyn

    def createOpPoint(self, opPoint, opPointRef='right-wrist'):
        self.opPoint = opPoint
        if self.opPointExist(opPoint):
            return
        self.dyn.createOpPoint(opPoint, opPointRef)

    def createOpPointModif(self):
        self.opPointModif = OpPointModifier('opmodif' + self.name)
        plug(self.dyn.signal(self.opPoint), self.opPointModif.signal('positionIN'))
        plug(self.dyn.signal('J' + self.opPoint), self.opPointModif.signal('jacobianIN'))
        self.opPointModif.activ = False

    def createFeatures(self):
        self.feature = FeaturePoint6d('feature' + self.name)
        self.featureDes = FeaturePoint6d('feature' + self.name + '_ref')
        self.feature.selec.value = '111111'
        self.feature.frame('current')

    def createTask(self):
        self.task = Task('task' + self.name)

    def createGain(self):
        self.gain = GainAdaptive('gain' + self.name)
        self.gain.set(0.1, 0.1, 125e3)

    def plugEverything(self):
        self.feature.setReference(self.featureDes.name)
        plug(self.dyn.signal(self.opPoint), self.feature.signal('position'))
        plug(self.dyn.signal('J' + self.opPoint), self.feature.signal('Jq'))
        self.task.add(self.feature.name)
        plug(self.task.error, self.gain.error)
        plug(self.gain.gain, self.task.controlGain)

    def keep(self):
        self.feature.position.recompute(self.dyn.position.time)
        self.feature.keep()

    def __init__(self, name, dyn, opPoint, opPointRef='right-wrist'):
        self.name = name
        self.defineDynEntities(dyn)
        self.createOpPoint(opPoint, opPointRef)
        self.createOpPointModif()
        self.createFeatures()
        self.createTask()
        self.createGain()
        self.plugEverything()

    @property
    def ref(self):
        return self.featureDes.position.value

    @ref.setter
    def ref(self, m):
        self.featureDes.position.value = m

    @property
    def opmodif(self):
        if not self.opPointModif.activ:
            return False
        else:
            return self.opPointModif.getTransformation()

    @opmodif.setter
    def opmodif(self, m):
        if isinstance(m, bool) and not m:
            plug(self.dyn.signal(self.opPoint), self.feature.signal('position'))
            plug(self.dyn.signal('J' + self.opPoint), self.feature.signal('Jq'))
            self.opPointModif.activ = False
        else:
            if not self.opPointModif.activ:
                plug(self.opPointModif.signal('position'), self.feature.position)
                plug(self.opPointModif.signal('jacobian'), self.feature.Jq)
            self.opPointModif.setTransformation(m)
            self.opPointModif.activ = True