kinetalos.py
Go to the documentation of this file.
1 # ______________________________________________________________________________
2 # ******************************************************************************
3 #
4 # The simplest robot task: Just go and reach a point
5 #
6 # ______________________________________________________________________________
7 # ******************************************************************************
8 
9 import pinocchio as pin
10 from numpy import eye
11 
12 # -----------------------------------------------------------------------------
13 # ------------------------------------------------------------------------------
14 # ---- Kinematic Stack of Tasks (SoT) -----------------------------------------
15 # ------------------------------------------------------------------------------
16 # ---- DYN --------------------------------------------------------------------
17 # -----------------------------------------------------------------------------
18 from pinocchio.robot_wrapper import RobotWrapper
19 
20 from dynamic_graph import plug
21 from dynamic_graph.sot.core.matrix_util import matrixToTuple
23  MetaTaskKine6d,
24  MetaTaskKineCom,
25  gotoNd,
26 )
27 from dynamic_graph.sot.core.sot import SOT
28 from dynamic_graph.sot.dynamic_pinocchio import fromSotToPinocchio
29 from dynamic_graph.sot.dynamic_pinocchio.humanoid_robot import HumanoidRobot
30 
31 # -----------------------------------------------------------------------------
32 # SET THE PATH TO THE URDF AND MESHES
33 # Define robotName, urdfpath and initialConfig
34 dt = 5e-3
35 urdfPath = "/PATH/TO/talos-data/robots/talos_full_collision.urdf"
36 urdfDir = ["/PATH/TO/talos-data"]
37 robotName = "TALOS"
38 OperationalPointsMap = {
39  "left-wrist": "arm_left_7_joint",
40  "right-wrist": "arm_right_7_joint",
41  "left-ankle": "leg_left_5_joint",
42  "right-ankle": "leg_right_5_joint",
43  "gaze": "head_2_joint",
44  "waist": "root_joint",
45  "chest": "torso_2_joint",
46 }
47 initialConfig = (
48  0.0,
49  0.0,
50  0.648702,
51  0.0,
52  0.0,
53  0.0, # Free flyer
54  0.0,
55  0.0,
56  -0.453786,
57  0.872665,
58  -0.418879,
59  0.0, # Left Leg
60  0.0,
61  0.0,
62  -0.453786,
63  0.872665,
64  -0.418879,
65  0.0, # Right Leg
66  0.0,
67  0.0, # Chest
68  0.261799,
69  0.17453,
70  0.0,
71  -0.523599,
72  0.0,
73  0.0,
74  0.1, # Left Arm
75  0.0,
76  0.0,
77  0.0,
78  0.0,
79  0.0,
80  0.0,
81  0.0, # Left gripper
82  -0.261799,
83  -0.17453,
84  0.0,
85  -0.523599,
86  0.0,
87  0.0,
88  0.1, # Right Arm
89  0.0,
90  0.0,
91  0.0,
92  0.0,
93  0.0,
94  0.0,
95  0.0, # Right gripper
96  0.0,
97  0.0, # Head
98 )
99 
100 # -----------------------------------------------------------------------------
101 # ---- ROBOT SPECIFICATIONS----------------------------------------------------
102 # -----------------------------------------------------------------------------
103 
104 pinocchioRobot = RobotWrapper(urdfPath, urdfDir, pin.JointModelFreeFlyer())
105 
106 pinocchioRobot.initDisplay(loadModel=True)
107 pinocchioRobot.display(fromSotToPinocchio(initialConfig))
108 
109 robot = HumanoidRobot(
110  robotName,
111  pinocchioRobot.model,
112  pinocchioRobot.data,
113  initialConfig,
114  OperationalPointsMap,
115 )
116 
117 sot = SOT("sot")
118 sot.setSize(robot.dynamic.getDimension())
119 plug(sot.control, robot.device.control)
120 
121 # ------------------------------------------------------------------------------
122 # ---- TASKS -------------------------------------------------------------------
123 
124 taskRH = MetaTaskKine6d(
125  "rh", robot.dynamic, "rh", robot.OperationalPointsMap["right-wrist"]
126 )
127 handMgrip = eye(4)
128 handMgrip[0:3, 3] = (0.1, 0, 0)
129 taskRH.opmodif = matrixToTuple(handMgrip)
130 taskRH.feature.frame("desired")
131 # --- STATIC COM (if not walking)
132 taskCom = MetaTaskKineCom(robot.dynamic)
133 robot.dynamic.com.recompute(0)
134 taskCom.featureDes.errorIN.value = robot.dynamic.com.value
135 taskCom.task.controlGain.value = 10
136 
137 # --- CONTACTS
138 # define contactLF and contactRF
139 for name, joint in [
140  ["LF", robot.OperationalPointsMap["left-ankle"]],
141  ["RF", robot.OperationalPointsMap["right-ankle"]],
142 ]:
143  contact = MetaTaskKine6d("contact" + name, robot.dynamic, 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.0)
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) # noqa TODO
156 sot.push(contactLF.task.name) # noqa TODO
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 range(n):
167  robot.device.increment(dt)
168  pinocchioRobot.display(fromSotToPinocchio(robot.device.state.value))
169 
170 
171 # runner(3000)
pinocchio::robot_wrapper::RobotWrapper
dynamic_graph::sot::core::meta_tasks_kine
dynamic_pinocchio.fromSotToPinocchio
def fromSotToPinocchio(q_sot, freeflyer=True)
Definition: __init__.py:7
kinetalos.runner
def runner(n)
Definition: kinetalos.py:165
pinocchio::robot_wrapper
dynamic_graph::sot::core::meta_tasks_kine::MetaTaskKineCom
dynamic_graph::sot::core::matrix_util


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