Пример #1
0
    def setup(cls, controller_factory, goal_object):
        """
        Set up the world.
        :param controller_factory: if the controller is passed, load the learned network
        :param goal_object: influence the colour of the docking station
        :return world, marxbot, docking_station

        """

        # Create an unbounded world
        world = pyenki.World()

        marxbot = MyMarxbot(name='marxbot%d' % 1,
                            controller=controller_factory())
        world.add_object(marxbot)

        size = 20.0
        height = 40.0

        d_object = cls.setup_docking_station(size, height, goal_object)
        world.add_object(d_object)

        # Decide the pose of the docking_station
        d_object.position = (0, 0)
        d_object.angle = 0

        return world, marxbot, d_object
    def setup(cls, controller_factory, myt_quantity, aseba: bool = False):
        """
        Set up the world as an unbounded world.

        :param controller_factory: if the controller is passed, load the learned network
        :param myt_quantity: number of robot in the simulation
        :param aseba: True
        :return world, myts: world and the agents in the world
        """
        # Create an unbounded world
        world = pyenki.World()

        myts = []

        for i in range(myt_quantity):
            controller = controller_factory()
            myt = DistributedThymio2(name='myt%d' % (i + 1),
                                     index=i,
                                     controller=controller,
                                     use_aseba_units=aseba)

            myts.append(myt)
            world.add_object(myt)

        return world, myts
