placo 0.9.15__0-cp311-cp311-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ from . import tf
2
+ from . import visualization
3
+
4
+ __all__ = ["tf", "visualization"]
@@ -0,0 +1 @@
1
+ import meshcat.transformations as tf
@@ -0,0 +1,37 @@
1
+ import argparse
2
+ import placo
3
+ import time
4
+ from placo_utils.visualization import *
5
+
6
+ arg_parser = argparse.ArgumentParser()
7
+ arg_parser.add_argument("path", help="Path to the URDF")
8
+ arg_parser.add_argument("--frames", help="Frame to display", nargs="+")
9
+ arg_parser.add_argument("--animate", help="Animate the robot", action="store_true")
10
+ args = arg_parser.parse_args()
11
+
12
+ robot = placo.RobotWrapper(args.path, placo.Flags.ignore_collisions)
13
+ robot.update_kinematics()
14
+
15
+ print("Joint names:")
16
+ print(list(robot.joint_names()))
17
+
18
+ print("Frame names:")
19
+ print(list(robot.frame_names()))
20
+
21
+ viz = robot_viz(robot)
22
+ t = 0
23
+
24
+ while True:
25
+ viz.display(robot.state.q)
26
+
27
+ if args.frames:
28
+ for frame in args.frames:
29
+ robot_frame_viz(robot, frame)
30
+
31
+ if args.animate:
32
+ for joint in robot.joint_names():
33
+ robot.set_joint(joint, np.sin(t))
34
+ robot.update_kinematics()
35
+
36
+ t += 0.01
37
+ time.sleep(0.01)
@@ -0,0 +1,356 @@
1
+ import meshcat
2
+ import pinocchio as pin
3
+ import pinocchio.visualize as pin_viz
4
+ import numpy as np
5
+ import meshcat.geometry as g
6
+ import meshcat.transformations as tf
7
+ import placo
8
+
9
+
10
+ viewer = None
11
+ robot_names: dict = {}
12
+
13
+
14
+ def get_viewer() -> meshcat.Visualizer:
15
+ """
16
+ Gets the meshcat viewer, if it doesn't exist, create it
17
+ """
18
+ global viewer
19
+
20
+ if viewer is None:
21
+ viewer = meshcat.Visualizer()
22
+
23
+ print(f"Viewer URL: {viewer.url()}")
24
+
25
+ return viewer
26
+
27
+
28
+ def robot_viz(
29
+ robot: placo.RobotWrapper, name: str = "robot"
30
+ ) -> pin_viz.MeshcatVisualizer:
31
+ """
32
+ Builds an instance of pinocchio MeshcatVisualizer, which allows to push the model to the meshcat
33
+ visualizer passed as parameter
34
+
35
+ The robot can further be displayed using:
36
+
37
+ > viz.display(q)
38
+ """
39
+ global robot_names
40
+
41
+ robot_names[robot] = name
42
+ viz = pin_viz.MeshcatVisualizer(
43
+ robot.model, robot.collision_model, robot.visual_model
44
+ )
45
+ viz.initViewer(viewer=get_viewer())
46
+ viz.loadViewerModel(name)
47
+
48
+ return viz
49
+
50
+
51
+ cylinders: dict = {}
52
+
53
+
54
+ def frame_viz(
55
+ name: str, T: np.ndarray, opacity: float = 1.0, scale: float = 1.0
56
+ ) -> None:
57
+ """
58
+ Visualizes a given frame
59
+ """
60
+ global cylinders
61
+ vis = get_viewer()
62
+ axises = {
63
+ "x": (0xFF0000, (-np.pi / 2, [0, 0, 1])),
64
+ "y": (0x00FF00, (0, [0, 1, 0])),
65
+ "z": (0x0000FF, (np.pi / 2, [1, 0, 0])),
66
+ }
67
+
68
+ for axis_name in axises:
69
+ color, rotate = axises[axis_name]
70
+ node_name = f"frames/{name}/{axis_name}"
71
+
72
+ if node_name not in cylinders:
73
+ cylinders[node_name] = vis[node_name]
74
+ cylinders[node_name].set_object(
75
+ g.Cylinder(0.1, 0.005),
76
+ g.MeshLambertMaterial(color=color, opacity=opacity),
77
+ )
78
+ obj = cylinders[node_name]
79
+
80
+ obj.set_transform(
81
+ T
82
+ @ tf.scale_matrix(scale)
83
+ @ tf.rotation_matrix(*rotate)
84
+ @ tf.translation_matrix([0, 0.05, 0])
85
+ )
86
+
87
+
88
+ def point_viz(
89
+ name: str,
90
+ point: np.ndarray,
91
+ radius: float = 0.01,
92
+ color: float = 0xFF0000,
93
+ opacity: float = 1.0,
94
+ ) -> None:
95
+ """
96
+ Prints a point (sphere)
97
+ """
98
+ vis = get_viewer()
99
+ vis["point"][name].set_object(
100
+ g.Sphere(radius), g.MeshPhongMaterial(color=color, opacity=opacity)
101
+ )
102
+ vis["point"][name].set_transform(tf.translation_matrix(point))
103
+
104
+
105
+ points_sizes = {}
106
+
107
+
108
+ def points_viz(
109
+ name: str,
110
+ points: np.ndarray,
111
+ radius: float = 0.01,
112
+ color: float = 0xFF0000,
113
+ opacity: float = 1.0,
114
+ ) -> None:
115
+ """
116
+ Prints a point (sphere)
117
+ """
118
+ global points_sizes
119
+ vis = get_viewer()
120
+ k = 0
121
+ for point in points:
122
+ entry = f"{name}_{k}"
123
+ k += 1
124
+ vis["points"][name][entry].set_object(
125
+ g.Sphere(radius), g.MeshPhongMaterial(color=color, opacity=opacity)
126
+ )
127
+ vis["points"][name][entry].set_transform(tf.translation_matrix(point))
128
+ while k < points_sizes.get(name, 0):
129
+ vis["points"][name][f"{name}_{k}"].delete()
130
+ k += 1
131
+ points_sizes[name] = len(points)
132
+
133
+
134
+ def robot_frame_viz(
135
+ robot: placo.RobotWrapper, frame: str, opacity: float = 1.0, scale: float = 1.0
136
+ ) -> None:
137
+ """
138
+ Draw a frame from the robot
139
+ """
140
+ node_name = f"{robot_names[robot]}_{frame}"
141
+ frame_viz(node_name, robot.get_T_world_frame(frame), opacity, scale)
142
+
143
+
144
+ steps: int = 0
145
+
146
+
147
+ def footsteps_viz(footsteps: placo.Footsteps, T: np.ndarray = np.eye(4)) -> None:
148
+ global steps
149
+ vis = get_viewer()
150
+
151
+ if len(footsteps) < steps:
152
+ vis["footsteps"].delete()
153
+ steps = len(footsteps)
154
+
155
+ k = 0
156
+ for footstep in footsteps:
157
+ k += 1
158
+ polygon = [(T @ [*xy, 0, 1])[:3] for xy in footstep.support_polygon()]
159
+ polygon = np.array([*polygon, polygon[-1]])
160
+
161
+ if isinstance(footstep, placo.Support):
162
+ if len(footstep.footsteps) >= 2:
163
+ color = 0x1111AA
164
+ else:
165
+ color = (
166
+ 0xFF3333 if str(footstep.footsteps[0].side) == "left" else 0x33FF33
167
+ )
168
+ else:
169
+ color = 0xFF3333 if str(footstep.side) == "left" else 0x33FF33
170
+
171
+ vis["footsteps"][str(k)].set_object(
172
+ g.LineLoop(g.PointsGeometry(polygon.T), g.MeshBasicMaterial(color=color))
173
+ )
174
+
175
+
176
+ def line_viz(name: str, points: np.ndarray, color: float = 0xFF0000) -> None:
177
+ """
178
+ Prints a line
179
+ """
180
+ vis = get_viewer()
181
+ vis["lines"][name].set_object(
182
+ g.LineSegments(g.PointsGeometry(points.T), g.LineBasicMaterial(color=color))
183
+ )
184
+
185
+
186
+ def cross_viz(
187
+ name: str, position: np.ndarray, size: float = 0.15, color: float = 0xFF0000
188
+ ) -> None:
189
+ """
190
+ Prints a cross
191
+ """
192
+ vis = get_viewer()
193
+
194
+ points = np.array(
195
+ [position - np.array([size, size]), position + np.array([size, size])]
196
+ )
197
+ vis["crosses"][f"{name}_1"].set_object(
198
+ g.LineSegments(g.PointsGeometry(points.T), g.LineBasicMaterial(color=color))
199
+ )
200
+ points = np.array(
201
+ [position - np.array([size, -size]), position + np.array([size, -size])]
202
+ )
203
+ vis["crosses"][f"{name}_2"].set_object(
204
+ g.LineSegments(g.PointsGeometry(points.T), g.LineBasicMaterial(color=color))
205
+ )
206
+
207
+
208
+ def path_viz(name: str, points: np.ndarray, color: float = 0xFF0000) -> None:
209
+ """
210
+ Prints a path
211
+ """
212
+ key = f"path_{name}"
213
+
214
+ vis = get_viewer()
215
+ vis[key].delete()
216
+
217
+ for k in range(len(points) - 1):
218
+ vis[key][str(k)].set_object(
219
+ g.LineSegments(
220
+ g.PointsGeometry(points[k : k + 2].T), g.LineBasicMaterial(color=color)
221
+ )
222
+ )
223
+
224
+
225
+ def cylinder_viz(
226
+ name: str,
227
+ position: np.ndarray,
228
+ length: float,
229
+ radius: float,
230
+ color: float = 0xFF0000,
231
+ opacity=1.0,
232
+ ) -> None:
233
+ vis = get_viewer()
234
+
235
+ cylinder = g.Cylinder(length, radius)
236
+ vis["cylinders"][name].set_object(
237
+ cylinder, g.MeshBasicMaterial(color=color, opacity=opacity)
238
+ )
239
+ vis["cylinders"][name].set_transform(
240
+ tf.translation_matrix((*position, length / 2))
241
+ @ tf.rotation_matrix(np.pi / 2, (1, 0, 0))
242
+ )
243
+
244
+
245
+ def arrow_viz(
246
+ name: str,
247
+ point_from: np.ndarray,
248
+ point_to: np.ndarray,
249
+ color: float = 0xFF0000,
250
+ radius: float = 0.003,
251
+ ) -> None:
252
+ """
253
+ Prints an arrow
254
+ """
255
+ head_length = radius * 3
256
+ vis = get_viewer()
257
+ length = np.linalg.norm(point_to - point_from)
258
+ length = max(1e-3, length - head_length)
259
+
260
+ cylinder = g.Cylinder(length, radius)
261
+ head = g.Cylinder(head_length, 2 * radius, 0.0, 2 * radius)
262
+
263
+ T = tf.translation_matrix(point_from)
264
+ if np.linalg.norm(point_to - point_from) > 1e-6:
265
+ T[:3, :3] = placo.rotation_from_axis(
266
+ "y", (point_to - point_from) / np.linalg.norm(point_to - point_from)
267
+ )
268
+
269
+ T_cylinder = T @ tf.translation_matrix(np.array([0, length / 2.0, 0.0]))
270
+ T_head = T @ tf.translation_matrix(np.array([0, length + head_length / 2.0, 0.0]))
271
+
272
+ vis["arrows"][name]["cylinder"].set_object(
273
+ cylinder, g.MeshBasicMaterial(color=color)
274
+ )
275
+ vis["arrows"][name]["cylinder"].set_transform(T_cylinder)
276
+ vis["arrows"][name]["head"].set_object(head, g.MeshBasicMaterial(color=color))
277
+ vis["arrows"][name]["head"].set_transform(T_head)
278
+
279
+
280
+ previous_contacts: int = 0
281
+
282
+
283
+ def contacts_viz(solver: placo.DynamicsSolver, ratio=0.1, radius=0.005):
284
+ global previous_contacts
285
+ robot = solver.robot
286
+ frames = robot.frame_names()
287
+ k = 0
288
+
289
+ for _ in range(solver.count_contacts()):
290
+ contact = solver.get_contact(k)
291
+ if not contact.active:
292
+ continue
293
+
294
+ if isinstance(contact, placo.PointContact):
295
+ frame_name = frames[contact.position_task().frame_index]
296
+ T_world_frame = robot.get_T_world_frame(frame_name)
297
+ arrow_viz(
298
+ f"contact_{k}",
299
+ T_world_frame[:3, 3],
300
+ T_world_frame[:3, 3] + contact.wrench * ratio,
301
+ color=0x00FF00,
302
+ radius=radius,
303
+ )
304
+ elif isinstance(contact, placo.Contact6D):
305
+ frame_name = frames[contact.position_task().frame_index]
306
+ T_world_frame = robot.get_T_world_frame(frame_name)
307
+ wrench = T_world_frame[:3, :3] @ contact.wrench[:3]
308
+
309
+ if np.linalg.norm(wrench) < 1e-6:
310
+ origin = T_world_frame[:3, 3]
311
+ else:
312
+ origin = T_world_frame[:3, 3] + T_world_frame[:3, :3] @ contact.zmp()
313
+
314
+ arrow_viz(
315
+ f"contact_{k}",
316
+ origin,
317
+ origin + wrench * ratio,
318
+ color=0x00FFAA,
319
+ radius=radius,
320
+ )
321
+ elif isinstance(contact, placo.LineContact):
322
+ frame_name = frames[contact.position_task().frame_index]
323
+ T_world_frame = robot.get_T_world_frame(frame_name)
324
+ wrench = T_world_frame[:3, :3] @ contact.wrench[:3]
325
+
326
+ if np.linalg.norm(wrench) < 1e-6:
327
+ origin = T_world_frame[:3, 3]
328
+ else:
329
+ origin = T_world_frame[:3, 3] + T_world_frame[:3, :3] @ contact.zmp()
330
+
331
+ arrow_viz(
332
+ f"contact_{k}",
333
+ origin,
334
+ origin + wrench * ratio,
335
+ color=0xFF33AA,
336
+ radius=radius,
337
+ )
338
+ elif isinstance(contact, placo.ExternalWrenchContact):
339
+ frame_name = frames[contact.frame_index]
340
+ T_world_frame = robot.get_T_world_frame(frame_name)
341
+ arrow_viz(
342
+ f"contact_{k}",
343
+ T_world_frame[:3, 3],
344
+ T_world_frame[:3, 3] + contact.w_ext[:3] * ratio,
345
+ color=0xFF2222,
346
+ radius=radius,
347
+ )
348
+
349
+ k += 1
350
+
351
+ vis = get_viewer()
352
+ k_d = k
353
+ while k_d < previous_contacts:
354
+ vis["arrows"][f"contact_{k_d}"].delete()
355
+ k_d += 1
356
+ previous_contacts = k
@@ -0,0 +1,62 @@
1
+ Metadata-Version: 2.4
2
+ Name: placo
3
+ Version: 0.9.15
4
+ Summary: PlaCo: Rhoban Planning and Control
5
+ Requires-Python: >= 3.8
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Author-email: Rhoban team <team@rhoban.com>
9
+ Project-URL: Changelog, https://github.com/rhoban/placo/blob/main/CHANGELOG.md
10
+ Home-page: https://placo.readthedocs.io/en/latest/
11
+ Project-URL: Repository, https://github.com/rhoban/placo.git
12
+ Requires-Dist: cmeel
13
+ Requires-Dist: eiquadprog >= 1.2.6, < 2
14
+ Requires-Dist: pin==3.4.0
15
+ Requires-Dist: rhoban-cmeel-jsoncpp
16
+ Requires-Dist: meshcat
17
+ Requires-Dist: ischedule
18
+ Provides-Extra: build
19
+ Requires-Dist: pin[build]==3.4.0 ; extra == "build"
20
+ Requires-Dist: doxystub >= 0.1.7 ; extra == "build"
21
+ Requires-Dist: cmake<4 ; extra == "build"
22
+ Description-Content-Type: text/markdown
23
+
24
+ <img width="400" src="https://placo.readthedocs.io/en/latest/_static/placo.png" />
25
+
26
+ ## Planning & Control
27
+
28
+ PlaCo is Rhoban's planning and control library. It is built on the top of [pinocchio](https://github.com/stack-of-tasks/pinocchio), [eiquadprog](https://github.com/stack-of-tasks/eiquadprog) QP solver, and fully written in C++ with Python bindings, allowing fast prototyping with good runtime performances. It features task-space inverse kinematics and dynamics (see below) high-level API for whole-body control tasks.
29
+
30
+ ### Task-Space Inverse Kinematics
31
+
32
+ [![Quadruoped demo](https://github.com/Rhoban/placo-examples/blob/master/kinematics/videos/quadruped_targets.gif?raw=true)](https://github.com/Rhoban/placo-examples/blob/master/kinematics/videos/quadruped_targets.mp4?raw=true)
33
+
34
+ High-level API to specify tasks for constrained inverse kinematics (IK).
35
+
36
+ - [See documentation](https://placo.readthedocs.io/en/latest/kinematics/getting_started.html)
37
+ - [Examples](https://placo.readthedocs.io/en/latest/kinematics/examples_gallery.html)
38
+
39
+ ### Task-Space Inverse Dynamics
40
+
41
+ [![Megabot demo](https://github.com/Rhoban/placo-examples/blob/master/dynamics/videos/megabot.gif?raw=true)](https://github.com/Rhoban/placo-examples/blob/master/dynamics/videos/megabot.mp4?raw=true)
42
+
43
+ High-level API to specify tasks for constrained inverse dynamics (ID).
44
+
45
+ - [See documentation](https://placo.readthedocs.io/en/latest/dynamics/getting_started.html)
46
+ - [Examples](https://placo.readthedocs.io/en/latest/dynamics/examples_gallery.html)
47
+
48
+
49
+ ## Installing
50
+
51
+ PlaCo can be installed from ``pip``
52
+
53
+ ```
54
+ pip install placo
55
+ ```
56
+
57
+ Or [built from sources](https://placo.readthedocs.io/en/latest/basics/installation_source.html)
58
+
59
+ ## Resources
60
+
61
+ * [Documentation](https://placo.readthedocs.io/en/latest/)
62
+ * [Examples](https://github.com/rhoban/placo-examples) repository
@@ -0,0 +1,12 @@
1
+ cmeel.prefix/lib/liblibplaco.dylib,sha256=B3K2ZL1cOLh4GsNkvF_cjOcEx9JDV4movMffJa_Df0Q,1359504
2
+ cmeel.prefix/lib/python3.11/site-packages/placo.pyi,sha256=igje8A4_ATZzaE5C8hOAdOxgCVm0qvMcsZwSQV9Jv78,162865
3
+ cmeel.prefix/lib/python3.11/site-packages/placo.so,sha256=jJ6RzRL0NyltTwAjoRUixOOaI9bfgwb2l1f9z3ZkXdc,6682888
4
+ cmeel.prefix/lib/python3.11/site-packages/placo_utils/__init__.py,sha256=UN-fc5KfBWQ-_qkm0Ajouh-T9tBGm5aUtuzBiH1tRtk,80
5
+ cmeel.prefix/lib/python3.11/site-packages/placo_utils/tf.py,sha256=fFRXNbeLlXzn5VOqYl7hcSuvOOtTDTiLi_Lpd9_l6wA,36
6
+ cmeel.prefix/lib/python3.11/site-packages/placo_utils/view.py,sha256=7KiLYGpTKaPJtFHZ6kjERdOzJiPSDUtkIKHbziHpkYk,928
7
+ cmeel.prefix/lib/python3.11/site-packages/placo_utils/visualization.py,sha256=z0IEIr4DW6qOwJ2ofEsm_JKx_Do2FF7wZY8Wt_7aqxM,9923
8
+ placo-0.9.15.dist-info/licenses/LICENSE,sha256=q2bBXvk4Eh7TmP11LoIOIGSUuJbR30JBI6ZZ37g52T4,1061
9
+ placo-0.9.15.dist-info/METADATA,sha256=NdaXI4FUVDlqvJ3P7ddsy-tRdrLs5_4_pgB3tzoDHvA,2623
10
+ placo-0.9.15.dist-info/WHEEL,sha256=t66Vmq09ySSuYNkvxj8pPRXN3x8PGEstXQgBdYltQZc,111
11
+ placo-0.9.15.dist-info/top_level.txt,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ placo-0.9.15.dist-info/RECORD,,
@@ -0,0 +1,6 @@
1
+ Wheel-Version: 1.0
2
+ Generator: cmeel 0.57.3
3
+ Root-Is-Purelib: false
4
+ Tag: cp311-cp311-macosx_11_0_arm64
5
+ Build: 0
6
+
@@ -0,0 +1,19 @@
1
+ Copyright (c) <2023-2099> Rhoban Team
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is furnished
8
+ to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
File without changes