예제 #1
0
    def __init__(self,
                 host='127.0.0.1',
                 port=2000,
                 city_name='Town03',
                 render_pygame=True,
                 warming_up_steps=50,
                 window_size=5):
        self.client = carla.Client(host, port)
        self.client.set_timeout(2.0)

        self.hud = HUD(1700, 1000)
        self._carla_world = self.client.get_world()

        settings = self._carla_world.get_settings()
        settings.synchronous_mode = True
        settings.fixed_delta_seconds = 0.05
        self._carla_world.apply_settings(settings)

        self.world = World(self._carla_world, self.hud)
        # time.sleep(2)
        self.render_pygame = render_pygame

        self.timestep = 0
        self.warming_up_steps = warming_up_steps
        self.window_size = 5
        self.current_state = defaultdict(
            list
        )  #  {"CAV":[window_size, num_features=9], "LHDV":[window_size, num_features=6]}
예제 #2
0
    def __init__(self, root_dir, source_limit, transform=None):

        self.world = World()

        self.speakers = []
        for d_name in os.listdir(root_dir):
            if os.path.isdir(os.path.join(root_dir, d_name)):
                self.speakers.append(d_name)
        print(self.speakers)

        self.data = []
        self.label = []
        for i, d_name in enumerate(self.speakers):
            data_dir = os.path.join(root_dir, d_name)
            if os.path.isfile(os.path.join(data_dir, d_name + "_mcep.pickle")):
                with open(os.path.join(data_dir, d_name + "_mcep.pickle"),
                          mode="rb") as data:
                    mceps = pickle.load(data)
                    mceps = mceps[:source_limit]
                    self.data.extend(mceps)
                    self.label.extend(np.ones((len(mceps))) * i)
                print("[{}] mcep loaded.".format(d_name))
            else:
                mceps = []
                f0s = []
                for f in tqdm_notebook(os.listdir(data_dir)):
                    if not ".wav" in f:
                        continue
                    file_path = os.path.join(data_dir, f)
                    wav, _ = librosa.load(file_path, sr=hparams.fs)
                    if len(wav) <= 10:
                        continue
                    wav, _ = librosa.effects.trim(wav)
                    wav = wav.astype(np.double)
                    f0, spec, ap = self.world.analyze(wav)
                    mcep = self.world.mcep_from_spec(spec)
                    mcep = mcep.reshape(mcep.shape[0], mcep.shape[1], 1)
                    if mcep.shape[0] < 128:
                        continue
                    mceps.append(mcep)
                    f0s.append(f0)
                # mceps = mceps[:source_limit]
                self.data.extend(mceps)
                self.label.extend(np.ones((len(mceps))) * i)
                with open(os.path.join(data_dir, d_name + "_mcep.pickle"),
                          mode='wb') as f:
                    pickle.dump(mceps, f)
                log_f0s_mean, log_f0s_std = logf0_statistics(f0s)
                mceps_mean, mceps_std = mcep_statistics(mceps)
                np.savez(os.path.join(data_dir, d_name + "_norm.npz"),
                         log_f0s_mean=log_f0s_mean,
                         log_f0s_std=log_f0s_std,
                         mceps_mean=mceps_mean,
                         mceps_std=mceps_std)
                print("[{}] voices converted.".format(d_name))

        self.transform = transform
        self.converter = Converter(root_dir, self.speakers)
예제 #3
0
def node(turtle_name, indx, step, no_turtles, world):
    x = 0.0
    y_start = indx * (world.window_height / no_turtles)
    y_end = (indx + 1) * (world.window_height / no_turtles)
    turtle = world.spawn(turtle_name, x, y_start)

    draw(turtle, y_start, y_end, world, step)

    world.kill(turtle_name)


if __name__ == '__main__':
    rospy.init_node('draw')
    task = rospy.get_param('~task', default='none')
    world = World()
    step = rospy.get_param('~step_size', default=0.5)
    no_turtles = int(math.ceil(world.window_height / (step)))
    nodes = []
    for i in range(no_turtles):
        nodes.append(
            Process(target=node,
                    args=('t' + str(i), i, step, no_turtles, world)))

    for node in nodes:
        node.start()

    for node in nodes:
        node.join()

    turtle1 = Turtle('turtle1')
예제 #4
0
from agents import *
from models import *
from utils.World import *
import sys
import pickle
"""
This script is to visualize evaluation result.

usage:
python view_result.py path_to_record_file
"""
# instantiate the class
f = open(sys.argv[1], 'rb')
record = pickle.load(f)
dT = record.dT
exec('robot = ' + record.model + '(' + record.algorithm + '(), dT)')
human = HumanBall3D(MobileAgent(), dT)

w = World(dT, human, robot, record)
base.run()
예제 #5
0
import sys

from utils import World, ElfLossException

if __name__ == "__main__":

    for power in range(4, 20):
        w = World(sys.argv[1], elves_power=power)
        try:
            n = w.play(verbose=False, elves_loss=True)
        except ElfLossException:
            print(f"Elf lost with power {power}")
        else:
            tot_hit_pts = sum([obj.hit_points for obj in w.goblins_and_elves])
            print(
                f"Battle with power {power} ended in round {n} with a total of "
                f"{tot_hit_pts}, solution is {tot_hit_pts*n}")
            break
예제 #6
0
pub = rospy.Publisher('scan', LaserScan, queue_size=10)

name = rospy.get_param('~turtle_name', default='turtle1')
map_tc = rospy.get_param('~map_topic', default='/map')
range_max = rospy.get_param('~range_max', default=3.0)
range_min = rospy.get_param('~range_min', default=0.0)
angle_min = rospy.get_param('~angle_min', default=-1.5)
angle_max = rospy.get_param('~angle_max', default=1.5)
frame_id = rospy.get_param('~frame_id', default='base_link')
linear_increment = rospy.get_param('~linear_increment', default=0.1)
angle_increment = rospy.get_param('~angle_increment', default=0.01)
freq = rospy.get_param('~rate', default=100)
rate = rospy.Rate(freq)

world = World(map_topic=map_tc)
turtle1 = Turtle(name)

msg = LaserScan()
msg.angle_min = angle_min
msg.angle_max = angle_max
msg.angle_increment = angle_increment
msg.range_max = range_max
msg.range_min = range_min
msg.time_increment = 0.001
msg.range_min = range_min
msg.header.frame_id = frame_id
start = time()
while not rospy.is_shutdown():
    scan_time = time() - start
    start = time()
예제 #7
0
import sys

from utils import World

if __name__ == "__main__":
    w = World(sys.argv[1])
    w.print()
    n = w.play(verbose=False)
    tot_hit_pts = sum([obj.hit_points for obj in w.goblins_and_elves])
    print(
        f"Battle ended in round {n} with a total of {tot_hit_pts}, solution is {tot_hit_pts*n}"
    )
    w.print()
예제 #8
0
from agents import *
from models import *
from utils.World import *

# end class world

# instantiate the class
dT = 0.05
# robot = RobotArm(SublevelSafeSet(), dT);
# robot = Unicycle(SafeSet(), dT);
robot = Ball(SafeSet(), dT)
# human = InteractiveHumanBall2D(SafeSet(d_min=1, k_v=2), dT);
human = HumanBall2D(MobileAgent, dT)
w = World(dT, human, robot)
base.run()