Exemple #1
0
            else:
                self.body.fc = (0, 1, 0)

    def algorithm_0(self):
        self.body.cmd_vel(v=0)

    def update(self):
        self.algorithm_0()
        super().update()


# MAIN
if __name__ == '__main__':
    name = 'Demo' + strftime("%Y%m%d%H%M", localtime())
    s = Space(name, T=RT, limits='')
    p = KPIdata(name, 2, TS)
    # a big nest in the second quadrant:
    bignest = Nest('BigNest',
                   pos=(uniform(-0.8 * W, -0.2 * W), uniform(0.4 * H,
                                                             0.6 * H)),
                   area=0.02,
                   fc=(0, 0, 1))
    smallnest = Nest('SmallNest',
                     pos=(uniform(0.8 * W,
                                  0.2 * W), uniform(-0.4 * H, -0.6 * H)),
                     area=0.04,
                     fc=(1, 0, 0))  #
    s.bodies.append(bignest)
    s.bodies.append(smallnest)
    N = 100
        return np.arctan2((n.pos.y - self.body.pos.y),
                          (n.pos.x - self.body.pos.x)) - b.th

    def rang(self, n):
        return np.linalg.norm([(n.pos.y - self.body.pos.y),
                               (n.pos.x - self.body.pos.x)])

        print('avarage: ', avarage)
        print(len(neigh))


## MAIN
if __name__ == '__main__':
    R = 1  # so goodistance=1 is little less than half R
    name = 'Boids_R' + str(R) + '_' + strftime("%Y%m%d%H%M", localtime())
    s = Space(name, T=RT, R=R, limits='')
    N = 50
    s.spawn_bodies(nm=N, room=[(-4, -4), (4, -4), (4, 4), (-4, 4)])

    for b in s.bodies:
        if isinstance(b, Mobot):
            Boid(b, s, 0.7, 0.1 * TS)  # ADD YOUR ARGUMENTS
    p = KPIdata(name, 5, TS)

    KPI = [0, 0, np.sqrt(N), 1, 0]

    end = False

    while not end:
        for b in s.bodies:
            if isinstance(b, MoBody):
Exemple #3
0
        # Alternative (fraction of tangential component): w = self.k_p * s_y

        self.body.cmd_vel(u, w, 0.0)

        # Draw the steering vector
        self.vertices = [(self.body.pos.x, self.body.pos.y),
                         (self.body.pos.x + v_steering.x / 2,
                          self.body.pos.y + v_steering.y / 2)]
        super().update()


## MAIN

R = 1.8  # so goodistance=1 is little less than half R
name = 'Boids_R' + str(R) + '_' + strftime("%Y%m%d%H%M", localtime())
s = Space(name, T=RT, R=R, limits='')
# KPI datastruct:
# [0]: Fraction of N still alive (1 means no collision)
# [1]: Fraction of still alive Mobot’s in the largest connected component (1 means all connected)
# [2]: Cohesion radius (maximum distance to centroid) divided by sqrt(N) * ”good distance”
# [3]: Average square (error to “good distance” divided by “good distance”)
# [4]: Effect of steering vector components
# [5]: ...
# [6]: ...
# [7]: ...

#p=KPIdata(name,7,TS)
N = 50
period = 0.1
total_time = 5 * 60
steps = int(total_time / period)
## Version: 20210510
## Author: Enrique Teruel (ET) [email protected]
## License: CC-BY-SA

from time import time_ns, time, localtime, strftime
import numpy as np
from random import uniform
from matplotlib.animation import FFMpegWriter  # requires having ffmpeg installed, from https://ffmpeg.org/

from small_worl2d_config import visual, TS, RT, room
from small_worl2d import Space, KPIdata, Mobot, Voronoid

## MAIN

name = 'BasicVoronoids' + strftime("%Y%m%d%H%M", localtime())
s = Space(name, T=RT, R=0, limits='')  # No comm
p = KPIdata(name, 1, 2 * TS)
s.spawn_bodies(100)  # Mobots only
for b in s.bodies:
    if isinstance(b, Mobot):
        Voronoid(
            b, s, 5, T=uniform(TS, 2 * TS), Q=room
        )  # rng=uniform(0.75*np.pi,0.95*np.pi) would be WithoutRearView
KPI = [1]
end = False
while not end:
    for b in s.bodies:
        if isinstance(b, Mobot):
            b.update()
    s.update_dist()
    s.remobodies(s.collisions())