def main(directory, P, I, D):
    """

    :param directory: directory were to save the images containing the step response
    :param P: proportional term of the PID controller
    :param I: integral term of the PID controller
    :param D: derivative term of the PID controller
    """
    world = pyenki.World()

    myt = Thymio(name='myt1', index=1, p=P, i=I, d=D, use_aseba_units=False)

    myt.position = (0, 0)
    myt.initial_position = myt.position
    myt.goal_position = (20, 0)
    myt.angle = 0

    world.add_object(myt)

    dt = 0.1
    T = 8
    steps = int(T // dt)

    positions = []
    for s in range(steps):
        positions.append(myt.position[0])
        world.step(dt=dt)

    time = np.arange(0, len(positions) * dt, dt)[:len(positions)]
    plt.figure()
    plt.xlabel('time (seconds)', fontsize=11)
    plt.ylabel('x position', fontsize=11)

    plt.plot(time,
             positions,
             label='Kp = %s, Ki = %s, Kd = %s' %
             (round(P, 2), round(I, 2), round(D, 2)))
    plt.plot(time, [myt.goal_position[0]] * len(positions),
             label='Setpoint',
             ls='--',
             color='black')
    plt.title('Step response')
    plt.ylim(top=myt.goal_position[0] + 10)
    plt.xlim(0, 7)

    plt.legend()
    my_plots.save_visualisation(
        'Step-responsep=kp%ski%skd%s' %
        (round(P, 2), round(I, 2), round(D, 2)), directory)
Пример #4
0
	def __init__(self):
		super(MyEPuck, self).__init__()
		self.timeout = 10
		
	def controlStep(self, dt):
		if self.timeout == 0:
			self.leftSpeed = random.uniform(-100,100)
			self.rightSpeed = random.uniform(-100,100)
			self.timeout = random.randint(1,10)
		else:
			self.timeout -= 1
		#print('Control step')
		#print('pos: ' + str(self.pos))
		#print('IR dists: ' + str(self.proximitySensorDistances))
		#print('IR values: ' + str(self.proximitySensorValues))
		#print('Cam image: ' + str(self.cameraImage))
		#print len(self.cameraImage), self.cameraImage[0]
		print id(self), self.pos


w = pyenki.World()

for i in range(0,10):
	for j in range(0,10):
		e = MyEPuck()
		e.pos = (i*10,j*10)
		w.addObject(e)

w.runInViewer()

Пример #5
0
def main(distances, front_prox_values, back_prox_values, front_prox_comms,
         back_prox_comms, myt_quantity, min_distance):
    """

    :param distances: array containing the distances among the agents for each experiment
    :param front_prox_values: array containing the value of the frontal sensor using prox_values
    :param back_prox_values: array containing the value corresponding to the average of the rear sensor readings using prox_values
    :param front_prox_comms: array containing the value of the frontal sensor using prox_comm
    :param back_prox_comms: array containing the value corresponding to the average of the rear sensor readings using prox_comm
    :param myt_quantity: number of agents
    :param min_distance: length of the agents
    """

    for idx, distance in enumerate(distances):

        initial_positions = np.array(
            [0, min_distance + distance, (min_distance + distance) * 2],
            dtype=np.float64)

        world = pyenki.World()

        myts = []
        for i in range(myt_quantity):
            myt = Thymio(name='myt%d' % (i + 1),
                         index=i,
                         use_aseba_units=False)

            myt.position = (initial_positions[i], 0)
            myt.initial_position = myt.position

            # Reset the parameters
            myt.angle = 0

            myt.prox_comm_tx = 0
            myt.prox_comm_enable = True

            myts.append(myt)
            world.add_object(myt)

        print('distance = %d' % distance)
        # for m in myts:
        #     print(m.name, round(m.initial_position[0], 1), round(m.position[0], 1))

        sensors = dict()

        a = []
        b = []
        c = []
        d = []
        for _ in range(5):
            world.step(dt=0.1)

            sensing = myts[1].get_input_sensing()
            front_prox_value = sensing[2]
            back_prox_value = np.mean([sensing[5], sensing[6]])

            front_prox_comm = sensing[9]
            back_prox_comm = np.mean([sensing[12], sensing[13]])

            a.append(int(front_prox_value))
            b.append(int(back_prox_value))
            c.append(int(front_prox_comm))
            d.append(int(back_prox_comm))

        front_prox_values[idx] = int(np.mean(a))
        back_prox_values[idx] = int(np.mean(b))
        front_prox_comms[idx] = int(np.mean(c))
        back_prox_comms[idx] = int(np.mean(d))

        sensors['front_prox_values'] = int(np.mean(a))
        sensors['back_prox_values'] = int(np.mean(b))
        sensors['front_prox_comm'] = int(np.mean(c))
        sensors['back_prox_comm'] = int(np.mean(d))

        print(sensors)

    sensing_to_distances = [
        distances, front_prox_values, back_prox_values, front_prox_comms,
        back_prox_comms
    ]

    file = os.path.join('controllers', 'sensing_to_distances.pkl')
    with open(file, 'wb') as f:
        pickle.dump(sensing_to_distances, f)

    plt.figure()
    plt.xlabel('distance', fontsize=11)
    plt.ylabel('sensing', fontsize=11)

    plt.plot(distances, front_prox_values, label='front_prox_values')
    plt.plot(distances, back_prox_values, label='back_prox_values')
    plt.plot(distances, front_prox_comms, label='front_prox_comm')
    plt.plot(distances, back_prox_comms, label='back_prox_comm')
    plt.legend()

    dir = os.path.join('controllers', 'images')
    utils.check_dir(dir)

    my_plots.save_visualisation('sensing_to_distances', dir)
import sys

import numpy as np

import matplotlib
import matplotlib.pyplot as plt

from PyQt5.QtCore import QObject
from PyQt5.QtWidgets import QApplication

import pyenki
from viz import LaserScannerViz

world = pyenki.World(200)

marxbot = pyenki.Marxbot()
marxbot.position = (0, 0)
# marxbot.left_wheel_target_speed = -10
# marxbot.right_wheel_target_speed = 10
world.add_object(marxbot)

marxbot2 = pyenki.Marxbot()
marxbot2.position = (20, -5)
marxbot2.left_wheel_target_speed = 4
marxbot2.right_wheel_target_speed = 4
world.add_object(marxbot2)

cube = pyenki.RectangularObject(10, 10, 15, -1, pyenki.Color(1.0))
cube.position = (-20, 10)
world.add_object(cube)
Пример #7
0
import pyenki
import random
import math as Math
from Configuration import Config as conf
import NeuralNetwork as nn

#Global world properties

wL = 200
wH = 100

w = pyenki.World(wL, wH, pyenki.Color(0.5, 0.5, 0.5))
w.steps = 100

#//runInviewer(Enki::World self, camPos, camAltitude, camYaw, camPitch, wallsHeight)
w.runInViewer((wL / 2, wH / 2), wH * 1.05, 0, Math.radians(-89.9), 10)