Exemple #1
0
    def test_random(self):
        cfg = VowelModel.defcfg._copy()
        vm = VowelModel(cfg)

        for _ in range(1000):
            m_signal = tools.random_signal(vm.m_channels)
            feedback = vm.execute(m_signal)
            self.assertEqual(set(feedback['s_signal'].keys()), set(c.name for c in vm.s_channels))
Exemple #2
0
    def test_random(self):
        cfg = VowelModel.defcfg._copy()
        vm = VowelModel(cfg)

        for _ in range(1000):
            m_signal = tools.random_signal(vm.m_channels)
            feedback = vm.execute(m_signal)
            self.assertEqual(set(feedback['s_signal'].keys()),
                             set(c.name for c in vm.s_channels))
Exemple #3
0
    def test_random(self):
        cfg = KinematicArm2D.defcfg._copy()
        cfg.dim = 5
        cfg.lengths = 10.0
        cfg.limits  = (-150, 150)
        vm = KinematicArm2D(cfg)

        for _ in range(1000):
            m_signal = tools.random_signal(vm.m_channels)
            feedback = vm.execute(m_signal)
            self.assertEqual(set(feedback['s_signal'].keys()), set(c.name for c in vm.s_channels))
Exemple #4
0
    def test_random(self):
        cfg = KinematicArm2D.defcfg._copy()
        cfg.dim = 5
        cfg.lengths = 10.0
        cfg.limits = (-150, 150)
        vm = KinematicArm2D(cfg)

        for _ in range(1000):
            m_signal = tools.random_signal(vm.m_channels)
            feedback = vm.execute(m_signal)
            self.assertEqual(set(feedback['s_signal'].keys()),
                             set(c.name for c in vm.s_channels))
Exemple #5
0
    def test_first(self):
        cfg = FirstSquare2D.defcfg._copy()
        cfg.x_coo = (0.5, 1.0)
        cfg.y_coo = (0.5, 1.0)

        sq = FirstSquare2D(cfg)

        for _ in range(1000):
            m_signal = tools.random_signal(sq.m_channels)
            m_signal['a'] = random.uniform(0.0, 0.5)
            m_signal['b'] = random.uniform(0.0, 0.5)
            feedback = sq.execute(m_signal)
            s_signal = feedback['s_signal']
            self.assertEqual(s_signal['x'], 0.0)
            self.assertEqual(s_signal['y'], 0.0)

        for _ in range(1000):
            m_signal = tools.random_signal(sq.m_channels)
            m_signal['a'] = random.uniform(0.5, 1.0)
            m_signal['b'] = random.uniform(0.5, 1.0)
            feedback = sq.execute(m_signal)
            s_signal = feedback['s_signal']
            self.assertTrue(s_signal['x'] != 0.0)
            self.assertTrue(s_signal['y'] != 0.0)
Exemple #6
0
    def test_first(self):
        cfg = FirstSquare2D.defcfg._copy()
        cfg.x_coo = (0.5, 1.0)
        cfg.y_coo = (0.5, 1.0)

        sq = FirstSquare2D(cfg)

        for _ in range(1000):
            m_signal = tools.random_signal(sq.m_channels)
            m_signal['a'] = random.uniform(0.0, 0.5)
            m_signal['b'] = random.uniform(0.0, 0.5)
            feedback = sq.execute(m_signal)
            s_signal = feedback['s_signal']
            self.assertEqual(s_signal['x'], 0.0)
            self.assertEqual(s_signal['y'], 0.0)

        for _ in range(1000):
            m_signal = tools.random_signal(sq.m_channels)
            m_signal['a'] = random.uniform(0.5, 1.0)
            m_signal['b'] = random.uniform(0.5, 1.0)
            feedback = sq.execute(m_signal)
            s_signal = feedback['s_signal']
            self.assertTrue(s_signal['x'] != 0.0)
            self.assertTrue(s_signal['y'] != 0.0)
