Beispiel #1
0
    def _proto_test(self, filename):

        revolve_bot = RevolveBot()
        revolve_bot.load_file(path=filename, conf_type='yaml')
        revolve_bot.save_file(path='/tmp/revolve_bot.yaml', conf_type='yaml')

        revolve_bot2 = RevolveBot()
        revolve_bot2.load_file(path='/tmp/revolve_bot.yaml', conf_type='yaml')

        self.revolve_bot_equal(revolve_bot, revolve_bot2)
Beispiel #2
0
async def run():

    settings = parser.parse_args()
    yaml_file = 'experiments/'+ settings.experiment_name sla+'/data_fullevolution/phenotypes/'+'phenotype_'+settings.test_robot+'.yaml'

    r = RevolveBot(_id=settings.test_robot)
    r.load_file(yaml_file, conf_type='yaml')
    #r.save_file('experiments/'+ settings +'/data_fullevolution/phenotype_35.sdf.xml', conf_type='sdf')
    #r.render_body('experiments/'+ settings +'/data_fullevolution/phenotypes/phenotype_35.body.png')

    connection = await World.create(settings, world_address=("127.0.0.1", settings.port_start))
    await connection.insert_robot(r)
Beispiel #3
0
 def __init__(self, pheno_filename):
     self.robot = RevolveBot()
     self.robot.load_file(os.path.join(phenotype_folder,
                                       pheno_filename))
     assert (f'{self.robot.id}.yaml' == pheno_filename)
     with open(os.path.join(folder_name,
                            f'life_{pheno_filename}')) as life_file:
         self.life = yaml.safe_load(life_file)
         birth = self.life['starting_time']
         age = self.life['age']
         self.life['death'] = None if age == 0 else birth + age
         del self.life['avg_orientation']
         del self.life['avg_pos']
         del self.life['charge']
         self.life['birth_reason'] = 'MATE'
Beispiel #4
0
    def test_load_save_yaml(self):
        """
        We load a YAML file and save it
        """

        revolve_bot = RevolveBot()
        revolve_bot.load_file(
            path='/Users/nihed/Desktop/nihedssnakes/nihedssnake6.yaml',
            conf_type='yaml')
        revolve_bot.save_file(path='/revolve_bot.yaml', conf_type='yaml')

        revolve_bot2 = RevolveBot()
        revolve_bot2.load_file(path='/revolve_bot.yaml', conf_type='yaml')

        self.assertEqual(revolve_bot, revolve_bot2)
Beispiel #5
0
    def late_development(self):

        self.phenotype = RevolveBot()
        self.phenotype._id = self.id if type(
            self.id) == str and self.id.startswith(
                "robot") else "robot_{}".format(self.id)
        self.phenotype._brain = BrainNN()

        for symbol in self.intermediate_phenotype:

            if symbol[self.index_symbol] == Alphabet.CORE_COMPONENT:
                module = CoreModule()
                self.phenotype._body = module
                module.id = str(self.quantity_modules)
                module.info = {
                    'orientation': Orientation.NORTH,
                    'new_module_type': Alphabet.CORE_COMPONENT
                }
                module.orientation = 0
                module.rgb = [1, 1, 0]
                self.mounting_reference = module

            if [symbol[self.index_symbol],
                []] in Alphabet.morphology_mounting_commands():
                self.morph_mounting_container = symbol[self.index_symbol]

            if [symbol[self.index_symbol], []] in Alphabet.modules() \
                    and symbol[self.index_symbol] is not Alphabet.CORE_COMPONENT \
                    and self.morph_mounting_container is not None:

                if type(self.mounting_reference) == CoreModule \
                        or type(self.mounting_reference) == BrickModule:
                    slot = self.get_slot(self.morph_mounting_container).value
                if type(self.mounting_reference) == ActiveHingeModule:
                    slot = Orientation.NORTH.value

                if self.quantity_modules < self.conf.max_structural_modules:
                    self.new_module(slot, symbol[self.index_symbol], symbol)

            if [symbol[self.index_symbol],
                []] in Alphabet.morphology_moving_commands():
                self.move_in_body(symbol)

            if [symbol[self.index_symbol],
                []] in Alphabet.controller_changing_commands():
                self.decode_brain_changing(symbol)

            if [symbol[self.index_symbol],
                []] in Alphabet.controller_moving_commands():
                self.decode_brain_moving(symbol)

        self.add_imu_nodes()
        logger.info('Robot ' + str(self.id) + ' was late-developed.')

        return self.phenotype
