forked from learnsyslab/crazyflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.py
More file actions
36 lines (28 loc) · 1.09 KB
/
Copy pathrender.py
File metadata and controls
36 lines (28 loc) · 1.09 KB
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
from collections import deque
import numpy as np
from crazyflow.constants import GRAVITY, MASS
from crazyflow.sim import Physics, Sim
from crazyflow.sim.visualize import draw_line
def main():
"""Spawn 25 drones in one world and render each with a trace behind it."""
n_worlds, n_drones = 1, 25
sim = Sim(n_worlds=n_worlds, n_drones=n_drones, physics=Physics.sys_id, device="cpu")
fps = 60
cmd = np.zeros((sim.n_worlds, sim.n_drones, 4))
cmd[..., 0] = MASS * GRAVITY * 1.2
rgbas = np.random.default_rng(0).uniform(0, 1, (n_drones, 4))
rgbas[..., 3] = 1.0
pos = deque(maxlen=15)
for i in range(int(5 * sim.control_freq)):
sim.attitude_control(cmd)
sim.step(sim.freq // sim.control_freq)
if i % 20 == 0:
pos.append(sim.data.states.pos[0, :])
if ((i * fps) % sim.control_freq) < fps:
lines = np.array(pos)
for i in range(n_drones):
draw_line(sim, lines[:, i, :], rgbas[i, :], start_size=0.3, end_size=3.0)
sim.render()
sim.close()
if __name__ == "__main__":
main()