-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathtutorial2.py
executable file
·63 lines (50 loc) · 1.56 KB
/
tutorial2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
import asyncio
import os
import sys
current_dir = os.path.dirname(os.path.abspath(__file__))
rvpath = os.path.join(current_dir, '..', '..')
sys.path.append(rvpath)
from pygazebo.pygazebo import DisconnectError
from pyrevolve.gazebo.manage import WorldManager as World
from pyrevolve.sdfbuilder import Link
from pyrevolve.sdfbuilder import Model
from pyrevolve.sdfbuilder import SDF
from pyrevolve.sdfbuilder.math import Vector3
async def run():
world = await World.create()
if world:
print("Connected to the simulator world.")
model = Model(
name='sdf_model',
static=True,
)
model.set_position(position=Vector3(0, 0, 1))
link = Link('sdf_link')
link.make_sphere(
mass=10e10,
radius=0.5,
)
link.make_color(0.7, 0.2, 0.0, 1.0)
model.add_element(link)
sdf_model = SDF(elements=[model])
await world.insert_model(sdf_model)
await world.pause(True)
while True:
await asyncio.sleep(10.0)
def main():
def handler(loop, context):
exc = context['exception']
if isinstance(exc, DisconnectError) \
or isinstance(exc, ConnectionResetError):
print("Got disconnect / connection reset - shutting down.")
sys.exit(0)
raise context['exception']
try:
loop = asyncio.get_event_loop()
loop.set_exception_handler(handler)
loop.run_until_complete(run())
except KeyboardInterrupt:
print("Got Ctrl+C, shutting down.")
if __name__ == "__main__":
main()