Exemple #7
0
    def test_kin(self):
        cfg0.execute.kin.force = 50.0
        cfg0.execute.simu.ppf = 1
        kinenv = KinEnvironment(cfg0)
        cols = []
        n = 1000

        for i in range(n):
            m_signal = tools.random_signal(kinenv.m_channels)
            feedback = kinenv.execute(m_signal)
            collided = feedback['s_signal']['push_saliency'] != 0.0
            if collided:
                cols.append((m_signal, feedback))

        print('{:.2f}% collisions'.format(100 * 1.0 * len(cols) / n))

        vrepb = sim_env.SimulationEnvironment(cfg0)
        for m_signal, feedback in cols:
            print(vrepb.execute(m_signal))
Exemple #8
0
    def test_kin(self):
        cfg0.execute.kin.force = 50.0
        cfg0.execute.simu.ppf  = 1
        kinenv = KinEnvironment(cfg0)
        cols = []
        n = 1000

        for i in range(n):
            m_signal = tools.random_signal(kinenv.m_channels)
            feedback = kinenv.execute(m_signal)
            collided = feedback['s_signal']['push_saliency'] != 0.0
            if collided:
                cols.append((m_signal, feedback))

        print('{:.2f}% collisions'.format(100*1.0*len(cols)/n))

        vrepb = sim_env.SimulationEnvironment(cfg0)
        for m_signal, feedback in cols:
            print(vrepb.execute(m_signal))
Exemple #9
0
def memory_usage():
    import resource
    rusage_denom = 1024.
    if sys.platform == 'darwin':
        # ... it seems that in OSX the output is different units ...
        rusage_denom = rusage_denom * rusage_denom
    mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom
    return mem


for i in range(n):

    print('{}: {:.2f} MiB'.format(i, memory_usage()))
    # if i == n-1:
    #     import pdb
    #     pdb.set_trace()
    done = False
    while not done:
        try:
            m_signal = tools.random_signal(he.m_channels)
            #print(', '.join('{:.2f}'.format(m_i) for m_i in tools.to_vector(m_signal, he.m_channels)))
            feedback = he.execute(m_signal)
            done = True
        except he.OrderNotExecutableError:
            pass

he.close()
dur = time.time() - start_time

print("{} movements, {:.1f}s ({:.1f}s per movements)".format(n, dur, dur / n))
Exemple #10
0
def memory_usage():
    import resource
    rusage_denom = 1024.
    if sys.platform == 'darwin':
        # ... it seems that in OSX the output is different units ...
        rusage_denom = rusage_denom * rusage_denom
    mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / rusage_denom
    return mem

for i in range(n):

    print('{}: {:.2f} MiB'.format(i, memory_usage()))
    # if i == n-1:
    #     import pdb
    #     pdb.set_trace()
    done = False
    while not done:
        try:
            m_signal = tools.random_signal(he.m_channels)
            #print(', '.join('{:.2f}'.format(m_i) for m_i in tools.to_vector(m_signal, he.m_channels)))
            feedback = he.execute(m_signal)
            done = True
        except he.OrderNotExecutableError:
            pass

he.close()
dur = time.time() - start_time

print("{} movements, {:.1f}s ({:.1f}s per movements)".format(n, dur, dur/n))
Exemple #11
0
from __future__ import print_function

import random

from environments import tools

import dotdot
from dovecot import KinDisplay

from cfg import cfg0


random.seed(0)

env = KinDisplay(cfg0)

m_signal = tools.random_signal(env.m_channels)
m_signal = {'slope0.1': 181.14479646325424, 'slope0.0': -68.46193962353374, 'offset4.0': -320.1722208063401, 'offset4.1': 157.3431183449925, 'offset5.1': 329.83394057807436, 'offset5.0': 234.61018700774264, 'slope4.1': -316.03494800617983, 'slope4.0': 119.88979086700294, 'width0': 0.07844771156742526, 'width1': 0.05483708100616313, 'offset3.1': 32.3450392227864, 'slope2.1': -277.54651569030165, 'slope2.0': -179.01303137182535, 'slope3.0': 84.94097475144986, 'slope3.1': -23.464723964847963, 'offset2.0': -251.01864318151596, 'offset2.1': -299.71125525742906, 'offset1.1': -273.0973722433321, 'offset1.0': -386.56948959861586, 'slope1.0': 10.713937120223363, 'slope1.1': -193.80197954927985, 'offset0.0': -183.06945065478376, 'offset0.1': -33.88587230578412, 'offset3.0': -308.3726865498285, 'slope5.0': 102.92252280430756, 'slope5.1': 152.0191201895134}
feedback = env.execute(m_signal, meta={})


