Skip to content

Commit be29346

Browse files
committed
chore: update python examples
1 parent 2059630 commit be29346

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: SubmodelParent
3+
layout: default
4+
parent: Attributes
5+
grand_parent: Python Library
6+
---
7+
8+
# Sub-Model Parent
9+
10+
When this object is parented to a hierarchical model, it attaches to a named sub-component of that model instead of the root position. Requires `parent` attribute.
11+
12+
This program loads a URDF model of a robot arm, and then attaches a see-though green ball at the tip of the armature at the sub-model component named `joint_6_t-flange` of the URDF model.
13+
14+
Additional Python properties are available in the [SubmodelParent API Reference](/content/python-api/attributes/submodel_parent).
15+
16+
```python
17+
from arena import *
18+
19+
scene = Scene(host="arenaxr.org", scene="example")
20+
21+
@scene.run_once
22+
def make_model_container():
23+
robot_arm = UrdfModel(
24+
object_id="robot_arm",
25+
position=(0, 0, -3),
26+
rotation=(-90, 0, 0),
27+
scale=(1, 1, 1),
28+
url="/store/users/mwfarb/xacro/motoman_gp4_support/urdf/gp4.xacro",
29+
urlBase="/store/users/mwfarb/xacro/motoman_gp4_support",
30+
)
31+
scene.add_object(robot_arm)
32+
green_ball = Sphere(
33+
object_id="green_ball",
34+
parent=robot_arm.object_id,
35+
scale=(0.05, 0.05, 0.05),
36+
material={"color": "#00ff00", "transparent": True, "opacity": 0.45},
37+
submodel_parent="joint_6_t-flange",
38+
)
39+
scene.add_object(green_ball)
40+
41+
scene.run_tasks()
42+
```

content/python/simple/device-scene.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ Demonstrate starting two connections, for a scene and a device, and communicatin
1111

1212
```python
1313
import json
14-
import random
1514
from datetime import datetime
1615

1716
from arena import Box, Device, Material, Scene
1817

19-
box = Box(object_id="box", position=(0, 2, -1), rotation=(0, 0, 0),
20-
scale=(2, 2, 2), material=Material(transparent=True, opacity=1))
18+
box = Box(
19+
object_id="box",
20+
position=(0, 2, -1),
21+
material=Material(transparent=True, opacity=1),
22+
)
2123

2224
scene = Scene(host="arenaxr.org", scene="example")
2325
device = Device(host="arenaxr.org", device="robot1")
@@ -34,10 +36,7 @@ def on_recv_message_device(client, userdata, msg):
3436
box.data.rotation.x += 0.1
3537
box.data.scale.y -= 0.01
3638
box.data.material.opacity = (box.data.material.opacity - 0.01) % 1
37-
print(scene.update_object(
38-
box,
39-
click_listener=True,
40-
))
39+
print(scene.update_object(box, click_listener=True))
4140
except:
4241
pass
4342

@@ -46,7 +45,7 @@ device.message_callback_add(CUSTOM_TOPIC, on_recv_message_device)
4645
@device.run_forever(interval_ms=1000)
4746
def on_second_publ_message():
4847
payload = {}
49-
d = datetime.now().isoformat()[:-3]+"Z"
48+
d = datetime.now().isoformat()[:-3] + "Z"
5049
payload["timestamp"] = d
5150
payload = json.dumps(payload)
5251
device.publish(CUSTOM_TOPIC, payload)

0 commit comments

Comments
 (0)