lambdas.py
Go to the documentation of this file.
1 #
2 # Copyright (c) 2016 CNRS
3 #
4 # ruff: noqa: E731
5 
6 import numpy as np
7 from pinocchio import Force, Motion, skew
8 from pinocchio.utils import zero
9 
10 
11 def jFromIdx(idxv, robot):
12  """Return the joint index from the velocity index"""
13  for j in range(1, robot.model.njoint):
14  if idxv in range(
15  robot.model.joints[j].idx_v,
16  robot.model.joints[j].idx_v + robot.model.joints[j].nv,
17  ):
18  return j
19 
20 
21 parent = lambda i, robot: robot.model.parents[i]
22 iv = lambda i, robot: list(
23  range(
24  robot.model.joints[i].idx_v,
25  robot.model.joints[i].idx_v + robot.model.joints[i].nv,
26  )
27 )
28 ancestors = lambda j, robot, res=[]: (
29  res
30  if j == 0
31  else ancestors(
32  robot.model.parents[j],
33  robot,
34  [j, *res],
35  )
36 )
37 
38 
39 class ancestorOf:
40  def __init__(self, i, robot):
41  self.dec = i
42  self.robot = robot
43 
44  def __contains__(self, anc):
45  dec = self.dec
46  while dec > 0:
47  if anc == dec:
48  return True
49  else:
50  dec = self.robot.model.parents[dec]
51 
52 
53 # descendants = lambda root,robot: filter(
54 # lambda i: root in ancestorOf(i,robot), range(root,robot.model.njoints) )
55 descendants = lambda root, robot: robot.model.subtrees[root]
56 
57 
58 def setRobotArgs(robot):
59  ancestors.__defaults__ = (robot, *ancestors.__defaults__)
60  descendants.__defaults__ = (robot,)
61  # ancestorsOf.__init__.__defaults__ = (robot,)
62  iv.__defaults__ = (robot,)
63  parent.__defaults__ = (robot,)
64  jFromIdx.__defaults__ = (robot,)
65 
66 
67 # --- SE3 operators
68 Mcross = lambda x, y: Motion(x).cross(Motion(y)).vector
69 Mcross.__doc__ = "Motion cross product"
70 
71 Fcross = lambda x, y: Motion(x).cross(Force(y)).vector
72 Fcross.__doc__ = "Force cross product"
73 
74 MCross = lambda V, v: np.bmat([Mcross(V[:, i], v) for i in range(V.shape[1])])
75 FCross = lambda V, f: np.bmat([Fcross(V[:, i], f) for i in range(V.shape[1])])
76 
77 
78 adj = lambda nu: np.bmat([[skew(nu[3:]), skew(nu[:3])], [zero([3, 3]), skew(nu[3:])]])
79 adj.__doc__ = "Motion pre-cross product (ie adjoint, lie bracket operator)"
80 
81 adjdual = lambda nu: np.bmat(
82  [[skew(nu[3:]), zero([3, 3])], [skew(nu[:3]), skew(nu[3:])]]
83 )
84 adjdual.__doc__ = "Force pre-cross product adjdual(a) = -adj(a)' "
85 
86 td = np.tensordot
87 quad = lambda H, v: np.array(td(td(H, v, [2, 0]), v, [1, 0]))
88 quad.__doc__ = """Tensor product v'*H*v, with H.shape = [ nop, nv, nv ]"""
89 
90 
91 def np_prettyprint(sarg="{: 0.5f}", eps=5e-7):
92  mformat = lambda x, sarg=sarg, eps=eps: (
93  sarg.format(x) if abs(x) > eps else " 0. "
94  )
95  np.set_printoptions(formatter={"float": mformat})
pinocchio::python::context::Force
ForceTpl< Scalar, Options > Force
Definition: bindings/python/context/generic.hpp:55
pinocchio::python::context::Motion
MotionTpl< Scalar, Options > Motion
Definition: bindings/python/context/generic.hpp:54
lambdas.ancestorOf.__init__
def __init__(self, i, robot)
Definition: lambdas.py:40
lambdas.np_prettyprint
def np_prettyprint(sarg="{: 0.5f}", eps=5e-7)
Definition: lambdas.py:91
lambdas.Fcross
Fcross
Definition: lambdas.py:71
lambdas.ancestorOf
Definition: lambdas.py:39
pinocchio.utils
Definition: bindings/python/pinocchio/utils.py:1
lambdas.ancestorOf.__contains__
def __contains__(self, anc)
Definition: lambdas.py:44
pinocchio::python::skew
Eigen::Matrix< typename Vector3::Scalar, 3, 3, Vector3::Options > skew(const Vector3 &v)
Definition: expose-skew.cpp:19
lambdas.Mcross
Mcross
Definition: lambdas.py:68
lambdas.ancestorOf.robot
robot
Definition: lambdas.py:42
pinocchio::cross
void cross(const Eigen::MatrixBase< Vector3 > &v, const Eigen::MatrixBase< Matrix3xIn > &Min, const Eigen::MatrixBase< Matrix3xOut > &Mout)
Applies the cross product onto the columns of M.
Definition: skew.hpp:228
lambdas.jFromIdx
def jFromIdx(idxv, robot)
Definition: lambdas.py:11
lambdas.setRobotArgs
def setRobotArgs(robot)
Definition: lambdas.py:58
lambdas.td
td
Definition: lambdas.py:86
pinocchio.utils.zero
def zero(n)
Definition: bindings/python/pinocchio/utils.py:37
lambdas.ancestors
list ancestors
Definition: lambdas.py:28
lambdas.ancestorOf.dec
dec
Definition: lambdas.py:41


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:11