meta_task_visual_point.py
Go to the documentation of this file.
1 from dynamic_graph import plug
2 from dynamic_graph.sot.core.feature_visual_point import FeatureVisualPoint
3 from dynamic_graph.sot.core.gain_adaptive import GainAdaptive
4 from dynamic_graph.sot.core.meta_tasks import setGain
5 from dynamic_graph.sot.core.op_point_modifier import OpPointModifier
6 from dynamic_graph.sot.core.task import Task
7 from dynamic_graph.sot.core.visual_point_projecter import VisualPointProjecter
8 
9 
10 class MetaTaskVisualPoint(object):
11  name = ""
12  opPoint = ""
13  dyn = 0
14  task = 0
15  feature = 0
16  featureDes = 0
17  proj = 0
18 
19  def opPointExist(self, opPoint):
20  sigsP = filter(
21  lambda x: x.getName().split(":")[-1] == opPoint, self.dyn.signals()
22  )
23  sigsJ = filter(
24  lambda x: x.getName().split(":")[-1] == "J" + opPoint, self.dyn.signals()
25  )
26  return len(sigsP) == 1 & len(sigsJ) == 1
27 
28  def defineDynEntities(self, dyn):
29  self.dyn = dyn
30 
31  def createOpPoint(self, opPoint, opPointRef="right-wrist"):
32  self.opPoint = opPoint
33  if self.opPointExist(opPoint):
34  return
35  self.dyn.createOpPoint(opPoint, opPointRef)
36 
37  def createOpPointModif(self):
38  self.opPointModif = OpPointModifier("opmodif" + self.name)
39  plug(self.dyn.signal(self.opPoint), self.opPointModif.signal("positionIN"))
40  plug(
41  self.dyn.signal("J" + self.opPoint), self.opPointModif.signal("jacobianIN")
42  )
43  self.opPointModif.activ = False
44 
45  def createFeatures(self):
46  self.feature = FeatureVisualPoint("feature" + self.name)
47  self.featureDes = FeatureVisualPoint("feature" + self.name + "_ref")
48  self.feature.selec.value = "11"
49 
50  def createTask(self):
51  self.task = Task("task" + self.name)
52 
53  def createGain(self):
54  self.gain = GainAdaptive("gain" + self.name)
55  self.gain.set(0.1, 0.1, 125e3)
56 
57  def createProj(self):
58  self.proj = VisualPointProjecter("proj" + self.name)
59 
60  def plugEverything(self):
61  self.feature.setReference(self.featureDes.name)
62  plug(self.dyn.signal(self.opPoint), self.proj.signal("transfo"))
63  plug(self.proj.signal("point2D"), self.feature.signal("xy"))
64  plug(self.proj.signal("depth"), self.feature.signal("Z"))
65  plug(self.dyn.signal("J" + self.opPoint), self.feature.signal("Jq"))
66  self.task.add(self.feature.name)
67  plug(self.task.error, self.gain.error)
68  plug(self.gain.gain, self.task.controlGain)
69 
70  def __init__(self, name, dyn, opPoint, opPointRef="right-wrist"):
71  self.name = name
72  self.defineDynEntities(dyn)
73  self.createOpPoint(opPoint, opPointRef)
74  self.createOpPointModif()
75  self.createFeatures()
76  self.createTask()
77  self.createGain()
78  self.createProj()
79  self.plugEverything()
80 
81  @property
82  def ref(self):
83  return self.featureDes.xy.value
84 
85  @ref.setter
86  def ref(self, m):
87  self.featureDes.xy.value = m
88 
89  @property
90  def target(self):
91  return self.proj.point3D
92 
93  @target.setter
94  def target(self, m):
95  self.proj.point3D.value = m
96 
97  @property
98  def opmodif(self):
99  if not self.opPointModif.activ:
100  return False
101  else:
102  return self.opPointModif.getTransformation()
103 
104  @opmodif.setter
105  def opmodif(self, m):
106  if isinstance(m, bool) and not m:
107  plug(self.dyn.signal(self.opPoint), self.proj.signal("transfo"))
108  plug(self.dyn.signal("J" + self.opPoint), self.feature.signal("Jq"))
109  self.opPointModif.activ = False
110  else:
111  if not self.opPointModif.activ:
112  plug(self.opPointModif.signal("position"), self.proj.signal("transfo"))
113  plug(self.opPointModif.signal("jacobian"), self.feature.signal("Jq"))
114  self.opPointModif.setTransformation(m)
115  self.opPointModif.activ = True
116 
117  def goto3D(self, point3D, gain=None, ref2D=None, selec=None):
118  self.target = point3D
119  if ref2D is not None:
120  self.ref = ref2D
121  if selec is not None:
122  self.feature.selec.value = selec
123  setGain(self.gain, gain)
void set(bool ownStorage, Vec3f *points_, unsigned int num_points_)
def goto3D(self, point3D, gain=None, ref2D=None, selec=None)
def __init__(self, name, dyn, opPoint, opPointRef="right-wrist")


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Wed Jun 21 2023 02:51:26