-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswarm.py
55 lines (41 loc) · 1.66 KB
/
swarm.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
#!/usr/bin/env python3
"""
Mini-example of Mujoco that demonstrates the key concepts we need.
"""
from mujoco_py import load_model_from_path, MjSim, MjViewer
import os
import random
model = load_model_from_path("xmls/default.xml")
sim = MjSim(model)
viewer = MjViewer(sim)
sim_state = sim.get_state()
#To see order or to change something with the movable parts of
#the agent, check xmls/swarm.xml
#Actions right now:
#sim.data.ctrl[0] = X direction of bot1 [-5 to 5] determines speed
#sim.data.ctrl[1] = Y direction of bot1 [-5 to 5] determines speed
#sim.data.ctrl[2] = X direction of bot2 [-5 to 5] determines speed
#sim.data.ctrl[3] = Y direction of bot2 [-5 to 5] determines speed
while True:
sim.set_state(sim_state)
print(sim.data.ctrl)
# print(sim.data.get_body_xpos("target"))
# print(sim.data.get_body_xvelp("target"))
# print(sim.data.get_body_xvelr("target"))
#sim.data has all the information available in the environment.
#We should pick and choose some select information.
# print(dir(sim.data))
for i in range(1000000): #each iteration and step in this environment is a single frame.
print('xpos:{}'.format(sim.data.get_body_xpos("target")))
print('xvelp:{}'.format(sim.data.get_body_xvelp("target")))
print('xvelr:{}'.format(sim.data.get_body_xvelr("target")))
#sim.data.ctrl[:] = random.uniform(-1,1)
sim.data.ctrl[::2] = -4
#sim.data.ctrl[0] = -1
#sim.data.ctrl[2] = -1
# if i % 100 == 0:
# print(i)
sim.step() #step like env.step(action)
viewer.render() #render like env.render()
if os.getenv('TESTING') is not None:
break