コード例 #1
0
ファイル: puppy_online_robot.py プロジェクト: eSMCs/HDPy
    # HDPy.puppy.PuppyHDP
    tumbled_reward  = 0.0,
    # HDPy.ADHDP
    reservoir       = reservoir,
    readout         = readout,
    # HDPy.ActorCritic
    plant           = plant,
    policy          = collector,
    gamma           = 0.5,
    alpha           = 1.0,
    init_steps      = 10,
    norm            = nrm
)

# robot
r = PuPy.robotBuilder(
    Robot,
    actor,
    sampling_period_ms  = 20,
    ctrl_period_ms      = 3000,
#    event_handlers      = actor.event_handler
)

## SIMULATION LOOP ##

# run the simulation
r.run()

# teardown
readout.save('/tmp/puppy_readout.pic')
コード例 #2
0
ファイル: collector.py プロジェクト: henrique/PuPy
# gait params
gait_params = {
    "frequency": (1.0, 1.0, 1.0, 1.0),
    "offset": (-0.23, -0.23, -0.37, -0.37),
    "amplitude": (0.56, 0.56, 0.65, 0.65),
    "phase": (0.0, 0.0, 0.5, 0.5),
}

# gaits
gait = PuPy.Gait(gait_params)

# Multidimensional collector
class MyCollector(PuPy.RobotCollector):
    def __call__(self, epoch, time_start_ms, time_end_ms, step_size):
        if len(epoch) > 0:
            epoch["random"] = np.random.normal(size=(100, 10))
        return super(MyCollector, self).__call__(epoch, time_start_ms, time_end_ms, step_size)


# actor
actor = PuPy.ConstantGaitControl(gait)
observer = MyCollector(actor, expfile="/tmp/puppy_sim.hdf5")


# robot
r = PuPy.robotBuilder(Robot, observer, sampling_period_ms=20, noise_ctrl=None, noise_obs=None)

# run
r.run()
コード例 #3
0
from controller import Supervisor
import PuPy

# checks
checks = []
checks.append(PuPy.RevertOutOfArena(arena_size=(-10, 10, -10, 10), distance=0, grace_time_ms=(3 * 3000)))
# respawn the robot at a random location in a bounded area
checks.append(PuPy.RevertTumbled(grace_time_ms=(3 * 3000)))

# set up supervisor
s = PuPy.supervisorBuilder(Supervisor, 20, checks)

# run
s.run()
コード例 #4
0
    while grp_name not in f and idx >= 0:
        idx -= 1
        grp_name = "traj_%03i" % (idx)

    if idx < 0:
        raise Exception("Could not find last trajectory")

    trajectory = f[grp_name][:]
    do_quit = True

f.close()

# Initialize the collector
collector = PuPy.RobotCollector(child=policy, expfile="/tmp/example_data.hdf5")

# Initialize the actor
actor = TrajectoryFollower(trajectory=trajectory, policy=collector, init_steps=10)

# Initialize the robot, bind it to webots
r = PuPy.robotBuilder(Robot, actor, sampling_period_ms=20, ctrl_period_ms=3000)

# Register robot in actor for signalling
actor.robot = r

if do_quit:
    # Quit the simulation when all trajectories are handled
    r.send_msg("quit_on_demand")

# Run the simulation
r.run()
コード例 #5
0
ファイル: commSupervisor.py プロジェクト: eSMCs/PuPy
from controller import Supervisor
import PuPy

# emitter checks
class EmitterCheck(PuPy.SupervisorCheck):
    def __call__(self, supervisor):
        supervisor.emitter.send('Emitting ' + str(supervisor.num_iter))

checks = []
checks.append(EmitterCheck())

# set up supervisor
PuPy.supervisorBuilder(Supervisor, 100, checks).run()
コード例 #6
0
from controller import Supervisor
import PuPy

# checks
checks = [PuPy.QuitOnDemand(), PuPy.RevertOnDemand()]

# set up supervisor
s = PuPy.supervisorBuilder(Supervisor, 20, [PuPy.ReceiverCheck(checks)])

# run
s.run()
コード例 #7
0
tumble_collector = PuPy.TumbleCollector(
    child              = data_collector,
    sampling_period_ms = sampling_period_ms,
    ctrl_period_ms     = ctrl_period_ms
)
collector = PuPy.ResetCollector(
    child              = tumble_collector,
    sampling_period_ms = sampling_period_ms,
    ctrl_period_ms     = ctrl_period_ms
)


# actor instantiation
actor = OfflinePuppy(
#    policy      = collector,
    policy      = data_collector,
    init_steps  = 10,
)

# robot instantiation
r = PuPy.robotBuilder(
    Robot,
    actor,
    sampling_period_ms  = sampling_period_ms,
    ctrl_period_ms      = ctrl_period_ms,
#    event_handlers      = [actor.event_handler, tumble_collector.event_handler, collector.event_handler]
)

# invoke the main loop, starts the simulation
r.run()
コード例 #8
0
ファイル: commRobot.py プロジェクト: eSMCs/PuPy
import os.path
import numpy as np

# gait params
gait_params = {
    'frequency' : (1.0, 1.0, 1.0, 1.0),
    'offset'    : ( -0.23, -0.23, -0.37, -0.37),
    'amplitude' : ( 0.56, 0.56, 0.65, 0.65),
    'phase'     : (0.0, 0.0, 0.5, 0.5)
}

# gaits
gait = PuPy.Gait(gait_params)

# receiver callback
def recv1(robot, epoch, current_time, msg):
    print "recv1", msg

def recv2(robot, epoch, current_time, msg):
    print "recv2", msg

# actor
actor = PuPy.ConstantGaitControl(gait)


# robot
r = PuPy.robotBuilder(Robot, actor, event_period_ms=50, event_handlers=[recv1, recv2])
r.run()