Beispiel #6
0
async def run():
    """
    The main coroutine, which is started below
    """
    log = logger.create_logger('experiment',
                               handlers=[
                                   logging.StreamHandler(sys.stdout),
                               ])

    # Set debug level to DEBUG
    log.setLevel(logging.DEBUG)

    # Parse command line / file input arguments
    settings = parser.parse_args()

    # Start Simulator
    if settings.simulator_cmd != 'debug':
        simulator_supervisor = DynamicSimSupervisor(
            world_file=settings.world,
            simulator_cmd=settings.simulator_cmd,
            simulator_args=["--verbose"],
            plugins_dir_path=os.path.join('.', 'build', 'lib'),
            models_dir_path=os.path.join('.', 'models'),
            simulator_name='gazebo')
        await simulator_supervisor.launch_simulator(port=settings.port_start)
        await asyncio.sleep(0.1)

    # Connect to the simulator and pause
    connection = await World.create(settings,
                                    world_address=('127.0.0.1',
                                                   settings.port_start))
    await asyncio.sleep(1)

    # initialization finished

    # load robot file
    robot = RevolveBot(_id=settings.test_robot)
    robot.load_file("/Users/nihed/Desktop/nihedssnakes/nihedssnake6.yaml",
                    conf_type='yaml')
    robot.save_file(
        f'{"/Users/nihed/Desktop/nihedssnakes/nihedssnake6.yaml"}.sdf',
        conf_type='sdf')

    # insert robot into the simulator
    robot_manager = await connection.insert_robot(robot,
                                                  Vector3(0, 0, 0.25),
                                                  life_timeout=None)
    await asyncio.sleep(1.0)

    # Start the main life loop
    while True:
        # Print robot fitness every second
        status = 'dead' if robot_manager.dead else 'alive'
        print(
            f"Robot fitness ({status}) is \n"
            f" OLD:     {fitness.online_old_revolve(robot_manager)}\n"
            f" DISPLAC: {fitness.displacement(robot_manager, robot)}\n"
            f" DIS_VEL: {fitness.displacement_velocity(robot_manager, robot)}")
        await asyncio.sleep(1.0)
async def test_collision_robot(robot_file_path: str):
    log = logger.create_logger('experiment', handlers=[
        logging.StreamHandler(sys.stdout),
    ])

    # Set debug level to DEBUG
    log.setLevel(logging.DEBUG)

    # Parse command line / file input arguments
    settings = parser.parse_args()

    assert (settings.test_robot_collision is not None)
    robot = RevolveBot(_id=settings.test_robot_collision)
    robot.load_file(robot_file_path, conf_type='yaml')
    robot.save_file(f'{robot_file_path}.sdf', conf_type='sdf')

    def simulator_died_callback(_process, _ret_code):
        pass

    # Start Simulator
    if settings.simulator_cmd != 'debug':
        simulator_supervisor = CollisionSimSupervisor(
            world_file=os.path.join('tools', 'analyzer', 'analyzer-world.world'),
            simulator_cmd=settings.simulator_cmd,
            simulator_args=["--verbose"],
            plugins_dir_path=os.path.join('.', 'build', 'lib'),
            models_dir_path=os.path.join('.', 'models'),
            simulator_name='gazebo',
            process_terminated_callback=simulator_died_callback,
        )
        await simulator_supervisor.launch_simulator(port=settings.port_start)
        await asyncio.sleep(0.1)

    log.debug("simulator ready")

    # Connect to the simulator and pause
    analyzer = await BodyAnalyzer.create('127.0.0.1', settings.port_start)
    log.debug("connection ready")
    await asyncio.sleep(1)

    log.info("Sending robot to the analyzer simulator")
    start = time.time()
    result = await analyzer.analyze_robot(robot)
    end = time.time()

    log.debug(f'Analyzer finished in {end-start}')
    log.debug('result:')
    log.debug(result)

    await analyzer.disconnect()
    log.debug("disconnected")

    if settings.simulator_cmd != 'debug':
        await simulator_supervisor.stop()

    log.debug("simulator killed")
Beispiel #8
0
    def _proto_test(self, filename):

        revolve_bot = RevolveBot()
        revolve_bot.load_file(
            path=filename,
            conf_type='yaml'
        )
        revolve_bot.save_file(
            path='/tmp/revolve_bot.yaml',
            conf_type='yaml'
        )

        revolve_bot2 = RevolveBot()
        revolve_bot2.load_file(
            path='/tmp/revolve_bot.yaml',
            conf_type='yaml'
        )

        self.revolve_bot_equal(revolve_bot, revolve_bot2)
Beispiel #9
0
def read_robot(file: str):
    bot = RevolveBot()
    bot.load_file(file)
    return bot