Exemplo n.º 1
0
from simulator import Simulator, Map, Agent
from devices import Device
import numpy as np
import simulator_config

env = Simulator(simulator_config)
map = Map()
map.get_map_from_geom2d(env,
                        kp=np.array([[-100, 100], [-100, -100], [100, -100],
                                     [100, 100]]))

robot = Agent(env,
              kp=np.array([[-2, 0], [2, 0]]),
              color=(1, 0, 0, 0.5),
              v_max=5)
robot.reset(init_state=np.array([0, 40, 0]))
device = Device(env,
                parent=robot,
                kp=np.array([[-10, 0], [10, 0]]),
                color=[0, 1, 0, 1],
                filled=False)
while True:
    robot.update(v=np.array([5, 0]))
    env._render()
Exemplo n.º 2
0
from simulator import Simulator, Map, Agent
import numpy as np
from time import time
import simulator_config

env = Simulator(config=simulator_config)
map = Map()
map.get_map_from_geom2d(env, np.array([[-100, 0], [100, 0]]))

n_targets = 10
n_robots = 10

targets = [
    Agent(env, kp=np.array([[-2, 0], [2, 0]]), color=(1, 0, 0, 0.5), v_max=1.5)
    for i in range(n_targets)
]
robots = [
    Agent(env, kp=np.array([[-2, 0], [2, 0]]), color=(0, 0, 1, 0.5), v_max=2)
    for i in range(n_targets, n_robots + n_targets)
]
tic = time()
# set speed betwee -2 to 2 in both direction
vs = (np.random.rand(n_targets + n_robots, 2) - 0.5) * 4

while True:
    env._render()
    for i in range(n_targets + n_robots):
        if np.random.rand() < 0.02:
            vs[i] = (np.random.rand(2) - 0.5) * 4
        else:
            vs[i] = vs[i]