5 from __future__
import print_function
8 from functools
import reduce
15 hasRobotViewer =
False
23 result = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
26 result[i][j] = tupleOfTuple[i][j]
32 (listOfList[0][0], listOfList[0][1], listOfList[0][2], listOfList[0][3]),
33 (listOfList[1][0], listOfList[1][1], listOfList[1][2], listOfList[1][3]),
34 (listOfList[2][0], listOfList[2][1], listOfList[2][2], listOfList[2][3]),
35 (listOfList[3][0], listOfList[3][1], listOfList[3][2], listOfList[3][3]),
41 Display nicely a 4x4 matrix (usually homogeneous matrix).
45 matrix_tuple = tuple(itertools.chain.from_iterable(matrix))
48 for i
in range(4 * 4):
49 formatStr +=
"{0[" + str(i) +
"]: <10} "
50 if i != 0
and (i + 1) % 4 == 0:
52 print(formatStr.format(matrix_tuple))
57 raise "bad configuration size"
60 s +=
" translation {0[0]: <+10f} {0[1]: <+10f} {0[2]: <+10f}\n"
61 s +=
" rotation {0[3]: <+10f} {0[4]: <+10f} {0[5]: <+10f}\n"
63 s +=
" hip {0[6]: <+10f} {0[7]: <+10f} {0[8]: <+10f}\n"
64 s +=
" knee {0[9]: <+10f}\n"
65 s +=
" ankle {0[10]: <+10f} {0[11]: <+10f}\n"
67 s +=
" hip {0[12]: <+10f} {0[13]: <+10f} {0[14]: <+10f}\n"
68 s +=
" knee {0[15]: <+10f}\n"
69 s +=
" ankle {0[16]: <+10f} {0[17]: <+10f}\n"
70 s +=
"Chest: {0[18]: <+10f} {0[19]: <+10f}\n"
71 s +=
"Head: {0[20]: <+10f} {0[21]: <+10f}\n"
73 s +=
" shoulder {0[22]: <+10f} {0[23]: <+10f} {0[24]: <+10f}\n"
74 s +=
" elbow {0[25]: <+10f}\n"
75 s +=
" wrist {0[26]: <+10f} {0[27]: <+10f}\n"
76 s +=
" clench {0[28]: <+10f}\n"
78 s +=
" shoulder {0[29]: <+10f} {0[30]: <+10f} {0[31]: <+10f}\n"
79 s +=
" elbow {0[32]: <+10f}\n"
80 s +=
" wrist {0[33]: <+10f} {0[34]: <+10f}\n"
81 s +=
" clench {0[35]: <+10f}\n"
86 """Initialize robotviewer is possible."""
90 clt = robotviewer.client()
92 print(
"failed to connect to robotviewer")
96 def reach(robot, op, tx, ty, tz):
97 sdes =
toList(robot.dynamic.signal(op).value)
101 robot.features[op].reference.value =
toTuple(sdes)
103 robot.features[op]._feature.signal(
"selec").value =
"000111"
104 robot.tasks[op].signal(
"controlGain").value = 1.0
108 """Compute the square of the distance between two configurations."""
112 return acc + abs(a - b) * abs(a - b)
114 return reduce(inner, zip(value, expectedValue), 0.0)
118 if sqrDist(position, finalPosition) >= 1e-3:
119 print(
"Wrong final position. Failing.")
122 print(
"Expected value:")
137 if "argv" in sys.__dict__:
138 from optparse
import OptionParser
139 from dynamic_graph.sot.dynamic_pinocchio.solver
import Solver
143 parser = OptionParser()
150 help=
"enable display using robotviewer",
158 help=
"Specify which robot model to use",
160 (options, args) = parser.parse_args()
163 if not hasRobotViewer:
164 print(
"Failed to import robotviewer client library.")
167 print(
"Failed to initialize robotviewer client library.")
170 robots = {
"Hrp2Laas": Hrp2Laas,
"Hrp2Jrl": Hrp2Jrl}
171 if options.robot
not in robots:
172 raise RuntimeError(
"invalid robot name (should by Hrp2Laas or Hrp2Jrl)")
173 robot = robots[options.robot](
"robot")
174 solver = Solver(robot)