env.close()
Exemple #12
0
hard_col = []
start = time.time()


# import pickle
# with open('hard_col.m_signals', 'r') as f:
#     m_signals = pickle.load(f)
# for i, m_signal in enumerate(m_signals):

for i in range(total):
    start_order = time.time()

    # if i == 100 or i == total-1:
    #     import pdb; pdb.set_trace()
    m_signal = tools.random_signal(vrepb.m_channels)
    meta = {}
    feedback = vrepb.execute(m_signal, meta=meta)
    if 'raw_sensors' in meta['log']:
        max_force = -1.0
        salient_contacts = meta['log']['raw_sensors']['salient_contacts']
        if salient_contacts['max'] is not None:
            max_force = salient_contacts['max'].force_norm
        #max_force = max([-1.0] + [c.force_norm for c in meta['log']['raw_sensors']['contacts']])
        print('max_force_sq: {} N'.format(max_force))
        if max_force > 10000.0:
            hard_col.append(m_signal)
            print(tools.to_vector(m_signal, vrepb.m_channels))
            print('{}{}{}'.format(gfx.green, tools.to_vector(feedback['s_signal'], vrepb.s_channels), gfx.end))
    s_vector = tools.to_vector(feedback['s_signal'], vrepb.s_channels)
    if s_vector[2] != 0.0:
Exemple #13
0
cfg = KinScene2D.defcfg._deepcopy()

cfg.dim = 7
cfg.arm_origin = (300.0, 300.0, 0.0)
cfg.limits = (-150.0, 150.0)
cfg.lengths = 200.0/cfg.dim
cfg.headless = False

cfg.m_prims.init_pos = [0.0]*7
cfg.m_prims.angular_step = 0.01

cfg.tip.mass   = 1.0
cfg.tip.radius = 3.0

cfg.objects.ball = KinScene2D.objcfg._deepcopy()
cfg.objects.ball.radius = 5.0
cfg.objects.ball.mass   = 1.0
cfg.objects.ball.pos    = (495.0, 315.0)
cfg.objects.ball.track  = True



ks = KinScene2D(cfg)

for t in range(1):
    m_signal = tools.random_signal(ks.m_channels)
    print(m_signal)
    m_signal = {'j{}'.format(i): 20 for i in range(cfg.dim)}
    s_signal = ks.execute(m_signal)

Exemple #14
0
cfg.tip.radius = 3.0

cfg.objects.ball = KinScene2D.objcfg._deepcopy()
cfg.objects.ball.radius = 5.0
cfg.objects.ball.mass = 20.0
cfg.objects.ball.pos = (480.0, 300.0)
cfg.objects.ball.track = True

bpos = cfg.objects.ball.pos
size = 200
cfg.s_prims.x_limits = (int(bpos[0] - size), int(bpos[0] + size))
cfg.s_prims.y_limits = (int(bpos[1] - size), int(bpos[1] + size))

ks = environments.Environment.create(cfg)
print(ks.s_channels)

random.seed(0)
collisions = 0
n = 25
for t in range(n):
    m_signal = tools.random_signal(ks.m_channels)
    feedback = ks.execute(m_signal)
    if feedback['s_signal'] != {
            'y': cfg.objects.ball.pos[1],
            'x': cfg.objects.ball.pos[0]
    }:
        collisions += 1
    print(feedback['s_signal'])

print('{}/{} ({:.2f}%)'.format(collisions, n, 100.0 * collisions / n))