2
2
3
3
# Copyright 2013, Florent Lamiraux, Francesco Morsillo CNRS
4
4
5
+ from numpy import eye
5
6
6
- from dynamic_graph .sot .core .feature_position import FeaturePosition
7
- from dynamic_graph .sot .core import FeatureGeneric , FeatureJointLimits , Task , \
8
- JointLimitator
9
- from dynamic_graph .sot .dyninv import SolverKine , TaskDynLimits , TaskDynInequality
10
- from dynamic_graph .sot .dyninv .meta_tasks_dyn import gotoNd , MetaTaskDynCom , \
11
- MetaTaskDynPosture
12
- from dynamic_graph .sot .dyninv .meta_task_dyn_6d import MetaTaskDyn6d
13
7
from dynamic_graph import plug
14
-
15
- from numpy import eye
8
+ from dynamic_graph .sot .core import FeatureGeneric
16
9
from dynamic_graph .sot .core .matrix_util import matrixToTuple
10
+ from dynamic_graph .sot .dyninv import SolverKine , TaskDynInequality , TaskDynLimits
11
+ from dynamic_graph .sot .dyninv .meta_task_dyn_6d import MetaTaskDyn6d
12
+ from dynamic_graph .sot .dyninv .meta_tasks_dyn import MetaTaskDynCom , MetaTaskDynPosture
17
13
18
- class Solver :
19
14
15
+ class Solver :
20
16
def __init__ (self , robot ):
21
17
self .robot = robot
22
-
23
18
"""
24
19
# Make sure control does not exceed joint limits.
25
20
self.jointLimitator = JointLimitator('joint_limitator')
@@ -32,13 +27,12 @@ def __init__(self, robot):
32
27
self .sot = SolverKine ('solver' )
33
28
self .sot .signal ('damping' ).value = 1e-6
34
29
self .sot .setSize (self .robot .dimension )
35
-
30
+
36
31
# Set second order computation
37
32
self .robot .device .setSecondOrderIntegration ()
38
33
self .sot .setSecondOrderKinematics ()
39
- plug (self .robot .device .velocity ,self .robot .dynamic .velocity )
40
- plug (self .robot .dynamic .velocity ,self .sot .velocity )
41
-
34
+ plug (self .robot .device .velocity , self .robot .dynamic .velocity )
35
+ plug (self .robot .dynamic .velocity , self .sot .velocity )
42
36
"""
43
37
# Plug the solver control into the filter.
44
38
plug(self.sot.control, self.jointLimitator.controlIN)
@@ -48,154 +42,151 @@ def __init__(self, robot):
48
42
49
43
if robot.device:
50
44
plug(self.jointLimitator.control, robot.device.control)
51
-
52
45
"""
53
46
54
47
# Plug the solver control into the robot.
55
48
plug (self .sot .control , robot .device .control )
56
49
57
-
58
- def push (self , task ):
50
+ def push (self , task ):
59
51
"""
60
52
Proxy method to push a task (not a MetaTask) in the sot
61
53
"""
62
- self .sot .push (task .name )
63
- if task .name != "taskposture" and "taskposture" in self .toList ():
54
+ self .sot .push (task .name )
55
+ if task .name != "taskposture" and "taskposture" in self .toList ():
64
56
self .sot .down ("taskposture" )
65
57
66
- def rm (self , task ):
58
+ def rm (self , task ):
67
59
"""
68
60
Proxy method to remove a task from the sot
69
61
"""
70
- self .sot .rm (task .name )
62
+ self .sot .rm (task .name )
71
63
72
- def pop (self ):
64
+ def pop (self ):
73
65
"""
74
66
Proxy method to remove the last (usually posture) task from the sot
75
67
"""
76
- self .sot .pop ()
68
+ self .sot .pop ()
77
69
78
- def __str__ (self ):
79
- return self .sot .display ()
70
+ def __str__ (self ):
71
+ return self .sot .display ()
80
72
81
73
def toList (self ):
82
74
"""
83
75
Creates the list of the tasks in the sot
84
76
"""
85
- return map (lambda x : x [1 :- 1 ],self .sot .dispStack ().split ('|' )[1 :])
77
+ return map (lambda x : x [1 :- 1 ], self .sot .dispStack ().split ('|' )[1 :])
86
78
87
79
def clear (self ):
88
80
"""
89
81
Proxy method to remove all tasks from the sot
90
82
"""
91
- self .sot .clear ()
83
+ self .sot .clear ()
92
84
93
85
94
- def setTaskLim (taskLim ,robot ):
86
+ def setTaskLim (taskLim , robot ):
95
87
"""
96
88
Sets the parameters for teh 'task-limits'
97
89
"""
98
90
# Angular position and velocity limits
99
- plug (robot .dynamic .position ,taskLim .position )
100
- plug (robot .dynamic .velocity ,taskLim .velocity )
91
+ plug (robot .dynamic .position , taskLim .position )
92
+ plug (robot .dynamic .velocity , taskLim .velocity )
101
93
taskLim .dt .value = robot .timeStep
102
94
robot .dynamic .upperJl .recompute (0 )
103
95
robot .dynamic .lowerJl .recompute (0 )
104
96
taskLim .referencePosInf .value = robot .dynamic .lowerJl .value
105
97
taskLim .referencePosSup .value = robot .dynamic .upperJl .value
106
- #dqup = (0, 0, 0, 0, 0, 0, 200, 220, 250, 230, 290, 520, 200, 220, 250, 230, 290, 520, 250, 140, 390, 390, 240, 140, 240, 130, 270, 180, 330, 240, 140, 240, 130, 270, 180, 330)
107
- dqup = (1000 ,)* robot .dimension ########################
108
- taskLim .referenceVelInf .value = tuple ([- val * 3.14 / 180 for val in dqup ])
109
- taskLim .referenceVelSup .value = tuple ([ val * 3.14 / 180 for val in dqup ])
98
+ # dqup = (0, 0, 0, 0, 0, 0, 200, 220, 250, 230, 290, 520, 200, 220, 250, 230, 290, 520, 250, 140, 390, 390, 240,
99
+ # 140, 240, 130, 270, 180, 330, 240, 140, 240, 130, 270, 180, 330)
100
+ dqup = (1000 , ) * robot .dimension
101
+ taskLim .referenceVelInf .value = tuple ([- val * 3.14 / 180 for val in dqup ])
102
+ taskLim .referenceVelSup .value = tuple ([val * 3.14 / 180 for val in dqup ])
110
103
taskLim .controlGain .value = 0.3
111
104
112
105
113
- def setContacts (contactLF ,contactRF ):
106
+ def setContacts (contactLF , contactRF ):
114
107
"""
115
108
Sets the parameters for teh contacts
116
109
"""
117
110
# Left foot
118
- contactLF .featureDes .velocity .value = (0 ,0 , 0 , 0 , 0 , 0 )
111
+ contactLF .featureDes .velocity .value = (0 , 0 , 0 , 0 , 0 , 0 )
119
112
contactLF .feature .frame ('desired' )
120
113
contactLF .name = "LF"
121
-
114
+
122
115
# Right foot
123
- contactRF .featureDes .velocity .value = (0 ,0 , 0 , 0 , 0 , 0 )
116
+ contactRF .featureDes .velocity .value = (0 , 0 , 0 , 0 , 0 , 0 )
124
117
contactRF .feature .frame ('desired' )
125
118
contactRF .name = "RF"
126
-
127
- contactRF .support = ((0.11 ,- 0.08 ,- 0.08 ,0.11 ),(- 0.045 ,- 0.045 ,0.07 ,0.07 ),(- 0.105 ,- 0.105 ,- 0.105 ,- 0.105 ))
128
- contactLF .support = ((0.11 ,- 0.08 ,- 0.08 ,0.11 ),(- 0.07 ,- 0.07 ,0.045 ,0.045 ),(- 0.105 ,- 0.105 ,- 0.105 ,- 0.105 ))
129
-
119
+
120
+ contactRF .support = ((0.11 , - 0.08 , - 0.08 , 0.11 ), (- 0.045 , - 0.045 , 0.07 , 0.07 ), (- 0.105 , - 0.105 , - 0.105 , - 0.105 ))
121
+ contactLF .support = ((0.11 , - 0.08 , - 0.08 , 0.11 ), (- 0.07 , - 0.07 , 0.045 , 0.045 ), (- 0.105 , - 0.105 , - 0.105 , - 0.105 ))
122
+
130
123
# Imposed errordot = 0
131
- contactLF .feature .errordot .value = (0 ,0 , 0 , 0 , 0 , 0 )
132
- contactRF .feature .errordot .value = (0 ,0 , 0 , 0 , 0 , 0 )
133
-
124
+ contactLF .feature .errordot .value = (0 , 0 , 0 , 0 , 0 , 0 )
125
+ contactRF .feature .errordot .value = (0 , 0 , 0 , 0 , 0 , 0 )
126
+
134
127
135
128
def createTasks (robot ):
136
-
129
+
137
130
# MetaTasks dictonary
138
131
robot .mTasks = dict ()
139
132
robot .tasksIne = dict ()
140
133
141
134
# Foot contacts
142
- robot .contactLF = MetaTaskDyn6d ('contactLF' ,robot .dynamic ,'lf' ,'left-ankle' )
143
- robot .contactRF = MetaTaskDyn6d ('contactRF' ,robot .dynamic ,'rf' ,'right-ankle' )
144
- setContacts (robot .contactLF ,robot .contactRF )
135
+ robot .contactLF = MetaTaskDyn6d ('contactLF' , robot .dynamic , 'lf' , 'left-ankle' )
136
+ robot .contactRF = MetaTaskDyn6d ('contactRF' , robot .dynamic , 'rf' , 'right-ankle' )
137
+ setContacts (robot .contactLF , robot .contactRF )
145
138
146
139
# MetaTasksDyn6d for other operational points
147
140
robot .mTasks ['waist' ] = MetaTaskDyn6d ('waist' , robot .dynamic , 'waist' , 'waist' )
148
141
robot .mTasks ['chest' ] = MetaTaskDyn6d ('chest' , robot .dynamic , 'chest' , 'chest' )
149
142
robot .mTasks ['rh' ] = MetaTaskDyn6d ('rh' , robot .dynamic , 'rh' , 'right-wrist' )
150
143
robot .mTasks ['lh' ] = MetaTaskDyn6d ('lh' , robot .dynamic , 'lh' , 'left-wrist' )
151
-
144
+
152
145
for taskName in robot .mTasks :
153
146
robot .mTasks [taskName ].feature .frame ('desired' )
154
147
robot .mTasks [taskName ].gain .setConstant (10 )
155
148
robot .mTasks [taskName ].task .dt .value = robot .timeStep
156
- robot .mTasks [taskName ].featureDes .velocity .value = (0 ,0 ,0 ,0 ,0 ,0 )
157
-
158
- handMgrip = eye (4 ); handMgrip [0 :3 ,3 ] = (0 ,0 ,- 0.14 )
149
+ robot .mTasks [taskName ].featureDes .velocity .value = (0 , 0 , 0 , 0 , 0 , 0 )
150
+
151
+ handMgrip = eye (4 )
152
+ handMgrip [0 :3 , 3 ] = (0 , 0 , - 0.14 )
159
153
robot .mTasks ['rh' ].opmodif = matrixToTuple (handMgrip )
160
154
robot .mTasks ['lh' ].opmodif = matrixToTuple (handMgrip )
161
-
162
155
163
156
# CoM Task
164
- robot .mTasks ['com' ] = MetaTaskDynCom (robot .dynamic ,robot .timeStep )
157
+ robot .mTasks ['com' ] = MetaTaskDynCom (robot .dynamic , robot .timeStep )
165
158
robot .dynamic .com .recompute (0 )
166
159
robot .mTasks ['com' ].featureDes .errorIN .value = robot .dynamic .com .value
167
160
robot .mTasks ['com' ].task .controlGain .value = 10
168
161
robot .mTasks ['com' ].feature .selec .value = '011'
169
162
170
163
# Posture Task
171
- robot .mTasks ['posture' ] = MetaTaskDynPosture (robot .dynamic ,robot .timeStep )
164
+ robot .mTasks ['posture' ] = MetaTaskDynPosture (robot .dynamic , robot .timeStep )
172
165
robot .mTasks ['posture' ].ref = robot .halfSitting
173
- robot .mTasks ['posture' ].gain .setConstant (5 )
166
+ robot .mTasks ['posture' ].gain .setConstant (5 )
174
167
175
-
176
- ## TASK INEQUALITY
168
+ # TASK INEQUALITY
177
169
178
170
# Task Height
179
171
featureHeight = FeatureGeneric ('featureHeight' )
180
- plug (robot .dynamic .com ,featureHeight .errorIN )
181
- plug (robot .dynamic .Jcom ,featureHeight .jacobianIN )
182
- robot .tasksIne ['taskHeight' ]= TaskDynInequality ('taskHeight' )
183
- plug (robot .dynamic .velocity ,robot .tasksIne ['taskHeight' ].qdot )
172
+ plug (robot .dynamic .com , featureHeight .errorIN )
173
+ plug (robot .dynamic .Jcom , featureHeight .jacobianIN )
174
+ robot .tasksIne ['taskHeight' ] = TaskDynInequality ('taskHeight' )
175
+ plug (robot .dynamic .velocity , robot .tasksIne ['taskHeight' ].qdot )
184
176
robot .tasksIne ['taskHeight' ].add (featureHeight .name )
185
177
robot .tasksIne ['taskHeight' ].selec .value = '100'
186
- robot .tasksIne ['taskHeight' ].referenceInf .value = (0. ,0. ,0. ) # Xmin, Ymin
187
- robot .tasksIne ['taskHeight' ].referenceSup .value = (0. ,0. ,0.80771 ) # Xmax, Ymax
188
- robot .tasksIne ['taskHeight' ].dt .value = robot .timeStep
178
+ robot .tasksIne ['taskHeight' ].referenceInf .value = (0. , 0. , 0. ) # Xmin, Ymin
179
+ robot .tasksIne ['taskHeight' ].referenceSup .value = (0. , 0. , 0.80771 ) # Xmax, Ymax
180
+ robot .tasksIne ['taskHeight' ].dt .value = robot .timeStep
189
181
190
182
191
- def createBalanceAndPosture (robot ,solver ):
183
+ def createBalanceAndPosture (robot , solver ):
192
184
193
185
solver .clear ()
194
-
186
+
195
187
# Task Limits
196
188
robot .taskLim = TaskDynLimits ('taskLim' )
197
- setTaskLim (robot .taskLim ,robot )
198
-
189
+ setTaskLim (robot .taskLim , robot )
199
190
200
191
# --- push tasks --- #
201
192
solver .sot .addContact (robot .contactLF )
@@ -205,16 +196,14 @@ def createBalanceAndPosture(robot,solver):
205
196
solver .push (robot .mTasks ['posture' ].task )
206
197
207
198
208
-
209
- def initialize (robot ):
199
+ def initialize (robot ):
210
200
211
201
# --- create solver --- #
212
- solver = Solver (robot )
213
-
202
+ solver = Solver (robot )
214
203
215
204
# --- create tasks --- #
216
205
createTasks (robot )
217
206
218
- createBalanceAndPosture (robot ,solver )
207
+ createBalanceAndPosture (robot , solver )
219
208
220
209
return solver
0 commit comments