Skip to content

Commit 49fb962

Browse files
author
Guilhem Saurel
committed
[Style] fix flake8, isort & yapf
1 parent d59165f commit 49fb962

File tree

4 files changed

+207
-240
lines changed

4 files changed

+207
-240
lines changed

setup.cfg

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[flake8]
2+
max-line-length = 119
3+
exclude = cmake
4+
5+
[yapf]
6+
column_limit = 119
7+
8+
[isort]
9+
line_length = 119
10+
skip = cmake

sot_application/acceleration/precomputed_meta_tasks.py

+65-76
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@
22

33
# Copyright 2013, Florent Lamiraux, Francesco Morsillo CNRS
44

5+
from numpy import eye
56

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
137
from dynamic_graph import plug
14-
15-
from numpy import eye
8+
from dynamic_graph.sot.core import FeatureGeneric
169
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
1713

18-
class Solver:
1914

15+
class Solver:
2016
def __init__(self, robot):
2117
self.robot = robot
22-
2318
"""
2419
# Make sure control does not exceed joint limits.
2520
self.jointLimitator = JointLimitator('joint_limitator')
@@ -32,13 +27,12 @@ def __init__(self, robot):
3227
self.sot = SolverKine('solver')
3328
self.sot.signal('damping').value = 1e-6
3429
self.sot.setSize(self.robot.dimension)
35-
30+
3631
# Set second order computation
3732
self.robot.device.setSecondOrderIntegration()
3833
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)
4236
"""
4337
# Plug the solver control into the filter.
4438
plug(self.sot.control, self.jointLimitator.controlIN)
@@ -48,154 +42,151 @@ def __init__(self, robot):
4842
4943
if robot.device:
5044
plug(self.jointLimitator.control, robot.device.control)
51-
5245
"""
5346

5447
# Plug the solver control into the robot.
5548
plug(self.sot.control, robot.device.control)
5649

57-
58-
def push (self, task):
50+
def push(self, task):
5951
"""
6052
Proxy method to push a task (not a MetaTask) in the sot
6153
"""
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():
6456
self.sot.down("taskposture")
6557

66-
def rm (self, task):
58+
def rm(self, task):
6759
"""
6860
Proxy method to remove a task from the sot
6961
"""
70-
self.sot.rm (task.name)
62+
self.sot.rm(task.name)
7163

72-
def pop (self):
64+
def pop(self):
7365
"""
7466
Proxy method to remove the last (usually posture) task from the sot
7567
"""
76-
self.sot.pop ()
68+
self.sot.pop()
7769

78-
def __str__ (self):
79-
return self.sot.display ()
70+
def __str__(self):
71+
return self.sot.display()
8072

8173
def toList(self):
8274
"""
8375
Creates the list of the tasks in the sot
8476
"""
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:])
8678

8779
def clear(self):
8880
"""
8981
Proxy method to remove all tasks from the sot
9082
"""
91-
self.sot.clear ()
83+
self.sot.clear()
9284

9385

94-
def setTaskLim(taskLim,robot):
86+
def setTaskLim(taskLim, robot):
9587
"""
9688
Sets the parameters for teh 'task-limits'
9789
"""
9890
# 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)
10193
taskLim.dt.value = robot.timeStep
10294
robot.dynamic.upperJl.recompute(0)
10395
robot.dynamic.lowerJl.recompute(0)
10496
taskLim.referencePosInf.value = robot.dynamic.lowerJl.value
10597
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])
110103
taskLim.controlGain.value = 0.3
111104

112105

113-
def setContacts(contactLF,contactRF):
106+
def setContacts(contactLF, contactRF):
114107
"""
115108
Sets the parameters for teh contacts
116109
"""
117110
# Left foot
118-
contactLF.featureDes.velocity.value=(0,0,0,0,0,0)
111+
contactLF.featureDes.velocity.value = (0, 0, 0, 0, 0, 0)
119112
contactLF.feature.frame('desired')
120113
contactLF.name = "LF"
121-
114+
122115
# Right foot
123-
contactRF.featureDes.velocity.value=(0,0,0,0,0,0)
116+
contactRF.featureDes.velocity.value = (0, 0, 0, 0, 0, 0)
124117
contactRF.feature.frame('desired')
125118
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+
130123
# 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+
134127

135128
def createTasks(robot):
136-
129+
137130
# MetaTasks dictonary
138131
robot.mTasks = dict()
139132
robot.tasksIne = dict()
140133

141134
# 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)
145138

146139
# MetaTasksDyn6d for other operational points
147140
robot.mTasks['waist'] = MetaTaskDyn6d('waist', robot.dynamic, 'waist', 'waist')
148141
robot.mTasks['chest'] = MetaTaskDyn6d('chest', robot.dynamic, 'chest', 'chest')
149142
robot.mTasks['rh'] = MetaTaskDyn6d('rh', robot.dynamic, 'rh', 'right-wrist')
150143
robot.mTasks['lh'] = MetaTaskDyn6d('lh', robot.dynamic, 'lh', 'left-wrist')
151-
144+
152145
for taskName in robot.mTasks:
153146
robot.mTasks[taskName].feature.frame('desired')
154147
robot.mTasks[taskName].gain.setConstant(10)
155148
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)
159153
robot.mTasks['rh'].opmodif = matrixToTuple(handMgrip)
160154
robot.mTasks['lh'].opmodif = matrixToTuple(handMgrip)
161-
162155

163156
# CoM Task
164-
robot.mTasks['com'] = MetaTaskDynCom(robot.dynamic,robot.timeStep)
157+
robot.mTasks['com'] = MetaTaskDynCom(robot.dynamic, robot.timeStep)
165158
robot.dynamic.com.recompute(0)
166159
robot.mTasks['com'].featureDes.errorIN.value = robot.dynamic.com.value
167160
robot.mTasks['com'].task.controlGain.value = 10
168161
robot.mTasks['com'].feature.selec.value = '011'
169162

170163
# Posture Task
171-
robot.mTasks['posture'] = MetaTaskDynPosture(robot.dynamic,robot.timeStep)
164+
robot.mTasks['posture'] = MetaTaskDynPosture(robot.dynamic, robot.timeStep)
172165
robot.mTasks['posture'].ref = robot.halfSitting
173-
robot.mTasks['posture'].gain.setConstant(5)
166+
robot.mTasks['posture'].gain.setConstant(5)
174167

175-
176-
## TASK INEQUALITY
168+
# TASK INEQUALITY
177169

178170
# Task Height
179171
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)
184176
robot.tasksIne['taskHeight'].add(featureHeight.name)
185177
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
189181

190182

191-
def createBalanceAndPosture(robot,solver):
183+
def createBalanceAndPosture(robot, solver):
192184

193185
solver.clear()
194-
186+
195187
# Task Limits
196188
robot.taskLim = TaskDynLimits('taskLim')
197-
setTaskLim(robot.taskLim,robot)
198-
189+
setTaskLim(robot.taskLim, robot)
199190

200191
# --- push tasks --- #
201192
solver.sot.addContact(robot.contactLF)
@@ -205,16 +196,14 @@ def createBalanceAndPosture(robot,solver):
205196
solver.push(robot.mTasks['posture'].task)
206197

207198

208-
209-
def initialize (robot):
199+
def initialize(robot):
210200

211201
# --- create solver --- #
212-
solver = Solver (robot)
213-
202+
solver = Solver(robot)
214203

215204
# --- create tasks --- #
216205
createTasks(robot)
217206

218-
createBalanceAndPosture(robot,solver)
207+
createBalanceAndPosture(robot, solver)
219208

220209
return solver

0 commit comments

Comments
 (0)