kineromeo.py
Go to the documentation of this file.
1 # flake8: noqa
2 # ______________________________________________________________________________
3 # ******************************************************************************
4 #
5 # The simplest robot task: Just go and reach a point
6 #
7 # ______________________________________________________________________________
8 # ******************************************************************************
9 import pinocchio as pin
10 from dynamic_graph import plug
11 from dynamic_graph.sot.core import *
12 from dynamic_graph.sot.core.matrix_util import matrixToTuple
14 from dynamic_graph.sot.dynamics import *
15 
16 # from dynamic_graph.sot.core.utils.viewer_helper import addRobotViewer,VisualPinger,updateComDisplay
17 from numpy import *
18 
19 # Taking input from pinocchio
20 from pinocchio.romeo_wrapper import RomeoWrapper
21 
22 set_printoptions(suppress=True, precision=7)
23 
24 # -----------------------------------------------------------------------------
25 # ---- ROBOT SPECIFICATIONS----------------------------------------------------
26 # -----------------------------------------------------------------------------
27 
28 # Define robotName, urdfpath and initialConfig
29 
30 # SET THE PATH TO THE URDF AND MESHES
31 urdfPath = "~/git/sot/pinocchio/models/romeo.urdf"
32 urdfDir = ["~/git/sot/pinocchio/models"]
33 pinocchioRobot = RomeoWrapper(urdfPath, urdfDir, pin.JointModelFreeFlyer())
34 robotName = "romeo"
35 pinocchioRobot.initDisplay(loadModel=True)
36 pinocchioRobot.display(pinocchioRobot.q0)
37 initialConfig = (
38  0,
39  0,
40  0.840252,
41  0,
42  0,
43  0, # FF
44  0,
45  0,
46  -0.3490658,
47  0.6981317,
48  -0.3490658,
49  0, # LLEG
50  0,
51  0,
52  -0.3490658,
53  0.6981317,
54  -0.3490658,
55  0, # RLEG
56  0, # TRUNK
57  1.5,
58  0.6,
59  -0.5,
60  -1.05,
61  -0.4,
62  -0.3,
63  -0.2, # LARM
64  0,
65  0,
66  0,
67  0, # HEAD
68  1.5,
69  -0.6,
70  0.5,
71  1.05,
72  -0.4,
73  -0.3,
74  -0.2, # RARM
75 )
76 
77 # -----------------------------------------------------------------------------
78 # ---- PINOCCHIO MODEL AND DATA --------------------------------------------------------------------
79 # -----------------------------------------------------------------------------
80 # pinocchioModel = pin.buildModelFromUrdf(urdfpath, pin.JointModelFreeFlyer())
81 # pinocchioData = pinocchioModel.createData()
82 
83 # -----------------------------------------------------------------------------
84 # ---- DYN --------------------------------------------------------------------
85 # -----------------------------------------------------------------------------
86 dyn = Dynamic("dyn")
87 dyn.setModel(pinocchioRobot.model)
88 dyn.setData(pinocchioRobot.data)
89 
90 dyn.displayModel()
91 
92 robotDim = dyn.getDimension()
93 inertiaRotor = (0,) * 6 + (5e-4,) * 31
94 gearRatio = (0,) * 6 + (200,) * 31
95 dyn.inertiaRotor.value = inertiaRotor
96 dyn.gearRatio.value = gearRatio
97 dyn.velocity.value = robotDim * (0.0,)
98 dyn.acceleration.value = robotDim * (0.0,)
99 
100 # ------------------------------------------------------------------------------
101 # --- ROBOT SIMULATION ---------------------------------------------------------
102 # ------------------------------------------------------------------------------
103 
104 robot = RobotSimu(robotName)
105 robot.resize(robotDim)
106 dt = 5e-3
107 
108 # TODO: This configuration follows xyzQuat format for freeflyer. Do something about it
109 # initialConfig = zip(*(list(matrixToTuple(pinocchioRobot.q0))))[0]
110 
111 robot.set(initialConfig)
112 plug(robot.state, dyn.position)
113 
114 # ------------------------------------------------------------------------------
115 # ---- Kinematic Stack of Tasks (SoT) -----------------------------------------
116 # ------------------------------------------------------------------------------
117 sot = SOT("sot")
118 sot.setSize(robotDim)
119 plug(sot.control, robot.control)
120 
121 # --------------------------------DISPLAY-----------------------------------------
122 
123 # ------------------------------------------------------------------------------
124 # ---- TASKS -------------------------------------------------------------------
125 # ------------------------------------------------------------------------------
126 # ---- TASK -----------------------------
127 
128 # ---- TASK GRIP
129 taskRH = MetaTaskKine6d("rh", dyn, "rh", "RWristPitch")
130 handMgrip = eye(4)
131 handMgrip[0:3, 3] = (0.1, 0, 0)
132 taskRH.opmodif = matrixToTuple(handMgrip)
133 taskRH.feature.frame("desired")
134 # --- STATIC COM (if not walking)
135 taskCom = MetaTaskKineCom(dyn)
136 dyn.com.recompute(0)
137 taskCom.featureDes.errorIN.value = dyn.com.value
138 taskCom.task.controlGain.value = 10
139 
140 # --- CONTACTS
141 # define contactLF and contactRF
142 for name, joint in [["LF", "LAnkleRoll"], ["RF", "RAnkleRoll"]]:
143  contact = MetaTaskKine6d("contact" + name, dyn, name, joint)
144  contact.feature.frame("desired")
145  contact.gain.setConstant(10)
146  contact.keep()
147  locals()["contact" + name] = contact
148 
149 target = (0.5, -0.2, 1.3)
150 
151 # addRobotViewer(robot, small=False)
152 # robot.viewer.updateElementConfig('zmp',target+(0,0,0))
153 
154 gotoNd(taskRH, target, "111", (4.9, 0.9, 0.01, 0.9))
155 sot.push(contactRF.task.name)
156 sot.push(contactLF.task.name)
157 sot.push(taskCom.task.name)
158 sot.push(taskRH.task.name)
159 
160 # -------------------------------------------------------------------------------
161 # ----- MAIN LOOP ---------------------------------------------------------------
162 # -------------------------------------------------------------------------------
163 
164 
165 def runner(n):
166  for i in xrange(n):
167  robot.increment(dt)
168  pinocchioRobot.display(fromSotToPinocchio(robot.state.value))
169 
170 
171 runner(1000)
dynamic_graph::sot::core
dynamic_graph::sot::core::meta_tasks_kine
dynamics
dynamic_pinocchio.fromSotToPinocchio
def fromSotToPinocchio(q_sot, freeflyer=True)
Definition: __init__.py:7
kineromeo.runner
def runner(n)
Definition: kineromeo.py:165
dynamic_graph::sot::core::meta_tasks_kine::MetaTaskKineCom
pinocchio::romeo_wrapper::RomeoWrapper
pinocchio::romeo_wrapper
dynamic_graph::sot::core::matrix_util


sot-dynamic-pinocchio
Author(s): Olivier Stasse
autogenerated on Fri Jul 28 2023 02:10:01